activity_button.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. package services
  2. import (
  3. "errors"
  4. "hongze/hongze_clpt/models"
  5. "hongze/hongze_clpt/utils"
  6. "strconv"
  7. "strings"
  8. "time"
  9. )
  10. // 获取用户已经报名的活动
  11. func GetActivitySignUpUserMap(activityIds []int, user *models.WxUserItem) (mapUserId map[int]int, err error) {
  12. userId := user.UserId
  13. var condition string
  14. var pars []interface{}
  15. activityIdsLen := len(activityIds)
  16. if activityIdsLen > 0 {
  17. condition += ` AND activity_id IN (` + utils.GetOrmInReplace(activityIdsLen) + `)`
  18. pars = append(pars, activityIds)
  19. }
  20. condition += ` AND user_id = ? AND do_fail_type = 0 `
  21. pars = append(pars, userId)
  22. list, e := models.GetActivitySignuListByUser(condition, pars)
  23. if e != nil {
  24. err = errors.New("GetCygxActivitySpecialTripList, Err: " + e.Error())
  25. return
  26. }
  27. mapUid := make(map[int]int)
  28. for _, v := range list {
  29. mapUid[v.ActivityId] = v.UserId
  30. }
  31. mapUserId = mapUid
  32. return
  33. }
  34. // 获取用户已经设置会议提醒的活动 cygx_activity_meeting_reminder
  35. func GetActivityReminderUserMasp(activityIds []int, user *models.WxUserItem) (mapUserId map[int]int, err error) {
  36. userId := user.UserId
  37. var condition string
  38. var pars []interface{}
  39. activityIdsLen := len(activityIds)
  40. if activityIdsLen > 0 {
  41. condition += ` AND activity_id IN (` + utils.GetOrmInReplace(activityIdsLen) + `)`
  42. pars = append(pars, activityIds)
  43. }
  44. condition += ` AND user_id = ? `
  45. pars = append(pars, userId)
  46. list, e := models.GetCygxReminderListByUser(condition, pars)
  47. if e != nil {
  48. err = errors.New("GetCygxReminderListByUser, Err: " + e.Error())
  49. return
  50. }
  51. mapUid := make(map[int]int)
  52. for _, v := range list {
  53. mapUid[v.ActivityId] = v.UserId
  54. }
  55. mapUserId = mapUid
  56. return
  57. }
  58. // 获取用户已经预约纪要的活动
  59. func GetActivityAppointmentUserMap(activityIds []int, user *models.WxUserItem) (mapUserId map[int]int, err error) {
  60. userId := user.UserId
  61. var condition string
  62. var pars []interface{}
  63. activityIdsLen := len(activityIds)
  64. if activityIdsLen > 0 {
  65. condition += ` AND activity_id IN (` + utils.GetOrmInReplace(activityIdsLen) + `)`
  66. pars = append(pars, activityIds)
  67. }
  68. condition += ` AND user_id = ? `
  69. pars = append(pars, userId)
  70. list, e := models.GetCygxAppointmentListByUser(condition, pars)
  71. if e != nil {
  72. err = errors.New("GetCygxActivitySpecialTripList, Err: " + e.Error())
  73. return
  74. }
  75. mapUid := make(map[int]int)
  76. for _, v := range list {
  77. mapUid[v.ActivityId] = v.UserId
  78. }
  79. mapUserId = mapUid
  80. return
  81. }
  82. // 活动列表的展示 HandleActivityListButton
  83. func HandleActivityListButton(list []*models.ActivityDetail, user *models.WxUserItem) (items []*models.ActivityDetail, err error) {
  84. var activityIds []int
  85. var activitySpecilalIds []int
  86. for k, v := range list {
  87. if v.SourceType == 2 {
  88. activitySpecilalIds = append(activitySpecilalIds, v.ActivityId)
  89. //把专项调研的线下改为活动的线下类型
  90. if v.ActivityType == 2 {
  91. list[k].ActivityType = 0
  92. }
  93. list[k].IsShowSignup = true
  94. } else {
  95. activityIds = append(activityIds, v.ActivityId)
  96. }
  97. }
  98. //处理活动
  99. if len(activityIds) > 0 {
  100. //处理用户是否报名
  101. mapSignUp, e := GetActivitySignUpUserMap(activityIds, user)
  102. if e != nil {
  103. err = errors.New("GetActivitySignUpUserMap, Err: " + e.Error())
  104. return
  105. }
  106. for k, v := range list {
  107. if v.SourceType != 2 {
  108. if _, ok := mapSignUp[v.ActivityId]; ok {
  109. list[k].IsSignup = 1
  110. }
  111. }
  112. }
  113. //处理用户是否预约纪要
  114. mapAppointment, e := GetActivityAppointmentUserMap(activityIds, user)
  115. if e != nil {
  116. err = errors.New("GetActivityAppointmentUserMap, Err: " + e.Error())
  117. return
  118. }
  119. for k, v := range list {
  120. if v.SourceType != 2 {
  121. if _, ok := mapAppointment[v.ActivityId]; ok {
  122. list[k].IsAppointment = 1
  123. }
  124. }
  125. }
  126. //处理用户是否预约会议提醒
  127. mapReminder, e := GetActivityReminderUserMasp(activityIds, user)
  128. if e != nil {
  129. err = errors.New("GetActivityReminderUserMasp, Err: " + e.Error())
  130. return
  131. }
  132. for k, v := range list {
  133. if v.SourceType != 2 {
  134. if _, ok := mapReminder[v.ActivityId]; ok {
  135. list[k].IsCancelMeetingReminder = 1
  136. }
  137. }
  138. }
  139. }
  140. //处理专项产业调研
  141. if len(activitySpecilalIds) > 0 {
  142. //处理用户是否报名
  143. UserMap, e := GetSpecialTripUserMap(activitySpecilalIds, user.UserId)
  144. if e != nil {
  145. err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  146. return
  147. }
  148. for k, v := range list {
  149. if v.SourceType == 2 {
  150. if _, ok := UserMap[v.ActivityId]; ok {
  151. list[k].IsSignup = 1
  152. }
  153. }
  154. }
  155. for k, v := range list {
  156. if v.SourceType == 2 {
  157. resultTimeStart := utils.StrTimeToTime(v.ActivityTime) //时间字符串格式转时间格式
  158. resultTimeEnd := utils.StrTimeToTime(v.ActivityTimeEnd) //时间字符串格式转时间格式
  159. if resultTimeStart.After(time.Now()) {
  160. list[k].ActiveState = strconv.Itoa(1)
  161. } else if time.Now().After(resultTimeEnd) {
  162. list[k].ActiveState = strconv.Itoa(3)
  163. } else {
  164. list[k].ActiveState = strconv.Itoa(2)
  165. }
  166. }
  167. }
  168. }
  169. //var isShow bool
  170. isShow, e := GetShowSustainableNew()
  171. if e != nil {
  172. err = errors.New("GetShowSustainableNew, Err: " + e.Error())
  173. return
  174. }
  175. detail, e := models.GetConfigByCode("city_img_url")
  176. if e != nil {
  177. err = errors.New("GetConfigByCode, Err: " + e.Error())
  178. return
  179. }
  180. detailChart, e := models.GetConfigByCode("chart_img_url")
  181. if e != nil {
  182. err = errors.New("GetConfigByCode, Err: " + e.Error())
  183. return
  184. }
  185. addressList := strings.Split(detail.ConfigValue, "{|}")
  186. mapAddress := make(map[string]string)
  187. chartList := strings.Split(detailChart.ConfigValue, "{|}")
  188. mapChart := make(map[string]string)
  189. var cityName string
  190. var chartName string
  191. var imgUrl string
  192. var imgUrlChart string
  193. var mapActivityId []int
  194. for _, v := range addressList {
  195. vslice := strings.Split(v, "_")
  196. cityName = vslice[0]
  197. imgUrl = vslice[len(vslice)-1]
  198. mapAddress[cityName] = imgUrl
  199. }
  200. for _, v := range chartList {
  201. vslice := strings.Split(v, "_")
  202. chartName = vslice[0]
  203. imgUrlChart = vslice[len(vslice)-1]
  204. mapChart[chartName] = imgUrlChart
  205. }
  206. for k, v := range list {
  207. if strings.Contains(v.ActivityName, "【") {
  208. list[k].IsBrackets = 1
  209. }
  210. if v.SignupNum > v.LimitPeopleNum {
  211. list[k].SignupNum = v.LimitPeopleNum
  212. }
  213. if isShow && strings.Contains(v.ChartPermissionName, "研选") {
  214. list[k].IsShowSustainable = true
  215. }
  216. if strings.Contains(v.ChartPermissionName, "研选") && v.ActivityTypeId == 1 {
  217. list[k].ActivityTypeName = "买方研选电话会"
  218. list[k].ImgUrlText = utils.YAN_XUAN_IMG
  219. }
  220. if v.SourceType == 1 {
  221. if v.ActivityType == 0 {
  222. if mapAddress[v.City] != "" {
  223. list[k].ImgUrl = mapAddress[v.City]
  224. } else {
  225. list[k].ImgUrl = mapAddress["其它"]
  226. }
  227. } else {
  228. if mapChart[v.ChartPermissionName] != "" {
  229. list[k].ImgUrl = mapChart[v.ChartPermissionName]
  230. }
  231. }
  232. } else {
  233. if mapChart[v.ChartPermissionName] != "" {
  234. list[k].ImgUrl = mapChart[v.ChartPermissionName]
  235. }
  236. }
  237. expertTxt, _ := GetReportContentTextSub(v.Expert)
  238. list[k].Expert = expertTxt
  239. if v.IsHideAppointment == 0 {
  240. list[k].IsShowAppointment = IsShowAppointment(v.ActivityTypeId, v.ChartPermissionName)
  241. }
  242. if v.ActivityTypeId == utils.C_CLASS_ACTIVITY_TYPE_ID {
  243. list[k].IsCClassMeeting = true
  244. }
  245. mapActivityId = append(mapActivityId, v.ActivityId)
  246. }
  247. //处理音频回放
  248. mapActivityVoice, e := GetActivityVoiceResp(mapActivityId)
  249. if e != nil {
  250. err = errors.New("GetActivityVoiceResp, Err: " + e.Error())
  251. return
  252. }
  253. //处理不同的报名方式按钮回显
  254. mapActivitySignup, e := GetActivitySignupResp(mapActivityId, user)
  255. if e != nil {
  256. err = errors.New("GetActivityVoiceResp, Err: " + e.Error())
  257. return
  258. }
  259. //处理视频回放
  260. mapActivityVideo, e := GetActivityVideoResp(mapActivityId)
  261. if e != nil {
  262. err = errors.New("GetActivityVoiceResp, Err: " + e.Error())
  263. return
  264. }
  265. for k, v := range list {
  266. if mapActivityVoice[v.ActivityId] != nil {
  267. list[k].FileType = 1
  268. list[k].AudioLink = true
  269. list[k].VoiceList = mapActivityVoice[v.ActivityId]
  270. }
  271. if mapActivityVideo[v.ActivityId] != nil {
  272. list[k].FileType = 2
  273. list[k].AudioLink = true
  274. list[k].VideoDetail = mapActivityVideo[v.ActivityId]
  275. }
  276. v.SignupType = mapActivitySignup[v.ActivityId]
  277. items = append(items, ActivityButtonShowSearch(v, user))
  278. }
  279. return
  280. }
  281. func ActivityButtonShowSearch(item *models.ActivityDetail, user *models.WxUserItem) (activityDetail *models.ActivityDetail) {
  282. activityDetail = item
  283. //IsShowAppointment bool `description:"是否展示预约纪要"`
  284. //IsShowOutboundCall bool `description:"是否展示预约外呼"`
  285. //IsShowMeetingReminder bool `description:"是否展示会议提醒"`
  286. //IsShowHelpSsk bool `description:"是否展示帮我带问"`
  287. //IsShowSignup bool `description:"是否展示我要报名"`
  288. //如果后台在添加活的时候,关联的报告类型不隐藏预约纪要按钮,而且满足以下展示预约纪要按钮类型就展示
  289. //if articleDetail.IsHideAppointment == 0 {
  290. // articleDetail.IsShowAppointment = IsShowAppointmentByactivityInfo(articleDetail, articleDetail.ChartPermissionName)
  291. //}
  292. activityPointsByUserAllMap := GetActivityPointsByUserAllMap() // 获取对用户进行研选扣点的活动
  293. activityDetail.IsResearchPoints = activityPointsByUserAllMap[activityDetail.ActivityId]
  294. if activityDetail.SiginupDeadline == utils.FormatDateTimeInit { //报名截止时间处理
  295. activityDetail.SiginupDeadline = ""
  296. }
  297. //如果报名截止时间不规范,或者是非研选扣点活动就把截止时间设置为空
  298. if activityDetail.CancelDeadline == utils.FormatDateTimeInit || !activityDetail.IsResearchPoints {
  299. activityDetail.CancelDeadline = ""
  300. }
  301. //articleDetail.SourceType = 1
  302. activityTimeText := activityDetail.ActivityTimeText
  303. activityTimeText = strings.Replace(activityTimeText, "(", "(", -1)
  304. activityTimeText = strings.Replace(activityTimeText, ")", ")", -1)
  305. activityDetail.ActivityTimeText = activityTimeText
  306. activityDetail.IsShowAppointment = false
  307. //易董的操作按钮都隐藏
  308. if activityDetail.YidongActivityId != "" {
  309. activityDetail.IsShowSignup = false
  310. activityDetail.IsShowDetails = true
  311. if activityDetail.YidongActivityId != "" {
  312. ydTgc, _ := GetYiDongCreateUserInfo(user)
  313. yidongLongLink, _ := GetYiDongOriginalLink(activityDetail)
  314. if yidongLongLink != "" {
  315. activityDetail.YidongActivityUrl = yidongLongLink + "%26source=11%26fromHz=true%26tgc=" + ydTgc
  316. }
  317. activityDetail.IsYidongActivity = true
  318. }
  319. } else {
  320. //专家电话会 1
  321. if activityDetail.ActivityTypeId == 1 && activityDetail.IsLimitPeople == 0 && (activityDetail.ActiveState == "1" || activityDetail.ActiveState == "2") {
  322. activityDetail.IsShowHelpSsk = true
  323. }
  324. if activityDetail.ActiveState == "1" {
  325. if activityDetail.IsCanAppointmentMinutes == 1 {
  326. activityDetail.IsShowAppointment = true
  327. }
  328. //专家电话会 1
  329. //专家电话会限制人数的展示我要报名,不限制的展示预约外外呼
  330. if activityDetail.ActivityTypeId == 1 {
  331. //articleDetail.IsShowOutboundCall = true
  332. if activityDetail.LimitPeopleNum == 0 {
  333. activityDetail.IsShowOutboundCall = true
  334. //articleDetail.IsShowHelpSsk = true
  335. } else {
  336. activityDetail.IsShowSignup = true
  337. }
  338. activityDetail.IsShowMeetingReminder = true
  339. activityDetail.IsShowHelpSsk = true
  340. }
  341. //分析师电话会 2
  342. if activityDetail.ActivityTypeId == 2 {
  343. if activityDetail.LimitPeopleNum == 0 {
  344. activityDetail.IsShowOutboundCall = true
  345. } else {
  346. activityDetail.IsShowSignup = true
  347. }
  348. activityDetail.IsShowMeetingReminder = true
  349. }
  350. //公司调研电话会 3
  351. if activityDetail.ActivityTypeId == 3 {
  352. //司调研电话会(3)、扣点的研选活动只展示我要报名
  353. if activityDetail.IsResearchPoints || activityDetail.LimitPeopleNum > 0 {
  354. activityDetail.IsShowSignup = true
  355. } else {
  356. activityDetail.IsShowMeetingReminder = true
  357. activityDetail.IsShowOutboundCall = true
  358. }
  359. }
  360. //公司线下调研 4
  361. if activityDetail.ActivityTypeId == 4 {
  362. activityDetail.IsShowSignup = true
  363. }
  364. //专家线下沙龙 5
  365. if activityDetail.ActivityTypeId == 5 {
  366. activityDetail.IsShowSignup = true
  367. }
  368. //分析师线下沙龙 6
  369. if activityDetail.ActivityTypeId == 6 {
  370. activityDetail.IsShowSignup = true
  371. }
  372. //分析师电话会(C类) 7
  373. if activityDetail.ActivityTypeId == 7 {
  374. activityDetail.IsShowSignup = true
  375. activityDetail.IsShowMeetingReminder = true
  376. }
  377. //买方线下交流 8 // 查研观向 11.0
  378. if activityDetail.ActivityTypeId == 8 {
  379. activityDetail.IsShowSignup = true
  380. }
  381. }
  382. }
  383. return
  384. }