admin_power.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. package cygx
  2. import (
  3. "errors"
  4. "hongze/hz_crm_api/models/company"
  5. "hongze/hz_crm_api/models/cygx"
  6. "hongze/hz_crm_api/models/system"
  7. "hongze/hz_crm_api/utils"
  8. "strconv"
  9. "strings"
  10. )
  11. // 获取这个销售所能查看的手机号权限
  12. func GetAdminLookUserMobile(adminInfo *system.Admin) (mapMobile map[string]string, err error) {
  13. //sellerIds, e := company.GetCompanyProductSellerIdByShareSellerId(adminInfo.AdminId)
  14. //if e != nil && e.Error() != utils.ErrNoRow() {
  15. // err = errors.New("GetCompanyProductSellerIdByShareSellerId 根据共享销售id查被共享的公司销售id, Err: " + e.Error())
  16. // return
  17. //}
  18. var companyIds []string
  19. var adminIds []string
  20. //如果是组长获取所属组员的ID
  21. if adminInfo.RoleTypeCode == "rai_group" {
  22. adminList, e := system.GetAdminListByGroupId(adminInfo.GroupId)
  23. if e != nil && e.Error() != utils.ErrNoRow() {
  24. err = errors.New("GetAdminListByGroupId, Err: " + e.Error())
  25. return
  26. }
  27. for _, v := range adminList {
  28. adminIds = append(adminIds, strconv.Itoa(v.AdminId))
  29. }
  30. } else {
  31. adminIds = append(adminIds, strconv.Itoa(adminInfo.AdminId))
  32. }
  33. //再获取组员下被共享的公司
  34. var pars []interface{}
  35. var condition string
  36. condition = " AND share_seller_id IN (" + strings.Join(adminIds, ",") + ") "
  37. listCompanyProduct, e := company.GetCompanyProductList(condition, pars)
  38. if e != nil {
  39. err = errors.New("GetCompanyProductList, Err: " + e.Error())
  40. return
  41. }
  42. for _, v := range listCompanyProduct {
  43. companyIds = append(companyIds, strconv.Itoa(v.CompanyId))
  44. }
  45. companyIds = append(companyIds, "0")
  46. var conditionMobile string
  47. //if adminInfo.RoleTypeCode == "rai_group" {
  48. //
  49. // //组长查看本组所有组员
  50. // conditionMobile = ` SELECT mobile FROM user_seller_relation WHERE seller_id IN (SELECT admin_id FROM admin WHERE group_id = (SELECT group_id FROM admin WHERE admin_id = ` + strconv.Itoa(adminInfo.AdminId) + ` )) `
  51. //} else {
  52. // //组员查看自己
  53. // if sellerIds != "" {
  54. // conditionMobile = ` SELECT mobile FROM user_seller_relation WHERE seller_id IN ( ` + strconv.Itoa(adminInfo.AdminId) + `,` + sellerIds + ` ) `
  55. // } else {
  56. // conditionMobile = ` SELECT mobile FROM user_seller_relation WHERE seller_id IN ( ` + strconv.Itoa(adminInfo.AdminId) + ` ) `
  57. // }
  58. //}
  59. conditionMobile = ` SELECT mobile FROM user_seller_relation WHERE 1=1 AND product_id = 2 AND (seller_id IN ( ` + strings.Join(adminIds, ",") + ` ) OR company_id IN (` + strings.Join(companyIds, ",") + `)) `
  60. mobileList, e := cygx.GetSellerUserMobile(conditionMobile)
  61. if e != nil {
  62. err = errors.New("GetSellerUserMobile 获取这个销售所能查看的手机号权限失败, Err: " + e.Error())
  63. return
  64. }
  65. mapUserMobile := make(map[string]string)
  66. for _, v := range mobileList {
  67. mapUserMobile[v.Mobile] = v.Mobile
  68. }
  69. mapMobile = mapUserMobile
  70. return
  71. }
  72. // 获取这个销售所能查看的手机号权限
  73. func GetAdminLookUserUserId(adminInfo *system.Admin) (userIds []int, err error) {
  74. var conditionMobile string
  75. if adminInfo.RoleTypeCode == "rai_group" {
  76. //组长查看本组所有组员
  77. conditionMobile = ` SELECT user_id FROM user_seller_relation WHERE seller_id IN (SELECT admin_id FROM admin WHERE group_id = (SELECT group_id FROM admin WHERE admin_id = ` + strconv.Itoa(adminInfo.AdminId) + ` )) `
  78. } else {
  79. //组员查看自己
  80. conditionMobile = ` SELECT user_id FROM user_seller_relation WHERE seller_id = ` + strconv.Itoa(adminInfo.AdminId)
  81. }
  82. conditionMobile += " LIMIT 10"
  83. userList, e := cygx.GetSellerUserMobile(conditionMobile)
  84. if e != nil {
  85. err = errors.New("GetSellerUserMobile 获取这个销售所能查看的手机号权限失败, Err: " + e.Error())
  86. return
  87. }
  88. userIds = make([]int, 0)
  89. for _, v := range userList {
  90. userIds = append(userIds, v.UserId)
  91. }
  92. return
  93. }
  94. //func init() {
  95. // sellerId, e := company.GetCompanyProductSellerIdByShareSellerId(163)
  96. // fmt.Println(e)
  97. // fmt.Println(sellerId)
  98. //}
  99. // 获取这个销售所能查看的手机号权限
  100. func GetAdminLookUserCompanyIds(sysUser *system.Admin) (companyIds []int, err error) {
  101. //如果不是管理员,权益管理员那么就对可见权限范围做处理
  102. adminIds := make([]int, 0)
  103. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_ADMIN {
  104. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  105. //如果是权益的组长就获取下面的组员
  106. adminList, e := system.GetAdminListByGroupId(sysUser.GroupId)
  107. if e != nil {
  108. err = errors.New("GetAdminListByGroupId , Err: " + e.Error())
  109. return
  110. }
  111. for _, v := range adminList {
  112. adminIds = append(adminIds, v.AdminId)
  113. }
  114. } else {
  115. adminIds = append(adminIds, sysUser.AdminId)
  116. }
  117. //adminIds = append(adminIds, sysUser.AdminId)
  118. var adminIdGroup string
  119. for _, v := range adminIds {
  120. adminIdGroup += strconv.Itoa(v) + ","
  121. }
  122. adminIdGroup = strings.TrimRight(adminIdGroup, ",")
  123. companyProductList, e := company.GetCompanyProductsBySellerId(adminIdGroup)
  124. if e != nil {
  125. err = errors.New("GetCompanyProductsBySellerId , Err: " + e.Error())
  126. return
  127. }
  128. for _, v := range companyProductList {
  129. companyIds = append(companyIds, v.CompanyId)
  130. }
  131. }
  132. companyIds = append(companyIds, 0) //添加潜在客户
  133. return
  134. }
  135. // 获取这个销售所能查看的公司权限
  136. func GetAdminLookUserCompanyIdsBySelf(sysUser *system.Admin) (companyIds []int, err error) {
  137. //如果不是管理员,权益管理员那么就对可见权限范围做处理
  138. adminIds := make([]int, 0)
  139. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_ADMIN && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_FINANCE {
  140. //if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  141. // //如果是权益的组长就获取下面的组员
  142. // adminList, e := system.GetAdminListByGroupId(sysUser.GroupId)
  143. // if e != nil {
  144. // err = errors.New("GetAdminListByGroupId , Err: " + e.Error())
  145. // return
  146. // }
  147. // for _, v := range adminList {
  148. // adminIds = append(adminIds, v.AdminId)
  149. // }
  150. //} else {
  151. // adminIds = append(adminIds, sysUser.AdminId)
  152. //}
  153. adminIds = append(adminIds, sysUser.AdminId)
  154. var adminIdGroup string
  155. for _, v := range adminIds {
  156. adminIdGroup += strconv.Itoa(v) + ","
  157. }
  158. adminIdGroup = strings.TrimRight(adminIdGroup, ",")
  159. companyProductList, e := company.GetCompanyProductsBySellerId(adminIdGroup)
  160. if e != nil {
  161. err = errors.New("GetCompanyProductsBySellerId , Err: " + e.Error())
  162. return
  163. }
  164. for _, v := range companyProductList {
  165. companyIds = append(companyIds, v.CompanyId)
  166. }
  167. companyIds = append(companyIds, 0) //添加潜在客户
  168. }
  169. return
  170. }
  171. // 获取这个销售所能查看的公司权限(研究员)
  172. func GetAdminLookUserCompanyIdsByResearcher(sysUser *system.Admin) (companyIds []int, err error) {
  173. //如果不是管理员,权益管理员那么就对可见权限范围做处理
  174. adminIds := make([]int, 0)
  175. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_ADMIN && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_RESEARCHR {
  176. adminIds = append(adminIds, sysUser.AdminId)
  177. var adminIdGroup string
  178. for _, v := range adminIds {
  179. adminIdGroup += strconv.Itoa(v) + ","
  180. }
  181. adminIdGroup = strings.TrimRight(adminIdGroup, ",")
  182. companyProductList, e := company.GetCompanyProductsBySellerId(adminIdGroup)
  183. if e != nil {
  184. err = errors.New("GetCompanyProductsBySellerId , Err: " + e.Error())
  185. return
  186. }
  187. for _, v := range companyProductList {
  188. companyIds = append(companyIds, v.CompanyId)
  189. }
  190. companyIds = append(companyIds, 0) //添加潜在客户
  191. }
  192. return
  193. }