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

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package models
  2. import (
  3. "github.com/ouxuanserver/osmanthuswine/src/core"
  4. "time"
  5. )
  6. const BaheTeamTable = TableNamePrefix + "bahe_team"
  7. //拔河队伍
  8. type BaheTeam struct {
  9. Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
  10. ActivityId int64 `json:"activity_id" xorm:"not null comment('活动id') INT(11)"`
  11. BaheActivityId int64 `json:"bahe_activity_id" xorm:"not null comment('拔河活动id') INT(11) "`
  12. BaheTeamName string `json:"bahe_team_name" xorm:"not null comment('拔河队伍得名称') VARCHAR(255)"`
  13. TotalScore int64 `json:"total_score" xorm:"-" description:"总分数"`
  14. Rank int `json:"rank" xorm:"-" description:"排名"`
  15. Members []*BaheTeamMember `json:"members" xorm:"-" description:"队伍人数"`
  16. Qrcode string `json:"qrcode" xorm:"-" description:"二维码"`
  17. IsDelete bool `json:"is_delete" xorm:"not null default(0) comment('是否已删除') TINYINT(1)"`
  18. CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"`
  19. UpdatedAt time.Time `json:"updated_at" xorm:"not null updated comment('更新时间') DATETIME"`
  20. }
  21. func (t *BaheTeam) TableName() string {
  22. return BaheTeamTable
  23. }
  24. func (t *BaheTeam) GetOtherTeam(id, bid int64) (bool, error) {
  25. return core.GetXormAuto().Where("is_delete=0 and id=? and bahe_activity_id=?", id, bid).Get(t)
  26. }
  27. func GetJoinTeamByTeamId(obj, teamId, rehearsalId interface{}) (bool, error) {
  28. return core.GetXormAuto().Table(new(BaheTeam)).Alias("t").
  29. Select("t.id as team_id, t.bahe_team_name as team_name, count(m.id) as number").
  30. Join("LEFT", new(BaheTeamMember).Alias("m"),
  31. "m.team_id=t.id and m.is_delete=0 and m.rehearsal_id=?", rehearsalId).
  32. Where("t.is_delete=0 and t.id=?", teamId).GroupBy("t.id").Get(&obj)
  33. }
  34. func GetJoinTeamByBaheId(obj, baheId, rehearsalId interface{}) (bool, error) {
  35. return core.GetXormAuto().Table(new(BaheTeam)).Alias("t").
  36. Select("t.id as team_id, t.bahe_team_name as team_name, count(m.id) as number").
  37. Join("LEFT", new(BaheTeamMember).Alias("m"),
  38. "m.team_id=t.id and m.is_delete=0 and m.rehearsal_id=?", rehearsalId).
  39. Where("t.is_delete=0 and t.bahe_activity_id=? ", baheId).
  40. GroupBy("t.id").Asc("number").Get(&obj)
  41. }