|
|
@ -10,8 +10,7 @@ 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:"-"` |
|
|
|
ArchId int `json:"arch_id" xorm:"not null default 0 comment('归档id') INT(11)"` |
|
|
|
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)"` |
|
|
@ -20,14 +19,19 @@ type CalorieUser struct { |
|
|
|
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"` |
|
|
|
|
|
|
|
// 无关变量
|
|
|
|
Avatar string `json:"avatar" xorm:"-"` |
|
|
|
Nickname string `json:"nickname" xorm:"-"` |
|
|
|
} |
|
|
|
|
|
|
|
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) GetByCalorieIdAndUserId(calorieId, archId, userId, rehearsalId interface{}) (bool, error) { |
|
|
|
return core.GetXormAuto().Where("is_delete=0 and calorie_id=? and arch_id=? and user_id=? and rehearsal_id=?", |
|
|
|
calorieId, archId, userId, rehearsalId).Get(t) |
|
|
|
} |
|
|
|
|
|
|
|
func (t *CalorieUser) IncrScore(archId, id, score interface{}) (int64, error) { |
|
|
@ -36,19 +40,19 @@ func (t *CalorieUser) IncrScore(archId, id, score interface{}) (int64, error) { |
|
|
|
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 (t *CalorieUser) CountByCalorieId(calorieId, archId, rehearsalId interface{}) (int64, error) { |
|
|
|
return core.GetXormAuto().Where("is_delete=0 and calorie_id=? and arch_id=? and rehearsal_id=?", |
|
|
|
calorieId, archId, rehearsalId).Count(&CalorieUser{}) |
|
|
|
} |
|
|
|
|
|
|
|
func GetCalorieUsersByCalorieIdAndScore(calorieId, rehearsalId, score interface{}) ([]*CalorieUser, error) { |
|
|
|
func GetCalorieUsersByCalorieIdAndScore(calorieId, archId, 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) |
|
|
|
err := core.GetXormAuto().Where("is_delete=0 and calorie_id=? and arch_id=? and rehearsal_id=? and score<=?", |
|
|
|
calorieId, archId, 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) |
|
|
|
func (t *CalorieUser) Count(calorieId, archId, rehearsalId interface{}) (int64, error) { |
|
|
|
return core.GetXormAuto().Where("is_delete=0 and calorie_id=? and arch_id=? and rehearsal_id=?", |
|
|
|
calorieId, archId, rehearsalId).Count(t) |
|
|
|
} |