sys_menu.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. // 审批配置
  65. confMap, e := models.GetBusinessConf()
  66. if e != nil {
  67. br.Msg = "获取失败"
  68. br.ErrMsg = "获取商家配置失败, Err: " + e.Error()
  69. return
  70. }
  71. openMap := map[string]bool{"false": false, "true": true}
  72. openApprove := openMap[confMap[models.BusinessConfIsReportApprove]]
  73. list, err := system.GetMenuListByRoleIds(roleIds)
  74. if err != nil {
  75. br.Msg = "获取失败"
  76. br.ErrMsg = "获取失败,Err:" + err.Error()
  77. return
  78. }
  79. lenList := len(list)
  80. menuList := make([]*system.MenuList, 0)
  81. for i := 0; i < lenList; i++ {
  82. item := list[i]
  83. // 审批关闭时隐藏审批菜单(这需求大可不必=_=!)
  84. if !openApprove && item.Name == "审批管理" {
  85. continue
  86. }
  87. child, err := system.GetMenuByParentIdRoleIds(roleIds, item.MenuId)
  88. if err != nil {
  89. br.Msg = "获取失败"
  90. br.ErrMsg = "获取子菜单数据失败,Err:" + err.Error()
  91. return
  92. }
  93. lenChild := len(child)
  94. for ci := 0; ci < lenChild; ci++ {
  95. if child[ci].Name == "领取列表" {
  96. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER {
  97. child[ci].Name = "权益客户"
  98. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  99. child[ci].Name = "ficc客户"
  100. }
  101. }
  102. }
  103. for mi, menu := range child {
  104. if menu.Name == "正式客户共享" && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN &&
  105. sysUser.AdminId != 66 && sysUser.AdminId != 15 {
  106. //如果不是admin角色、共享客户分组下用户、楼颖丹账号、王沛账号 就不显示该页面
  107. if ok, _ := shareSellerMap[sysUser.AdminId]; !ok {
  108. child = append(child[:mi], child[mi+1:]...)
  109. }
  110. }
  111. // 审批关闭时隐藏系统管理下的审批流配置
  112. if menu.Name == "审批流配置" && !openApprove {
  113. child = append(child[:mi], child[mi+1:]...)
  114. }
  115. }
  116. if strings.Contains(item.Name, "出差管理") && sysUser.AdminId == 66 {
  117. cm := new(system.ChildMenu)
  118. cm.MenuId = 10000
  119. cm.Name = "出差审批"
  120. cm.NameEn = "Business Trip Approval"
  121. cm.Path = "businessTripApproval"
  122. cm.Component = "businessTripApproval"
  123. cm.IconPath = ""
  124. cm.Hidden = false
  125. child = append(child, cm)
  126. }
  127. //if lenChild > 1 {
  128. // list[i].IsLevel = 2
  129. //} else {
  130. // list[i].IsLevel = 1
  131. // list[i].LevelPath = ""
  132. //}
  133. list[i].Children = child
  134. menuList = append(menuList, list[i])
  135. }
  136. resp := new(system.MenuListResp)
  137. resp.List = menuList
  138. br.Ret = 200
  139. br.Success = true
  140. br.Msg = "获取成功"
  141. br.Data = resp
  142. }