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.
59 lines
2.8 KiB
59 lines
2.8 KiB
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/ouxuanserver/osmanthuswine/src/core"
|
|
)
|
|
|
|
const CalorieUserTableName = TableNamePrefix + "calorie_user"
|
|
|
|
type CalorieUser struct {
|
|
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
|
|
ActivityId int `json:"activity_id" xorm:"not null comment('互动id') INT(11)"`
|
|
ArchId int `json:"arch_id" xorm:"not null default 0 comment('归档id') INT(11)"`
|
|
UserId int `json:"user_id" xorm:"not null comment('用户表id') INT(11)"`
|
|
CalorieId int `json:"calorie_id" xorm:"not null comment('calorie表id') INT(11)"`
|
|
RehearsalId int `json:"rehearsal_id" xorm:"not null default(0) comment('彩排id') INT(11)"`
|
|
Score int `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"`
|
|
|
|
// 无关变量
|
|
Avatar string `json:"avatar" xorm:"-"`
|
|
Nickname string `json:"nickname" xorm:"-"`
|
|
}
|
|
|
|
func (t *CalorieUser) TableName() string {
|
|
return CalorieUserTableName
|
|
}
|
|
|
|
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) {
|
|
t.JoinTime = time.Now().UnixNano()
|
|
return core.GetXormAuto().Where("is_delete=0 and arch_id=? and id=?", archId, id).
|
|
Cols("score", "join_time").Incr("score", score).Update(t)
|
|
}
|
|
|
|
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, archId, rehearsalId, score interface{}) ([]*CalorieUser, error) {
|
|
users := make([]*CalorieUser, 0)
|
|
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, 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)
|
|
}
|