互动
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
3.4 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package pc
  2. import (
  3. "fmt"
  4. "hudongzhuanjia/controllers"
  5. "hudongzhuanjia/models"
  6. "hudongzhuanjia/utils/code"
  7. "hudongzhuanjia/utils/define"
  8. "time"
  9. )
  10. //活动
  11. type ActivityCtl struct {
  12. controllers.AuthorCtl
  13. //controllers.BaseCtl
  14. }
  15. func (t *ActivityCtl) StartActivity() {
  16. activityId := t.MustGetInt64("activity_id")
  17. mode := t.MustGetInt("mode") // 标识彩排 mode=0正式 mode=1彩排
  18. uid := t.MustGetUID()
  19. limit := t.DefaultInt64("limit", 10)
  20. activity := new(models.Activity)
  21. exist, err := models.Get(activity, activityId)
  22. t.CheckErr(err)
  23. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  24. // 检测活动状态 ==》 必须为未开始
  25. if activity.Status != define.StatusNotBegin {
  26. t.ERROR(fmt.Sprintf("该活动状态%s", activity.Status), code.MSG_ERR)
  27. }
  28. // 检测彩排活动是否进行中
  29. if activity.RehearsalId != 0 {
  30. t.ERROR("该活动在彩排中", code.MSG_ERR)
  31. }
  32. if mode == 1 {
  33. rehearsal := models.Rehearsal{
  34. CustomerId: uid,
  35. ActivityId: activityId,
  36. LimitNumber: limit,
  37. Status: 1,
  38. IsDelete: false,
  39. }
  40. _, err = models.Add(rehearsal)
  41. t.CheckErr(err)
  42. activity.RehearsalId = rehearsal.Id
  43. }
  44. activity.Status = define.StatusRunning
  45. activity.UpdatedAt = time.Now()
  46. // todo: 校验
  47. _, err = models.Update(activity.Id, "status", "rehearsal_id")
  48. t.CheckErr(err)
  49. t.JSON(map[string]interface{}{
  50. "rehearsal_id": activity.RehearsalId,
  51. })
  52. }
  53. func (t *ActivityCtl) StopActivity() {
  54. activityId := t.MustGetInt64("activity_id")
  55. activity := new(models.Activity)
  56. exist, err := models.Get(activity, activityId)
  57. t.CheckErr(err)
  58. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  59. if activity.Status != define.StatusRunning {
  60. t.ERROR(fmt.Sprintf("该活动%s", activity.Status), code.MSG_ERR)
  61. }
  62. if activity.RehearsalId != 0 { // 彩排回归最初结果
  63. // 竞拍
  64. _, err = models.UpdateAuctionStatusByActivityId(activityId)
  65. t.CheckErr(err)
  66. // 抽奖 -> 抽奖活动->抽奖规则-> 抽奖阶梯
  67. lotteryIds, err := models.GetLDActivityIdsByActivityId(activityId)
  68. t.CheckErr(err)
  69. lotteryRuleIds, err := models.GetLDRuleIdsByLDActivityId(lotteryIds)
  70. t.CheckErr(err)
  71. _, err = models.UpdateLDLadderStatusByLDRuleIds(lotteryRuleIds)
  72. t.CheckErr(err)
  73. // 订单抽奖-> 订单抽奖活动->抽奖规则->抽奖阶梯
  74. orderIds, err := models.GetODActivityIdsByActivityId(activityId)
  75. t.CheckErr(err)
  76. orderRuleIds, err := models.GetODRuleIdsByODActivityIds(orderIds)
  77. t.CheckErr(err)
  78. _, err = models.UpdateODLadderStatusByODRuleIds(orderRuleIds)
  79. t.CheckErr(err)
  80. // 摇红包->摇红包活动->摇红包规则
  81. shakeRbIds, err := models.GetSREActivityIdsByActivityId(activityId)
  82. t.CheckErr(err)
  83. _, err = models.UpdateSRERuleStatusBySREActivityIds(shakeRbIds)
  84. t.CheckErr(err)
  85. // 拔河->拔河活动
  86. _, err = models.UpdateTOWStatusByActivityId(activityId)
  87. t.CheckErr(err)
  88. // 投票->投票活动
  89. _, err = models.UpdateVoteStatusByActiviytId(activityId)
  90. t.CheckErr(err)
  91. // 卡路里->卡路里活动
  92. _, err = models.UpdateCalorieStatusByActivityId(activityId)
  93. t.CheckErr(err)
  94. // 订单开启
  95. _, err = new(models.CustomerOrderOption).Switch(activityId, 0)
  96. t.CheckErr(err)
  97. activity.Status = define.StatusNotBegin
  98. } else {
  99. activity.Status = define.StatusEnding
  100. }
  101. activity.RehearsalId = 0
  102. _, err = models.Update(activity.Id, activity, "status", "rehearsal_id")
  103. t.CheckErr(err)
  104. t.SUCCESS("success")
  105. }