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

166 lines
4.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
  1. package client
  2. import (
  3. "github.com/ouxuanserver/osmanthuswine/src/core"
  4. "hudongzhuanjia/controllers"
  5. "hudongzhuanjia/models"
  6. activity_service "hudongzhuanjia/services/activity"
  7. "hudongzhuanjia/utils/code"
  8. "hudongzhuanjia/utils/define"
  9. )
  10. type LotteryCtl struct {
  11. controllers.AuthorCtl
  12. }
  13. func (t *LotteryCtl) UserLotteries() {
  14. uid := t.MustGetUID()
  15. userPrizes := make([]*models.UserPrize, 0)
  16. err := core.GetXormAuto().Where("is_delete=0 and user_id=? ", uid).
  17. Desc("created_at").Find(&userPrizes)
  18. t.CheckErr(err)
  19. t.JSON(map[string]interface{}{
  20. "list": userPrizes,
  21. "total": len(userPrizes),
  22. })
  23. }
  24. func (t *LotteryCtl) CashLottery() {
  25. uid := t.MustGetUID()
  26. prizeId := t.MustGetInt64("prize_id")
  27. name := t.MustGet("name")
  28. phone := t.MustGet("phone")
  29. wxNo := t.MustGet("wx_no")
  30. address := t.MustGet("address")
  31. prize := new(models.UserPrize)
  32. prize.Id = prizeId
  33. prize.UserId = uid
  34. prize.Status = 1
  35. err := prize.Update("status")
  36. t.CheckErr(err)
  37. record := new(models.LotteryDrawRecord)
  38. exist, err := record.GetByUserPrizeId(prizeId)
  39. t.CheckErr(err)
  40. t.Assert(exist, code.MSG_LOTTERY_DRAW_RECORD_NOT_EXIST, "中奖记录不存在")
  41. record.Name = name
  42. record.Phone = phone
  43. record.WxNo = wxNo
  44. record.Address = address
  45. record.Status = 1
  46. _, err = record.Update(record.Id, "name", "phone", "wx_no", "address", "status")
  47. t.CheckErr(err)
  48. t.SUCCESS("兑奖成功")
  49. }
  50. func (t *LotteryCtl) CheckLottery() {
  51. uid := t.MustGetUID()
  52. ladderId := t.MustGetInt64("lottery_draw_ladder_id")
  53. ladder := new(models.LotteryDrawRuleLadder)
  54. exist, err := models.GetById(ladder, ladderId)
  55. t.CheckErr(err)
  56. t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在")
  57. record := new(models.LotteryDrawRecord)
  58. exist, err = record.GetByUserIdAndLadderId(uid, ladderId)
  59. t.CheckErr(err)
  60. //t.Assert(exist, code.MSG_LOTTERY_DRAW_NOT_HIT, "没有中奖")
  61. t.JSON(map[string]interface{}{
  62. "record": record,
  63. "ladder": ladder,
  64. "status": exist,
  65. })
  66. }
  67. //type WinnersResult struct {
  68. // UserId int64 `json:"user_id"`
  69. // UserName string `json:"user_name"`
  70. // UserPhone string `json:"user_phone"`
  71. // Avatar string `json:"avatar"`
  72. // PrizeName string `json:"prize_name"`
  73. //}
  74. //获取中奖名单
  75. func (t *LotteryCtl) Winners() {
  76. activityId := t.MustGetInt64("activity_id")
  77. ladderId := t.MustGetInt64("lottery_draw_ladder_id")
  78. activity := new(models.Activity)
  79. exist, err := models.GetById(activity, activityId)
  80. t.CheckErr(err)
  81. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  82. ladder := new(models.LotteryDrawRuleLadder)
  83. exist, err = models.GetById(ladder, ladderId)
  84. t.CheckErr(err)
  85. t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在")
  86. result := make([]*LotteryUsersResult, 0)
  87. err = core.GetXormAuto().Table(new(models.LotteryDrawRecord)).Alias("record").
  88. Join("LEFT", new(models.User).Alias("user"), "user.id=record.user_id and user.is_delete=0").
  89. Where("record.is_delete=0 and record.lottery_draw_rule_ladder_id=? and record.rehearsal_id=?", ladderId,
  90. activity.RehearsalId).
  91. Find(&result)
  92. t.CheckErr(err)
  93. t.JSON(map[string]interface{}{
  94. "total": len(result),
  95. "ladder": ladder,
  96. "list": result,
  97. })
  98. }
  99. type LotteryUsersResult struct {
  100. UserId int64 `json:"user_id"`
  101. Username string `json:"username"`
  102. Avatar string `json:"avatar"`
  103. }
  104. // 抽奖用户
  105. func (t *LotteryCtl) Users() {
  106. activityId := t.MustGetInt64("activity_id")
  107. ladderId := t.MustGetInt64("lottery_draw_ladder_id")
  108. areaId := t.MustGetInt64("area_id")
  109. activity := new(models.Activity)
  110. exist, err := models.GetById(activity, activityId)
  111. t.CheckErr(err)
  112. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  113. ladder := new(models.LotteryDrawRuleLadder)
  114. exist, err = models.GetById(ladder, ladderId)
  115. t.CheckErr(err)
  116. t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在")
  117. result := make([]*LotteryUsersResult, 0)
  118. session := core.GetXormAuto().Table(new(models.SignHistory)).Alias("h").
  119. Select("h.user_id, u.nickname as username, u.avatar").Distinct("h.user_id").
  120. Join("LEFT", new(models.User).Alias("u"), "h.user_id=u.id and u.is_delete = 0").
  121. Where("h.is_delete=0 and h.area_id=? and h.activity_id=? and h.rehearsal_id=?",
  122. areaId, activityId, activity.RehearsalId)
  123. moduleService, exist, err := activity_service.GetModuleService(define.MODULE_LOTTERY, activityId)
  124. t.CheckErr(err)
  125. t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "活动模块不存在")
  126. if moduleService.BesideRepeat == define.MODULE_BESIDE_REPEAT {
  127. // 去重标志
  128. recordIds := make([]int64, 0)
  129. err = core.GetXormAuto().Table(new(models.LotteryDrawRecord)).Select("user_id").
  130. Where("lottery_draw_rule_id=? and rehearsal_id=? and area_id=? and is_delete=0",
  131. ladder.LotteryDrawRuleId, activity.RehearsalId, areaId).Find(&recordIds)
  132. t.CheckErr(err)
  133. session = session.NotIn("h.user_id", recordIds)
  134. }
  135. err = session.Find(&result)
  136. t.CheckErr(err)
  137. t.JSON(map[string]interface{}{
  138. "ladder": ladder,
  139. "total": len(result),
  140. "list": result,
  141. })
  142. }