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

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