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
51 lines
2.0 KiB
package models
|
|
|
|
import (
|
|
"hudongzhuanjia/utils/define"
|
|
"time"
|
|
|
|
"github.com/ouxuanserver/osmanthuswine/src/core"
|
|
)
|
|
|
|
type TugOfWar struct {
|
|
Id int64 `json:"id" description:"主键"`
|
|
Model string `json:"model" description:"拔河模式.随机分配模式|H5挑选模式|大屏幕二维码模式"`
|
|
Status string `json:"status" description:"拔河活动状态[未开始,准备中,进行中,已结束]"`
|
|
Number int `json:"number" description:"预测人数"`
|
|
ActivityId int64 `json:"activity_id" description:"主活动id"`
|
|
IsDelete bool `json:"is_delete" xorm:"default(0)" description:"是否删除"`
|
|
CreatedAt time.Time `json:"created_at" xorm:"created" description:"创建时间"`
|
|
UpdatedAt time.Time `json:"updated_at" xorm:"updated" description:"更新时间"`
|
|
}
|
|
|
|
func (t *TugOfWar) TableName() string {
|
|
return TableNamePrefix + "tug_of_war"
|
|
}
|
|
|
|
func (t *TugOfWar) GetByActivityId(aid int64, status string) (bool, error) {
|
|
return core.GetXormAuto().Where("is_delete=0 and activity_id=? and status=?", aid, status).
|
|
Desc("created_at").Get(t)
|
|
}
|
|
|
|
func (t *TugOfWar) GetCurrent(aid int64) (bool, error) {
|
|
return core.GetXormAuto().Where("is_delete=0 and activity_id=? and (status=? or status=?)",
|
|
aid, define.StatusReady, define.StatusRunning).Get(t)
|
|
}
|
|
|
|
func (t *TugOfWar) UpdateStatusById(id int64, status string) (int64, error) {
|
|
t.Status = status
|
|
t.UpdatedAt = time.Now()
|
|
return core.GetXormAuto().Where("is_delete=0 and id=?", id).Cols("status", "updated_at").Update(t)
|
|
}
|
|
|
|
func (t *TugOfWar) UpdateToStatusByAid(aid int64, before, after string) (int64, error) {
|
|
t.Status = after
|
|
t.UpdatedAt = time.Now()
|
|
return core.GetXormAuto().Where("is_delete=0 and status=? and activity_id=?", before, aid).
|
|
Cols("status", "updated_at").Update(t)
|
|
}
|
|
|
|
func UpdateTOWStatusByActivityId(aid int64) (int64, error) {
|
|
return core.GetXormAuto().Where("is_delete=0 and activity_id=?", aid).
|
|
Update(&TugOfWar{Status: define.StatusNotBegin})
|
|
}
|