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

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