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

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