sys_menu.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package controllers
  2. import (
  3. "eta_gn/eta_api/models"
  4. "eta_gn/eta_api/models/system"
  5. "strconv"
  6. )
  7. type SysMenuController struct {
  8. BaseAuthController
  9. }
  10. // @Title 获取用户权限菜单
  11. // @Description 获取用户权限菜单接口
  12. // @Success 200 {object} system.MenuListResp
  13. // @router /menu/list [get]
  14. func (this *SysRoleController) SysMenuList() {
  15. br := new(models.BaseResponse).Init()
  16. defer func() {
  17. this.Data["json"] = br
  18. this.ServeJSON()
  19. }()
  20. sysUser := this.SysUser
  21. if sysUser == nil {
  22. br.Msg = "请登录"
  23. br.ErrMsg = "请登录,SysUser Is Empty"
  24. return
  25. }
  26. roleId := sysUser.RoleId
  27. //roleId=1
  28. if roleId <= 0 {
  29. br.Msg = "参数错误"
  30. return
  31. }
  32. roleIds := strconv.Itoa(roleId)
  33. //查询账号绑定的其他角色
  34. otherRoles, err := system.GetRoleIdsByAdminId(sysUser.AdminId)
  35. if err != nil {
  36. br.Msg = "获取其他角色失败"
  37. br.ErrMsg = "获取其他角色失败,Err:" + err.Error()
  38. return
  39. }
  40. if len(otherRoles) > 0 {
  41. for _, v := range otherRoles {
  42. roleIds += "," + strconv.Itoa(v.RoleId)
  43. }
  44. }
  45. // 审批配置
  46. //confMap, e := models.GetBusinessConf()
  47. //if e != nil {
  48. // br.Msg = "获取失败"
  49. // br.ErrMsg = "获取商家配置失败, Err: " + e.Error()
  50. // return
  51. //}
  52. //openMap := map[string]bool{"false": false, "true": true}
  53. //openApprove := openMap[confMap[models.BusinessConfIsReportApprove]]
  54. list, err := system.GetMenuListAllByRoleIds(roleIds)
  55. if err != nil {
  56. br.Msg = "获取失败"
  57. br.ErrMsg = "获取失败,Err:" + err.Error()
  58. return
  59. }
  60. rootList, err := system.GetMenuListByRoleIds(roleIds)
  61. if err != nil {
  62. br.Msg = "获取失败"
  63. br.ErrMsg = "获取失败,Err:" + err.Error()
  64. return
  65. }
  66. menuMap := make(map[int][]*system.MenuList)
  67. for _, v := range list {
  68. if menus, ok := menuMap[v.ParentId]; !ok {
  69. menus = make([]*system.MenuList, 0)
  70. menus = append(menus, v)
  71. menuMap[v.ParentId] = menus
  72. } else {
  73. menus = append(menus, v)
  74. menuMap[v.ParentId] = menus
  75. }
  76. }
  77. //menuList := make([]*system.MenuList, 0)
  78. for _, firstMenus := range rootList {
  79. if secondMenus, ok := menuMap[firstMenus.MenuId]; ok {
  80. for _, sencodMenu := range secondMenus {
  81. if thirdMenus, ok := menuMap[sencodMenu.MenuId]; ok {
  82. sencodMenu.Children = thirdMenus
  83. } else {
  84. thirdMenuList := make([]*system.MenuList, 0)
  85. sencodMenu.Children = thirdMenuList
  86. }
  87. }
  88. firstMenus.Children = secondMenus
  89. }
  90. }
  91. resp := new(system.MenuListResp)
  92. resp.List = rootList
  93. br.Ret = 200
  94. br.Success = true
  95. br.Msg = "获取成功"
  96. br.Data = resp
  97. }