activity_my_schedule.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package services
  2. import (
  3. "errors"
  4. "hongze/hongze_mfyx/models"
  5. "hongze/hongze_mfyx/utils"
  6. "strconv"
  7. "time"
  8. )
  9. // 我的日程 GetScheduleAndSpecilList
  10. func GetScheduleAndSpecilList(user *models.WxUserItem, condition string, startSize, pageSize int) (items []*models.ActivityDetail, err error) {
  11. var conditionSpecil string
  12. var pars, parsSpecil []interface{}
  13. condition += ` AND my.user_id = ?`
  14. pars = append(pars, user.UserId)
  15. conditionSpecil += ` AND my.user_id = ? AND my.is_cancel = 0 `
  16. parsSpecil = append(parsSpecil, user.UserId)
  17. list, e := models.GetScheduleAndSpecilList(condition, pars, conditionSpecil, parsSpecil, startSize, pageSize)
  18. if e != nil {
  19. err = errors.New("GetScheduleAndSpecilList, Err: " + e.Error())
  20. return
  21. }
  22. var activityIds []int
  23. var activitySpecilalIds []int
  24. for k, v := range list {
  25. if v.SourceType == 2 {
  26. activitySpecilalIds = append(activitySpecilalIds, v.ActivityId)
  27. //把专项调研的线下改为活动的线下类型
  28. if v.ActivityType == 2 {
  29. list[k].ActivityType = 0
  30. }
  31. list[k].IsShowSignup = true
  32. } else {
  33. activityIds = append(activityIds, v.ActivityId)
  34. }
  35. }
  36. //处理活动
  37. if len(activityIds) > 0 {
  38. //处理用户是否报名
  39. mapSignUp, e := GetActivitySignUpUserMap(activityIds, user)
  40. if e != nil {
  41. err = errors.New("GetActivitySignUpUserMap, Err: " + e.Error())
  42. return
  43. }
  44. for k, v := range list {
  45. if v.SourceType != 2 {
  46. if _, ok := mapSignUp[v.ActivityId]; ok {
  47. list[k].IsSignup = 1
  48. }
  49. }
  50. }
  51. //处理用户是否预约纪要
  52. mapAppointment, e := GetActivityAppointmentUserMap(activityIds, user)
  53. if e != nil {
  54. err = errors.New("GetActivityAppointmentUserMap, Err: " + e.Error())
  55. return
  56. }
  57. for k, v := range list {
  58. if v.SourceType != 2 {
  59. if _, ok := mapAppointment[v.ActivityId]; ok {
  60. list[k].IsAppointment = 1
  61. }
  62. }
  63. }
  64. //处理用户是否预约会议提醒
  65. mapReminder, e := GetActivityReminderUserMasp(activityIds, user)
  66. if e != nil {
  67. err = errors.New("GetActivityReminderUserMasp, Err: " + e.Error())
  68. return
  69. }
  70. for k, v := range list {
  71. if v.SourceType != 2 {
  72. if _, ok := mapReminder[v.ActivityId]; ok {
  73. list[k].IsCancelMeetingReminder = 1
  74. }
  75. }
  76. }
  77. }
  78. //处理专项产业调研
  79. if len(activitySpecilalIds) > 0 {
  80. //处理用户是否报名
  81. for k, v := range list {
  82. if v.SourceType == 2 {
  83. resultTimeStart := utils.StrTimeToTime(v.ActivityTime) //时间字符串格式转时间格式
  84. resultTimeEnd := utils.StrTimeToTime(v.ActivityTimeEnd) //时间字符串格式转时间格式
  85. if resultTimeStart.After(time.Now()) {
  86. list[k].ActiveState = strconv.Itoa(1)
  87. } else if time.Now().After(resultTimeEnd) {
  88. list[k].ActiveState = strconv.Itoa(3)
  89. } else {
  90. list[k].ActiveState = strconv.Itoa(2)
  91. }
  92. }
  93. }
  94. }
  95. items = list
  96. return
  97. }