activity_meet.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. package cygx
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/cygx"
  7. "hongze/hz_crm_api/services/alarm_msg"
  8. "hongze/hz_crm_api/utils"
  9. "strconv"
  10. )
  11. // 获取线上活动到会更新时间
  12. func GetActivityMeetUpdateTime(activityIdS []int) (mapResp map[int]string, err error) {
  13. defer func() {
  14. if err != nil {
  15. fmt.Println("err:", err)
  16. go alarm_msg.SendAlarmMsg("获取线上活动到会更新时间失败,Err:"+err.Error()+fmt.Sprint(activityIdS), 3)
  17. }
  18. }()
  19. lenNum := len(activityIdS)
  20. if lenNum == 0 {
  21. return
  22. }
  23. var condition string
  24. var pars []interface{}
  25. condition = ` AND a.activity_id IN (` + utils.GetOrmInReplace(lenNum) + `)`
  26. pars = append(pars, activityIdS)
  27. condition += ` GROUP BY a.activity_id `
  28. list, e := cygx.GetCygxActivityAttendanceDetailList(condition, pars, 0, lenNum)
  29. if e != nil {
  30. err = errors.New("GetCygxActivityAttendanceDetailList,Err" + e.Error())
  31. return
  32. }
  33. mapResp = make(map[int]string, 0)
  34. for _, v := range list {
  35. mapResp[v.ActivityId] = v.CreateTime.Format(utils.FormatDateTime)
  36. }
  37. return
  38. }
  39. func AddCygxActivityMeetDetailLogOffline(meetingUids string, activityId int) (err error) {
  40. defer func() {
  41. if err != nil {
  42. fmt.Println("err:", err)
  43. go alarm_msg.SendAlarmMsg("添加线下到会记录失败,Err:"+err.Error()+fmt.Sprint(activityId), 3)
  44. }
  45. }()
  46. if meetingUids == "" {
  47. return
  48. }
  49. list, e := cygx.GetOfflineMeetingListByUser(meetingUids, activityId)
  50. if e != nil {
  51. err = errors.New("GetOfflineMeetingListByUser" + e.Error())
  52. return
  53. }
  54. var companyIdArr []int
  55. var mobileArr []string
  56. var items []*cygx.CygxActivityMeetDetailLog
  57. if err != nil {
  58. return
  59. }
  60. //插入新的数据
  61. for _, v := range list {
  62. item := new(cygx.CygxActivityMeetDetailLog)
  63. item.ActivityId = v.ActivityId
  64. item.Mobile = v.Mobile
  65. item.CompanyName = v.CompanyName
  66. item.CompanyId = v.CompanyId
  67. item.CreateTime = v.CreateTime
  68. if v.Mobile != "" {
  69. mobileArr = append(mobileArr, v.Mobile)
  70. }
  71. if v.CompanyId > 0 {
  72. companyIdArr = append(companyIdArr, v.CompanyId)
  73. }
  74. items = append(items, item)
  75. }
  76. var condition string
  77. var pars []interface{}
  78. var itemsUpdateCompany []*cygx.MeetDetailLoggGroupCount
  79. lencompanyIdArr := len(companyIdArr)
  80. if lencompanyIdArr > 0 {
  81. condition = ` AND company_id IN (` + utils.GetOrmInReplace(lencompanyIdArr) + `) GROUP BY company_id `
  82. pars = append(pars, companyIdArr)
  83. listCompanyIdCount, e := cygx.GetMeetDetailLogGroupCount(condition, pars)
  84. if e != nil {
  85. err = errors.New("GetMeetDetailLogGroupCount" + e.Error())
  86. return
  87. }
  88. for _, v := range listCompanyIdCount {
  89. item := new(cygx.MeetDetailLoggGroupCount)
  90. item.CompanyId = v.CompanyId
  91. item.Count = v.Count
  92. itemsUpdateCompany = append(itemsUpdateCompany, item)
  93. }
  94. }
  95. fmt.Println(111)
  96. var itemsUpdateMobile []*cygx.MeetDetailLoggGroupCount
  97. lenmobileArr := len(mobileArr)
  98. if lenmobileArr > 0 {
  99. pars = make([]interface{}, 0)
  100. condition = ` AND mobile IN (` + utils.GetOrmInReplace(lenmobileArr) + `) GROUP BY mobile `
  101. pars = append(pars, mobileArr)
  102. listMobileCount, e := cygx.GetMeetDetailLogGroupCount(condition, pars)
  103. if e != nil {
  104. err = errors.New("GetMeetDetailLogGroupCount" + e.Error())
  105. return
  106. }
  107. for _, v := range listMobileCount {
  108. item := new(cygx.MeetDetailLoggGroupCount)
  109. item.Mobile = v.Mobile
  110. item.Count = v.Count
  111. itemsUpdateMobile = append(itemsUpdateMobile, item)
  112. }
  113. }
  114. e = cygx.UpdatecygxActivityMeetDetailLogOffline(items, itemsUpdateCompany, itemsUpdateMobile, activityId)
  115. if e != nil {
  116. err = errors.New("UpdatecygxActivityMeetDetailLogOffline" + e.Error())
  117. return
  118. }
  119. return
  120. }
  121. // AddctivitySignupDetailList
  122. func AddctivitySignupDetailList(itemsDetail []*cygx.CygxActivitySignupDetail, activityId int) (err error) {
  123. defer func() {
  124. if err != nil {
  125. fmt.Println(err)
  126. go alarm_msg.SendAlarmMsg("通过进门财经添加用户参数信息失败 ErrMsg:"+err.Error(), 2)
  127. }
  128. }()
  129. activityIds := make([]int, 0)
  130. activityIds = append(activityIds, activityId)
  131. actLen := len(activityIds)
  132. var condition string
  133. var pars []interface{}
  134. if actLen > 0 {
  135. condition += ` AND activity_id IN (` + utils.GetOrmInReplace(actLen) + `)`
  136. pars = append(pars, activityIds)
  137. }
  138. signUpDetailList, err := cygx.GetSignupDetailList(condition, pars)
  139. if err != nil && err.Error() != utils.ErrNoRow() {
  140. return err
  141. }
  142. mapsignUpDetai := make(map[string]string)
  143. if len(signUpDetailList) > 0 {
  144. for _, v := range signUpDetailList {
  145. mapsignUpDetai[fmt.Sprint("ActivityId", v.ActivityId, "Mobile", v.Mobile)] = v.Mobile
  146. }
  147. }
  148. //获取当天已经结束了 活动的报名人数
  149. signUpList, err := cygx.GetSignupDetailBySignup(condition, pars)
  150. if err != nil && err.Error() != utils.ErrNoRow() {
  151. return err
  152. }
  153. //建立外呼号与手机号的绑定
  154. mapsignUp := make(map[string]string)
  155. if len(signUpList) > 0 {
  156. for _, v := range signUpList {
  157. mapsignUp[fmt.Sprint(v.OutboundMobile)] = v.Mobile
  158. }
  159. }
  160. var itemsAdd []*cygx.CygxActivitySignupDetail
  161. var itemsUpdate []*cygx.CygxActivitySignupDetail
  162. for _, v := range itemsDetail {
  163. var item = new(cygx.CygxActivitySignupDetail)
  164. item.ActivityId = v.ActivityId
  165. //item.RealName = v.RealName
  166. //如果手机号存在那么就是报名的,不存在就是直接参与的
  167. if _, ok := mapsignUp[v.Mobile]; ok {
  168. item.Mobile = mapsignUp[v.Mobile]
  169. } else {
  170. item.Mobile = v.Mobile
  171. }
  172. item.UserId = v.UserId
  173. item.RealName = v.RealName
  174. item.OutboundMobile = v.Mobile
  175. item.CompanyName = v.CompanyName
  176. item.CompanyId = v.CompanyId
  177. item.SellerName = v.SellerName
  178. item.FirstMeetingTime = v.FirstMeetingTime
  179. item.LastMeetingTime = v.LastMeetingTime
  180. item.Duration = v.Duration
  181. item.MeetingTypeStr = v.MeetingTypeStr
  182. item.MeetingAuthentication = v.MeetingAuthentication
  183. item.MeetingStatusStr = v.MeetingStatusStr
  184. item.CreateTime = v.CreateTime
  185. item.Position = v.Position
  186. item.IsMeeting = v.IsMeeting
  187. item.UseridEntity = v.UseridEntity
  188. item.ActivityTime = v.ActivityTime
  189. item.CrmCompanyMapStatusId = v.CrmCompanyMapStatusId
  190. if _, ok := mapsignUpDetai[fmt.Sprint("ActivityId", v.ActivityId, "Mobile", item.Mobile)]; !ok {
  191. itemsAdd = append(itemsAdd, item)
  192. } else {
  193. itemsUpdate = append(itemsUpdate, item)
  194. }
  195. }
  196. //return err
  197. if len(itemsAdd) > 0 {
  198. err = cygx.AddCygxActivitySignupDetail(itemsAdd)
  199. if err != nil {
  200. return
  201. }
  202. }
  203. if len(itemsUpdate) > 0 {
  204. err = cygx.UpdateActivitySignupDetailMulti(itemsUpdate)
  205. if err != nil {
  206. return
  207. }
  208. }
  209. return err
  210. }
  211. // AddctivitySignupDetailListByHand 手动匹配进门财经信息
  212. func AddctivitySignupDetailListByHand(itemsDetail []*cygx.CygxActivityAttendanceDetail, activityId int) (err error) {
  213. defer func() {
  214. if err != nil {
  215. fmt.Println(err)
  216. go alarm_msg.SendAlarmMsg("通过进门财经添加用户参数信息失败 ErrMsg:"+err.Error(), 2)
  217. }
  218. }()
  219. activityIds := make([]int, 0)
  220. activityIds = append(activityIds, activityId)
  221. actLen := len(activityIds)
  222. var condition string
  223. var pars []interface{}
  224. if actLen > 0 {
  225. condition += ` AND activity_id IN (` + utils.GetOrmInReplace(actLen) + `)`
  226. pars = append(pars, activityIds)
  227. }
  228. signUpDetailList, err := cygx.GetSignupDetailList(condition, pars)
  229. if err != nil && err.Error() != utils.ErrNoRow() {
  230. return err
  231. }
  232. mapsignUpDetai := make(map[string]string)
  233. if len(signUpDetailList) > 0 {
  234. for _, v := range signUpDetailList {
  235. mapsignUpDetai[fmt.Sprint("ActivityId", v.ActivityId, "Mobile", v.Mobile)] = v.Mobile
  236. }
  237. }
  238. //获取当天已经结束了 活动的报名人数
  239. signUpList, err := cygx.GetSignupDetailBySignup(condition, pars)
  240. if err != nil && err.Error() != utils.ErrNoRow() {
  241. return err
  242. }
  243. //建立外呼号与手机号的绑定
  244. mapsignUp := make(map[string]string)
  245. if len(signUpList) > 0 {
  246. for _, v := range signUpList {
  247. mapsignUp[fmt.Sprint(v.OutboundMobile)] = v.Mobile
  248. }
  249. }
  250. var itemsAdd []*cygx.CygxActivitySignupDetail
  251. var itemsUpdate []*cygx.CygxActivitySignupDetail
  252. var mobiles []string
  253. mobileMap := make(map[string]bool)
  254. mobileUserMap := make(map[string]int)
  255. for _, v := range itemsDetail {
  256. if !mobileMap[v.Mobile] {
  257. mobiles = append(mobiles, v.Mobile)
  258. }
  259. mobileMap[v.Mobile] = true
  260. }
  261. //根据手机号获取这些用户的信息
  262. listUser, e := models.GetWxUserByOutboundMobiles(mobiles)
  263. if e != nil {
  264. err = errors.New("GetWxUserOutboundMobiles, Err: " + e.Error())
  265. return
  266. }
  267. for _, v := range listUser {
  268. mobileUserMap[v.Mobile] = int(v.UserId)
  269. }
  270. for _, v := range itemsDetail {
  271. var item = new(cygx.CygxActivitySignupDetail)
  272. item.ActivityId = v.ActivityId
  273. //item.RealName = v.RealName
  274. //如果手机号存在那么就是报名的,不存在就是直接参与的
  275. if _, ok := mapsignUp[v.Mobile]; ok {
  276. item.Mobile = mapsignUp[v.Mobile]
  277. } else {
  278. item.Mobile = v.Mobile
  279. }
  280. item.UserId = mobileUserMap[v.Mobile]
  281. item.RealName = v.RealName
  282. item.OutboundMobile = v.Mobile
  283. item.CompanyName = v.CompanyName
  284. item.CompanyId = v.CompanyId
  285. item.SellerName = v.SellerName
  286. item.FirstMeetingTime = v.FirstMeetingTime
  287. item.LastMeetingTime = v.LastMeetingTime
  288. item.Duration = v.Duration
  289. item.MeetingTypeStr = v.MeetingTypeStr
  290. item.MeetingAuthentication = v.MeetingAuthentication
  291. item.MeetingStatusStr = v.MeetingStatusStr
  292. item.CreateTime = v.CreateTime
  293. item.Position = v.Position
  294. item.IsMeeting = 1
  295. item.UseridEntity = v.UseridEntity
  296. item.ActivityTime = v.ActivityTime
  297. item.CrmCompanyMapStatusId = v.CrmCompanyMapStatusId
  298. if _, ok := mapsignUpDetai[fmt.Sprint("ActivityId", v.ActivityId, "Mobile", item.Mobile)]; !ok {
  299. itemsAdd = append(itemsAdd, item)
  300. } else {
  301. itemsUpdate = append(itemsUpdate, item)
  302. }
  303. }
  304. //return err
  305. if len(itemsAdd) > 0 {
  306. err = cygx.AddCygxActivitySignupDetail(itemsAdd)
  307. if err != nil {
  308. return
  309. }
  310. }
  311. if len(itemsUpdate) > 0 {
  312. err = cygx.UpdateActivitySignupDetailMulti(itemsUpdate)
  313. if err != nil {
  314. return
  315. }
  316. }
  317. return err
  318. }
  319. // AddctivitySignupDetailListByAdminSignup 已结束的活动,管理员手动添加报名,把信息写入到联系人列表参会信息中
  320. func AddctivitySignupDetailListByAdminSignup(activityIdsStr string) (err error) {
  321. defer func() {
  322. if err != nil {
  323. fmt.Println(err)
  324. go alarm_msg.SendAlarmMsg(fmt.Sprint("已结束的活动,管理员手动添加报名,把信息写入到联系人列表参会信息中 ErrMsg:"+err.Error(), "activityIds:", activityIdsStr), 2)
  325. }
  326. }()
  327. var condition string
  328. var pars []interface{}
  329. condition = ` AND active_state = 3 AND activity_id IN (` + activityIdsStr + `) `
  330. list, e := cygx.GetActivityListAll(condition, pars, 0, 9999)
  331. if e != nil && e.Error() != utils.ErrNoRow() {
  332. err = errors.New("GetWxUserOutboundMobiles, Err: " + e.Error())
  333. return
  334. }
  335. if len(list) == 0 {
  336. return
  337. }
  338. var activityIds []int
  339. for _, v := range list {
  340. activityIds = append(activityIds, v.ActivityId)
  341. }
  342. actLen := len(activityIds)
  343. condition = ` AND activity_id IN (` + utils.GetOrmInReplace(actLen) + `)`
  344. pars = append(pars, activityIds)
  345. //获取已经写入的信息,并建立map
  346. signUpDetailList, err := cygx.GetSignupDetailList(condition, pars)
  347. if err != nil && err.Error() != utils.ErrNoRow() {
  348. return err
  349. }
  350. mapsignUpDetai := make(map[string]string)
  351. if len(signUpDetailList) > 0 {
  352. for _, v := range signUpDetailList {
  353. mapsignUpDetai[fmt.Sprint("ActivityId", v.ActivityId, "Mobile", v.Mobile)] = v.Mobile
  354. }
  355. }
  356. pars = make([]interface{}, 0)
  357. condition = ` AND activity_id IN (` + utils.GetOrmInReplace(actLen) + `) AND do_fail_type = 0`
  358. pars = append(pars, activityIds)
  359. //获取成功报名的人员信息
  360. signUpList, err := cygx.GetSignupDetailBySignup(condition, pars)
  361. if err != nil && err.Error() != utils.ErrNoRow() {
  362. return err
  363. }
  364. //建立外呼号与手机号的绑定
  365. mapsignUp := make(map[string]string)
  366. if len(signUpList) > 0 {
  367. for _, v := range signUpList {
  368. mapsignUp[fmt.Sprint(v.OutboundMobile)] = v.Mobile
  369. }
  370. }
  371. var items []*cygx.CygxActivitySignupDetail
  372. if len(signUpList) > 0 {
  373. for _, v := range signUpList {
  374. if _, ok := mapsignUpDetai[fmt.Sprint("ActivityId", v.ActivityId, "Mobile", v.Mobile)]; !ok {
  375. item := new(cygx.CygxActivitySignupDetail)
  376. item.UserId = v.UserId
  377. item.RealName = v.RealName
  378. item.SellerName = v.SellerName
  379. item.ActivityId = v.ActivityId
  380. item.CreateTime = v.CreateTime
  381. item.Mobile = v.Mobile
  382. item.OutboundMobile = v.OutboundMobile
  383. item.Email = v.Email
  384. item.CompanyId = v.CompanyId
  385. item.CompanyName = v.CompanyName
  386. item.SignupType = v.SignupType
  387. item.FailType = v.FailType
  388. item.DoFailType = v.DoFailType
  389. items = append(items, item)
  390. }
  391. }
  392. }
  393. if len(items) > 0 {
  394. e = cygx.AddCygxActivitySignupDetail(items)
  395. if e != nil {
  396. err = errors.New("AddCygxActivitySignupDetail, Err: " + e.Error())
  397. return
  398. }
  399. }
  400. return err
  401. }
  402. func init77777() {
  403. var condition string
  404. var pars []interface{}
  405. listAct, errList := cygx.GetActivityListAll(condition+"AND active_state = 3 AND activity_id > 3000 AND publish_status = 1 ", pars, 0, 9999)
  406. if errList != nil {
  407. fmt.Println(errList)
  408. return
  409. }
  410. fmt.Println(len(listAct))
  411. for _, v := range listAct {
  412. condition = ` AND a.activity_id = ` + strconv.Itoa(v.ActivityId)
  413. //pars = append(pars)
  414. list, e := cygx.GetCygxActivityAttendanceDetailList(condition, pars, 0, 999)
  415. if e != nil {
  416. fmt.Println(e)
  417. return
  418. }
  419. fmt.Println("ActivityId", v.ActivityId, "list", len(list))
  420. AddctivitySignupDetailListByHand(list, v.ActivityId)
  421. }
  422. }