互动
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.2 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. calorie_service "hudongzhuanjia/services/calorie"
  7. "hudongzhuanjia/utils"
  8. "hudongzhuanjia/utils/code"
  9. "hudongzhuanjia/utils/define"
  10. "time"
  11. )
  12. type CalorieCtl struct {
  13. controllers.AuthorCtl
  14. }
  15. func (t *CalorieCtl) Ready() {
  16. calorieId := t.MustGetInt64("calorie_id")
  17. calorie := new(models.Calorie)
  18. exist, err := models.Get(calorie, calorieId)
  19. t.CheckErr(err)
  20. t.Assert(exist, code.MSG_CALORIE_NOT_EXIST, "卡路里活动不存在")
  21. if calorie.Status != define.StatusNotBegin {
  22. t.ERROR(fmt.Sprintf("该活动%s", calorie.Status), code.MSG_MODULE_STATUS_ERROR)
  23. }
  24. activity := new(models.Activity)
  25. exist, err = models.Get(activity, calorie.ActivityId)
  26. t.CheckErr(err)
  27. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  28. _, err = calorie.UpdateToStatusByActivityId(calorie.ActivityId, define.StatusReady, define.StatusNotBegin)
  29. t.CheckErr(err)
  30. calorie.StartTime = 0
  31. _, err = calorie.UpdateStatusById(calorieId, define.StatusReady)
  32. t.CheckErr(err)
  33. t.SUCCESS("操作成功")
  34. }
  35. // 开始, 加一个开始时间
  36. func (t *CalorieCtl) Start() {
  37. calorieId := t.MustGetInt64("calorie_id")
  38. calorie := new(models.Calorie)
  39. exist, err := models.Get(calorie, calorieId)
  40. t.CheckErr(err)
  41. t.Assert(exist, code.MSG_CALORIE_NOT_EXIST, "卡路里活动不存在")
  42. if calorie.Status != define.StatusReady {
  43. t.ERROR(fmt.Sprintf("该活动%s", calorie.Status), code.MSG_MODULE_STATUS_ERROR)
  44. }
  45. activity := new(models.Activity)
  46. exist, err = models.Get(activity, calorie.ActivityId)
  47. t.CheckErr(err)
  48. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  49. calorie.StartTime = time.Now().Unix()
  50. _, err = calorie.UpdateStatusById(calorieId, define.StatusRunning)
  51. t.CheckErr(err)
  52. t.SUCCESS("操作成功")
  53. }
  54. // 彩排活动需要恢复
  55. func (t *CalorieCtl) Stop() {
  56. calorieId := t.MustGetInt64("calorie_id")
  57. calorie := new(models.Calorie)
  58. exist, err := models.Get(calorie, calorieId)
  59. t.CheckErr(err)
  60. t.Assert(exist, code.MSG_CALORIE_NOT_EXIST, "卡路里活动不存在")
  61. if calorie.Status != define.StatusRunning {
  62. t.ERROR(fmt.Sprintf("该活动%s", calorie.Status), code.MSG_MODULE_STATUS_ERROR)
  63. }
  64. activity := new(models.Activity)
  65. exist, err = models.Get(activity, calorie.ActivityId)
  66. t.CheckErr(err)
  67. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  68. _, err = calorie.UpdateStatusById(calorieId, define.StatusEnding)
  69. t.CheckErr(err)
  70. t.SUCCESS("操作成功")
  71. }
  72. // 列出轮次, 包括倒计时
  73. func (t *CalorieCtl) List() {
  74. activityId := t.MustGetInt64("activity_id")
  75. calories, err := models.GetCaloriesByActivityId(activityId)
  76. t.CheckErr(err)
  77. t.JSON(map[string]interface{}{
  78. "list": calories,
  79. "count": len(calories),
  80. })
  81. }
  82. // 二维码
  83. func (t *CalorieCtl) Qrcode() {
  84. activityId := t.MustGetInt64("activity_id")
  85. uid := t.MustGetUID()
  86. calorieId := t.MustGetInt64("calorie_id")
  87. area := new(models.AreaStore)
  88. exist, err := area.GetByCustomerId(uid, activityId)
  89. t.CheckErr(err)
  90. t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户信息异常")
  91. qrcode, err := utils.GenH5Qrcode(define.H5Calorie, map[string]interface{}{
  92. "activity_id": activityId,
  93. "customer_id": uid,
  94. "area_id": area.Id,
  95. "calorie_id": calorieId,
  96. })
  97. t.CheckErr(err)
  98. t.JSON(map[string]interface{}{
  99. "qrcode": qrcode,
  100. })
  101. }
  102. // 统计一些数据, 包括参与人数, 包括当前排名
  103. func (t *CalorieCtl) Count() {
  104. activityId := t.MustGetInt64("activity_id")
  105. calorieId := t.MustGetInt64("calorie_id")
  106. limit := t.DefaultInt("limit", 10)
  107. activity := new(models.Activity)
  108. exist, err := models.Get(activity, activityId)
  109. t.CheckErr(err)
  110. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  111. t.CheckRunning(activity.Status)
  112. calorie := new(models.Calorie)
  113. exist, err = models.Get(calorie, calorieId)
  114. t.CheckErr(err)
  115. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "卡路里不存在")
  116. // 统计人数
  117. count, err := new(models.CalorieUser).Count(calorieId, activity.RehearsalId)
  118. t.CheckErr(err)
  119. // 统计排名
  120. result, err := calorie_service.RankCalorieUser(calorieId, activity.RehearsalId, limit)
  121. t.CheckErr(err)
  122. t.JSON(map[string]interface{}{
  123. "list": result, // 排名统计
  124. "count": count, // 人数统计
  125. })
  126. }