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

150 lines
4.1 KiB

5 years ago
  1. package pc
  2. import (
  3. "fmt"
  4. "github.com/ouxuanserver/osmanthuswine/src/core"
  5. "hudongzhuanjia/controllers"
  6. "hudongzhuanjia/models"
  7. "hudongzhuanjia/utils/code"
  8. "hudongzhuanjia/utils/define"
  9. "time"
  10. )
  11. //活动
  12. type ActivityCtl struct {
  13. controllers.AuthorCtl
  14. }
  15. // 废弃
  16. func (t *ActivityCtl) List() {
  17. customerId := t.MustGetUID()
  18. list := make([]*models.Activity, 0)
  19. err := core.GetXormAuto().Where("is_delete=0 and customer_id=? and status<>?",
  20. customerId, define.StatusEnding).Find(&list)
  21. t.CheckErr(err)
  22. t.JSON(map[string]interface{}{
  23. "list": list,
  24. "total": len(list),
  25. })
  26. }
  27. func (t *ActivityCtl) StartActivity() {
  28. activityId := t.MustGetInt64("activity_id")
  29. mode := t.MustGetInt("mode") // 标识彩排 mode=0正式 mode=1彩排
  30. uid := t.MustGetUID()
  31. limit := t.DefaultInt64("limit", 10)
  32. activity := new(models.Activity)
  33. exist, err := models.GetById(activity, activityId)
  34. t.CheckErr(err)
  35. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  36. // 检测活动状态 ==》 必须为未开始
  37. if activity.Status != define.StatusNotBegin {
  38. t.ERROR(fmt.Sprintf("该活动状态%s", activity.Status), code.MSG_ERR)
  39. }
  40. // 检测彩排活动是否进行中
  41. if activity.RehearsalId != 0 {
  42. t.ERROR("该活动在彩排中", code.MSG_ERR)
  43. }
  44. var rehearsalId int64 = 0
  45. if mode == 1 {
  46. rehearsal := new(models.Rehearsal)
  47. rehearsal.Status = 1
  48. rehearsal.ActivityId = activityId
  49. rehearsal.CustomerId = uid
  50. rehearsal.LimitNumber = limit
  51. rehearsal.IsDelete = false
  52. rehearsal.UpdatedAt = time.Now()
  53. rehearsal.CreatedAt = time.Now()
  54. _, err := core.GetXormAuto().InsertOne(rehearsal)
  55. t.CheckErr(err)
  56. rehearsalId = rehearsal.Id
  57. }
  58. activity.Status = define.StatusRunning
  59. activity.RehearsalId = rehearsalId
  60. activity.UpdatedAt = time.Now()
  61. // todo: 校验
  62. err = models.Save(map[string]interface{}{
  63. "id=": activityId,
  64. "is_delete=": 0,
  65. }, activity, "status", "rehearsal_id", "updated_at")
  66. t.CheckErr(err)
  67. t.JSON(map[string]interface{}{
  68. "rehearsal_id": rehearsalId,
  69. })
  70. }
  71. func (t *ActivityCtl) StopActivity() {
  72. activityId := t.MustGetInt64("activity_id")
  73. activity := new(models.Activity)
  74. exist, err := models.GetById(activity, activityId)
  75. t.CheckErr(err)
  76. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  77. if activity.Status != define.StatusRunning {
  78. t.ERROR(fmt.Sprintf("该活动%s", activity.Status), code.MSG_ERR)
  79. }
  80. if activity.RehearsalId != 0 { // 彩排回归最初结果
  81. // todo:其他的活动也要回复到最初的状态
  82. // 竞拍
  83. _, err = models.UpdateAuctionStatusByActivityId(activityId)
  84. t.CheckErr(err)
  85. // 抽奖
  86. lotteryIds, err := models.GetLDActivityIdsByActivityId(activityId)
  87. t.CheckErr(err)
  88. //_, err = models.UpdateLDRuleStatusByLDActiviytIds(lotteryIds)
  89. lotteryRuleIds, err := models.GetLDRuleIdsByLDActivityId(lotteryIds)
  90. t.CheckErr(err)
  91. _, err = models.UpdateLDLadderStatusByLDRuleIds(lotteryRuleIds)
  92. t.CheckErr(err)
  93. // 订单抽奖
  94. orderIds, err := models.GetODActivityIdsByActivityId(activityId)
  95. t.CheckErr(err)
  96. //_, err = models.UpdateODRuleStatusByODActivityIds(orderIds)
  97. orderRuleIds, err := models.GetODRuleIdsByODActivityIds(orderIds)
  98. t.CheckErr(err)
  99. _, err = models.UpdateODLadderStatusByODRuleIds(orderRuleIds)
  100. t.CheckErr(err)
  101. // 摇红包
  102. shakeRbIds, err := models.GetSREActivityIdsByActivityId(activityId)
  103. t.CheckErr(err)
  104. _, err = models.UpdateSRERuleStatusBySREActivityIds(shakeRbIds)
  105. t.CheckErr(err)
  106. // 拔河
  107. _, err = models.UpdateTOWStatusByActivityId(activityId)
  108. t.CheckErr(err)
  109. // 投票
  110. _, err = models.UpdateVoteStatusByActiviytId(activityId)
  111. t.CheckErr(err)
  112. // 卡路里
  113. _, err = models.UpdateCalorieStatusByActivityId(activityId)
  114. t.CheckErr(err)
  115. // 订单开启
  116. _, err = new(models.CustomerOrderOption).Switch(activityId, 0)
  117. t.CheckErr(err)
  118. activity.Status = define.StatusNotBegin
  119. } else {
  120. activity.Status = define.StatusEnding
  121. }
  122. activity.UpdatedAt = time.Now()
  123. activity.RehearsalId = 0
  124. models.Save(map[string]interface{}{
  125. "id=": activity.Id,
  126. }, activity, "status", "rehearsal_id", "updated_at")
  127. t.SUCCESS("success")
  128. }