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

155 lines
4.5 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
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.GetAccountId()
  15. activityId := t.MustGetInt("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.GetAccountId()
  29. prizeId := t.MustGetInt("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.GetAccountId()
  55. ladderId := t.MustGetInt("lottery_draw_ladder_id")
  56. ladder := &models.LotteryDrawRuleLadder{}
  57. exist, err := models.Get(ladder, ladderId)
  58. t.CheckErr(err)
  59. t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在")
  60. rule := &models.LotteryDrawRule{}
  61. exist, err = models.Get(rule, ladder.LotteryDrawRuleId)
  62. t.CheckErr(err)
  63. t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在")
  64. lottery := &models.LotteryDrawActivity{}
  65. exist, err = models.Get(lottery, rule.LotteryDrawActivityId)
  66. t.CheckErr(err)
  67. t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在")
  68. activity := &models.Activity{}
  69. exist, err = models.Get(activity, lottery.ActivityId)
  70. t.CheckErr(err)
  71. t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在")
  72. record := new(models.LotteryDrawRecord)
  73. exist, err = record.GetByUserIdAndLadderId(uid, ladderId, activity.ArchId, ladder.RollNum)
  74. t.CheckErr(err)
  75. t.JSON(map[string]interface{}{
  76. "record": record,
  77. "ladder": ladder,
  78. "status": exist,
  79. })
  80. }
  81. //获取中奖名单
  82. func (t *LotteryCtl) Winners() {
  83. activityId := t.MustGetInt("activity_id")
  84. ladderId := t.MustGetInt("lottery_draw_ladder_id")
  85. activity := new(models.Activity)
  86. exist, err := models.Get(activity, activityId)
  87. t.CheckErr(err)
  88. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  89. ladder := new(models.LotteryDrawRuleLadder)
  90. exist, err = models.Get(ladder, ladderId)
  91. t.CheckErr(err)
  92. t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在")
  93. result, err := lottery_service.GetLotteryUsersResultByRollNum(ladderId, activity.RehearsalId, activity.ArchId, ladder.RollNum)
  94. t.CheckErr(err)
  95. t.JSON(map[string]interface{}{
  96. "total": len(result),
  97. "ladder": ladder,
  98. "list": result,
  99. })
  100. }
  101. // 抽奖用户
  102. func (t *LotteryCtl) Users() {
  103. activityId := t.MustGetInt("activity_id")
  104. ladderId := t.MustGetInt("lottery_draw_ladder_id")
  105. areaId := t.MustGetInt("area_id")
  106. activity := new(models.Activity)
  107. exist, err := models.Get(activity, activityId)
  108. t.CheckErr(err)
  109. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  110. ladder := new(models.LotteryDrawRuleLadder)
  111. exist, err = models.Get(ladder, ladderId)
  112. t.CheckErr(err)
  113. t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在")
  114. moduleService, exist, err := activity_service.GetModuleService(define.MODULE_LOTTERY, activityId)
  115. t.CheckErr(err)
  116. t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "活动模块不存在")
  117. recordIds := make([]int, 0)
  118. if moduleService.BesideRepeat == define.MODULE_BESIDE_REPEAT {
  119. // 去重标志
  120. recordIds, err = models.GetUserIdsByLotteryDrawRuleId(ladder.LotteryDrawRuleId, activity.RehearsalId, areaId, activity.ArchId)
  121. t.CheckErr(err)
  122. }
  123. result, err := lottery_service.GetLotteryUsersResult(areaId, activity.Id, activity.RehearsalId, activity.ArchId, recordIds)
  124. t.CheckErr(err)
  125. t.JSON(map[string]interface{}{
  126. "ladder": ladder,
  127. "total": len(result),
  128. "list": result,
  129. })
  130. }