Browse Source

fix bug

master
黄梓健 5 years ago
parent
commit
4427e3d5db
  1. 40
      controllers/client/tug_war.go
  2. 2
      controllers/pc/tug_war.go
  3. 2
      log/hdzj.log
  4. 23
      models/bahe_team.go
  5. 2
      models/base.go
  6. 41
      services/bahe/tug_war.go

40
controllers/client/tug_war.go

@ -13,17 +13,6 @@ type TugOfWarCtl struct {
controllers.AuthorCtl
}
// 获取当前状态(废弃)
// @Summary client tug war
// @Description get current status
// @Tags client tug war
// @Accept json
// @Produce json
// @Param bahe_activity_id query int true "Bahe Activity ID"
// @Success 0 {object} models.TugOfWar
// @Failure 503 {string} string "参数不存在"
// @Failure 504 {object} string "用户不存在"
// @Router /Client/TugOfWarCtl/status [get]
func (t *TugOfWarCtl) Status() {
// 获取此次活动的状态
baheId := t.MustGetInt64("bahe_activity_id")
@ -119,12 +108,6 @@ func (t *TugOfWarCtl) Shake() {
})
}
type JoinTeamResult struct {
Number int
TeamId int64
TeamName string
}
func (t *TugOfWarCtl) JoinTeam() {
teamId := t.MustGetInt64("bahe_team_id")
baheActivityId := t.MustGetInt64("bahe_activity_id")
@ -154,9 +137,26 @@ func (t *TugOfWarCtl) JoinTeam() {
})
return
}
team := new(JoinTeamResult)
exist, err = models.GetJoinTeamByBaheId(team, bahe.Id, teamId, activity.RehearsalId)
//
//team := new(JoinTeamResult)
//session := 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 and m.is_delete=0 and m.rehearsal_id=?", activity.RehearsalId)
//if teamId == 0 { // 人数最少的一队
// session = session.Where("t.is_delete=0 and t.bahe_activity_id=? ", bahe.Id).
// GroupBy("t.id").Asc("number")
//} else {
// session = session.Where("t.is_delete=0 and t.id=?", teamId).GroupBy("t.id")
//}
//exist, err = session.Get(team)
var team *bahe_service.JoinTeamResult
if teamId == 0 {
team, exist, err = bahe_service.GetJoinTeamByBaheId(bahe.Id, activity.RehearsalId)
} else {
team, exist, err = bahe_service.GetJoinTeamByTeamId(teamId, activity.RehearsalId)
}
t.CheckErr(err)
t.Assert(exist, code.MSG_ERR, "队伍信息错误, 请重新扫码")
t.Assert(team.Number < bahe.Number, code.MSG_TUGWAR_TEAM_OVER_LIMIT, "队伍满人,请等待下一轮")

2
controllers/pc/tug_war.go

