activity_button.go 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. package services
  2. import (
  3. "errors"
  4. "hongze/hongze_cygx/models"
  5. "hongze/hongze_cygx/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. mapActivityVideo, e := GetActivityVideoResp(mapActivityId)
  255. if e != nil {
  256. err = errors.New("GetActivityVoiceResp, Err: " + e.Error())
  257. return
  258. }
  259. //处理不同的报名方式按钮回显
  260. mapActivitySignup, e := GetActivitySignupResp(mapActivityId, user)
  261. if e != nil {
  262. e = errors.New("mapActivitySignup, 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, ActivityButtonShow(v))
  278. }
  279. return
  280. }