sys_menu.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. package controllers
  2. import (
  3. "eta/eta_api/models"
  4. "eta/eta_api/models/system"
  5. "eta/eta_api/utils"
  6. "strconv"
  7. "strings"
  8. )
  9. type SysMenuController struct {
  10. BaseAuthController
  11. }
  12. // @Title 获取用户权限菜单
  13. // @Description 获取用户权限菜单接口
  14. // @Success 200 {object} system.MenuListResp
  15. // @router /menu/list [get]
  16. func (this *SysRoleController) SysMenuList() {
  17. br := new(models.BaseResponse).Init()
  18. defer func() {
  19. this.Data["json"] = br
  20. this.ServeJSON()
  21. }()
  22. sysUser := this.SysUser
  23. if sysUser == nil {
  24. br.Msg = "请登录"
  25. br.ErrMsg = "请登录,SysUser Is Empty"
  26. return
  27. }
  28. roleId := sysUser.RoleId
  29. //roleId=1
  30. if roleId <= 0 {
  31. br.Msg = "参数错误"
  32. return
  33. }
  34. roleIds := strconv.Itoa(roleId)
  35. //查询账号绑定的其他角色
  36. otherRoles, err := system.GetRoleIdsByAdminId(sysUser.AdminId)
  37. if err != nil {
  38. br.Msg = "获取其他角色失败"
  39. br.ErrMsg = "获取其他角色失败,Err:" + err.Error()
  40. return
  41. }
  42. if len(otherRoles) > 0 {
  43. for _, v := range otherRoles {
  44. roleIds += "," + strconv.Itoa(v.RoleId)
  45. }
  46. }
  47. groupId := 0
  48. if utils.RunMode == "release" {
  49. groupId = 37
  50. } else {
  51. groupId = 61
  52. }
  53. //共享客户组下的用户
  54. shareSellerMap := make(map[int]bool, 0)
  55. subAdmins, err := system.GetAdminByGroupId(groupId)
  56. if err != nil && err.Error() != utils.ErrNoRow() {
  57. br.Msg = "获取销售失败"
  58. br.ErrMsg = "获取销售失败,Err:" + err.Error()
  59. return
  60. }
  61. for _, admin := range subAdmins {
  62. shareSellerMap[admin.AdminId] = true
  63. }
  64. list, err := system.GetMenuListByRoleIds(roleIds)
  65. if err != nil {
  66. br.Msg = "获取失败"
  67. br.ErrMsg = "获取失败,Err:" + err.Error()
  68. return
  69. }
  70. lenList := len(list)
  71. for i := 0; i < lenList; i++ {
  72. item := list[i]
  73. child, err := system.GetMenuByParentIdRoleIds(roleIds, item.MenuId)
  74. if err != nil {
  75. br.Msg = "获取失败"
  76. br.ErrMsg = "获取子菜单数据失败,Err:" + err.Error()
  77. return
  78. }
  79. lenChild := len(child)
  80. for ci := 0; ci < lenChild; ci++ {
  81. if child[ci].Name == "领取列表" {
  82. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER {
  83. child[ci].Name = "权益客户"
  84. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  85. child[ci].Name = "ficc客户"
  86. }
  87. }
  88. }
  89. for i, menu := range child {
  90. if menu.Name == "正式客户共享" && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN &&
  91. sysUser.AdminId != 66 && sysUser.AdminId != 15 {
  92. //如果不是admin角色、共享客户分组下用户、楼颖丹账号、王沛账号 就不显示该页面
  93. if ok, _ := shareSellerMap[sysUser.AdminId]; !ok {
  94. child = append(child[:i], child[i+1:]...)
  95. }
  96. }
  97. }
  98. if strings.Contains(item.Name, "出差管理") && sysUser.AdminId == 66 {
  99. cm := new(system.ChildMenu)
  100. cm.MenuId = 10000
  101. cm.Name = "出差审批"
  102. cm.Path = "businessTripApproval"
  103. cm.Component = "businessTripApproval"
  104. cm.IconPath = ""
  105. cm.Hidden = false
  106. child = append(child, cm)
  107. }
  108. //if lenChild > 1 {
  109. // list[i].IsLevel = 2
  110. //} else {
  111. // list[i].IsLevel = 1
  112. // list[i].LevelPath = ""
  113. //}
  114. list[i].Children = child
  115. }
  116. resp := new(system.MenuListResp)
  117. resp.List = list
  118. br.Ret = 200
  119. br.Success = true
  120. br.Msg = "获取成功"
  121. br.Data = resp
  122. }