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

package client
import (
"hudongzhuanjia/controllers"
"hudongzhuanjia/models"
activity_service "hudongzhuanjia/services/activity"
lottery_service "hudongzhuanjia/services/lottery"
"hudongzhuanjia/utils/code"
"hudongzhuanjia/utils/define"
)
type LotteryCtl struct {
controllers.AuthorCtl
}
func (t *LotteryCtl) UserLotteries() {
userId := t.MustGetUID()
activityId := t.MustGetInt64("activity_id")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
prizes, err := models.GetUserPrizesByUserIdAndActivityId(userId, activityId, activity.RehearsalId)
t.CheckErr(err)
t.JSON(map[string]interface{}{
"list": prizes,
"total": len(prizes),
})
}
func (t *LotteryCtl) CashLottery() {
uid := t.MustGetUID()
prizeId := t.MustGetInt64("prize_id")
name := t.MustGet("name")
phone := t.MustGet("phone")
wxNo := t.MustGet("wx_no")
address := t.MustGet("address")
prize := new(models.UserPrize)
prize.Id = prizeId
prize.UserId = uid
prize.Status = 1
err := prize.Update("status")
t.CheckErr(err)
record := new(models.LotteryDrawRecord)
exist, err := record.GetByUserPrizeId(prizeId)
t.CheckErr(err)
t.Assert(exist, code.MSG_LOTTERY_DRAW_RECORD_NOT_EXIST, "中奖记录不存在")
record.Name = name
record.Phone = phone
record.WxNo = wxNo
record.Address = address
record.Status = 1
_, err = models.Update(record.Id, record, "name", "phone", "wx_no", "address", "status")
t.CheckErr(err)
t.SUCCESS("兑奖成功")
}
func (t *LotteryCtl) CheckLottery() {
uid := t.MustGetUID()
ladderId := t.MustGetInt64("lottery_draw_ladder_id")
ladder := new(models.LotteryDrawRuleLadder)
exist, err := models.Get(ladder, ladderId)
t.CheckErr(err)
t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在")
record := new(models.LotteryDrawRecord)
exist, err = record.GetByUserIdAndLadderId(uid, ladderId, ladder.RollNum)
t.CheckErr(err)
t.JSON(map[string]interface{}{
"record": record,
"ladder": ladder,
"status": exist,
})
}
//获取中奖名单
func (t *LotteryCtl) Winners() {
activityId := t.MustGetInt64("activity_id")
ladderId := t.MustGetInt64("lottery_draw_ladder_id")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
ladder := new(models.LotteryDrawRuleLadder)
exist, err = models.Get(ladder, ladderId)
t.CheckErr(err)
t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在")
result, err := lottery_service.GetLotteryUsersResultByRollNum(ladderId, activity.RehearsalId, ladder.RollNum)
t.CheckErr(err)
t.JSON(map[string]interface{}{
"total": len(result),
"ladder": ladder,
"list": result,
})
}
// 抽奖用户
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.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
ladder := new(models.LotteryDrawRuleLadder)
exist, err = models.Get(ladder, ladderId)
t.CheckErr(err)
t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在")
moduleService, exist, err := activity_service.GetModuleService(define.MODULE_LOTTERY, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "活动模块不存在")
recordIds := make([]int64, 0)
if moduleService.BesideRepeat == define.MODULE_BESIDE_REPEAT {
// 去重标志
recordIds, err = models.GetUserIdsByLotteryDrawRuleId(ladder.LotteryDrawRuleId, activity.RehearsalId, areaId)
t.CheckErr(err)
}
result, err := lottery_service.GetLotteryUsersResult(areaId, activity.Id, activity.RehearsalId, recordIds)
t.CheckErr(err)
t.JSON(map[string]interface{}{
"ladder": ladder,
"total": len(result),
"list": result,
})
}