互动
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.

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