Browse Source

add winners and users

master
黄梓健 5 years ago
parent
commit
f0c025c02d
  1. 90
      controllers/client/lottery.go

90
controllers/client/lottery.go

@ -4,7 +4,9 @@ import (
"github.com/ouxuanserver/osmanthuswine/src/core"
"hudongzhuanjia/controllers"
"hudongzhuanjia/models"
activity_service "hudongzhuanjia/services/activity"
"hudongzhuanjia/utils/code"
"hudongzhuanjia/utils/define"
)
type LotteryCtl struct {
@ -55,3 +57,91 @@ func (t *LotteryCtl) CheckLottery() {
t.Assert(exist, code.MSG_LOTTERY_DRAW_NOT_HIT, "没有中奖")
t.JSON(record)
}
type WinnersResult struct {
UserId int64 `json:"user_id"`
UserName string `json:"user_name"`
UserPhone string `json:"user_phone"`
Avatar string `json:"avatar"`
PrizeName string `json:"prize_name"`
}
//获取中奖名单
func (t *LotteryCtl) Winners() {
activityId := t.MustGetInt64("activity_id")
ladderId := t.MustGetInt64("lottery_draw_ladder_id")
activity := new(models.Activity)
exist, err := models.GetById(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
ladder := new(models.LotteryDrawRuleLadder)
exist, err = models.GetById(ladder, ladderId)
t.CheckErr(err)
t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在")
result := make([]*WinnersResult, 0)
err = core.GetXormAuto().Table("ox_lottery_draw_record").Alias("record").
Join("LEFT", new(models.User).Alias("user"), "user.id=record.user_id and user.is_delete=0").
Where("record.is_delete=0 and record.lottery_draw_rule_id=? and record.rehearsal_id=?", ladder.LotteryDrawRuleId,
activity.RehearsalId).
Find(&result)
t.CheckErr(err)
t.JSON(map[string]interface{}{
"total": len(result),
"list": result,
})
}
type LotteryUsersResult struct {
UserId int64 `json:"user_id"`
Username string `json:"username"`
Avatar string `json:"avatar"`
}
// 抽奖用户
func (t *LotteryCtl) Users() {
activityId := t.MustGetInt64("activity_id")
ladderId := t.MustGetInt64("lottery_draw_ladder_id")
areaId := t.MustGetInt64("area_id")
activity := new(models.Activity)
exist, err := models.GetById(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
ladder := new(models.LotteryDrawRuleLadder)
exist, err = models.GetById(ladder, ladderId)
t.CheckErr(err)
t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在")
result := make([]*LotteryUsersResult, 0)
session := core.GetXormAuto().Table(new(models.SignHistory)).Alias("h").
Select("h.user_id, u.nickname as username, u.avatar").Distinct("h.user_id").
Join("LEFT", new(models.User).Alias("u"), "h.user_id=u.id and u.is_delete = 0").
Where("h.is_delete=0 and h.area_id=? and h.activity_id=? and h.rehearsal_id=?",
areaId, activityId, activity.RehearsalId)
moduleService, exist, err := activity_service.GetModuleService(define.MODULE_LOTTERY, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "活动模块不存在")
if moduleService.BesideRepeat == define.MODULE_BESIDE_REPEAT {
// 去重标志
recordIds := make([]int64, 0)
err = core.GetXormAuto().Table(new(models.LotteryDrawRecord)).Select("user_id").
Where("lottery_draw_rule_id=? and rehearsal_id=? and area_id=? and is_delete=0",
ladder.LotteryDrawRuleId, activity.RehearsalId, areaId).Find(&recordIds)
t.CheckErr(err)
session = session.NotIn("h.user_id", recordIds)
}
err = session.Find(&result)
t.CheckErr(err)
t.JSON(map[string]interface{}{
"total": len(result),
"list": result,
})
}
Loading…
Cancel
Save