@ -1,7 +1,6 @@
package client
import (
"github.com/ouxuanserver/osmanthuswine/src/core"
"hudongzhuanjia/controllers"
"hudongzhuanjia/models"
activity_service "hudongzhuanjia/services/activity"
@ -14,16 +13,20 @@ type LotteryCtl struct {
}
func ( t * LotteryCtl ) UserLotteries ( ) {
uid := t . MustGetUID ( )
userId := t . MustGetUID ( )
activityId := t . MustGetInt64 ( "activity_id" )
userPrizes := make ( [ ] * models . UserPrize , 0 )
err := core . GetXormAuto ( ) . Where ( "is_delete=0 and user_id=? " , uid ) .
Desc ( "created_at" ) . Find ( & userPrizes )
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" : userP rizes,
"total" : len ( userP rizes) ,
"list" : p rizes,
"total" : len ( p rizes) ,
} )
}
@ -67,7 +70,6 @@ func (t *LotteryCtl) CheckLottery() {
record := new ( models . LotteryDrawRecord )
exist , err = record . GetByUserIdAndLadderId ( uid , ladderId )
t . CheckErr ( err )
//t.Assert(exist, code.MSG_LOTTERY_DRAW_NOT_HIT, "没有中奖")
t . JSON ( map [ string ] interface { } {
"record" : record ,
"ladder" : ladder ,
@ -75,14 +77,6 @@ func (t *LotteryCtl) CheckLottery() {
} )
}
//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" )
@ -99,11 +93,7 @@ func (t *LotteryCtl) Winners() {
t . Assert ( exist , code . MSG_LOTTERY_RULE_NOT_EXIST , "抽奖规则不存在" )
result := make ( [ ] * LotteryUsersResult , 0 )
err = core . GetXormAuto ( ) . Table ( new ( models . LotteryDrawRecord ) ) . 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_ladder_id=? and record.rehearsal_id=?" , ladderId ,
activity . RehearsalId ) .
Find ( & result )
err = models . GetLotteryUsersResultByLotteryDrawRecord ( result , ladderId , activity . RehearsalId )
t . CheckErr ( err )
t . JSON ( map [ string ] interface { } {
"total" : len ( result ) ,
@ -134,28 +124,19 @@ func (t *LotteryCtl) Users() {
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 , "活动模块不存在" )
recordIds := make ( [ ] int64 , 0 )
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 )
err = models . GetUserIdsByLotteryDrawRuleId ( recordIds , ladder . LotteryDrawRuleId , activity . RehearsalId , areaId )
t . CheckErr ( err )
session = session . NotIn ( "h.user_id" , recordIds )
}
err = session . Find ( & result )
result := make ( [ ] * LotteryUsersResult , 0 )
err = models . GetLotteryUsersResultBySignHistory ( result , areaId , activity . Id , activity . RehearsalId , recordIds )
t . CheckErr ( err )
t . JSON ( map [ string ] interface { } {