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

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 int64 `json:"id" description:"主键"`
  9. Model string `json:"model" description:"拔河模式.随机分配模式|H5挑选模式|大屏幕二维码模式"`
  10. Status string `json:"status" description:"拔河活动状态[未开始,准备中,进行中,已结束]"`
  11. Number int `json:"number" description:"预测人数"`
  12. ActivityId int64 `json:"activity_id" description:"主活动id"`
  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 int64, 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(aid int64) (bool, error) {
  25. return core.GetXormAuto().Where("is_delete=0 and activity_id=? and (status=? or status=?)",
  26. aid, define.StatusReady, define.StatusRunning).Get(t)
  27. }
  28. func (t *TugOfWar) UpdateStatusById(id int64, 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 int64, 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 int64) (int64, error) {
  40. return core.GetXormAuto().Where("is_delete=0 and activity_id=?", aid).
  41. Update(&TugOfWar{Status: define.StatusNotBegin})
  42. }