@ -108,7 +108,7 @@ func (t *TugOfWarCtl) Team() {
area := new(models.AreaStore)
exist, err := area.GetByCustomerId(customerId)
t.CheckErr(err)
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区信息异常")
//t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区信息异常")
bahe := new(models.TugOfWar)
exist, err = models.Get(bahe, baheId)

2
log/hdzj.log

@ -92,3 +92,5 @@
2020-05-21 10:36:20.616 ERROR logger/logger.go:87 查询订单出现错误{错误原因 15 0 Post https://api2.mch.weixin.qq.com/pay/orderquery: context deadline exceeded <nil>} {交易订单号 15 0 7bAPWxQhdAHtQfJV2XMHelZLwDU7BYz2 <nil>}
2020-05-21 10:38:01.658 ERROR logger/logger.go:87 查询订单出现错误{错误原因 15 0 invalid connection <nil>} {交易订单号 15 0 7bAPWxQhdAHtQfJV2XMHelZLwDU7BYz2 <nil>}
2020-05-21 10:38:23.165 ERROR logger/logger.go:87 查询订单出现错误{错误原因 15 0 invalid connection <nil>} {交易订单号 15 0 W1zSTjb10NTYuLM2D4EKOGM25MbbHuG2 <nil>}
2020-05-21 15:38:53.530 ERROR logger/logger.go:87 check err{error 25 0 sql: expected 3 destination arguments in Scan, not 1}
2020-05-21 15:45:57.936 ERROR logger/logger.go:87 check err{error 25 0 sql: expected 3 destination arguments in Scan, not 1}

23
models/bahe_team.go

@ -30,16 +30,19 @@ func (t *BaheTeam) GetOtherTeam(id, bid int64) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and id=? and bahe_activity_id=?", id, bid).Get(t)
}
func GetJoinTeamByBaheId(obj, baheId, teamId, rehearsalId interface{}) (bool, error) {
session := core.GetXormAuto().Table(new(BaheTeam)).Alias("t").
func GetJoinTeamByTeamId(obj, teamId, rehearsalId interface{}) (bool, error) {
return core.GetXormAuto().Table(new(BaheTeam)).Alias("t").
Select("t.id as team_id, t.bahe_team_name as team_name, count(m.id) as number").
Join("LEFT", new(BaheTeamMember).Alias("m"),
"m.team_id=t.id and m.is_delete=0 and m.rehearsal_id=?", rehearsalId)
if teamId == 0 { // 人数最少的一队
session = session.Where("t.is_delete=0 and t.bahe_activity_id=? ", baheId).
GroupBy("t.id").Asc("number")
} else {
session = session.Where("t.is_delete=0 and t.id=?", teamId).GroupBy("t.id")
}
return session.Get(&obj)
"m.team_id=t.id and m.is_delete=0 and m.rehearsal_id=?", rehearsalId).
Where("t.is_delete=0 and t.id=?", teamId).GroupBy("t.id").Get(&obj)
}
func GetJoinTeamByBaheId(obj, baheId, rehearsalId interface{}) (bool, error) {
return core.GetXormAuto().Table(new(BaheTeam)).Alias("t").
Select("t.id as team_id, t.bahe_team_name as team_name, count(m.id) as number").
Join("LEFT", new(BaheTeamMember).Alias("m"),
"m.team_id=t.id and m.is_delete=0 and m.rehearsal_id=?", rehearsalId).
Where("t.is_delete=0 and t.bahe_activity_id=? ", baheId).
GroupBy("t.id").Asc("number").Get(&obj)
}

2
models/base.go

@ -116,7 +116,7 @@ func Save(condition map[string]interface{}, obj interface{}, filed ...string) er
return err
} else {
//不存在则插入
_, err := session.InsertOne(obj)
_, err := core.GetXormAuto().InsertOne(obj)
return err
}
}

41
services/bahe/tug_war.go

@ -69,3 +69,44 @@ func GetCurrentTugWar(aid, uid, rid int64) (map[string]interface{}, error) {
"limit": bahe.Number,
}, nil
}
type JoinTeamResult struct {
Number int
TeamId int64
TeamName string
}
func GetJoinTeamByTeamId(teamId, rehearsalId interface{}) (*JoinTeamResult, bool, error) {
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 and m.is_delete=0 and m.rehearsal_id=?", rehearsalId).
Where("t.is_delete=0 and t.id=?", teamId).GroupBy("t.id").Get(result)
return result, exist, err
}
func GetJoinTeamByBaheId(baheId, rehearsalId interface{}) (*JoinTeamResult, bool, error) {
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 and m.is_delete=0 and m.rehearsal_id=?", rehearsalId).
Where("t.is_delete=0 and t.bahe_activity_id=? ", baheId).
GroupBy("t.id").Asc("number").Get(result)
return result, exist, err
}
//
//team := new(JoinTeamResult)
//session := 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 and m.is_delete=0 and m.rehearsal_id=?", activity.RehearsalId)
//if teamId == 0 { // 人数最少的一队
// session = session.Where("t.is_delete=0 and t.bahe_activity_id=? ", bahe.Id).
// GroupBy("t.id").Asc("number")
//} else {
// session = session.Where("t.is_delete=0 and t.id=?", teamId).GroupBy("t.id")
//}
//exist, err = session.Get(team)
Loading…
Cancel
Save