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

80 lines
4.2 KiB

package models
import (
"github.com/ouxuanserver/osmanthuswine/src/core"
"time"
)
const LotteryDrawRecordTableName = TableNamePrefix + "lottery_draw_record"
type LotteryDrawRecord struct {
Id int64 `json:"id" xorm:"pk autoincr"`
ActivityId int64 `json:"activity_id" xorm:"not null comment('主活动id')"`
RehearsalId int64 `json:"rehearsal_id" xorm:"not null comment('彩排id/0正式')"`
UserPrizeId int64 `json:"user_prize_id" xorm:"not null comment('用户奖品id') INT(11)"`
LotteryDrawActivityId int64 `json:"lottery_draw_activity_id" xorm:"not null comment('抽奖活动id')"`
LotteryDrawRuleId int64 `json:"lottery_draw_rule_id" xorm:"not null comment('抽奖规则id') BIGINT(20)"`
LotteryDrawRuleLadderId int64 `json:"lottery_draw_rule_ladder_id" xorm:"not null comment('规则阶梯id')"`
UserId int64 `json:"user_id" xorm:"not null comment('用户id')"`
RollNum int `json:"roll_num" xrom:"not null default 0 comment('滚动次数') INT(11)"`
UserName string `json:"user_name" description:"用户名" xorm:"not null comment('用户名')"`
UserPhone string `json:"user_phone" description:"电话" xorm:"not null comment('电话号码')"`
PrizeName string `json:"prize_name" description:"奖品名字" xorm:"not null comment('奖品名字')"`
AreaName string `json:"area_name" description:"名字" xorm:"not null comment('地区名字')"`
AreaId int64 `json:"area_id" xorm:"not null default(0) comment('地区id')"`
Status int `json:"status" xorm:"not null default 0 comment('是否已经兑奖0否1是') TINYINT(1)"`
Name string `json:"name" xorm:"not null default '' comment('姓名') VARCHAR(128)"`
Phone string `json:"phone" xorm:"not null default '' comment('电话号码') VARCHAR(128)"`
WxNo string `json:"wx_no" xorm:"not null default '' comment('微信号') VARCHAR(128)"`
Address string `json:"address" xorm:"not null default '' comment('地址') VARCHAR(128)"`
IsDelete bool `json:"-" xorm:"default(0)"`
CreatedAt time.Time `json:"-" xorm:"created"`
UpdatedAt time.Time `json:"-" xorm:"updated"`
// 无关变量
User *User `json:"user" xorm:"-"`
LotteryDrawRuleLadder *LotteryDrawRuleLadder `json:"lottery_draw_rule_ladder" xorm:"-"`
}
func (t *LotteryDrawRecord) TableName() string {
return LotteryDrawRecordTableName
}
func (t *LotteryDrawRecord) GetByUserIdAndLadderId(userId, ladderId interface{}, rollNum int) (bool, error) {
session := core.GetXormAuto().Where("is_delete=0 and user_id=? and lottery_draw_rule_ladder_id=?", userId, ladderId)
defer session.Close()
if rollNum > 0 {
session.Where("roll_num=?", rollNum)
}
return session.Get(t)
}
func (t *LotteryDrawRecord) GetByUserPrizeId(upId int64) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and user_prize_id=?", upId).Get(t)
}
func GetLotteryUsersResultByLotteryDrawRecord(obj, ladderId, rehearsalId interface{}, rollNum int) error {
session := core.GetXormAuto().Table(new(LotteryDrawRecord)).Alias("r").
Join("LEFT", new(User).Alias("u"), "u.id=r.user_id").
Where("r.is_delete=0 and r.lottery_draw_rule_ladder_id=? and "+
"r.rehearsal_id=?", ladderId, rehearsalId)
defer session.Close()
if rollNum > 0 {
session = session.Where("roll_num=?", rollNum)
}
return session.Find(&obj)
}
func GetUserIdsByLotteryDrawRuleId(ruleId, rehearsalId, areaId interface{}) ([]int64, error) {
recordIds := make([]int64, 0)
err := core.GetXormAuto().Table(new(LotteryDrawRecord)).Select("user_id").
Where("lottery_draw_rule_id=? and rehearsal_id=? and area_id=? and is_delete=0",
ruleId, rehearsalId, areaId).Find(&recordIds)
return recordIds, err
}
func (t *LotteryDrawRecord) CountRecord(ruleId, ladderId, rehearsalId, areaId interface{}) (int64, error) {
return core.GetXormAuto().Where("lottery_draw_rule_id=? and lottery_draw_rule_ladder_id=? "+
"and rehearsal_id=? and area_id=? and is_delete=0", ruleId, ladderId, rehearsalId, areaId).
Count(t)
}