diff --git a/controllers/client/tug_war.go b/controllers/client/tug_war.go index d24d5e0..e71eeff 100644 --- a/controllers/client/tug_war.go +++ b/controllers/client/tug_war.go @@ -115,8 +115,13 @@ func (t *TugOfWarCtl) JoinTeam() { exist, err := models.Get(bahe, baheActivityId) t.CheckErr(err) t.Assert(exist, code.MSG_TUGWAR_TEAM_OVER_LIMIT, "拔河不存在") + if bahe.Status == define.StatusNotBegin { + t.ERROR("该拔河活动尚未开始", code.MSG_MODULE_STATUS_NOT_RUNNING) + return + } if bahe.Status == define.StatusEnding { t.ERROR("该拔河活动已结束", code.MSG_MODULE_STATUS_END) + return } activity := new(models.Activity) @@ -140,7 +145,7 @@ func (t *TugOfWarCtl) JoinTeam() { if teamId == 0 { team, exist, err = bahe_service.GetJoinTeamByBaheId(bahe.Id, activity.RehearsalId, activity.ArchId) } else { - team, exist, err = bahe_service.GetJoinTeamByTeamId(teamId, activity.RehearsalId) + team, exist, err = bahe_service.GetJoinTeamByTeamId(teamId, activity.RehearsalId, activity.ArchId) } t.CheckErr(err) t.Assert(exist, code.MSG_ERR, "队伍信息错误, 请重新扫码") diff --git a/controllers/pc/lottery_draw.go b/controllers/pc/lottery_draw.go index 053bc2e..1195778 100644 --- a/controllers/pc/lottery_draw.go +++ b/controllers/pc/lottery_draw.go @@ -290,7 +290,7 @@ func (t *LotteryDrawCtl) Lottery() { t.Assert(exist, code.MSG_DATA_NOT_EXIST, "抽奖等级不存在") t.CheckRunning(ladder.Status) - count, err := new(models.LotteryDrawRecord).CountRecord(ruleId, ladder.Id, activity.RehearsalId, area.Id) + count, err := new(models.LotteryDrawRecord).CountRecord(ruleId, ladder.Id, activity.RehearsalId, area.Id, activity.ArchId) t.CheckErr(err) prizeNum := ladder.PrizeNumber - int(count) @@ -302,7 +302,8 @@ func (t *LotteryDrawCtl) Lottery() { t.CheckErr(err) t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "活动模块不存在") // 取设置 - userIds, err := lottery_service.GetLotteryUserIds(module.BesideRepeat, activityId, ruleId, ladder.Id, activity.RehearsalId, area.Id) + userIds, err := lottery_service.GetLotteryUserIds(module.BesideRepeat, activityId, ruleId, ladder.Id, + activity.RehearsalId, area.Id, activity.ArchId) if len(userIds) < number { t.ERROR("抽奖人数不足", code.MSG_LOTTERY_PEOPLE_NOT_ENOUGH) } diff --git a/main.go b/main.go index d731077..c4ebc05 100644 --- a/main.go +++ b/main.go @@ -6,11 +6,12 @@ import ( "hudongzhuanjia/controllers/client" "hudongzhuanjia/controllers/common" "hudongzhuanjia/controllers/pc" + "hudongzhuanjia/utils/define" //_ "net/http/pprof" ) func main() { - //define.SetDebug(true) + define.SetDebug(true) // pc core.GetInstanceRouterManage().Registered(new(pc.WsCtl)) // 用户 diff --git a/models/lottery_draw_record.go b/models/lottery_draw_record.go index 2aa6b2e..490fddd 100644 --- a/models/lottery_draw_record.go +++ b/models/lottery_draw_record.go @@ -75,8 +75,7 @@ func GetUserIdsByLotteryDrawRuleId(ruleId, rehearsalId, areaId, archId interface return recordIds, err } -func (t *LotteryDrawRecord) CountRecord(ruleId, ladderId, rehearsalId, areaId interface{}) (int64, error) { - return core.GetXormAuto().Where("lottery_draw_rule_id=? and lottery_draw_rule_ladder_id=? "+ - "and rehearsal_id=? and area_id=? and is_delete=0", ruleId, ladderId, rehearsalId, areaId). - Count(t) +func (t *LotteryDrawRecord) CountRecord(ruleId, ladderId, rehearsalId, areaId, archId interface{}) (int64, error) { + return core.GetXormAuto().Where("lottery_draw_rule_id=? and lottery_draw_rule_ladder_id=? and rehearsal_id=? "+ + " and area_id=? and arch_id=? and is_delete=0", ruleId, ladderId, rehearsalId, areaId, archId).Count(t) } diff --git a/services/bahe/tug_war.go b/services/bahe/tug_war.go index 78ea45e..e84caed 100644 --- a/services/bahe/tug_war.go +++ b/services/bahe/tug_war.go @@ -80,8 +80,9 @@ func GetJoinTeamByTeamId(teamId, rehearsalId, archId interface{}) (*JoinTeamResu result := new(JoinTeamResult) exist, err := core.GetXormAuto().Table(new(models.BaheTeam)).Alias("t"). Select("t.id as team_id, t.bahe_team_name as team_name, count(m.id) as number"). - Join("LEFT", new(models.BaheTeamMember).Alias("m"), "m.team_id=t.id"). - Where("t.is_delete=0 and t.id=? and m.rehearsal_id=? and m.arch_id=?", teamId, archId). + Join("LEFT", new(models.BaheTeamMember).Alias("m"), + "m.team_id=t.id and m.rehearsal_id=? and m.arch_id=?", rehearsalId, archId). + Where("t.is_delete=0 and t.id=?", teamId). GroupBy("t.id").Get(result) return result, exist, err } @@ -90,9 +91,9 @@ func GetJoinTeamByBaheId(baheId, rehearsalId, archId interface{}) (*JoinTeamResu result := new(JoinTeamResult) exist, err := core.GetXormAuto().Table(new(models.BaheTeam)).Alias("t"). Select("t.id as team_id, t.bahe_team_name as team_name, count(m.id) as number"). - Join("LEFT", new(models.BaheTeamMember).Alias("m"), "m.team_id=t.id"). - Where("t.is_delete=0 and t.bahe_activity_id=? and m.rehearsal_id=? and m.arch_id=? ", - baheId, rehearsalId, archId). + Join("LEFT", new(models.BaheTeamMember).Alias("m"), + "m.team_id=t.id and m.rehearsal_id=? and m.arch_id=?", rehearsalId, archId). + Where("t.is_delete=0 and t.bahe_activity_id=? ", baheId). GroupBy("t.id").Asc("number").Get(result) return result, exist, err } diff --git a/services/lottery/lottery.go b/services/lottery/lottery.go index e43cc18..24290f5 100644 --- a/services/lottery/lottery.go +++ b/services/lottery/lottery.go @@ -37,27 +37,27 @@ func RandLotteryUserIds(users []int64) { } } -func GetLotteryUserIds(repeat string, activityId, ruleId, ladderId, rehearsalId, areaId interface{}) ([]int64, error) { +func GetLotteryUserIds(repeat string, activityId, ruleId, ladderId, rehearsalId, areaId, archId interface{}) ([]int64, error) { var err error userIds := make([]int64, 0) recordIds := make([]int64, 0) if repeat == define.MODULE_BESIDE_REPEAT { // 去除同规则中将用户 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", - ruleId, rehearsalId, areaId).Find(&recordIds) + Where("lottery_draw_rule_id=? and rehearsal_id=? and area_id=? and arch_id=? and is_delete=0", + ruleId, rehearsalId, areaId, archId).Find(&recordIds) } else { // 去除同规则中将用户 err = core.GetXormAuto().Table(new(models.LotteryDrawRecord)).Select("user_id"). - Where("lottery_draw_rule_ladder_id=? and rehearsal_id=? and area_id=? and is_delete=0", - ladderId, rehearsalId, areaId).Find(&recordIds) + Where("lottery_draw_rule_ladder_id=? and rehearsal_id=? and area_id=? and arch_id=? and is_delete=0", + ladderId, rehearsalId, areaId, archId).Find(&recordIds) } if err != nil { return nil, err } err = core.GetXormAuto().Table(new(models.SignHistory)).Select("user_id"). - Where("is_delete=0 and rehearsal_id=? and area_id=? and activity_id=?", - rehearsalId, areaId, activityId).NotIn("user_id", recordIds).Find(&userIds) + Where("is_delete=0 and rehearsal_id=? and area_id=? and activity_id=? and arch_id=?", + rehearsalId, areaId, activityId, archId).NotIn("user_id", recordIds).Find(&userIds) return userIds, nil }