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

50 lines
2.3 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
  1. package models
  2. import (
  3. "github.com/ouxuanserver/osmanthuswine/src/core"
  4. "time"
  5. )
  6. const UserPrizeTableName = TableNamePrefix + "user_prize"
  7. type UserPrize struct {
  8. Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
  9. UserId int64 `json:"user_id" xorm:"not null comment('用户表id') INT(11)"`
  10. ActivityId int64 `json:"activity_id" xorm:"not null comment('互动表id') INT(11)"`
  11. RehearsalId int64 `json:"rehearsal_id" xorm:"not null default(0) comment('彩排id') INT(11)"`
  12. ArchId int `json:"arch_id" xorm:"not null default 0 comment('归档id') INT(11)"`
  13. ActivityName string `json:"activity_name" xorm:"not null default('') comment('互动名字') VARCHAR(128)"`
  14. PrizeName string `json:"prize_name" xorm:"not null default('') comment('奖品名字') VARCHAR(128)"`
  15. PrizeImg string `json:"prize_img" xorm:"not null default('') comment('奖品图片') VARCHAR(255)"`
  16. PrizeType int `json:"prize_type" xorm:"not null default(0) comment('订单来源1普通抽奖2订单抽奖3订单送礼4直播下单') INT(11)"`
  17. Status int `json:"status" xorm:"not null default 0 comment('是否已经兑奖0否1是') TINYINT(1)"`
  18. IsDelete bool `json:"is_delete" xorm:"not null default(0) comment('软删除') TINYINT(1)"`
  19. CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"`
  20. UpdatedAt time.Time `json:"updated_at" xorm:"not null updated comment('更新时间') DATETIME"`
  21. }
  22. func (t *UserPrize) TableName() string {
  23. return UserPrizeTableName
  24. }
  25. func (t *UserPrize) SoftDeleteById(id int64) (int64, error) {
  26. t.IsDelete = true
  27. return core.GetXormAuto().Where("id=?", id).Cols("is_delete").Update(t)
  28. }
  29. func (t *UserPrize) Add() (int64, error) {
  30. return core.GetXormAuto().InsertOne(t)
  31. }
  32. func (t *UserPrize) Update(fields ...string) error {
  33. _, err := core.GetXormAuto().Where("is_delete=0 and id = ? and user_id =?", t.Id, t.UserId).Cols(fields...).Update(t)
  34. return err
  35. }
  36. func GetUserPrizesByUserIdAndActivityId(userId, activityId, rehearsalId interface{}) ([]*UserPrize, error) {
  37. prizes := make([]*UserPrize, 0)
  38. err := core.GetXormAuto().Where("is_delete=0 and user_id=? and activity_id=? and rehearsal_id=?",
  39. userId, activityId, rehearsalId).
  40. Desc("created_at").Find(&prizes)
  41. return prizes, err
  42. }