activity_signup_detail.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. // AddctivitySignupDetailByJmcj 通过进门财经添加用户参数信息
  91. func AddctivitySignupDetailByJmcj(itemsDetail []*models.CygxActivityAttendanceDetail, activityId 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. fmt.Println("活动ID", activityId)
  99. activityIds := make([]int, 0)
  100. activityIds = append(activityIds, activityId)
  101. actLen := len(activityIds)
  102. var condition string
  103. var pars []interface{}
  104. if actLen > 0 {
  105. condition += ` AND activity_id IN (` + utils.GetOrmInReplace(actLen) + `)`
  106. pars = append(pars, activityIds)
  107. }
  108. signUpDetailList, err := models.GetSignupDetailList(condition, pars)
  109. if err != nil && err.Error() != utils.ErrNoRow() {
  110. return err
  111. }
  112. mapsignUpDetai := make(map[string]string)
  113. if len(signUpDetailList) > 0 {
  114. for _, v := range signUpDetailList {
  115. mapsignUpDetai[fmt.Sprint("ActivityId", v.ActivityId, "Mobile", v.Mobile)] = v.Mobile
  116. }
  117. }
  118. //获取当天已经结束了 活动的报名人数
  119. signUpList, err := models.GetSignupDetailBySignup(condition, pars)
  120. if err != nil && err.Error() != utils.ErrNoRow() {
  121. return err
  122. }
  123. //建立外呼号与手机号的绑定
  124. mapsignUp := make(map[string]string)
  125. if len(signUpList) > 0 {
  126. for _, v := range signUpList {
  127. mapsignUp[fmt.Sprint(v.OutboundMobile)] = v.Mobile
  128. }
  129. }
  130. var itemsAdd []*models.CygxActivitySignupDetail
  131. var itemsUpdate []*models.CygxActivitySignupDetail
  132. for _, v := range itemsDetail {
  133. var item = new(models.CygxActivitySignupDetail)
  134. item.ActivityId = v.ActivityId
  135. item.RealName = v.RealName
  136. //如果手机号存在那么就是报名的,不存在就是直接参与的
  137. if _, ok := mapsignUp[v.Mobile]; ok {
  138. item.Mobile = mapsignUp[v.Mobile]
  139. } else {
  140. item.Mobile = v.Mobile
  141. }
  142. item.OutboundMobile = v.Mobile
  143. item.CompanyName = v.CompanyName
  144. item.CompanyId = v.CompanyId
  145. item.SellerName = v.SellerName
  146. item.FirstMeetingTime = v.FirstMeetingTime
  147. item.LastMeetingTime = v.LastMeetingTime
  148. item.Duration = v.Duration
  149. item.MeetingTypeStr = v.MeetingTypeStr
  150. item.MeetingAuthentication = v.MeetingAuthentication
  151. item.MeetingStatusStr = v.MeetingStatusStr
  152. item.CreateTime = v.CreateTime
  153. item.Position = v.Position
  154. item.IsMeeting = 1
  155. item.UseridEntity = v.UseridEntity
  156. item.ActivityTime = v.ActivityTime
  157. item.CrmCompanyMapStatusId = v.CrmCompanyMapStatusId
  158. if _, ok := mapsignUpDetai[fmt.Sprint("ActivityId", v.ActivityId, "Mobile", item.Mobile)]; !ok {
  159. itemsAdd = append(itemsAdd, item)
  160. } else {
  161. itemsUpdate = append(itemsUpdate, item)
  162. }
  163. }
  164. //return err
  165. if len(itemsAdd) > 0 {
  166. err = models.AddCygxActivitySignupDetail(itemsAdd)
  167. if err != nil {
  168. return
  169. }
  170. }
  171. if len(itemsUpdate) > 0 {
  172. err = models.UpdateActivitySignupDetailMulti(itemsUpdate)
  173. if err != nil {
  174. return
  175. }
  176. }
  177. //处理研选扣点信息
  178. YanXuanActivityPointsBillSubmitMeeting(activityId, 0)
  179. return err
  180. }
  181. //func GetCygxActivityAttendanceDetail() {
  182. // listAll, err := models.GetActivityAttendanceDetailListAll()
  183. // if err != nil {
  184. // fmt.Println(err)
  185. // }
  186. // mapDetal := make(map[int][]*models.CygxActivityAttendanceDetail)
  187. //
  188. // for _, v := range listAll {
  189. // mapDetal[v.ActivityId] = append(mapDetal[v.ActivityId], v)
  190. // }
  191. //
  192. // for k, v := range mapDetal {
  193. // AddctivitySignupDetailByJmcj(v, k)
  194. // }
  195. // //fmt.Println(mapDetal)
  196. //}
  197. // AddctivitySignupDetailByJmcj 通过进门财经添加用户参数信息
  198. func AddctivitySignupDetailByJmcjNew(itemsDetail []*models.CygxActivityAttendanceDetail, activityIds []int) (err error) {
  199. defer func() {
  200. if err != nil {
  201. fmt.Println(err)
  202. go utils.SendAlarmMsg("通过进门财经添加用户参数信息失败 ErrMsg:"+err.Error(), 2)
  203. }
  204. }()
  205. actLen := len(activityIds)
  206. var condition string
  207. var pars []interface{}
  208. if actLen > 0 {
  209. condition += ` AND activity_id IN (` + utils.GetOrmInReplace(actLen) + `)`
  210. pars = append(pars, activityIds)
  211. }
  212. signUpDetailList, err := models.GetSignupDetailList(condition, pars)
  213. if err != nil && err.Error() != utils.ErrNoRow() {
  214. return err
  215. }
  216. mapsignUpDetai := make(map[string]string)
  217. if len(signUpDetailList) > 0 {
  218. for _, v := range signUpDetailList {
  219. mapsignUpDetai[fmt.Sprint("ActivityId", v.ActivityId, "Mobile", v.Mobile)] = v.Mobile
  220. }
  221. }
  222. //获取当天已经结束了 活动的报名人数
  223. signUpList, err := models.GetSignupDetailBySignup(condition, pars)
  224. if err != nil && err.Error() != utils.ErrNoRow() {
  225. return err
  226. }
  227. //建立外呼号与手机号的绑定
  228. mapsignUp := make(map[string]string)
  229. if len(signUpList) > 0 {
  230. for _, v := range signUpList {
  231. mapsignUp[fmt.Sprint(v.OutboundMobile)] = v.Mobile
  232. }
  233. }
  234. var itemsAdd []*models.CygxActivitySignupDetail
  235. var itemsUpdate []*models.CygxActivitySignupDetail
  236. var mobiles []string
  237. mobileMap := make(map[string]bool)
  238. mobileUserMap := make(map[string]int)
  239. for _, v := range itemsDetail {
  240. if !mobileMap[v.Mobile] {
  241. mobiles = append(mobiles, v.Mobile)
  242. }
  243. mobileMap[v.Mobile] = true
  244. }
  245. //mobiles = make([]string, 0)
  246. //mobiles = append(mobiles, "13054631616")
  247. //根据手机号获取这些用户的信息
  248. listUser, e := models.GetWxUserByOutboundMobiles(mobiles)
  249. if e != nil {
  250. err = errors.New("GetWxUserOutboundMobiles, Err: " + e.Error())
  251. return
  252. }
  253. for _, v := range listUser {
  254. mobileUserMap[v.Mobile] = v.UserId
  255. }
  256. for _, v := range itemsDetail {
  257. var item = new(models.CygxActivitySignupDetail)
  258. item.ActivityId = v.ActivityId
  259. item.RealName = v.RealName
  260. //如果手机号存在那么就是报名的,不存在就是直接参与的
  261. if _, ok := mapsignUp[v.Mobile]; ok {
  262. item.Mobile = mapsignUp[v.Mobile]
  263. } else {
  264. item.Mobile = v.Mobile
  265. }
  266. item.OutboundMobile = v.Mobile
  267. item.CompanyName = v.CompanyName
  268. item.CompanyId = v.CompanyId
  269. item.SellerName = v.SellerName
  270. item.FirstMeetingTime = v.FirstMeetingTime
  271. item.LastMeetingTime = v.LastMeetingTime
  272. item.Duration = v.Duration
  273. item.MeetingTypeStr = v.MeetingTypeStr
  274. item.MeetingAuthentication = v.MeetingAuthentication
  275. item.MeetingStatusStr = v.MeetingStatusStr
  276. item.CreateTime = v.CreateTime
  277. item.Position = v.Position
  278. item.IsMeeting = 1
  279. item.UseridEntity = v.UseridEntity
  280. item.ActivityTime = v.ActivityTime
  281. item.CrmCompanyMapStatusId = v.CrmCompanyMapStatusId
  282. item.UserId = mobileUserMap[v.Mobile]
  283. if _, ok := mapsignUpDetai[fmt.Sprint("ActivityId", v.ActivityId, "Mobile", item.Mobile)]; !ok {
  284. itemsAdd = append(itemsAdd, item)
  285. } else {
  286. itemsUpdate = append(itemsUpdate, item)
  287. }
  288. }
  289. if len(itemsAdd) > 0 {
  290. err = models.AddCygxActivitySignupDetail(itemsAdd)
  291. if err != nil {
  292. return
  293. }
  294. }
  295. if len(itemsUpdate) > 0 {
  296. err = models.UpdateActivitySignupDetailMulti(itemsUpdate)
  297. if err != nil {
  298. return
  299. }
  300. }
  301. //获取所有研选扣点的活动,如果是就行扣点流水处理
  302. mapActivityPoints, _ := GetActivityPointsAll()
  303. for _, v := range activityIds {
  304. if mapActivityPoints[v] {
  305. YanXuanActivityPointsBillSubmitMeeting(v, 0)
  306. }
  307. }
  308. return err
  309. }
  310. //func init() {
  311. // var err error
  312. // defer func() {
  313. // if err != nil {
  314. // fmt.Println(err)
  315. // }
  316. // }()
  317. // var condition string
  318. // var pars []interface{}
  319. // condition = " AND user_id = 0 AND company_id > 1 AND mobile != '' "
  320. // signUpDetailList, e := models.GetSignupDetailList(condition, pars)
  321. // if e != nil && e.Error() != utils.ErrNoRow() {
  322. // err = errors.New("GetSignupDetailList, Err: " + e.Error())
  323. // return
  324. // }
  325. // var mobiles []string
  326. // mobileMap := make(map[string]bool)
  327. // for _, v := range signUpDetailList {
  328. // if !mobileMap[v.Mobile] {
  329. // mobiles = append(mobiles, v.Mobile)
  330. // }
  331. // mobileMap[v.Mobile] = true
  332. // }
  333. // //mobiles = make([]string, 0)
  334. // //mobiles = append(mobiles, "13054631616")
  335. // //根据手机号获取这些用户的信息
  336. // listUser, e := models.GetWxUserByOutboundMobiles(mobiles)
  337. // if e != nil {
  338. // err = errors.New("GetWxUserOutboundMobiles, Err: " + e.Error())
  339. // return
  340. // }
  341. //
  342. // var itemsUpdate []*models.CygxActivitySignupDetail
  343. // for _, v := range listUser {
  344. // item := new(models.CygxActivitySignupDetail)
  345. // item.UserId = v.UserId
  346. // item.Mobile = v.Mobile
  347. // itemsUpdate = append(itemsUpdate, item)
  348. // }
  349. // fmt.Println(len(itemsUpdate))
  350. // err = models.UpdateActivitySignupDetailMultiMobileAndUserId(itemsUpdate)
  351. //}