activity_button.go 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. package services
  2. import (
  3. "errors"
  4. "hongze/hongze_mfyx/models"
  5. "hongze/hongze_mfyx/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. for k, v := range list {
  144. if v.SourceType == 2 {
  145. resultTimeStart := utils.StrTimeToTime(v.ActivityTime) //时间字符串格式转时间格式
  146. resultTimeEnd := utils.StrTimeToTime(v.ActivityTimeEnd) //时间字符串格式转时间格式
  147. if resultTimeStart.After(time.Now()) {
  148. list[k].ActiveState = strconv.Itoa(1)
  149. } else if time.Now().After(resultTimeEnd) {
  150. list[k].ActiveState = strconv.Itoa(3)
  151. } else {
  152. list[k].ActiveState = strconv.Itoa(2)
  153. }
  154. }
  155. }
  156. }
  157. //var isShow bool
  158. isShow, e := GetShowSustainableNew()
  159. if e != nil {
  160. err = errors.New("GetShowSustainableNew, Err: " + e.Error())
  161. return
  162. }
  163. detail, e := models.GetConfigByCode("city_img_url")
  164. if e != nil {
  165. err = errors.New("GetConfigByCode, Err: " + e.Error())
  166. return
  167. }
  168. detailChart, e := models.GetConfigByCode("chart_img_url")
  169. if e != nil {
  170. err = errors.New("GetConfigByCode, Err: " + e.Error())
  171. return
  172. }
  173. addressList := strings.Split(detail.ConfigValue, "{|}")
  174. mapAddress := make(map[string]string)
  175. chartList := strings.Split(detailChart.ConfigValue, "{|}")
  176. mapChart := make(map[string]string)
  177. var cityName string
  178. var chartName string
  179. var imgUrl string
  180. var imgUrlChart string
  181. var mapActivityId []int
  182. for _, v := range addressList {
  183. vslice := strings.Split(v, "_")
  184. cityName = vslice[0]
  185. imgUrl = vslice[len(vslice)-1]
  186. mapAddress[cityName] = imgUrl
  187. }
  188. for _, v := range chartList {
  189. vslice := strings.Split(v, "_")
  190. chartName = vslice[0]
  191. imgUrlChart = vslice[len(vslice)-1]
  192. mapChart[chartName] = imgUrlChart
  193. }
  194. for k, v := range list {
  195. if strings.Contains(v.ActivityName, "【") {
  196. list[k].IsBrackets = 1
  197. }
  198. if v.SignupNum > v.LimitPeopleNum {
  199. list[k].SignupNum = v.LimitPeopleNum
  200. }
  201. if isShow && strings.Contains(v.ChartPermissionName, "研选") {
  202. list[k].IsShowSustainable = true
  203. }
  204. if strings.Contains(v.ChartPermissionName, "研选") && v.ActivityTypeId == 1 {
  205. list[k].ActivityTypeName = "买方研选电话会"
  206. list[k].ImgUrlText = utils.YAN_XUAN_IMG
  207. }
  208. if v.SourceType == 1 {
  209. if v.ActivityType == 0 {
  210. if mapAddress[v.City] != "" {
  211. list[k].ImgUrl = mapAddress[v.City]
  212. } else {
  213. list[k].ImgUrl = mapAddress["其它"]
  214. }
  215. } else {
  216. if mapChart[v.ChartPermissionName] != "" {
  217. list[k].ImgUrl = mapChart[v.ChartPermissionName]
  218. }
  219. }
  220. } else {
  221. if mapChart[v.ChartPermissionName] != "" {
  222. list[k].ImgUrl = mapChart[v.ChartPermissionName]
  223. }
  224. }
  225. expertTxt, _ := GetReportContentTextSub(v.Expert)
  226. list[k].Expert = expertTxt
  227. if v.IsHideAppointment == 0 {
  228. list[k].IsShowAppointment = IsShowAppointment(v.ActivityTypeId, v.ChartPermissionName)
  229. }
  230. if v.ActivityTypeId == utils.C_CLASS_ACTIVITY_TYPE_ID {
  231. list[k].IsCClassMeeting = true
  232. }
  233. mapActivityId = append(mapActivityId, v.ActivityId)
  234. }
  235. //处理音频回放
  236. mapActivityVoice, e := GetActivityVoiceResp(mapActivityId)
  237. if e != nil {
  238. err = errors.New("GetActivityVoiceResp, Err: " + e.Error())
  239. return
  240. }
  241. //处理视频回放
  242. mapActivityVideo, e := GetActivityVideoResp(mapActivityId)
  243. if e != nil {
  244. err = errors.New("GetActivityVoiceResp, Err: " + e.Error())
  245. return
  246. }
  247. //处理不同的报名方式按钮回显
  248. mapActivitySignup, e := GetActivitySignupResp(mapActivityId, user)
  249. if e != nil {
  250. e = errors.New("mapActivitySignup, Err: " + e.Error())
  251. return
  252. }
  253. for k, v := range list {
  254. if mapActivityVoice[v.ActivityId] != nil {
  255. list[k].FileType = 1
  256. list[k].AudioLink = true
  257. list[k].VoiceList = mapActivityVoice[v.ActivityId]
  258. }
  259. if mapActivityVideo[v.ActivityId] != nil {
  260. list[k].FileType = 2
  261. list[k].AudioLink = true
  262. list[k].VideoDetail = mapActivityVideo[v.ActivityId]
  263. }
  264. v.SignupType = mapActivitySignup[v.ActivityId]
  265. items = append(items, ActivityButtonShow(v))
  266. }
  267. return
  268. }