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

151 lines
4.1 KiB

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