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

51 lines
2.1 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
5 years ago
5 years ago
5 years ago
  1. package models
  2. import (
  3. "hudongzhuanjia/utils/define"
  4. "time"
  5. "github.com/ouxuanserver/osmanthuswine/src/core"
  6. )
  7. type TugOfWar struct {
  8. Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
  9. Model string `json:"model" xorm:"not null default '随机分配模式' comment('拔河模式.随机分配模式|H5挑选模式|大屏幕二维码模式') VARCHAR(128)"`
  10. Status string `json:"status" xorm:"not null default '未开始' comment('拔河活动状态[未开始,准备中,进行中,已结束]') VARCHAR(128)"`
  11. Number int `json:"number" xorm:"not null default 0 comment('预测人数') INT(11)"`
  12. ActivityId int `json:"activity_id" xorm:"not null default 0 comment('主活动id') INT(11)"`
  13. IsDelete bool `json:"is_delete" xorm:"default(0)" description:"是否删除"`
  14. CreatedAt time.Time `json:"created_at" xorm:"created" description:"创建时间"`
  15. UpdatedAt time.Time `json:"updated_at" xorm:"updated" description:"更新时间"`
  16. }
  17. func (t *TugOfWar) TableName() string {
  18. return TableNamePrefix + "tug_of_war"
  19. }
  20. func (t *TugOfWar) GetByActivityId(aid int, status string) (bool, error) {
  21. return core.GetXormAuto().Where("is_delete=0 and activity_id=? and status=?", aid, status).
  22. Desc("created_at").Get(t)
  23. }
  24. func (t *TugOfWar) GetCurrent(activityId interface{}) (bool, error) {
  25. return core.GetXormAuto().Where("is_delete=0 and activity_id=? and (status=? or status=?)",
  26. activityId, define.StatusReady, define.StatusRunning).Get(t)
  27. }
  28. func (t *TugOfWar) UpdateStatusById(id int, status string) (int64, error) {
  29. t.Status = status
  30. t.UpdatedAt = time.Now()
  31. return core.GetXormAuto().Where("is_delete=0 and id=?", id).Cols("status", "updated_at").Update(t)
  32. }
  33. func (t *TugOfWar) UpdateToStatusByAid(aid int, before, after string) (int64, error) {
  34. t.Status = after
  35. t.UpdatedAt = time.Now()
  36. return core.GetXormAuto().Where("is_delete=0 and status=? and activity_id=?", before, aid).
  37. Cols("status", "updated_at").Update(t)
  38. }
  39. func UpdateTOWStatusByActivityId(aid int) (int64, error) {
  40. return core.GetXormAuto().Where("is_delete=0 and activity_id=?", aid).
  41. Update(&TugOfWar{Status: define.StatusNotBegin})
  42. }