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

134 lines
3.8 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
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. } else { //非彩排
  44. if activity.StartTime.After(time.Now()) {
  45. t.ERROR("互动设置开始时间尚未到,无法正式开始", code.MSG_ACTIVITY_NOT_EXIST)
  46. }
  47. arch := &models.Arch{}
  48. count, err := arch.Count(activity.Id)
  49. t.CheckErr(err)
  50. arch.Date = time.Now().Format("2006-01-02")
  51. arch.Name = fmt.Sprintf("第%d场", count)
  52. _, err = models.Update(activity.ArchId, arch, "name", "date")
  53. t.CheckErr(err)
  54. }
  55. activity.Status = define.StatusRunning
  56. _, err = models.Update(activity.Id, activity, "status", "rehearsal_id")
  57. t.CheckErr(err)
  58. t.JSON(map[string]interface{}{
  59. "rehearsal_id": activity.RehearsalId,
  60. })
  61. }
  62. func (t *ActivityCtl) StopActivity() {
  63. activityId := t.MustGetInt64("activity_id")
  64. activity := new(models.Activity)
  65. exist, err := models.Get(activity, activityId)
  66. t.CheckErr(err)
  67. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  68. if activity.Status != define.StatusRunning {
  69. t.ERROR(fmt.Sprintf("该活动%s", activity.Status), code.MSG_ERR)
  70. }
  71. if activity.RehearsalId != 0 { // 彩排回归最初结果
  72. // 竞拍
  73. _, err = models.UpdateAuctionStatusByActivityId(activityId)
  74. t.CheckErr(err)
  75. // 抽奖 -> 抽奖活动->抽奖规则-> 抽奖阶梯
  76. lotteryIds, err := models.GetLDActivityIdsByActivityId(activityId)
  77. t.CheckErr(err)
  78. lotteryRuleIds, err := models.GetLDRuleIdsByLDActivityId(lotteryIds)
  79. t.CheckErr(err)
  80. _, err = models.UpdateLDLadderStatusByLDRuleIds(lotteryRuleIds)
  81. t.CheckErr(err)
  82. // 订单抽奖-> 订单抽奖活动->抽奖规则->抽奖阶梯
  83. orderIds, err := models.GetODActivityIdsByActivityId(activityId)
  84. t.CheckErr(err)
  85. orderRuleIds, err := models.GetODRuleIdsByODActivityIds(orderIds)
  86. t.CheckErr(err)
  87. _, err = models.UpdateODLadderStatusByODRuleIds(orderRuleIds)
  88. t.CheckErr(err)
  89. // 摇红包->摇红包活动->摇红包规则
  90. shakeRbIds, err := models.GetSREActivityIdsByActivityId(activityId)
  91. t.CheckErr(err)
  92. _, err = models.UpdateSRERuleStatusBySREActivityIds(shakeRbIds)
  93. t.CheckErr(err)
  94. // 拔河->拔河活动
  95. _, err = models.UpdateTOWStatusByActivityId(activityId)
  96. t.CheckErr(err)
  97. // 投票->投票活动
  98. _, err = models.UpdateVoteStatusByActivityId(activityId)
  99. t.CheckErr(err)
  100. // 卡路里->卡路里活动
  101. _, err = models.UpdateCalorieStatusByActivityId(activityId)
  102. t.CheckErr(err)
  103. // 订单开启
  104. _, err = new(models.CustomerOrderOption).Switch(activityId, 0)
  105. t.CheckErr(err)
  106. activity.Status = define.StatusNotBegin
  107. } else {
  108. activity.Status = define.StatusEnding
  109. }
  110. activity.RehearsalId = 0
  111. _, err = models.Update(activity.Id, activity, "status", "rehearsal_id")
  112. t.CheckErr(err)
  113. t.SUCCESS("success")
  114. }