auth_rule.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package auth_service
  2. import (
  3. "gfast/app/model/auth_rule"
  4. "github.com/gogf/gf/frame/g"
  5. "github.com/gogf/gf/os/gtime"
  6. "github.com/gogf/gf/util/gconv"
  7. )
  8. //菜单对象
  9. type MenuReq struct {
  10. IsMenu int `p:"ismenu" c:"ismenu" v:"min:0|max:1#菜单类型最小值为:min|菜单类型最大值为:max"`
  11. Pid int `p:"pid" c:"pid" v:"min:0"`
  12. Name string `p:"name" c:"name" v:"required#请填写规则名称"`
  13. Title string `p:"title" c:"title" v:"required|length:1,100#请填写标题|标题长度在:min到:max位"`
  14. Icon string `p:"icon" c:"icon"`
  15. Weigh int `p:"weigh" c:"weigh"`
  16. Condition string `p:"condition" c:"condition"`
  17. Remark string `p:"remark" c:"remark"`
  18. Status int `p:"status" c:"status"`
  19. }
  20. //获取菜单列表
  21. func GetMenuList(where string, params ...interface{}) (error, g.List) {
  22. var err error
  23. var list []*auth_rule.Entity
  24. if where != "" {
  25. list, err = auth_rule.Model.Where(where, params...).Order("weigh desc,id asc").FindAll()
  26. } else {
  27. list, err = auth_rule.Model.Order("weigh desc,id asc").FindAll()
  28. }
  29. if err != nil {
  30. g.Log().Error(err)
  31. return err, nil
  32. }
  33. var gList = make(g.List, len(list))
  34. for k, v := range list {
  35. tMap := gconv.Map(v)
  36. gList[k] = tMap
  37. }
  38. return nil, gList
  39. }
  40. // 添加菜单操作
  41. func AddMenu(req *MenuReq) (err error, insertId int64) {
  42. menuMap := gconv.Map(req)
  43. now := gtime.Timestamp()
  44. menuMap["createtime"] = now
  45. menuMap["updatetime"] = now
  46. res, e := auth_rule.Model.Insert(menuMap)
  47. err = e
  48. insertId, _ = res.LastInsertId()
  49. return
  50. }
  51. //修改菜单操作
  52. func EditMenu(req *MenuReq, id int) (err error, rows int64) {
  53. menuMap := gconv.Map(req)
  54. now := gtime.Timestamp()
  55. menuMap["updatetime"] = now
  56. res, e := auth_rule.Model.Where("id=?", id).Update(menuMap)
  57. err = e
  58. rows, _ = res.RowsAffected()
  59. return
  60. }