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.
|
|
package models
import ( "hudongzhuanjia/utils/define" "time"
"git.ouxuan.net/tommy/osmanthuswine/src/core" )
const CalorieTableName = TableNamePrefix + "calorie"
type Calorie struct { Id int `json:"id" xorm:"not null pk autoincr INT(11)"` ActivityId int `json:"activity_id" xorm:"not null comment('互动id') INT(11)"` GameDuration int `json:"game_duration" xorm:"not null default(60) comment('游戏时长秒') INT(11)"` StartTime int64 `json:"start_time" xorm:"not null default(0) comment('游戏开始时间') INT(11)"` Status string `json:"status" xorm:"not null default('未开始') comment('状态[未开始,准备中,进行中,已结束]') VARCHAR(11)"` IsDelete bool `json:"is_delete" xorm:"not null default(0) comment('是否删除') TINYINT(1)"` CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"` UpdatedAt time.Time `json:"updated_at" xorm:"not null default(CURRENT_TIMESTAMP) updated TIMESTAMP"` }
func (t *Calorie) TableName() string { return CalorieTableName }
func (t *Calorie) UpdateToStatusByActivityId(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 (t *Calorie) 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", "start_time", "updated_at").Update(t) }
func (t *Calorie) GetCurrent(aid interface{}) (bool, error) { return core.GetXormAuto().Where("is_delete=0 and activity_id=? and (status=? or status=?)", aid, define.StatusReady, define.StatusRunning).Desc("created_at").Get(t) }
func UpdateCalorieStatusByActivityId(aid int) (int64, error) { return core.GetXormAuto().Where("is_delete=0 and activity_id=?", aid). Update(&Calorie{Status: define.StatusNotBegin}) }
func GetCaloriesByActivityId(activityId interface{}) ([]*Calorie, error) { calories := make([]*Calorie, 0) err := core.GetXormAuto().Where("is_delete=0 and activity_id=?", activityId).Find(&calories) return calories, err }
|