admin.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_clpt/models"
  6. "hongze/hongze_clpt/models/company"
  7. "hongze/hongze_clpt/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. //func init() {
  95. // fmt.Println(GetAdminActivityPermission(542))
  96. //}
  97. // GetAdminActivityPermission 获取本组组员ID
  98. func GetAdminActivityPermission(adminId int) (adminIdArr []int) {
  99. var err error
  100. defer func() {
  101. if err != nil {
  102. go utils.SendAlarmMsg("GetAdminActivityPermission失败 ErrMsg:"+err.Error(), 2)
  103. }
  104. }()
  105. adminUser, e := models.GetSellerByAdminId(adminId)
  106. if e != nil {
  107. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  108. return
  109. }
  110. adminList, err := models.GetAdminListByGroupId(adminUser.GroupId)
  111. if err != nil {
  112. return
  113. }
  114. adminIdArr = make([]int, 0)
  115. for _, v := range adminList {
  116. adminIdArr = append(adminIdArr, v.AdminId)
  117. }
  118. return
  119. }
  120. // 获取本组的销售ID
  121. func GetSelleridWhichGroup(companyId, productId int, mobile string) (adminIds string) {
  122. var err error
  123. defer func() {
  124. if err != nil {
  125. fmt.Println(err)
  126. go utils.SendAlarmMsg("获取本组的销售ID GetSelleridWhichGroup失败 ErrMsg:"+err.Error(), 2)
  127. }
  128. }()
  129. adminIds, e := models.GetSelleridWhichGroup(companyId, productId)
  130. if e != nil {
  131. err = errors.New("GetSelleridWhichGroup, Err: " + e.Error())
  132. return
  133. }
  134. if mobile != "" && adminIds != "" {
  135. adminUser, e := models.GetSellerByAdminMobile(mobile)
  136. if e != nil && e.Error() != utils.ErrNoRow() {
  137. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  138. return
  139. }
  140. if adminUser != nil {
  141. adminList, e := models.GetAdminListByGroupId(adminUser.GroupId)
  142. if e != nil && e.Error() != utils.ErrNoRow() {
  143. err = errors.New("models GetAdminListByGroupId, Err: " + e.Error())
  144. return
  145. }
  146. if len(adminList) > 0 {
  147. var adminIdArr []string
  148. for _, v := range adminList {
  149. adminIdArr = append(adminIdArr, strconv.Itoa(v.AdminId))
  150. }
  151. adminIds += "," + strings.Join(adminIdArr, ",")
  152. }
  153. }
  154. }
  155. return
  156. }
  157. // 根据公司ID获取权益销售、共享销售手机号
  158. func GetCompanySellerAndShareMobileByRai(companyId int) (mobiles []string, err error) {
  159. productDetail, e := company.GetCompanyProductDetailByCompanyId(companyId, 2)
  160. if e != nil {
  161. err = errors.New("GetCompanyProductDetailByCompanyId, Err: " + e.Error())
  162. return
  163. }
  164. var adminIds []int
  165. adminIds = append(adminIds, productDetail.SellerId)
  166. if productDetail.ShareSellerId > 0 {
  167. adminIds = append(adminIds, productDetail.ShareSellerId)
  168. }
  169. listAdmin, e := models.GetAdminByAdminIds(adminIds)
  170. if e != nil {
  171. err = errors.New("GetAdminByAdminIds, Err: " + e.Error())
  172. return
  173. }
  174. mobiles = make([]string, 0)
  175. for _, v := range listAdmin {
  176. if v.Mobile != "" {
  177. mobiles = append(mobiles, v.Mobile)
  178. }
  179. }
  180. return
  181. }