|
|
package models
import ( "github.com/ouxuanserver/osmanthuswine/src/core" "time" )
const CalorieUserTableName = TableNamePrefix + "calorie_user"
type CalorieUser struct { Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"` ActivityId int64 `json:"activity_id" xorm:"not null comment('互动id') INT(11)"` Avatar string `json:"avatar" xorm:"-"` Nickname string `json:"nickname" xorm:"-"` UserId int64 `json:"user_id" xorm:"not null comment('用户表id') INT(11)"` CalorieId int64 `json:"calorie_id" xorm:"not null comment('calorie表id') INT(11)"` RehearsalId int64 `json:"rehearsal_id" xorm:"not null default(0) comment('彩排id') INT(11)"` Score int64 `json:"score" xorm:"not null default(0) comment('分数') INT(11)"` JoinTime int64 `json:"join_time" xorm:"not null default('0') comment('加入时间纳秒') VARCHAR(128)"` 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 comment('创建时间') TIMESTAMP"` }
func (t *CalorieUser) TableName() string { return CalorieUserTableName }
func (t *CalorieUser) GetByCalorieIdAndUserId(cid, uid, rid int64) (bool, error) { return core.GetXormAuto().Where("is_delete=0 and calorie_id=? and user_id=? and rehearsal_id=?", cid, uid, rid).Get(t) }
func (t *CalorieUser) IncrScore(score int) (int64, error) { t.JoinTime = time.Now().UnixNano() return core.GetXormAuto().Where("is_delete=0 and id=?", t.Id).Cols("score", "join_time").Incr("score", score).Update(t) }
func (t *CalorieUser) CountByCalorieId(calorieId, rehearsalId interface{}) (int64, error) { return core.GetXormAuto().Where("is_delete=0 and calorie_id=? and rehearsal_id=?", calorieId, rehearsalId).Count(&CalorieUser{}) }
func GetCalorieUsersByCalorieIdAndScore(calorieId, rehearsalId, score interface{}) ([]*CalorieUser, error) { users := make([]*CalorieUser, 0) err := core.GetXormAuto().Where("is_delete=0 and calorie_id=? and rehearsal_id=? and score<=?", calorieId, rehearsalId, score).Desc("score").Asc("join_time").Find(&users) return users, err }
func (t *CalorieUser) Count(calorieId, rehearsalId interface{}) (int64, error) { return core.GetXormAuto().Where("is_delete=0 and calorie_id=? and rehearsal_id=?", calorieId, rehearsalId).Count(t) }
|