互动
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

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package models
  2. import (
  3. "time"
  4. "github.com/ouxuanserver/osmanthuswine/src/core"
  5. )
  6. const CalorieUserTableName = TableNamePrefix + "calorie_user"
  7. type CalorieUser struct {
  8. Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
  9. ActivityId int `json:"activity_id" xorm:"not null comment('互动id') INT(11)"`
  10. ArchId int `json:"arch_id" xorm:"not null default 0 comment('归档id') INT(11)"`
  11. UserId int `json:"user_id" xorm:"not null comment('用户表id') INT(11)"`
  12. CalorieId int `json:"calorie_id" xorm:"not null comment('calorie表id') INT(11)"`
  13. RehearsalId int `json:"rehearsal_id" xorm:"not null default(0) comment('彩排id') INT(11)"`
  14. Score int `json:"score" xorm:"not null default(0) comment('分数') INT(11)"`
  15. JoinTime int64 `json:"join_time" xorm:"not null default('0') comment('加入时间纳秒') VARCHAR(128)"`
  16. IsDelete bool `json:"is_delete" xorm:"not null default(0) comment('是否删除') TINYINT(1)"`
  17. CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"`
  18. UpdatedAt time.Time `json:"updated_at" xorm:"not null default(CURRENT_TIMESTAMP) updated comment('创建时间') TIMESTAMP"`
  19. // 无关变量
  20. Avatar string `json:"avatar" xorm:"-"`
  21. Nickname string `json:"nickname" xorm:"-"`
  22. }
  23. func (t *CalorieUser) TableName() string {
  24. return CalorieUserTableName
  25. }
  26. func (t *CalorieUser) GetByCalorieIdAndUserId(calorieId, archId, userId, rehearsalId interface{}) (bool, error) {
  27. return core.GetXormAuto().Where("is_delete=0 and calorie_id=? and arch_id=? and user_id=? and rehearsal_id=?",
  28. calorieId, archId, userId, rehearsalId).Get(t)
  29. }
  30. func (t *CalorieUser) IncrScore(archId, id, score interface{}) (int64, error) {
  31. t.JoinTime = time.Now().UnixNano()
  32. return core.GetXormAuto().Where("is_delete=0 and arch_id=? and id=?", archId, id).
  33. Cols("score", "join_time").Incr("score", score).Update(t)
  34. }
  35. func (t *CalorieUser) CountByCalorieId(calorieId, archId, rehearsalId interface{}) (int64, error) {
  36. return core.GetXormAuto().Where("is_delete=0 and calorie_id=? and arch_id=? and rehearsal_id=?",
  37. calorieId, archId, rehearsalId).Count(&CalorieUser{})
  38. }
  39. func GetCalorieUsersByCalorieIdAndScore(calorieId, archId, rehearsalId, score interface{}) ([]*CalorieUser, error) {
  40. users := make([]*CalorieUser, 0)
  41. err := core.GetXormAuto().Where("is_delete=0 and calorie_id=? and arch_id=? and rehearsal_id=? and score<=?",
  42. calorieId, archId, rehearsalId, score).Desc("score").Asc("join_time").Find(&users)
  43. return users, err
  44. }
  45. func (t *CalorieUser) Count(calorieId, archId, rehearsalId interface{}) (int64, error) {
  46. return core.GetXormAuto().Where("is_delete=0 and calorie_id=? and arch_id=? and rehearsal_id=?",
  47. calorieId, archId, rehearsalId).Count(t)
  48. }