package models import ( "time" "github.com/ouxuanserver/osmanthuswine/src/core" ) const ReWardHistoryTableName = TableNamePrefix + "reward_history" //打赏历史 type RewardHistory struct { Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"` IsDelete bool `json:"is_delete" xorm:"not null default(0) comment('是否删除') TINYINT(1)"` CreatedAt time.Time `json:"create_at" xorm:"created comment('创建时间') TIMESTAMP"` UpdatedAt time.Time `json:"update_at" xorm:"updated comment('更新时间') TIMESTAMP"` OutTradeNo string `json:"out_trade_no" xorm:"not null default '' comment('微信订单号') VARCHAR(128)"` CustomerId int64 `json:"customer_id" xorm:"not null default 0 comment('客户id') INT(11)"` RewardServerId int64 `json:"reward_server_id" xorm:"not null default 0 comment('打赏服务id') INT(11)"` ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('主活动id') INT(11)"` RehearsalId int64 `json:"rehearsal_id" xorm:"not null default 0 comment('彩排id/0正式') INT(11)"` UserId int64 `json:"user_id" xorm:"not null default 0 comment('用户得id') INT(11)"` Content string `json:"content" xorm:"not null comment('内容') text"` Amount float64 `json:"amount" xorm:"not null default(0.00) comment('金额') DECIMAL(18)"` Status int `json:"status" xorm:"not null default(0) comment('-1未支付,0未审核,1未通过,2已通过,3已推送,4已退款') INT(11)"` ReviewTime int64 `json:"review_time" xorm:"not null default(0) comment('审核时间') INT(11)"` ExpireTime int64 `json:"expire_time" xorm:"not null default(0) comment('过期时间') INT(11)"` Type int `json:"type" xorm:"not null default 0 comment('线下h5/直播 = 0/1') TINYINT(1)"` Version int64 `json:"version" xorm:"not null version comment('乐观锁') INT(11)"` // 额外字段 RewardAmount string `json:"reward_amount" xorm:"-" description:"同上, 字符串"` User *User `json:"user" xorm:"-" description:"用户信息"` } func (t *RewardHistory) TableName() string { return ReWardHistoryTableName } func (t *RewardHistory) GetByOutTradeNo(outTradeNo string) (bool, error) { return core.GetXormAuto().Where("is_delete=0 and out_trade_no=?", outTradeNo).Get(t) } func (t *RewardHistory) UpdateStatus(id int64, status int) (int64, error) { t.Status = status return core.GetXormAuto().Where("id=?", id).Cols("status").Update(t) } func (t *RewardHistory) UpdateStatusByIds(ids []int64, status int) error { if len(ids) > 0 { _, err := core.GetXormAuto().In("id", ids).Cols("status"). Update(&RewardHistory{Status: status}) return err } return nil } func GetRewardHistoryByIds(ids interface{}) ([]*RewardHistory, error) { result := make([]*RewardHistory, 0) err := core.GetXormAuto().Where("is_delete=0 and status=0").In("id", ids).Find(&result) return result, err } func GetExpireRewardHistory() ([]*RewardHistory, error) { result := make([]*RewardHistory, 0) err := core.GetXormAuto().Where("rehearsal_id = 0 or type <> 0"). Where("is_delete=0 and status=0 and expire_time<=?", time.Now().Unix()).Find(&result) return result, err } func (t *RewardHistory) SumMoney(serverId, rehearsalId interface{}) (float64, error) { return core.GetXormAuto().Where("reward_server_id=? and status=3 and is_delete=0 "+ " and rehearsal_id=?", serverId, rehearsalId).Sum(t, "amount") }