admin.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_cygx/models"
  6. "hongze/hongze_cygx/models/company"
  7. "hongze/hongze_cygx/utils"
  8. "strconv"
  9. "strings"
  10. )
  11. func GetAdminMobileMap() (mapItem map[string]string, err error) {
  12. adminList, e := models.GetRaiAdmin()
  13. if e != nil {
  14. err = e
  15. return
  16. }
  17. mapMobile := make(map[string]string)
  18. for _, v := range adminList {
  19. mapMobile[v.Mobile] = v.Mobile
  20. }
  21. mapItem = mapMobile
  22. return
  23. }
  24. func GetActivityCcustomerTypeList() (mapItem map[int]string, err error) {
  25. list, e := models.GetActivityCcustomerTypeList()
  26. if e != nil {
  27. err = e
  28. return
  29. }
  30. mapUserType := make(map[int]string)
  31. for _, v := range list {
  32. mapUserType[v.CustomerTypeId] = v.PermissionValue
  33. }
  34. mapUserType[0] = "0"
  35. mapItem = mapUserType
  36. return
  37. }
  38. // GetRaiAdminMobileMap 获取权益内部人员手机号
  39. func GetRaiAdminMobileMap() (mapItem map[string]string) {
  40. var err error
  41. defer func() {
  42. if err != nil {
  43. go utils.SendAlarmMsg("获取权益内部人员手机号失败 ErrMsg:"+err.Error(), 2)
  44. }
  45. }()
  46. adminList, e := models.GetRaiAdmin()
  47. if e != nil {
  48. err = e
  49. return
  50. }
  51. mapMobile := make(map[string]string)
  52. for _, v := range adminList {
  53. mapMobile[v.Mobile] = v.Mobile
  54. }
  55. mapItem = mapMobile
  56. return
  57. }
  58. // GetRaiAdminMobileItMap 获取it内部人员手机号
  59. func GetRaiAdminMobileItMap() (mapItem map[string]string) {
  60. var err error
  61. defer func() {
  62. if err != nil {
  63. go utils.SendAlarmMsg("获取权益内部人员手机号失败 ErrMsg:"+err.Error(), 2)
  64. }
  65. }()
  66. adminList, e := models.GetRaiAdminIt()
  67. if e != nil {
  68. err = e
  69. return
  70. }
  71. mapMobile := make(map[string]string)
  72. for _, v := range adminList {
  73. mapMobile[v.Mobile] = v.Mobile
  74. }
  75. mapItem = mapMobile
  76. return
  77. }
  78. // 根据手机号判断是否属于权益
  79. func GetBelongingRai(mobile string) (isBelong bool) {
  80. mapItem := GetRaiAdminMobileMap()
  81. if mapItem[mobile] != "" {
  82. isBelong = true
  83. }
  84. return
  85. }
  86. // 根据手机号判断是否属于IT人员
  87. func GetBelongingRaiIt(mobile string) (isBelong bool) {
  88. mapItem := GetRaiAdminMobileItMap()
  89. if mapItem[mobile] != "" {
  90. isBelong = true
  91. }
  92. return
  93. }
  94. // GetAdminCheckUserMobileMap 获取对应销售所能查看的用户手机号
  95. func GetAdminCheckUserMobileMap(user *models.WxUserItem) (mapItem map[string]string, err error) {
  96. admin, e := models.GetSysAdminByMobile(user.Mobile)
  97. if e != nil {
  98. err = e
  99. return
  100. }
  101. userList, e := models.GetSellerUserMobile(admin.AdminId)
  102. if e != nil {
  103. err = e
  104. return
  105. }
  106. mapMobile := make(map[string]string)
  107. for _, v := range userList {
  108. mapMobile[v.Mobile] = v.Mobile
  109. }
  110. mapItem = mapMobile
  111. return
  112. }
  113. // 获取本组的销售ID
  114. func GetSelleridWhichGroup(companyId, productId int, mobile string) (adminIds string) {
  115. var err error
  116. defer func() {
  117. if err != nil {
  118. fmt.Println(err)
  119. go utils.SendAlarmMsg("获取本组的销售ID GetSelleridWhichGroup失败 ErrMsg:"+err.Error(), 2)
  120. }
  121. }()
  122. adminIds, e := models.GetSelleridWhichGroup(companyId, productId)
  123. if e != nil {
  124. err = errors.New("GetSelleridWhichGroup, Err: " + e.Error())
  125. return
  126. }
  127. if mobile != "" && adminIds != "" {
  128. adminUser, e := models.GetSellerByAdminMobile(mobile)
  129. if e != nil && e.Error() != utils.ErrNoRow() {
  130. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  131. return
  132. }
  133. if adminUser != nil {
  134. adminList, e := models.GetAdminListByGroupId(adminUser.GroupId)
  135. if e != nil && e.Error() != utils.ErrNoRow() {
  136. err = errors.New("models GetAdminListByGroupId, Err: " + e.Error())
  137. return
  138. }
  139. if len(adminList) > 0 {
  140. var adminIdArr []string
  141. for _, v := range adminList {
  142. adminIdArr = append(adminIdArr, strconv.Itoa(v.AdminId))
  143. }
  144. adminIds += "," + strings.Join(adminIdArr, ",")
  145. }
  146. }
  147. }
  148. return
  149. }
  150. // 根据公司ID获取权益销售、共享销售手机号
  151. func GetCompanySellerAndShareMobileByRai(companyId int) (mobiles []string, err error) {
  152. productDetail, e := company.GetCompanyProductDetailByCompanyId(companyId, 2)
  153. if e != nil {
  154. err = errors.New("GetCompanyProductDetailByCompanyId, Err: " + e.Error())
  155. return
  156. }
  157. var adminIds []int
  158. adminIds = append(adminIds, productDetail.SellerId)
  159. if productDetail.ShareSellerId > 0 {
  160. adminIds = append(adminIds, productDetail.ShareSellerId)
  161. }
  162. listAdmin, e := models.GetAdminByAdminIds(adminIds)
  163. if e != nil {
  164. err = errors.New("GetAdminByAdminIds, Err: " + e.Error())
  165. return
  166. }
  167. mobiles = make([]string, 0)
  168. for _, v := range listAdmin {
  169. if v.Mobile != "" {
  170. mobiles = append(mobiles, v.Mobile)
  171. }
  172. }
  173. return
  174. }