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

48 lines
2.3 KiB

package models
import (
"github.com/ouxuanserver/osmanthuswine/src/core"
"time"
)
const BaheTeamTable = TableNamePrefix + "bahe_team"
//拔河队伍
type BaheTeam struct {
Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
ActivityId int64 `json:"activity_id" xorm:"not null comment('活动id') INT(11)"`
BaheActivityId int64 `json:"bahe_activity_id" xorm:"not null comment('拔河活动id') INT(11) "`
BaheTeamName string `json:"bahe_team_name" xorm:"not null comment('拔河队伍得名称') VARCHAR(255)"`
TotalScore int64 `json:"total_score" xorm:"-" description:"总分数"`
Rank int `json:"rank" xorm:"-" description:"排名"`
Members []*BaheTeamMember `json:"members" xorm:"-" description:"队伍人数"`
Qrcode string `json:"qrcode" xorm:"-" description:"二维码"`
IsDelete bool `json:"is_delete" xorm:"not null default(0) comment('是否已删除') TINYINT(1)"`
CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"`
UpdatedAt time.Time `json:"updated_at" xorm:"not null updated comment('更新时间') DATETIME"`
}
func (t *BaheTeam) TableName() string {
return BaheTeamTable
}
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 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).
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)
}