company_seller.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package controllers
  2. import (
  3. "fmt"
  4. "hongze/hongze_mobile_admin/models/tables/system"
  5. "hongze/hongze_mobile_admin/services"
  6. "hongze/hongze_mobile_admin/utils"
  7. )
  8. // CompanySellerController 销售管理
  9. type CompanySellerController struct {
  10. BaseAuth
  11. }
  12. // RoadshowFiccList
  13. // @Title 路演FICC销售列表
  14. // @Description 路演FICC销售列表
  15. // @Success 200 {object} system.RoadshowGroupResp
  16. // @router /seller/roadshow_ficc/list [get]
  17. func (c *CompanySellerController) RoadshowFiccList() {
  18. sysUser := c.AdminWx
  19. resp := new(system.RoadshowGroupResp)
  20. productId := services.GetProductId(sysUser.RoleTypeCode)
  21. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  22. c.OkDetailed(resp, "获取成功")
  23. return
  24. }
  25. // 分组
  26. departmentId := 2
  27. groups, e := system.GetGroupByDepartmentId(departmentId)
  28. if e != nil {
  29. c.FailWithMessage("获取失败", "获取FICC分组失败, Err: "+e.Error())
  30. return
  31. }
  32. teamGroupId := make(map[int]int, 0) // 小组ID对应的大组ID
  33. var list []system.RoadshowGroups
  34. for _, g := range groups {
  35. if g.ParentId > 0 {
  36. teamGroupId[g.GroupId] = g.ParentId
  37. continue
  38. }
  39. // 大组
  40. list = append(list, system.RoadshowGroups{
  41. GroupId: g.GroupId,
  42. GroupName: g.GroupName,
  43. })
  44. }
  45. // 销售
  46. roleArr := []string{
  47. utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_FICC_DEPARTMENT, utils.ROLE_TYPE_CODE_FICC_GROUP,
  48. utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_FICC_SELLER,
  49. }
  50. cond := fmt.Sprintf(` AND role_type_code IN (%s)`, utils.GetOrmInReplace(len(roleArr)))
  51. pars := make([]interface{}, 0)
  52. pars = append(pars, roleArr)
  53. sellers, e := system.GetSysUserItemsOrderByCreated(cond, pars)
  54. if e != nil {
  55. c.FailWithMessage("获取失败", "获取FICC销售失败, Err: "+e.Error())
  56. return
  57. }
  58. groupIdChild := make(map[int][]system.RoadshowGroupSellers) // 大组ID对应的销售
  59. for _, s := range sellers {
  60. var seller system.RoadshowGroupSellers
  61. seller.AdminId = s.AdminId
  62. seller.AdminName = s.RealName
  63. gid := teamGroupId[s.GroupId]
  64. if gid > 0 {
  65. // 小组
  66. seller.GroupId = gid
  67. seller.TeamId = s.GroupId
  68. } else {
  69. // 大组
  70. seller.GroupId = s.GroupId
  71. }
  72. groupIdChild[seller.GroupId] = append(groupIdChild[seller.GroupId], seller)
  73. }
  74. // 根据当前角色过滤可选项
  75. for _, v := range list {
  76. // 如果是销售、组长、主管, 那么过滤掉自己大组外的其他组
  77. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER {
  78. if sysUser.GroupId != v.GroupId && teamGroupId[sysUser.GroupId] != v.GroupId {
  79. continue
  80. }
  81. }
  82. child := groupIdChild[v.GroupId]
  83. // 如果是小组长, 那么只能看到自己小组的信息
  84. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM {
  85. var team []system.RoadshowGroupSellers
  86. for _, c := range child {
  87. if c.TeamId == sysUser.GroupId {
  88. team = append(team, c)
  89. }
  90. }
  91. v.Child = team
  92. resp.List = append(resp.List, v)
  93. continue
  94. }
  95. // 如果是普通销售, 那么只能看到分组中的自己
  96. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER {
  97. var self []system.RoadshowGroupSellers
  98. for _, c := range child {
  99. if c.AdminId == sysUser.AdminId {
  100. self = append(self, c)
  101. break
  102. }
  103. }
  104. v.Child = self
  105. resp.List = append(resp.List, v)
  106. continue
  107. }
  108. // 非以上两种情况, 可见该大组所有销售
  109. v.Child = child
  110. resp.List = append(resp.List, v)
  111. }
  112. c.OkDetailed(resp, "获取成功")
  113. }