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

141 lines
4.0 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
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 client
  2. import (
  3. "hudongzhuanjia/controllers"
  4. "hudongzhuanjia/models"
  5. activity_service "hudongzhuanjia/services/activity"
  6. lottery_service "hudongzhuanjia/services/lottery"
  7. "hudongzhuanjia/utils/code"
  8. "hudongzhuanjia/utils/define"
  9. )
  10. type LotteryCtl struct {
  11. controllers.AuthorCtl
  12. }
  13. func (t *LotteryCtl) UserLotteries() {
  14. userId := t.MustGetUID()
  15. activityId := t.MustGetInt64("activity_id")
  16. activity := new(models.Activity)
  17. exist, err := models.Get(activity, activityId)
  18. t.CheckErr(err)
  19. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  20. prizes, err := models.GetUserPrizesByUserIdAndActivityId(userId, activityId, activity.RehearsalId)
  21. t.CheckErr(err)
  22. t.JSON(map[string]interface{}{
  23. "list": prizes,
  24. "total": len(prizes),
  25. })
  26. }
  27. func (t *LotteryCtl) CashLottery() {
  28. uid := t.MustGetUID()
  29. prizeId := t.MustGetInt64("prize_id")
  30. name := t.MustGet("name")
  31. phone := t.MustGet("phone")
  32. wxNo := t.MustGet("wx_no")
  33. address := t.MustGet("address")
  34. prize := new(models.UserPrize)
  35. prize.Id = prizeId
  36. prize.UserId = uid
  37. prize.Status = 1
  38. err := prize.Update("status")
  39. t.CheckErr(err)
  40. record := new(models.LotteryDrawRecord)
  41. exist, err := record.GetByUserPrizeId(prizeId)
  42. t.CheckErr(err)
  43. t.Assert(exist, code.MSG_LOTTERY_DRAW_RECORD_NOT_EXIST, "中奖记录不存在")
  44. record.Name = name
  45. record.Phone = phone
  46. record.WxNo = wxNo
  47. record.Address = address
  48. record.Status = 1
  49. _, err = models.Update(record.Id, record, "name", "phone", "wx_no", "address", "status")
  50. t.CheckErr(err)
  51. t.SUCCESS("兑奖成功")
  52. }
  53. func (t *LotteryCtl) CheckLottery() {
  54. uid := t.MustGetUID()
  55. ladderId := t.MustGetInt64("lottery_draw_ladder_id")
  56. ladder := new(models.LotteryDrawRuleLadder)
  57. exist, err := models.Get(ladder, ladderId)
  58. t.CheckErr(err)
  59. t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在")
  60. record := new(models.LotteryDrawRecord)
  61. exist, err = record.GetByUserIdAndLadderId(uid, ladderId, ladder.RollNum)
  62. t.CheckErr(err)
  63. t.JSON(map[string]interface{}{
  64. "record": record,
  65. "ladder": ladder,
  66. "status": exist,
  67. })
  68. }
  69. //获取中奖名单
  70. func (t *LotteryCtl) Winners() {
  71. activityId := t.MustGetInt64("activity_id")
  72. ladderId := t.MustGetInt64("lottery_draw_ladder_id")
  73. activity := new(models.Activity)
  74. exist, err := models.Get(activity, activityId)
  75. t.CheckErr(err)
  76. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  77. ladder := new(models.LotteryDrawRuleLadder)
  78. exist, err = models.Get(ladder, ladderId)
  79. t.CheckErr(err)
  80. t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在")
  81. result := make([]*LotteryUsersResult, 0)
  82. err = models.GetLotteryUsersResultByLotteryDrawRecord(result, ladderId, activity.RehearsalId, ladder.RollNum)
  83. t.CheckErr(err)
  84. t.JSON(map[string]interface{}{
  85. "total": len(result),
  86. "ladder": ladder,
  87. "list": result,
  88. })
  89. }
  90. // 抽奖用户
  91. func (t *LotteryCtl) Users() {
  92. activityId := t.MustGetInt64("activity_id")
  93. ladderId := t.MustGetInt64("lottery_draw_ladder_id")
  94. areaId := t.MustGetInt64("area_id")
  95. activity := new(models.Activity)
  96. exist, err := models.Get(activity, activityId)
  97. t.CheckErr(err)
  98. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  99. ladder := new(models.LotteryDrawRuleLadder)
  100. exist, err = models.Get(ladder, ladderId)
  101. t.CheckErr(err)
  102. t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在")
  103. moduleService, exist, err := activity_service.GetModuleService(define.MODULE_LOTTERY, activityId)
  104. t.CheckErr(err)
  105. t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "活动模块不存在")
  106. recordIds := make([]int64, 0)
  107. if moduleService.BesideRepeat == define.MODULE_BESIDE_REPEAT {
  108. // 去重标志
  109. recordIds, err = models.GetUserIdsByLotteryDrawRuleId(ladder.LotteryDrawRuleId, activity.RehearsalId, areaId)
  110. t.CheckErr(err)
  111. }
  112. result, err := lottery_service.GetLotteryUsersResult(areaId, activity.Id, activity.RehearsalId, recordIds)
  113. t.CheckErr(err)
  114. t.JSON(map[string]interface{}{
  115. "ladder": ladder,
  116. "total": len(result),
  117. "list": result,
  118. })
  119. }