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
51 lines
2.1 KiB
package models
|
|
|
|
import (
|
|
"hudongzhuanjia/utils/define"
|
|
"time"
|
|
|
|
"git.ouxuan.net/tommy/osmanthuswine/src/core"
|
|
)
|
|
|
|
type TugOfWar struct {
|
|
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
|
|
Model string `json:"model" xorm:"not null default '随机分配模式' comment('拔河模式.随机分配模式|H5挑选模式|大屏幕二维码模式') VARCHAR(128)"`
|
|
Status string `json:"status" xorm:"not null default '未开始' comment('拔河活动状态[未开始,准备中,进行中,已结束]') VARCHAR(128)"`
|
|
Number int `json:"number" xorm:"not null default 0 comment('预测人数') INT(11)"`
|
|
ActivityId int `json:"activity_id" xorm:"not null default 0 comment('主活动id') INT(11)"`
|
|
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 int, 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(activityId interface{}) (bool, error) {
|
|
return core.GetXormAuto().Where("is_delete=0 and activity_id=? and (status=? or status=?)",
|
|
activityId, define.StatusReady, define.StatusRunning).Get(t)
|
|
}
|
|
|
|
func (t *TugOfWar) UpdateStatusById(id int, 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 int, 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 int) (int64, error) {
|
|
return core.GetXormAuto().Where("is_delete=0 and activity_id=?", aid).
|
|
Update(&TugOfWar{Status: define.StatusNotBegin})
|
|
}
|