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

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
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. ArchId int `json:"arch_id" xorm:"not null default 0 comment('归档id') INT(11)"`
  11. BaheActivityId int64 `json:"bahe_activity_id" xorm:"not null default(0) comment('拔河活動id') BIGINT(20)"`
  12. TeamId int64 `json:"team_id" xorm:"not null default(0) comment('队伍id') BIGINT(20)"`
  13. TeamName string `json:"team_name" xorm:"not null default('') comment('队伍名字') VARCHAR(255)"`
  14. MemberId int64 `json:"member_id" xorm:"not null comment('用户id') BIGINT(20)"`
  15. Score int64 `json:"score" xorm:"not null default(0) comment('分数') INT(11)"`
  16. RehearsalId int64 `json:"rehearsal_id" xorm:"not null default(0) comment('彩排id/0正式') BIGINT(20)"`
  17. Avatar string `json:"avatar" xorm:"not null comment('头像') VARCHAR(255)"`
  18. NickName string `json:"nick_name" xorm:"not null comment('昵称') VARCHAR(255)"`
  19. SortTime int64 `json:"sort_time" xorm:"not null default '0' comment('排序时间') VARCHAR(20)"`
  20. IsDelete bool `json:"-" xorm:"not null default(0) comment('软删除') TINYINT(1)"`
  21. CreatedAt time.Time `json:"-" xorm:"not null created comment('创建时间') DATETIME"`
  22. UpdatedAt time.Time `json:"-" xorm:"not null updated comment('更新时间') DATETIME"`
  23. }
  24. func (t *BaheTeamMember) TableName() string {
  25. return BaheTeamMemberTableName
  26. }
  27. func (t *BaheTeamMember) Alias(name string) string {
  28. return Alias(t, name)
  29. }
  30. func (t *BaheTeamMember) GetMemberByBaheIdAndUserId(archId, userId, baheId, rehearsalId interface{}) (bool, error) {
  31. return core.GetXormAuto().Where("arch_id=? and member_id=? and bahe_activity_id=? "+
  32. " and rehearsal_id=? and is_delete=0", archId, userId, baheId, rehearsalId).Get(t)
  33. }
  34. func (t *BaheTeamMember) IncrScoreById(archId, id, score interface{}) (int64, error) {
  35. t.SortTime = time.Now().UnixNano()
  36. return core.GetXormAuto().Where("arch_id=? and id=?", archId, id).
  37. Incr("score", score).Cols("score, sort_time").Update(t)
  38. }
  39. func GetBaheMembersByTeamId(teamId, rehearsalId interface{}) ([]*BaheTeamMember, error) {
  40. members := make([]*BaheTeamMember, 0)
  41. err := core.GetXormAuto().Where("is_delete=0 and team_id=? and rehearsal_id=?",
  42. teamId, rehearsalId).Desc("score").Asc("sort_time").Find(&members)
  43. return members, err
  44. }