activity_meet.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. package cygx
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hz_crm_api/models/cygx"
  6. "hongze/hz_crm_api/services/alarm_msg"
  7. "hongze/hz_crm_api/utils"
  8. )
  9. // 获取线上活动到会更新时间
  10. func GetActivityMeetUpdateTime(activityIdS []int) (mapResp map[int]string, err error) {
  11. defer func() {
  12. if err != nil {
  13. fmt.Println("err:", err)
  14. go alarm_msg.SendAlarmMsg("获取线上活动到会更新时间失败,Err:"+err.Error()+fmt.Sprint(activityIdS), 3)
  15. }
  16. }()
  17. lenNum := len(activityIdS)
  18. if lenNum == 0 {
  19. return
  20. }
  21. var condition string
  22. var pars []interface{}
  23. condition = ` AND a.activity_id IN (` + utils.GetOrmInReplace(lenNum) + `)`
  24. pars = append(pars, activityIdS)
  25. condition += ` GROUP BY a.activity_id `
  26. list, e := cygx.GetCygxActivityAttendanceDetailList(condition, pars, 0, lenNum)
  27. if e != nil {
  28. err = errors.New("GetCygxActivityAttendanceDetailList,Err" + e.Error())
  29. return
  30. }
  31. mapResp = make(map[int]string, 0)
  32. for _, v := range list {
  33. mapResp[v.ActivityId] = v.CreateTime.Format(utils.FormatDateTime)
  34. }
  35. return
  36. }
  37. func AddCygxActivityMeetDetailLogOffline(meetingUids string, activityId int) (err error) {
  38. defer func() {
  39. if err != nil {
  40. fmt.Println("err:", err)
  41. go alarm_msg.SendAlarmMsg("添加线下到会记录失败,Err:"+err.Error()+fmt.Sprint(activityId), 3)
  42. }
  43. }()
  44. if meetingUids == "" {
  45. return
  46. }
  47. list, e := cygx.GetOfflineMeetingListByUser(meetingUids, activityId)
  48. if e != nil {
  49. err = errors.New("GetOfflineMeetingListByUser" + e.Error())
  50. return
  51. }
  52. var companyIdArr []int
  53. var mobileArr []string
  54. var items []*cygx.CygxActivityMeetDetailLog
  55. if err != nil {
  56. return
  57. }
  58. //插入新的数据
  59. for _, v := range list {
  60. item := new(cygx.CygxActivityMeetDetailLog)
  61. item.ActivityId = v.ActivityId
  62. item.Mobile = v.Mobile
  63. item.CompanyName = v.CompanyName
  64. item.CompanyId = v.CompanyId
  65. item.CreateTime = v.CreateTime
  66. if v.Mobile != "" {
  67. mobileArr = append(mobileArr, v.Mobile)
  68. }
  69. if v.CompanyId > 0 {
  70. companyIdArr = append(companyIdArr, v.CompanyId)
  71. }
  72. items = append(items, item)
  73. }
  74. var condition string
  75. var pars []interface{}
  76. var itemsUpdateCompany []*cygx.MeetDetailLoggGroupCount
  77. lencompanyIdArr := len(companyIdArr)
  78. if lencompanyIdArr > 0 {
  79. condition = ` AND company_id IN (` + utils.GetOrmInReplace(lencompanyIdArr) + `) GROUP BY company_id `
  80. pars = append(pars, companyIdArr)
  81. listCompanyIdCount, e := cygx.GetMeetDetailLogGroupCount(condition, pars)
  82. if e != nil {
  83. err = errors.New("GetMeetDetailLogGroupCount" + e.Error())
  84. return
  85. }
  86. for _, v := range listCompanyIdCount {
  87. item := new(cygx.MeetDetailLoggGroupCount)
  88. item.CompanyId = v.CompanyId
  89. item.Count = v.Count
  90. itemsUpdateCompany = append(itemsUpdateCompany, item)
  91. }
  92. }
  93. fmt.Println(111)
  94. var itemsUpdateMobile []*cygx.MeetDetailLoggGroupCount
  95. lenmobileArr := len(mobileArr)
  96. if lenmobileArr > 0 {
  97. pars = make([]interface{}, 0)
  98. condition = ` AND mobile IN (` + utils.GetOrmInReplace(lenmobileArr) + `) GROUP BY mobile `
  99. pars = append(pars, mobileArr)
  100. listMobileCount, e := cygx.GetMeetDetailLogGroupCount(condition, pars)
  101. if e != nil {
  102. err = errors.New("GetMeetDetailLogGroupCount" + e.Error())
  103. return
  104. }
  105. for _, v := range listMobileCount {
  106. item := new(cygx.MeetDetailLoggGroupCount)
  107. item.Mobile = v.Mobile
  108. item.Count = v.Count
  109. itemsUpdateMobile = append(itemsUpdateMobile, item)
  110. }
  111. }
  112. e = cygx.UpdatecygxActivityMeetDetailLogOffline(items, itemsUpdateCompany, itemsUpdateMobile, activityId)
  113. if e != nil {
  114. err = errors.New("UpdatecygxActivityMeetDetailLogOffline" + e.Error())
  115. return
  116. }
  117. return
  118. }
  119. // AddctivitySignupDetailList
  120. func AddctivitySignupDetailList(itemsDetail []*cygx.CygxActivitySignupDetail, activityId int) (err error) {
  121. defer func() {
  122. if err != nil {
  123. fmt.Println(err)
  124. go alarm_msg.SendAlarmMsg("通过进门财经添加用户参数信息失败 ErrMsg:"+err.Error(), 2)
  125. }
  126. }()
  127. activityIds := make([]int, 0)
  128. activityIds = append(activityIds, activityId)
  129. actLen := len(activityIds)
  130. var condition string
  131. var pars []interface{}
  132. if actLen > 0 {
  133. condition += ` AND activity_id IN (` + utils.GetOrmInReplace(actLen) + `)`
  134. pars = append(pars, activityIds)
  135. }
  136. signUpDetailList, err := cygx.GetSignupDetailList(condition, pars)
  137. if err != nil && err.Error() != utils.ErrNoRow() {
  138. return err
  139. }
  140. mapsignUpDetai := make(map[string]string)
  141. if len(signUpDetailList) > 0 {
  142. for _, v := range signUpDetailList {
  143. mapsignUpDetai[fmt.Sprint("ActivityId", v.ActivityId, "Mobile", v.Mobile)] = v.Mobile
  144. }
  145. }
  146. //获取当天已经结束了 活动的报名人数
  147. signUpList, err := cygx.GetSignupDetailBySignup(condition, pars)
  148. if err != nil && err.Error() != utils.ErrNoRow() {
  149. return err
  150. }
  151. //建立外呼号与手机号的绑定
  152. mapsignUp := make(map[string]string)
  153. if len(signUpList) > 0 {
  154. for _, v := range signUpList {
  155. mapsignUp[fmt.Sprint(v.OutboundMobile)] = v.Mobile
  156. }
  157. }
  158. var itemsAdd []*cygx.CygxActivitySignupDetail
  159. var itemsUpdate []*cygx.CygxActivitySignupDetail
  160. for _, v := range itemsDetail {
  161. var item = new(cygx.CygxActivitySignupDetail)
  162. item.ActivityId = v.ActivityId
  163. //item.RealName = v.RealName
  164. //如果手机号存在那么就是报名的,不存在就是直接参与的
  165. if _, ok := mapsignUp[v.Mobile]; ok {
  166. item.Mobile = mapsignUp[v.Mobile]
  167. } else {
  168. item.Mobile = v.Mobile
  169. }
  170. item.UserId = v.UserId
  171. item.RealName = v.RealName
  172. item.OutboundMobile = v.Mobile
  173. item.CompanyName = v.CompanyName
  174. item.CompanyId = v.CompanyId
  175. item.SellerName = v.SellerName
  176. item.FirstMeetingTime = v.FirstMeetingTime
  177. item.LastMeetingTime = v.LastMeetingTime
  178. item.Duration = v.Duration
  179. item.MeetingTypeStr = v.MeetingTypeStr
  180. item.MeetingAuthentication = v.MeetingAuthentication
  181. item.MeetingStatusStr = v.MeetingStatusStr
  182. item.CreateTime = v.CreateTime
  183. item.Position = v.Position
  184. item.IsMeeting = v.IsMeeting
  185. item.UseridEntity = v.UseridEntity
  186. item.ActivityTime = v.ActivityTime
  187. item.CrmCompanyMapStatusId = v.CrmCompanyMapStatusId
  188. if _, ok := mapsignUpDetai[fmt.Sprint("ActivityId", v.ActivityId, "Mobile", item.Mobile)]; !ok {
  189. itemsAdd = append(itemsAdd, item)
  190. } else {
  191. itemsUpdate = append(itemsUpdate, item)
  192. }
  193. }
  194. //return err
  195. if len(itemsAdd) > 0 {
  196. err = cygx.AddCygxActivitySignupDetail(itemsAdd)
  197. if err != nil {
  198. return
  199. }
  200. }
  201. if len(itemsUpdate) > 0 {
  202. err = cygx.UpdateActivitySignupDetailMulti(itemsUpdate)
  203. if err != nil {
  204. return
  205. }
  206. }
  207. return err
  208. }