auth.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /**********************************************
  2. ** @Des: 权限因子
  3. ** @Author: haodaquan
  4. ** @Date: 2017-09-09 16:14:31
  5. ** @Last Modified by: haodaquan
  6. ** @Last Modified time: 2017-09-17 11:23:40
  7. ***********************************************/
  8. package backgroundc
  9. import (
  10. "fmt"
  11. "strings"
  12. "time"
  13. "wuyebaoxiuapi/utils"
  14. "strconv"
  15. "wuyebaoxiuapi/models/backgroundm"
  16. "github.com/patrickmn/go-cache"
  17. )
  18. type AuthController struct {
  19. BaseController
  20. }
  21. func (self *AuthController) Index() {
  22. self.Data["pageTitle"] = "权限因子"
  23. self.display()
  24. }
  25. func (self *AuthController) List() {
  26. self.Data["zTree"] = true //引入ztreecss
  27. self.Data["pageTitle"] = "权限因子"
  28. self.display()
  29. }
  30. //获取全部节点
  31. func (self *AuthController) GetNodes() {
  32. filters := make([]interface{}, 0)
  33. filters = append(filters, "status", 1)
  34. result, count := backgroundm.AuthGetList(1, 1000, filters...)
  35. list := make([]map[string]interface{}, len(result))
  36. for k, v := range result {
  37. row := make(map[string]interface{})
  38. row["id"] = v.Id
  39. row["pId"] = v.Pid
  40. row["name"] = v.AuthName
  41. row["open"] = true
  42. list[k] = row
  43. }
  44. self.ajaxList("成功", MSG_OK, count, list)
  45. }
  46. //获取一个节点
  47. func (self *AuthController) GetNode() {
  48. id, _ := self.GetInt("id")
  49. result, _ := backgroundm.AuthGetById(id)
  50. // if err == nil {
  51. // self.ajaxMsg(err.Error(), MSG_ERR)
  52. // }
  53. row := make(map[string]interface{})
  54. row["id"] = result.Id
  55. row["pid"] = result.Pid
  56. row["auth_name"] = result.AuthName
  57. row["auth_url"] = result.AuthUrl
  58. row["sort"] = result.Sort
  59. row["is_show"] = result.IsShow
  60. row["icon"] = result.Icon
  61. fmt.Println(row)
  62. self.ajaxList("成功", MSG_OK, 0, row)
  63. }
  64. //新增或修改
  65. func (self *AuthController) AjaxSave() {
  66. auth := new(backgroundm.Auth)
  67. auth.UserId = self.userId
  68. auth.Pid, _ = self.GetInt("pid")
  69. auth.AuthName = strings.TrimSpace(self.GetString("auth_name"))
  70. auth.AuthUrl = strings.TrimSpace(self.GetString("auth_url"))
  71. auth.Sort, _ = self.GetInt("sort")
  72. auth.IsShow, _ = self.GetInt("is_show")
  73. auth.Icon = strings.TrimSpace(self.GetString("icon"))
  74. auth.UpdateTime = time.Now().Unix()
  75. auth.Status = 1
  76. id, _ := self.GetInt("id")
  77. if id == 0 {
  78. //新增
  79. auth.CreateTime = time.Now().Unix()
  80. auth.CreateId = self.userId
  81. auth.UpdateId = self.userId
  82. if _, err := backgroundm.AuthAdd(auth); err != nil {
  83. self.ajaxMsg(err.Error(), MSG_ERR)
  84. }
  85. } else {
  86. auth.Id = id
  87. auth.UpdateId = self.userId
  88. if err := auth.Update(); err != nil {
  89. self.ajaxMsg(err.Error(), MSG_ERR)
  90. }
  91. }
  92. utils.Che.Set("menu"+strconv.Itoa(self.user.Id), nil, cache.DefaultExpiration)
  93. self.ajaxMsg("", MSG_OK)
  94. }
  95. //删除
  96. func (self *AuthController) AjaxDel() {
  97. id, _ := self.GetInt("id")
  98. auth, _ := backgroundm.AuthGetById(id)
  99. auth.Id = id
  100. auth.Status = 0
  101. if err := auth.Update(); err != nil {
  102. self.ajaxMsg(err.Error(), MSG_ERR)
  103. }
  104. utils.Che.Set("menu"+strconv.Itoa(self.user.Id), nil, cache.DefaultExpiration)
  105. self.ajaxMsg("", MSG_OK)
  106. }