system.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package services
  2. import (
  3. "eta_gn/eta_api/models/company"
  4. "eta_gn/eta_api/models/roadshow"
  5. "eta_gn/eta_api/models/system"
  6. "eta_gn/eta_api/utils"
  7. "fmt"
  8. )
  9. func GetRoleTypeCode(roleType string) string {
  10. var roleTypeCode string
  11. switch roleType {
  12. case utils.ROLE_TYPE_ADMIN:
  13. roleTypeCode = utils.ROLE_TYPE_CODE_ADMIN
  14. case utils.ROLE_TYPE_FICC_ADMIN:
  15. roleTypeCode = utils.ROLE_TYPE_CODE_FICC_ADMIN
  16. case utils.ROLE_TYPE_FICC_SELLER:
  17. roleTypeCode = utils.ROLE_TYPE_CODE_FICC_SELLER
  18. case utils.ROLE_TYPE_RAI_ADMIN:
  19. roleTypeCode = utils.ROLE_TYPE_CODE_RAI_ADMIN
  20. case utils.ROLE_TYPE_FICC_GROUP, utils.ROLE_TYPE_FICC_MANAGER:
  21. roleTypeCode = utils.ROLE_TYPE_CODE_FICC_GROUP
  22. case utils.ROLE_TYPE_RAI_GROUP:
  23. roleTypeCode = utils.ROLE_TYPE_CODE_RAI_GROUP
  24. case utils.ROLE_TYPE_FICC_DEPARTMENT:
  25. roleTypeCode = utils.ROLE_TYPE_CODE_FICC_DEPARTMENT
  26. case utils.ROLE_TYPE_RAI_DEPARTMENT:
  27. roleTypeCode = utils.ROLE_TYPE_CODE_RAI_DEPARTMENT
  28. case utils.ROLE_TYPE_FICC_RESEARCHR:
  29. roleTypeCode = utils.ROLE_TYPE_CODE_FICC_RESEARCHR
  30. case utils.ROLE_TYPE_RAI_RESEARCHR:
  31. roleTypeCode = utils.ROLE_TYPE_CODE_RAI_RESEARCHR
  32. default:
  33. roleTypeCode = utils.ROLE_TYPE_ADMIN
  34. }
  35. return roleTypeCode
  36. }
  37. type AdminGroup struct {
  38. GroupId int `description:"分组id"`
  39. GroupName string `description:"分组名称"`
  40. ResearcherList []*roadshow.Researcher
  41. }
  42. // CheckAdminIsSameBigGroup 判断是否两个系统用户是否同一个大组内
  43. func CheckAdminIsSameBigGroup(adminInfo1, adminInfo2 *system.Admin) (isSame bool, err error) {
  44. // 如果销售和创建人是同一个小组
  45. if adminInfo1.GroupId == adminInfo2.GroupId {
  46. isSame = true
  47. return
  48. }
  49. var admin1BigGroupId, admin2BigGroupId int
  50. //获取第一个系统用户的大组id
  51. {
  52. //获取该账号的大组id
  53. pid, tmpErr := company.GetParentIdFromGroup(adminInfo1.GroupId)
  54. if tmpErr != nil {
  55. err = tmpErr
  56. return
  57. }
  58. if pid != nil && *pid > 0 {
  59. //该账号放在了三级分组下
  60. admin1BigGroupId = *pid
  61. } else {
  62. //该账号放在了二级分组下
  63. admin1BigGroupId = adminInfo1.GroupId
  64. }
  65. }
  66. //获取第二个系统用户的大组id
  67. {
  68. //获取该账号的大组id
  69. pid, tmpErr := company.GetParentIdFromGroup(adminInfo2.GroupId)
  70. if tmpErr != nil {
  71. err = tmpErr
  72. return
  73. }
  74. if pid != nil && *pid > 0 {
  75. //该账号放在了三级分组下
  76. admin2BigGroupId = *pid
  77. } else {
  78. //该账号放在了二级分组下
  79. admin2BigGroupId = adminInfo2.GroupId
  80. }
  81. }
  82. if admin1BigGroupId == admin2BigGroupId {
  83. isSame = true
  84. return
  85. }
  86. return
  87. }
  88. // CheckRaiAdmin 判断是否为权益内部人员
  89. func CheckRaiAdmin(adminId int) (isRai bool, err error) {
  90. raiAdmins, e := system.GetRaiAdmin()
  91. if e != nil {
  92. err = fmt.Errorf("获取权益内部人员失败, GetRaiAdmin Err: %s", e.Error())
  93. return
  94. }
  95. for _, r := range raiAdmins {
  96. if adminId == r.AdminId {
  97. isRai = true
  98. break
  99. }
  100. }
  101. return
  102. }
  103. // GetMenuTreeRecursive 递归菜单树
  104. func GetMenuTreeRecursive(list []*system.SysMenuItem, parentId int) []*system.SysMenuItem {
  105. res := make([]*system.SysMenuItem, 0)
  106. for _, v := range list {
  107. if v.ParentId == parentId {
  108. v.Children = GetMenuTreeRecursive(list, v.MenuId)
  109. res = append(res, v)
  110. }
  111. }
  112. return res
  113. }