activity_signup_detail.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_mfyx/models"
  6. "hongze/hongze_mfyx/utils"
  7. )
  8. // AddctivitySignupDetailByJmcj 通过进门财经添加用户参数信息
  9. func AddctivitySignupDetailByJmcjNew(itemsDetail []*models.CygxActivityAttendanceDetail, activityIds []int) (err error) {
  10. defer func() {
  11. if err != nil {
  12. fmt.Println(err)
  13. go utils.SendAlarmMsg("通过进门财经添加用户参数信息失败 ErrMsg:"+err.Error(), 2)
  14. }
  15. }()
  16. actLen := len(activityIds)
  17. var condition string
  18. var pars []interface{}
  19. if actLen > 0 {
  20. condition += ` AND activity_id IN (` + utils.GetOrmInReplace(actLen) + `)`
  21. pars = append(pars, activityIds)
  22. }
  23. signUpDetailList, err := models.GetSignupDetailList(condition, pars)
  24. if err != nil && err.Error() != utils.ErrNoRow() {
  25. return err
  26. }
  27. mapsignUpDetai := make(map[string]string)
  28. if len(signUpDetailList) > 0 {
  29. for _, v := range signUpDetailList {
  30. mapsignUpDetai[fmt.Sprint("ActivityId", v.ActivityId, "Mobile", v.Mobile)] = v.Mobile
  31. }
  32. }
  33. //获取当天已经结束了 活动的报名人数
  34. signUpList, err := models.GetSignupDetailBySignup(condition, pars)
  35. if err != nil && err.Error() != utils.ErrNoRow() {
  36. return err
  37. }
  38. //建立外呼号与手机号的绑定
  39. mapsignUp := make(map[string]string)
  40. if len(signUpList) > 0 {
  41. for _, v := range signUpList {
  42. mapsignUp[fmt.Sprint(v.OutboundMobile)] = v.Mobile
  43. }
  44. }
  45. var itemsAdd []*models.CygxActivitySignupDetail
  46. var itemsUpdate []*models.CygxActivitySignupDetail
  47. var mobiles []string
  48. mobileMap := make(map[string]bool)
  49. mobileUserMap := make(map[string]int)
  50. for _, v := range itemsDetail {
  51. if !mobileMap[v.Mobile] {
  52. mobiles = append(mobiles, v.Mobile)
  53. }
  54. mobileMap[v.Mobile] = true
  55. }
  56. //mobiles = make([]string, 0)
  57. //mobiles = append(mobiles, "13054631616")
  58. //根据手机号获取这些用户的信息
  59. listUser, e := models.GetWxUserByOutboundMobiles(mobiles)
  60. if e != nil {
  61. err = errors.New("GetWxUserOutboundMobiles, Err: " + e.Error())
  62. return
  63. }
  64. for _, v := range listUser {
  65. mobileUserMap[v.Mobile] = v.UserId
  66. }
  67. for _, v := range itemsDetail {
  68. var item = new(models.CygxActivitySignupDetail)
  69. item.ActivityId = v.ActivityId
  70. item.RealName = v.RealName
  71. //如果手机号存在那么就是报名的,不存在就是直接参与的
  72. if _, ok := mapsignUp[v.Mobile]; ok {
  73. item.Mobile = mapsignUp[v.Mobile]
  74. } else {
  75. item.Mobile = v.Mobile
  76. }
  77. item.OutboundMobile = v.Mobile
  78. item.CompanyName = v.CompanyName
  79. item.CompanyId = v.CompanyId
  80. item.SellerName = v.SellerName
  81. item.FirstMeetingTime = v.FirstMeetingTime
  82. item.LastMeetingTime = v.LastMeetingTime
  83. item.Duration = v.Duration
  84. item.MeetingTypeStr = v.MeetingTypeStr
  85. item.MeetingAuthentication = v.MeetingAuthentication
  86. item.MeetingStatusStr = v.MeetingStatusStr
  87. item.CreateTime = v.CreateTime
  88. item.Position = v.Position
  89. item.IsMeeting = 1
  90. item.UseridEntity = v.UseridEntity
  91. item.ActivityTime = v.ActivityTime
  92. item.CrmCompanyMapStatusId = v.CrmCompanyMapStatusId
  93. item.UserId = mobileUserMap[v.Mobile]
  94. if _, ok := mapsignUpDetai[fmt.Sprint("ActivityId", v.ActivityId, "Mobile", item.Mobile)]; !ok {
  95. itemsAdd = append(itemsAdd, item)
  96. } else {
  97. itemsUpdate = append(itemsUpdate, item)
  98. }
  99. }
  100. if len(itemsAdd) > 0 {
  101. err = models.AddCygxActivitySignupDetail(itemsAdd)
  102. if err != nil {
  103. return
  104. }
  105. }
  106. if len(itemsUpdate) > 0 {
  107. err = models.UpdateActivitySignupDetailMulti(itemsUpdate)
  108. if err != nil {
  109. return
  110. }
  111. }
  112. //获取所有研选扣点的活动,如果是就行扣点流水处理
  113. mapActivityPoints, _ := GetActivityPointsAll()
  114. for _, v := range activityIds {
  115. if mapActivityPoints[v] {
  116. YanXuanActivityPointsBillSubmitMeeting(v, 0)
  117. }
  118. }
  119. return err
  120. }