activity_meeting.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. package services
  2. import (
  3. "context"
  4. "errors"
  5. "fmt"
  6. "hongze/hongze_cygx/models"
  7. "hongze/hongze_cygx/utils"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. //func init() {
  13. // fmt.Println(strings.Contains("渠道新声第583期运动服饰渠道调研更新反馈", "运动服饰渠道调研更新反馈"))
  14. // fmt.Println(len("反馈"))
  15. // GroupingActivityToJmcj()
  16. // GetActivityMeetingByJmcj()
  17. //}
  18. // GroupingActivityToJmcj 建立与进门财经的活动关联
  19. func GroupingActivityToJmcj(cont context.Context) (err error) {
  20. //func GroupingActivityToJmcj() (err error) {
  21. defer func() {
  22. if err != nil {
  23. fmt.Println(err)
  24. go utils.SendAlarmMsg("建立与进门财经的活动关联失败"+err.Error(), 2)
  25. }
  26. }()
  27. dateTime := time.Now().AddDate(0, 0, -7).Format(utils.FormatDate)
  28. dateNow := time.Now().AddDate(0, 0, 0).Format(utils.FormatDate)
  29. startDate := dateTime + " 00:00:00"
  30. endDate := dateNow + " 23:59:59"
  31. var condition string
  32. var pars []interface{}
  33. condition = " AND roadshow_begin_time BETWEEN ? AND ? "
  34. //condition += " AND roadshow_id = 95871 "
  35. pars = append(pars, startDate, endDate)
  36. condition += ` GROUP BY roadshow_id `
  37. listJmcj, e := models.GetJmcjRoadshowDataList(condition, pars)
  38. if e != nil {
  39. err = errors.New("GetJmcjRoadshowDataList, Err: " + e.Error())
  40. return
  41. }
  42. textLen := 15
  43. pars = make([]interface{}, 0)
  44. //进门财经的不匹配的易董办会的
  45. condition = " AND activity_time BETWEEN ? AND ? AND publish_status = 1 AND jmcj_activity_id = '' AND yidong_activity_id_by_cygx = '' AND yidong_activity_id = '' "
  46. //condition += " AND activity_id = 1339 "
  47. pars = append(pars, startDate, endDate)
  48. listHz, e := models.GetActivityListByCondition(condition, pars)
  49. if e != nil {
  50. err = errors.New("GetActivityListByCondition, Err: " + e.Error())
  51. return
  52. }
  53. mapGroupActivityid := make(map[int]string)
  54. //通过进门财经匹配弘则
  55. for _, vJmcj := range listJmcj {
  56. var roadshowTitle, roadshowTitle1, roadshowTitle2, roadshowTitle3, roadshowTitle4 string
  57. roadshowTitle = vJmcj.RoadshowTitle
  58. roadshowTitle = strings.Replace(roadshowTitle, " ", "", -1)
  59. roadshowBeginTime := utils.TimeRemoveHms2(vJmcj.RoadshowBeginTime)
  60. nameSlice1 := strings.Split(roadshowTitle, "|")
  61. nameSlice2 := strings.Split(roadshowTitle, ":")
  62. nameSlice3 := strings.Split(roadshowTitle, "】")
  63. nameSlice4 := strings.Split(roadshowTitle, "-")
  64. if len(nameSlice1) >= 1 {
  65. roadshowTitle1 = nameSlice1[len(nameSlice1)-1]
  66. }
  67. if len(nameSlice2) >= 1 {
  68. roadshowTitle2 = nameSlice2[len(nameSlice2)-1]
  69. }
  70. if len(nameSlice3) >= 1 {
  71. roadshowTitle3 = nameSlice3[len(nameSlice3)-1]
  72. }
  73. if len(nameSlice4) >= 1 {
  74. roadshowTitle4 = nameSlice4[len(nameSlice4)-1]
  75. }
  76. if roadshowTitle == "" {
  77. continue
  78. }
  79. //fmt.Println(roadshowTitle1)
  80. //fmt.Println(roadshowTitle2)
  81. //fmt.Println(roadshowTitle3)
  82. //fmt.Println(roadshowTitle4)
  83. for _, vHz := range listHz {
  84. //如果同一时间标题匹配就建立匹配关系
  85. if roadshowBeginTime == utils.TimeRemoveHms2(vHz.ActivityTime) {
  86. if strings.Contains(vHz.ActivityNameTask, roadshowTitle) || strings.Contains(vHz.JmcjRoadshowTitle, roadshowTitle) {
  87. mapGroupActivityid[vHz.ActivityId] = vJmcj.RoadshowId
  88. break
  89. }
  90. //去掉空格标识,完全等于时候的匹配
  91. if strings.Replace(vHz.ActivityName, " ", "", -1) == strings.Replace(vJmcj.RoadshowTitle, " ", "", -1) {
  92. mapGroupActivityid[vHz.ActivityId] = vJmcj.RoadshowId
  93. break
  94. }
  95. if len(roadshowTitle1) > textLen {
  96. if strings.Contains(vHz.ActivityNameTask, roadshowTitle1) || strings.Contains(vHz.JmcjRoadshowTitle, roadshowTitle1) {
  97. mapGroupActivityid[vHz.ActivityId] = vJmcj.RoadshowId
  98. break
  99. }
  100. }
  101. if len(roadshowTitle2) > textLen {
  102. if strings.Contains(vHz.ActivityNameTask, roadshowTitle2) || strings.Contains(vHz.JmcjRoadshowTitle, roadshowTitle2) {
  103. mapGroupActivityid[vHz.ActivityId] = vJmcj.RoadshowId
  104. break
  105. }
  106. }
  107. if len(roadshowTitle3) > textLen {
  108. if strings.Contains(vHz.ActivityNameTask, roadshowTitle3) || strings.Contains(vHz.JmcjRoadshowTitle, roadshowTitle3) {
  109. mapGroupActivityid[vHz.ActivityId] = vJmcj.RoadshowId
  110. break
  111. }
  112. }
  113. if len(roadshowTitle4) > textLen {
  114. if strings.Contains(vHz.ActivityNameTask, roadshowTitle4) || strings.Contains(vHz.JmcjRoadshowTitle, roadshowTitle4) {
  115. mapGroupActivityid[vHz.ActivityId] = vJmcj.RoadshowId
  116. break
  117. }
  118. }
  119. }
  120. }
  121. }
  122. //通过弘则匹配进门财经
  123. for _, vHz := range listHz {
  124. if mapGroupActivityid[vHz.ActivityId] != "" {
  125. continue
  126. }
  127. var roadshowTitle string
  128. roadshowTitle = vHz.ActivityName
  129. nameSlice := strings.Split(roadshowTitle, "】")
  130. if len(nameSlice) >= 1 {
  131. roadshowTitle = nameSlice[len(nameSlice)-1]
  132. if len(roadshowTitle) > textLen {
  133. vHz.ActivityTime = utils.TimeRemoveHms2(vHz.ActivityTime)
  134. for _, vJmcj := range listJmcj {
  135. //如果同一时间标题匹配就建立匹配关系
  136. if vHz.ActivityTime == utils.TimeRemoveHms2(vJmcj.RoadshowBeginTime) {
  137. if strings.Contains(vJmcj.RoadshowTitle, roadshowTitle) {
  138. mapGroupActivityid[vHz.ActivityId] = vJmcj.RoadshowId
  139. break
  140. }
  141. if strings.Contains(vJmcj.RoadshowTitle, vHz.JmcjRoadshowTitle) && vHz.JmcjRoadshowTitle != "" {
  142. mapGroupActivityid[vHz.ActivityId] = vJmcj.RoadshowId
  143. break
  144. }
  145. }
  146. }
  147. }
  148. }
  149. }
  150. if len(mapGroupActivityid) > 0 {
  151. e = models.UpdateJmcjActivityIdGroup(mapGroupActivityid)
  152. if e != nil {
  153. err = errors.New("UpdateJmcjActivityIdGroup, Err: " + e.Error())
  154. }
  155. }
  156. return
  157. }
  158. // GetActivityMeetingByJmcj 同步进门财经到会信息,并处理爽约记录
  159. func GetActivityMeetingByJmcj(cont context.Context) (err error) {
  160. defer func() {
  161. if err != nil {
  162. fmt.Println(err)
  163. go utils.SendAlarmMsg("获取进门财经的到会信息失败,Err"+err.Error(), 2)
  164. }
  165. }()
  166. //获取需要一直同步的活动信息
  167. configCode := "jin_meng_activity_id"
  168. detail, e := models.GetConfigByCode(configCode)
  169. if e != nil {
  170. err = errors.New("GetConfigByCode, Err: " + e.Error())
  171. return
  172. }
  173. mapActivityIdlLongTime := make(map[string]string)
  174. sliceValue := strings.Split(detail.ConfigValue, ",")
  175. for _, v := range sliceValue {
  176. mapActivityIdlLongTime[v] = v
  177. }
  178. dateTime := time.Now().AddDate(0, 0, -14).Format(utils.FormatDate)
  179. dateNow := time.Now().AddDate(0, 0, 0).Format(utils.FormatDate)
  180. startDate := dateTime + " 00:00:00"
  181. endDate := dateNow + " 23:59:59"
  182. var condition string
  183. var pars []interface{}
  184. //获取弘则要同步到会信息的活动
  185. condition = ` AND activity_time BETWEEN ? AND ? AND publish_status = 1 AND jmcj_activity_id != '' AND yidong_activity_id_by_cygx = '' AND yidong_activity_id = '' OR ( activity_id IN (` + detail.ConfigValue + `) AND publish_status = 1 AND jmcj_activity_id != '' ) `
  186. pars = append(pars, startDate, endDate)
  187. listHz, e := models.GetActivityListByCondition(condition, pars)
  188. if e != nil && e.Error() != utils.ErrNoRow() {
  189. err = errors.New("GetActivityListByCondition, Err: " + e.Error())
  190. return
  191. }
  192. var jmcjActivityIds []string
  193. var activityIds []int
  194. mapGroupActivityid := make(map[string]int)
  195. mapGroupActivityTime := make(map[string]string)
  196. for _, v := range listHz {
  197. jmcjActivityIds = append(jmcjActivityIds, v.JmcjActivityId)
  198. activityIds = append(activityIds, v.ActivityId)
  199. mapGroupActivityid[v.JmcjActivityId] = v.ActivityId
  200. mapGroupActivityTime[v.JmcjActivityId] = v.ActivityTime
  201. }
  202. //return
  203. lenjmcjActivityIds := len(jmcjActivityIds)
  204. if lenjmcjActivityIds == 0 {
  205. return
  206. }
  207. //获取进门财经对应的路演ID的到会列表
  208. pars = make([]interface{}, 0)
  209. condition = ` AND roadshow_id IN (` + utils.GetOrmInReplace(lenjmcjActivityIds) + `)`
  210. pars = append(pars, jmcjActivityIds)
  211. listJmcj, e := models.GetJmcjRoadshowDataList(condition, pars)
  212. if e != nil {
  213. err = errors.New("GetJmcjRoadshowDataList, Err: " + e.Error())
  214. return
  215. }
  216. //获取已经写入到会信息的参会人员
  217. lenactivityIds := len(activityIds)
  218. pars = make([]interface{}, 0)
  219. condition = ` AND activity_id IN (` + utils.GetOrmInReplace(lenactivityIds) + `)`
  220. pars = append(pars, activityIds)
  221. attendanceDetailList, e := models.GetActivityAttendanceDetailListCondition(condition, pars)
  222. if e != nil {
  223. err = errors.New("GetActivityAttendanceDetailListCondition, Err: " + e.Error())
  224. return
  225. }
  226. mapAttendanceDetail := make(map[string]int)
  227. for _, v := range attendanceDetailList {
  228. mapAttendanceDetail[fmt.Sprint("ActivityId:", v.ActivityId, "Mobile:", v.Mobile)] = v.ActivityId
  229. }
  230. var mobiles []string
  231. var mobileMap = make(map[string]string)
  232. //var isPlayback bool // 是否包含回放
  233. var isPlaybackMap = make(map[int]bool) // 是否包含回放map
  234. var activityIdsLongTime string //包含回放的活动ID
  235. needAddAttendanc := make([]*models.CygxActivityAttendanceDetail, 0)
  236. for _, v := range listJmcj {
  237. if v.UserPhone == "" {
  238. continue
  239. }
  240. if mapGroupActivityid[v.RoadshowId] == 0 {
  241. continue
  242. }
  243. //如果数据已经存在了那么就不做数据更新
  244. if mapAttendanceDetail[fmt.Sprint("ActivityId:", mapGroupActivityid[v.RoadshowId], "Mobile:", v.UserPhone)] > 0 {
  245. continue
  246. }
  247. item := new(models.CygxActivityAttendanceDetail)
  248. item.ActivityId = mapGroupActivityid[v.RoadshowId]
  249. item.RealName = v.UserName
  250. item.Mobile = v.UserPhone
  251. item.CompanyName = v.Company
  252. item.FirstMeetingTime = v.FirstWatchTime
  253. item.LastMeetingTime = v.LastWatchTime
  254. item.IsMeetingStr = 1
  255. item.Duration = utils.GetAttendanceDetailSeconds(v.JoinTime)
  256. if v.JoinType == 1 {
  257. item.MeetingTypeStr = "网络"
  258. } else {
  259. item.MeetingTypeStr = "电话"
  260. }
  261. item.MeetingAuthentication = v.AuthInfo
  262. if v.DataType == 1 {
  263. item.MeetingStatusStr = "直播"
  264. } else {
  265. item.MeetingStatusStr = "回放"
  266. if !isPlaybackMap[item.ActivityId] && mapActivityIdlLongTime[strconv.Itoa(item.ActivityId)] == "" {
  267. activityIdsLongTime += strconv.Itoa(item.ActivityId) + ","
  268. }
  269. isPlaybackMap[item.ActivityId] = true
  270. }
  271. item.Position = v.Occupation
  272. item.UseridEntity = v.UseridEntity
  273. item.ActivityTime = mapGroupActivityTime[v.RoadshowId]
  274. item.CrmCompanyMapStatusId = v.CrmCompanyMapStatusId
  275. item.CreateTime = time.Now()
  276. needAddAttendanc = append(needAddAttendanc, item)
  277. if mobileMap[v.UserPhone] == "" {
  278. mobiles = append(mobiles, v.UserPhone)
  279. mobileMap[v.UserPhone] = v.UserPhone
  280. }
  281. }
  282. if len(needAddAttendanc) == 0 {
  283. return
  284. }
  285. //根据手机号获取这些用户的信息
  286. listUser, e := models.GetWxUserOutboundMobiles(mobiles)
  287. if e != nil {
  288. err = errors.New("GetWxUserOutboundMobiles, Err: " + e.Error())
  289. return
  290. }
  291. mapUser := make(map[string]*models.WxUserOutboundMobile)
  292. for _, v := range listUser {
  293. mapUser[v.Mobile] = v
  294. mapUser[v.OutboundMobile] = v
  295. }
  296. var updateActivityIds []int // 需要更新的活动ID
  297. var updateActivityIdsMap = make(map[int]bool) // 需要更新的活动ID
  298. for k, v := range needAddAttendanc {
  299. if needAddAttendanc[k].CompanyId == 0 && mapUser[v.Mobile] != nil {
  300. needAddAttendanc[k].CompanyId = mapUser[v.Mobile].CompanyId
  301. needAddAttendanc[k].SellerName = mapUser[v.Mobile].SellerName
  302. needAddAttendanc[k].CompanyName = mapUser[v.Mobile].CompanyName
  303. needAddAttendanc[k].IsMeetingStr = 1
  304. }
  305. if !updateActivityIdsMap[v.ActivityId] {
  306. updateActivityIds = append(updateActivityIds, v.ActivityId)
  307. updateActivityIdsMap[v.ActivityId] = true
  308. }
  309. attendanceDetailList = append(attendanceDetailList, v)
  310. }
  311. if len(updateActivityIds) == 0 {
  312. return
  313. }
  314. // 更新需要长时间同步到会信息的活动
  315. if activityIdsLongTime != "" {
  316. activityIdsLongTime = strings.TrimRight(activityIdsLongTime, ",")
  317. activityIdsLongTime = detail.ConfigValue + "," + activityIdsLongTime
  318. e = models.UpdateConfigByCode(activityIdsLongTime, configCode)
  319. if e != nil {
  320. err = errors.New("UpdateConfigByCode, Err: " + e.Error())
  321. return
  322. }
  323. }
  324. //return
  325. {
  326. //参会记录
  327. e = models.AddAttendancDetailNew(needAddAttendanc, updateActivityIds)
  328. if e != nil {
  329. err = errors.New("AddAttendancDetailNew, Err: " + e.Error())
  330. return err
  331. }
  332. }
  333. {
  334. //标记到会信息
  335. e = models.UpdateCygxActivitySignupIsMeeting(needAddAttendanc)
  336. if e != nil {
  337. err = errors.New("UpdateCygxActivitySignupIsMeeting, Err: " + e.Error())
  338. return err
  339. }
  340. }
  341. {
  342. //处理是否限制报名
  343. AddCygxActivityRestrictSignupByAdminNew(updateActivityIds)
  344. }
  345. {
  346. //通过进门财经添加用户参数信息
  347. AddctivitySignupDetailByJmcjNew(needAddAttendanc, updateActivityIds)
  348. }
  349. {
  350. //添加报名日志 (对个人以及机构互动数量进行排序下载使用)
  351. CygxActivityMeetSort(needAddAttendanc, updateActivityIds)
  352. }
  353. return
  354. }
  355. // 查研观向处理活动用户限制报名
  356. func AddCygxActivityRestrictSignupByAdminNew(activityIds []int) (err error) {
  357. defer func() {
  358. if err != nil {
  359. fmt.Println("err:", err)
  360. go utils.SendAlarmMsg("查研观向处理活动用户限制报名失败,AddCygxActivityRestrictSignupByAdminNew,Err:"+err.Error()+"activityIds"+fmt.Sprint(activityIds), 3)
  361. }
  362. }()
  363. var condition string
  364. var pars []interface{}
  365. lenactivityIds := len(activityIds)
  366. if lenactivityIds == 0 {
  367. return
  368. }
  369. condition = ` AND is_meeting = 1 AND activity_id IN (` + utils.GetOrmInReplace(lenactivityIds) + `)`
  370. pars = append(pars, activityIds)
  371. //获取到会了的人员
  372. meetingList, e := models.GetActivitySignupList(condition, pars)
  373. if e != nil {
  374. err = errors.New("GetActivitySignupList" + e.Error())
  375. return
  376. }
  377. var userIdArr []int
  378. if len(meetingList) > 0 {
  379. for _, v := range meetingList {
  380. userIdArr = append(userIdArr, v.UserId)
  381. }
  382. lenuserIdArr := len(userIdArr)
  383. var condition string
  384. var pars []interface{}
  385. condition = ` AND user_id IN (` + utils.GetOrmInReplace(lenuserIdArr) + `)`
  386. pars = append(pars, userIdArr)
  387. restrictSignupList, e := models.GetCygxActivityRestrictSignupList(condition, pars, 0, 9999)
  388. if e != nil {
  389. err = errors.New("GetCygxActivityRestrictSignupList" + e.Error())
  390. return
  391. }
  392. //获取这些用户是否被加入到限制报名了
  393. maptotalRestrict := make(map[int]bool)
  394. for _, v := range restrictSignupList {
  395. maptotalRestrict[v.UserId] = true
  396. }
  397. pars = make([]interface{}, 0)
  398. condition = ` AND a.is_limit_people = 1 AND v.is_meeting = 0 AND v.do_fail_type = 0 AND v.user_id IN (` + utils.GetOrmInReplace(lenuserIdArr) + `) AND a.activity_id IN (` + utils.GetOrmInReplace(lenactivityIds) + `)`
  399. pars = append(pars, userIdArr, activityIds)
  400. listSignup, e := models.GetActivitySignupInnerActivityList(condition, pars)
  401. if e != nil && e.Error() != utils.ErrNoRow() {
  402. err = errors.New("GetActivitySignupInnerActivityList" + e.Error())
  403. return
  404. }
  405. mapNomeet := make(map[int]int)
  406. if len(listSignup) > 0 {
  407. for _, v := range listSignup {
  408. mapNomeet[v.UserId]++
  409. }
  410. }
  411. var userIdDelArr []int
  412. for _, v := range meetingList {
  413. //如果加入了爽约限制但是爽约次数少于3条就删除爽约记录
  414. if maptotalRestrict[v.UserId] && mapNomeet[v.UserId] < 3 {
  415. userIdDelArr = append(userIdDelArr, v.UserId)
  416. }
  417. }
  418. //if len(userIdDelArr) > 0 {
  419. // e = models.DeleteCygxActivityRestrictSignupByUserIds(userIdDelArr)
  420. // if e != nil {
  421. // err = errors.New("DeleteCygxActivityRestrictSignupByUserIds" + e.Error())
  422. // return
  423. // }
  424. //}
  425. }
  426. //获取未到会的人员
  427. pars = make([]interface{}, 0)
  428. condition = ` AND v.is_meeting = 0 AND v.do_fail_type = 0 AND v.activity_id IN (` + utils.GetOrmInReplace(lenactivityIds) + `)`
  429. pars = append(pars, activityIds)
  430. nomeetingListlist, e := models.GetActivitySignupInnerActivityList(condition, pars)
  431. if e != nil {
  432. err = errors.New("GetActivitySignupNomeetingCountList" + e.Error())
  433. return
  434. }
  435. var userIdSiginArr []int
  436. var items []*models.CygxActivitySignupBreak
  437. for _, v := range nomeetingListlist {
  438. userIdSiginArr = append(userIdSiginArr, v.UserId)
  439. //添加爽约记录
  440. item := new(models.CygxActivitySignupBreak)
  441. item.UserId = v.UserId
  442. item.ActivityId = v.ActivityId
  443. item.CreateTime = time.Now()
  444. item.Mobile = v.Mobile
  445. item.Email = v.Email
  446. item.CompanyId = v.CompanyId
  447. item.CompanyName = v.CompanyName
  448. item.RealName = v.RealName
  449. item.SellerName = v.SellerName
  450. items = append(items, item)
  451. }
  452. lenuserIdSiginArr := len(userIdSiginArr)
  453. if lenuserIdSiginArr == 0 {
  454. return
  455. }
  456. var itemsRestrict []*models.CygxActivityRestrictSignup
  457. maptotalRestrict := make(map[int]bool)
  458. //var condition string
  459. pars = make([]interface{}, 0)
  460. condition = ""
  461. restrictSignupList, e := models.GetCygxActivityRestrictSignupList(condition, pars, 0, 9999)
  462. if e != nil {
  463. err = errors.New("GetCygxActivityRestrictSignupList" + e.Error())
  464. return
  465. }
  466. //获取这些用户是否被加入到限制报名了
  467. for _, v := range restrictSignupList {
  468. maptotalRestrict[v.UserId] = true
  469. }
  470. pars = make([]interface{}, 0)
  471. condition = ` AND a.is_limit_people = 1 AND v.is_meeting = 0 AND v.do_fail_type = 0 AND user_id IN (` + utils.GetOrmInReplace(lenuserIdSiginArr) + `)`
  472. pars = append(pars, userIdSiginArr)
  473. listSignup, e := models.GetActivitySignupInnerActivityList(condition, pars)
  474. if e != nil && e.Error() != utils.ErrNoRow() {
  475. err = errors.New("GetActivitySignupInnerActivityList" + e.Error())
  476. return
  477. }
  478. mapNomeet := make(map[int]int)
  479. if len(listSignup) > 0 {
  480. for _, v := range listSignup {
  481. mapNomeet[v.UserId]++
  482. }
  483. }
  484. for _, v := range meetingList {
  485. //如果加入了爽约限制但是爽约次数少于3条就删除爽约记录
  486. if !maptotalRestrict[v.UserId] && mapNomeet[v.UserId] >= 3 {
  487. itemRestrict := new(models.CygxActivityRestrictSignup)
  488. itemRestrict.UserId = v.UserId
  489. itemRestrict.CreateTime = time.Now()
  490. itemRestrict.Mobile = v.Mobile
  491. itemRestrict.Email = v.Email
  492. itemRestrict.CompanyId = v.CompanyId
  493. itemRestrict.CompanyName = v.CompanyName
  494. itemRestrict.IsRestrict = 1
  495. itemsRestrict = append(itemsRestrict, itemRestrict)
  496. maptotalRestrict[v.UserId] = true
  497. }
  498. }
  499. e = models.DeleteCygxActivitySignupBreakByIds(activityIds)
  500. if e != nil {
  501. err = errors.New("DeleteCygxActivitySignupBreakById" + e.Error())
  502. return
  503. }
  504. //添加爽约记录
  505. if len(items) > 0 {
  506. _, e = models.AddCygxActivitySignupBreakList(items)
  507. if e != nil {
  508. err = errors.New("AddCygxActivitySignupBreakList, Err: " + e.Error())
  509. return
  510. }
  511. }
  512. //添加报名限制
  513. if len(itemsRestrict) > 0 {
  514. _, e = models.AddCygxActivityRestrictSignupList(itemsRestrict)
  515. if e != nil {
  516. err = errors.New("AddCygxActivityRestrictSignupList, Err: " + e.Error())
  517. return
  518. }
  519. }
  520. return
  521. }
  522. // 对个人以及机构互动数量进行排序下载使用
  523. func CygxActivityMeetSort(list []*models.CygxActivityAttendanceDetail, activityIds []int) (err error) {
  524. defer func() {
  525. if err != nil {
  526. fmt.Println("err:", err)
  527. go utils.SendAlarmMsg("查研观向处理活动用户限制报名失败,AddCygxActivityRestrictSignupByAdminNew,Err:"+err.Error()+"activityIds"+fmt.Sprint(activityIds), 3)
  528. }
  529. }()
  530. var items []*models.CygxActivityMeetDetailLog
  531. var condition string
  532. var pars []interface{}
  533. lenactivityIds := len(activityIds)
  534. if lenactivityIds == 0 {
  535. return
  536. }
  537. //获取已经写入到会信息的参会人员
  538. pars = make([]interface{}, 0)
  539. condition = ` AND activity_id IN (` + utils.GetOrmInReplace(lenactivityIds) + `)`
  540. pars = append(pars, activityIds)
  541. activityMeetDetailLogList, e := models.GetCygxActivityMeetDetailLogList(condition, pars)
  542. if e != nil {
  543. err = errors.New("GetCygxActivityMeetDetailLogList, Err: " + e.Error())
  544. return
  545. }
  546. mapActivityMeetDetailL := make(map[string]int)
  547. for _, v := range activityMeetDetailLogList {
  548. mapActivityMeetDetailL[fmt.Sprint("ActivityId:", v.ActivityId, "Mobile:", v.Mobile)] = v.ActivityId
  549. }
  550. var companyIds []int
  551. var companyIdsMap = make(map[int]bool)
  552. var mobiles []string
  553. var mobilesMap = make(map[string]bool)
  554. for _, v := range list {
  555. if mapActivityMeetDetailL[fmt.Sprint("ActivityId:", v.ActivityId, "Mobile:", v.Mobile)] > 0 {
  556. continue
  557. }
  558. item := new(models.CygxActivityMeetDetailLog)
  559. item.ActivityId = v.ActivityId
  560. item.Mobile = v.Mobile
  561. item.CompanyName = v.CompanyName
  562. item.CompanyId = v.CompanyId
  563. item.ActivityTime = v.ActivityTime
  564. item.CreateTime = v.CreateTime
  565. if !companyIdsMap[v.CompanyId] {
  566. companyIds = append(companyIds, v.CompanyId)
  567. }
  568. if !mobilesMap[v.Mobile] {
  569. mobiles = append(mobiles, v.Mobile)
  570. }
  571. items = append(items, item)
  572. }
  573. //插入
  574. e = models.AddCygxActivityMeetDetailLogMulti(items)
  575. if e != nil {
  576. err = errors.New("AddCygxActivityMeetDetailLogMulti, Err: " + e.Error())
  577. return
  578. }
  579. {
  580. //批量修改个人参会数量
  581. listMobileCount, e := models.GetActivityMeetDetailLogCountMobile(mobiles)
  582. if e != nil {
  583. err = errors.New("GetActivityMeetDetailLogCountCompany, Err: " + e.Error())
  584. return
  585. }
  586. if len(listMobileCount) > 0 {
  587. e = models.UpdateCygxActivityMeetDetailLogMobileNumMulti(listMobileCount)
  588. if e != nil {
  589. err = errors.New("UpdateCygxActivityMeetDetailLogMobileNumMulti, Err: " + e.Error())
  590. return
  591. }
  592. }
  593. }
  594. {
  595. //批量修改机构参会数量
  596. listCompanyCount, e := models.GetActivityMeetDetailLogCountCompany(companyIds)
  597. if e != nil {
  598. err = errors.New("GetActivityMeetDetailLogCountCompany, Err: " + e.Error())
  599. return
  600. }
  601. if len(listCompanyCount) > 0 {
  602. e = models.UpdateCygxActivityMeetDetailLogCompanyNumMulti(listCompanyCount)
  603. if e != nil {
  604. err = errors.New("UpdateCygxActivityMeetDetailLogCompanyNumMulti, Err: " + e.Error())
  605. return
  606. }
  607. }
  608. }
  609. return
  610. }