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

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package models
  2. import (
  3. "time"
  4. "github.com/ouxuanserver/osmanthuswine/src/core"
  5. )
  6. const BaheTeamMemberTableName = TableNamePrefix + "bahe_team_member"
  7. //拔河队伍人员
  8. type BaheTeamMember struct {
  9. Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
  10. BaheActivityId int64 `json:"bahe_activity_id" xorm:"not null default(0) comment('拔河活動id') BIGINT(20)"`
  11. TeamId int64 `json:"team_id" xorm:"not null default(0) comment('队伍id') BIGINT(20)"`
  12. TeamName string `json:"team_name" xorm:"not null default('') comment('队伍名字') VARCHAR(255)"`
  13. MemberId int64 `json:"member_id" xorm:"not null comment('用户id') BIGINT(20)"`
  14. Score int64 `json:"score" xorm:"not null default(0) comment('分数') INT(11)"`
  15. RehearsalId int64 `json:"rehearsal_id" xorm:"not null default(0) comment('彩排id/0正式') BIGINT(20)"`
  16. Avatar string `json:"avatar" xorm:"not null comment('头像') VARCHAR(255)"`
  17. NickName string `json:"nick_name" xorm:"not null comment('昵称') VARCHAR(255)"`
  18. SortTime int64 `json:"sort_time" xorm:"not null default '0' comment('排序时间') VARCHAR(20)"`
  19. IsDelete bool `json:"-" xorm:"not null default(0) comment('软删除') TINYINT(1)"`
  20. CreatedAt time.Time `json:"-" xorm:"not null created comment('创建时间') DATETIME"`
  21. UpdatedAt time.Time `json:"-" xorm:"not null updated comment('更新时间') DATETIME"`
  22. }
  23. func (t *BaheTeamMember) TableName() string {
  24. return BaheTeamMemberTableName
  25. }
  26. func (t *BaheTeamMember) Alias(name string) string {
  27. return AliasTableName(t, name)
  28. }
  29. func (t *BaheTeamMember) GetMemberByBaheIdAndUserId(uid, bid, rid int64) (bool, error) {
  30. return core.GetXormAuto().Where("member_id=? and bahe_activity_id=? and rehearsal_id=? and is_delete=0", uid, bid, rid).Get(t)
  31. }
  32. func (t *BaheTeamMember) IncrScoreById(id, score int64) (int64, error) {
  33. t.SortTime = time.Now().UnixNano()
  34. return core.GetXormAuto().ID(id).Incr("score", score).Cols("score, sort_time").Update(t)
  35. }
  36. func GetBaheMembersByTeamId(teamId, rehearsalId interface{}) (members []*BaheTeamMember, err error) {
  37. err = core.GetXormAuto().Where("is_delete=0 and team_id=? and rehearsal_id=?",
  38. teamId, rehearsalId).Desc("score").Asc("sort_time").Find(&members)
  39. return
  40. }