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.
49 lines
2.3 KiB
49 lines
2.3 KiB
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/ouxuanserver/osmanthuswine/src/core"
|
|
)
|
|
|
|
const BaheTeamMemberTableName = TableNamePrefix + "bahe_team_member"
|
|
|
|
//拔河队伍人员
|
|
type BaheTeamMember struct {
|
|
Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
|
|
BaheActivityId int64 `json:"bahe_activity_id" xorm:"not null default(0) comment('拔河活動id') BIGINT(20)"`
|
|
TeamId int64 `json:"team_id" xorm:"not null default(0) comment('队伍id') BIGINT(20)"`
|
|
TeamName string `json:"team_name" xorm:"not null default('') comment('队伍名字') VARCHAR(255)"`
|
|
MemberId int64 `json:"member_id" xorm:"not null comment('用户id') BIGINT(20)"`
|
|
Score int64 `json:"score" xorm:"not null default(0) comment('分数') INT(11)"`
|
|
RehearsalId int64 `json:"rehearsal_id" xorm:"not null default(0) comment('彩排id/0正式') BIGINT(20)"`
|
|
Avatar string `json:"avatar" xorm:"not null comment('头像') VARCHAR(255)"`
|
|
NickName string `json:"nick_name" xorm:"not null comment('昵称') VARCHAR(255)"`
|
|
SortTime int64 `json:"sort_time" xorm:"not null default '0' comment('排序时间') VARCHAR(20)"`
|
|
IsDelete bool `json:"-" xorm:"not null default(0) comment('软删除') TINYINT(1)"`
|
|
CreatedAt time.Time `json:"-" xorm:"not null created comment('创建时间') DATETIME"`
|
|
UpdatedAt time.Time `json:"-" xorm:"not null updated comment('更新时间') DATETIME"`
|
|
}
|
|
|
|
func (t *BaheTeamMember) TableName() string {
|
|
return BaheTeamMemberTableName
|
|
}
|
|
|
|
func (t *BaheTeamMember) Alias(name string) string {
|
|
return AliasTableName(t, name)
|
|
}
|
|
|
|
func (t *BaheTeamMember) GetMemberByBaheIdAndUserId(uid, bid, rid int64) (bool, error) {
|
|
return core.GetXormAuto().Where("member_id=? and bahe_activity_id=? and rehearsal_id=? and is_delete=0", uid, bid, rid).Get(t)
|
|
}
|
|
|
|
func (t *BaheTeamMember) IncrScoreById(id, score int64) (int64, error) {
|
|
t.SortTime = time.Now().UnixNano()
|
|
return core.GetXormAuto().ID(id).Incr("score", score).Cols("score, sort_time").Update(t)
|
|
}
|
|
|
|
func GetBaheMembersByTeamId(teamId, rehearsalId interface{}) (members []*BaheTeamMember, err error) {
|
|
err = core.GetXormAuto().Where("is_delete=0 and team_id=? and rehearsal_id=?",
|
|
teamId, rehearsalId).Desc("score").Asc("sort_time").Find(&members)
|
|
return
|
|
}
|