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

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