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.
54 lines
2.5 KiB
54 lines
2.5 KiB
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/ouxuanserver/osmanthuswine/src/core"
|
|
)
|
|
|
|
const BaheTeamMemberTableName = TableNamePrefix + "bahe_team_member"
|
|
|
|
//拔河队伍人员
|
|
type BaheTeamMember struct {
|
|
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
|
|
ArchId int `json:"arch_id" xorm:"not null default 0 comment('归档id') INT(11)"`
|
|
BaheActivityId int `json:"bahe_activity_id" xorm:"not null default(0) comment('拔河活動id') BIGINT(20)"`
|
|
TeamId int `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 int `json:"member_id" xorm:"not null comment('用户id') BIGINT(20)"`
|
|
Score int `json:"score" xorm:"not null default(0) comment('分数') INT(11)"`
|
|
RehearsalId int `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 Alias(t, name)
|
|
}
|
|
|
|
func (t *BaheTeamMember) GetMemberByBaheIdAndUserId(archId, userId, baheId, rehearsalId interface{}) (bool, error) {
|
|
return core.GetXormAuto().Where("arch_id=? and member_id=? and bahe_activity_id=? "+
|
|
" and rehearsal_id=? and is_delete=0", archId, userId, baheId, rehearsalId).Get(t)
|
|
}
|
|
|
|
func (t *BaheTeamMember) IncrScoreById(archId, id, score interface{}) (int64, error) {
|
|
t.SortTime = time.Now().UnixNano()
|
|
return core.GetXormAuto().Where("arch_id=? and id=?", archId, id).
|
|
Incr("score", score).Cols("score, sort_time").Update(t)
|
|
}
|
|
|
|
func GetBaheMembersByTeamId(teamId, rehearsalId interface{}) ([]*BaheTeamMember, error) {
|
|
members := make([]*BaheTeamMember, 0)
|
|
err := core.GetXormAuto().Where("is_delete=0 and team_id=? and rehearsal_id=?",
|
|
teamId, rehearsalId).Desc("score").Asc("sort_time").Find(&members)
|
|
return members, err
|
|
|
|
}
|