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

140 lines
3.9 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
  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, err := lottery_service.GetLotteryUsersResultByRollNum(ladderId, activity.RehearsalId, ladder.RollNum)
  82. t.CheckErr(err)
  83. t.JSON(map[string]interface{}{
  84. "total": len(result),
  85. "ladder": ladder,
  86. "list": result,
  87. })
  88. }
  89. // 抽奖用户
  90. func (t *LotteryCtl) Users() {
  91. activityId := t.MustGetInt64("activity_id")
  92. ladderId := t.MustGetInt64("lottery_draw_ladder_id")
  93. areaId := t.MustGetInt64("area_id")
  94. activity := new(models.Activity)
  95. exist, err := models.Get(activity, activityId)
  96. t.CheckErr(err)
  97. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  98. ladder := new(models.LotteryDrawRuleLadder)
  99. exist, err = models.Get(ladder, ladderId)
  100. t.CheckErr(err)
  101. t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在")
  102. moduleService, exist, err := activity_service.GetModuleService(define.MODULE_LOTTERY, activityId)
  103. t.CheckErr(err)
  104. t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "活动模块不存在")
  105. recordIds := make([]int64, 0)
  106. if moduleService.BesideRepeat == define.MODULE_BESIDE_REPEAT {
  107. // 去重标志
  108. recordIds, err = models.GetUserIdsByLotteryDrawRuleId(ladder.LotteryDrawRuleId, activity.RehearsalId, areaId)
  109. t.CheckErr(err)
  110. }
  111. result, err := lottery_service.GetLotteryUsersResult(areaId, activity.Id, activity.RehearsalId, recordIds)
  112. t.CheckErr(err)
  113. t.JSON(map[string]interface{}{
  114. "ladder": ladder,
  115. "total": len(result),
  116. "list": result,
  117. })
  118. }