activity_points.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_clpt/models"
  6. "hongze/hongze_clpt/utils"
  7. "strconv"
  8. "time"
  9. )
  10. //func init() {
  11. // GetActivityPointsByUserAllMap()
  12. //}
  13. // GetActivityPointsByUserAllMap 获取所有针对用户扣点的活动
  14. func GetActivityPointsByUserAllMap() (mapResp map[int]bool) {
  15. var err error
  16. defer func() {
  17. if err != nil {
  18. fmt.Println(err)
  19. go utils.SendAlarmMsg("GetActivityPointsByUserAllMap,Err:"+err.Error(), 2)
  20. }
  21. }()
  22. var condition string
  23. var pars []interface{}
  24. //获取所有研选类型的活动
  25. condition = ` AND chart_permission_id = ` + strconv.Itoa(utils.CHART_PERMISSION_ID_YANXUAN)
  26. listActivity, e := models.GetActivityListByCondition(condition, pars)
  27. if e != nil {
  28. err = errors.New("GetActivityListByCondition, Err: " + e.Error())
  29. return
  30. }
  31. var activityIds []int
  32. condition = ""
  33. pars = make([]interface{}, 0)
  34. for _, v := range listActivity {
  35. activityIds = append(activityIds, v.ActivityId)
  36. }
  37. condition += ` AND points_object IN (1,3) `
  38. condition += ` AND activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `) `
  39. pars = append(pars, activityIds)
  40. list, e := models.GetCygxActivityPointsSetList(condition, pars, 0, 0)
  41. if e != nil {
  42. err = errors.New("GetCygxActivityPointsSetList, Err: " + e.Error())
  43. return
  44. }
  45. mapResp = make(map[int]bool, 0)
  46. for _, v := range list {
  47. mapResp[v.ActivityId] = true
  48. }
  49. return
  50. }
  51. // 用户报名添加到处理研选扣点
  52. func YanXuanActivityPointsBillSignupAdd(activityId, uid int) (err error) {
  53. defer func() {
  54. if err != nil {
  55. fmt.Println(err)
  56. msg := fmt.Sprint("activityId:", activityId, "userId:", uid)
  57. go utils.SendAlarmMsg("用户报名添加到处理研选扣点,写入Redis队列消息失败:"+err.Error()+msg, 2)
  58. }
  59. }()
  60. //SourceType int `description:"1:报名、 2:取消报名、3:活动编辑、4:活动发布,取消发布、5:活动到会。"`
  61. log := &models.YanXuanActivityPointsRedis{UserId: uid, ActivityId: activityId, SourceType: 1, RegisterPlatform: utils.REGISTER_PLATFORM, Source: 1, CreateTime: time.Now()}
  62. if utils.Re == nil {
  63. err := utils.Rc.LPush(utils.CYGX_YANXUAN_POINTS_KEY, log)
  64. if err != nil {
  65. fmt.Println("YanXuanActivityPointsRedis LPush Err:" + err.Error())
  66. }
  67. }
  68. return
  69. }
  70. // 用户取消报名添加到处理研选扣点
  71. func YanXuanActivityPointsBillSignupCancel(activityId, uid int) (err error) {
  72. defer func() {
  73. if err != nil {
  74. fmt.Println(err)
  75. msg := fmt.Sprint("activityId:", activityId, "userId:", uid)
  76. go utils.SendAlarmMsg("用户取消报名添加到处理研选扣点,写入Redis队列消息失败:"+err.Error()+msg, 2)
  77. }
  78. }()
  79. //SourceType int `description:"1:报名、 2:取消报名、3:活动编辑、4:活动发布,取消发布、5:活动到会。"`
  80. log := &models.YanXuanActivityPointsRedis{UserId: uid, ActivityId: activityId, SourceType: 2, RegisterPlatform: utils.REGISTER_PLATFORM, Source: 1, CreateTime: time.Now()}
  81. if utils.Re == nil {
  82. err := utils.Rc.LPush(utils.CYGX_YANXUAN_POINTS_KEY, log)
  83. if err != nil {
  84. fmt.Println("YanXuanActivityPointsRedis LPush Err:" + err.Error())
  85. }
  86. }
  87. return
  88. }