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

package models
import (
"github.com/ouxuanserver/osmanthuswine/src/core"
"time"
)
const UserPrizeTableName = TableNamePrefix + "user_prize"
type UserPrize struct {
Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
UserId int64 `json:"user_id" xorm:"not null comment('用户表id') INT(11)"`
ActivityId int64 `json:"activity_id" xorm:"not null comment('互动表id') INT(11)"`
RehearsalId int64 `json:"rehearsal_id" xorm:"not null default(0) comment('彩排id') INT(11)"`
ActivityName string `json:"activity_name" xorm:"not null default('') comment('互动名字') VARCHAR(128)"`
PrizeName string `json:"prize_name" xorm:"not null default('') comment('奖品名字') VARCHAR(128)"`
PrizeImg string `json:"prize_img" xorm:"not null default('') comment('奖品图片') VARCHAR(255)"`
PrizeType int `json:"prize_type" xorm:"not null default(0) comment('订单来源1普通抽奖2订单抽奖3订单送礼4直播下单') INT(11)"`
Status int `json:"status" xorm:"not null default 0 comment('是否已经兑奖0否1是') TINYINT(1)"`
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 updated comment('更新时间') DATETIME"`
}
func (t *UserPrize) TableName() string {
return UserPrizeTableName
}
func (t *UserPrize) SoftDeleteById(id int64) (int64, error) {
t.IsDelete = true
return core.GetXormAuto().Where("id=?", id).Cols("is_delete").Update(t)
}
func (t *UserPrize) Add() (int64, error) {
return core.GetXormAuto().InsertOne(t)
}
func (t *UserPrize) Update(fields ...string) error {
_, err := core.GetXormAuto().Where("is_delete=0 and id = ? and user_id =?", t.Id, t.UserId).Cols(fields...).Update(t)
return err
}
func GetUserPrizesByUserIdAndActivityId(userId, activityId, rehearsalId interface{}) ([]*UserPrize, error) {
prizes := make([]*UserPrize, 0)
err := core.GetXormAuto().Where("is_delete=0 and user_id=? and activity_id=? and rehearsal_id=?",
userId, activityId, rehearsalId).
Desc("created_at").Find(&prizes)
return prizes, err
}