activity_signup_detail.go 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. package services
  2. import (
  3. "context"
  4. "errors"
  5. "fmt"
  6. "hongze/hongze_cygx/models"
  7. "hongze/hongze_cygx/utils"
  8. )
  9. // AddctivitySignupDetail 获取当天已结束的活动的报名信息。添加到到会详情
  10. func AddctivitySignupDetail(cont context.Context) (err error) {
  11. defer func() {
  12. if err != nil {
  13. fmt.Println(err)
  14. go utils.SendAlarmMsg(" 获取当天已结束的活动的报名信息。添加到到会详情失败, ErrMsg:"+err.Error(), 2)
  15. }
  16. }()
  17. actList, err := models.GetActivitySattusToComplete()
  18. if err != nil && err.Error() != utils.ErrNoRow() {
  19. return err
  20. }
  21. if len(actList) == 0 {
  22. return err
  23. }
  24. activityIds := make([]int, 0)
  25. for _, v := range actList {
  26. activityIds = append(activityIds, v.ActivityId)
  27. }
  28. actLen := len(activityIds)
  29. var condition string
  30. var pars []interface{}
  31. if actLen > 0 {
  32. condition += ` AND activity_id IN (` + utils.GetOrmInReplace(actLen) + `)`
  33. pars = append(pars, activityIds)
  34. } else {
  35. return err
  36. }
  37. //condition = ""
  38. //获取当天已经结束了 活动的报名人数
  39. signUpList, err := models.GetSignupDetailBySignup(condition, pars)
  40. if err != nil && err.Error() != utils.ErrNoRow() {
  41. return err
  42. }
  43. signUpDetailList, err := models.GetSignupDetailList(condition, pars)
  44. if err != nil && err.Error() != utils.ErrNoRow() {
  45. return err
  46. }
  47. mapsignUpDetai := make(map[string]string)
  48. if len(signUpDetailList) > 0 {
  49. for _, v := range signUpDetailList {
  50. mapsignUpDetai[fmt.Sprint("ActivityId", v.ActivityId, "Mobile", v.Mobile)] = v.Mobile
  51. }
  52. }
  53. var items []*models.CygxActivitySignupDetail
  54. if len(signUpList) > 0 {
  55. for _, v := range signUpList {
  56. if _, ok := mapsignUpDetai[fmt.Sprint("ActivityId", v.ActivityId, "Mobile", v.Mobile)]; !ok {
  57. item := new(models.CygxActivitySignupDetail)
  58. item.UserId = v.UserId
  59. item.RealName = v.RealName
  60. item.SellerName = v.SellerName
  61. item.ActivityId = v.ActivityId
  62. item.CreateTime = v.CreateTime
  63. item.Mobile = v.Mobile
  64. item.OutboundMobile = v.OutboundMobile
  65. item.Email = v.Email
  66. item.CompanyId = v.CompanyId
  67. item.CompanyName = v.CompanyName
  68. item.SignupType = v.SignupType
  69. item.FailType = v.FailType
  70. item.DoFailType = v.DoFailType
  71. items = append(items, item)
  72. if len(items)%2000 == 0 {
  73. err = models.AddCygxActivitySignupDetail(items)
  74. if err != nil {
  75. return
  76. }
  77. items = make([]*models.CygxActivitySignupDetail, 0)
  78. }
  79. }
  80. }
  81. }
  82. if len(items) > 0 {
  83. err = models.AddCygxActivitySignupDetail(items)
  84. if err != nil {
  85. return
  86. }
  87. }
  88. return err
  89. }
  90. // AddctivitySignupDetailByJmcjNew 通过进门财经添加用户参数信息
  91. func AddctivitySignupDetailByJmcjNew(itemsDetail []*models.CygxActivityAttendanceDetail, activityIds []int) (err error) {
  92. defer func() {
  93. if err != nil {
  94. fmt.Println(err)
  95. go utils.SendAlarmMsg("通过进门财经添加用户参数信息失败 ErrMsg:"+err.Error(), 2)
  96. }
  97. }()
  98. actLen := len(activityIds)
  99. var condition string
  100. var pars []interface{}
  101. if actLen > 0 {
  102. condition += ` AND activity_id IN (` + utils.GetOrmInReplace(actLen) + `)`
  103. pars = append(pars, activityIds)
  104. }
  105. signUpDetailList, err := models.GetSignupDetailList(condition, pars)
  106. if err != nil && err.Error() != utils.ErrNoRow() {
  107. return err
  108. }
  109. mapsignUpDetai := make(map[string]string)
  110. if len(signUpDetailList) > 0 {
  111. for _, v := range signUpDetailList {
  112. mapsignUpDetai[fmt.Sprint("ActivityId", v.ActivityId, "Mobile", v.Mobile)] = v.Mobile
  113. }
  114. }
  115. //获取当天已经结束了 活动的报名人数
  116. signUpList, err := models.GetSignupDetailBySignup(condition, pars)
  117. if err != nil && err.Error() != utils.ErrNoRow() {
  118. return err
  119. }
  120. //建立外呼号与手机号的绑定
  121. mapsignUp := make(map[string]string)
  122. if len(signUpList) > 0 {
  123. for _, v := range signUpList {
  124. mapsignUp[fmt.Sprint(v.OutboundMobile)] = v.Mobile
  125. }
  126. }
  127. var itemsAdd []*models.CygxActivitySignupDetail
  128. var itemsUpdate []*models.CygxActivitySignupDetail
  129. var mobiles []string
  130. mobileMap := make(map[string]bool)
  131. mobileUserMap := make(map[string]int)
  132. for _, v := range itemsDetail {
  133. if !mobileMap[v.Mobile] {
  134. mobiles = append(mobiles, v.Mobile)
  135. }
  136. mobileMap[v.Mobile] = true
  137. }
  138. //mobiles = make([]string, 0)
  139. //mobiles = append(mobiles, "13054631616")
  140. //根据手机号获取这些用户的信息
  141. listUser, e := models.GetWxUserByOutboundMobiles(mobiles)
  142. if e != nil {
  143. err = errors.New("GetWxUserOutboundMobiles, Err: " + e.Error())
  144. return
  145. }
  146. for _, v := range listUser {
  147. mobileUserMap[v.Mobile] = v.UserId
  148. }
  149. for _, v := range itemsDetail {
  150. var item = new(models.CygxActivitySignupDetail)
  151. item.ActivityId = v.ActivityId
  152. item.RealName = v.RealName
  153. //如果手机号存在那么就是报名的,不存在就是直接参与的
  154. if _, ok := mapsignUp[v.Mobile]; ok {
  155. item.Mobile = mapsignUp[v.Mobile]
  156. } else {
  157. item.Mobile = v.Mobile
  158. }
  159. item.OutboundMobile = v.Mobile
  160. item.CompanyName = v.CompanyName
  161. item.CompanyId = v.CompanyId
  162. item.SellerName = v.SellerName
  163. item.FirstMeetingTime = v.FirstMeetingTime
  164. item.LastMeetingTime = v.LastMeetingTime
  165. item.Duration = v.Duration
  166. item.MeetingTypeStr = v.MeetingTypeStr
  167. item.MeetingAuthentication = v.MeetingAuthentication
  168. item.MeetingStatusStr = v.MeetingStatusStr
  169. item.CreateTime = v.CreateTime
  170. item.Position = v.Position
  171. item.IsMeeting = 1
  172. item.UseridEntity = v.UseridEntity
  173. item.ActivityTime = v.ActivityTime
  174. item.CrmCompanyMapStatusId = v.CrmCompanyMapStatusId
  175. item.UserId = mobileUserMap[v.Mobile]
  176. if _, ok := mapsignUpDetai[fmt.Sprint("ActivityId", v.ActivityId, "Mobile", item.Mobile)]; !ok {
  177. itemsAdd = append(itemsAdd, item)
  178. } else {
  179. itemsUpdate = append(itemsUpdate, item)
  180. }
  181. }
  182. if len(itemsAdd) > 0 {
  183. err = models.AddCygxActivitySignupDetail(itemsAdd)
  184. if err != nil {
  185. return
  186. }
  187. }
  188. if len(itemsUpdate) > 0 {
  189. err = models.UpdateActivitySignupDetailMulti(itemsUpdate)
  190. if err != nil {
  191. return
  192. }
  193. }
  194. //获取所有研选扣点的活动,如果是就行扣点流水处理
  195. mapActivityPoints, _ := GetActivityPointsAll()
  196. for _, v := range activityIds {
  197. if mapActivityPoints[v] {
  198. YanXuanActivityPointsBillSubmitMeeting(v, 0)
  199. }
  200. }
  201. return err
  202. }
  203. //func init() {
  204. // var err error
  205. // defer func() {
  206. // if err != nil {
  207. // fmt.Println(err)
  208. // }
  209. // }()
  210. // var condition string
  211. // var pars []interface{}
  212. // condition = " AND user_id = 0 AND company_id > 1 AND mobile != '' "
  213. // signUpDetailList, e := models.GetSignupDetailList(condition, pars)
  214. // if e != nil && e.Error() != utils.ErrNoRow() {
  215. // err = errors.New("GetSignupDetailList, Err: " + e.Error())
  216. // return
  217. // }
  218. // var mobiles []string
  219. // mobileMap := make(map[string]bool)
  220. // for _, v := range signUpDetailList {
  221. // if !mobileMap[v.Mobile] {
  222. // mobiles = append(mobiles, v.Mobile)
  223. // }
  224. // mobileMap[v.Mobile] = true
  225. // }
  226. // //mobiles = make([]string, 0)
  227. // //mobiles = append(mobiles, "13054631616")
  228. // //根据手机号获取这些用户的信息
  229. // listUser, e := models.GetWxUserByOutboundMobiles(mobiles)
  230. // if e != nil {
  231. // err = errors.New("GetWxUserOutboundMobiles, Err: " + e.Error())
  232. // return
  233. // }
  234. //
  235. // var itemsUpdate []*models.CygxActivitySignupDetail
  236. // for _, v := range listUser {
  237. // item := new(models.CygxActivitySignupDetail)
  238. // item.UserId = v.UserId
  239. // item.Mobile = v.Mobile
  240. // itemsUpdate = append(itemsUpdate, item)
  241. // }
  242. // fmt.Println(len(itemsUpdate))
  243. // err = models.UpdateActivitySignupDetailMultiMobileAndUserId(itemsUpdate)
  244. //}