|
|
package models
import ( "time"
"github.com/ouxuanserver/osmanthuswine/src/core" )
const ShakeRedEnvelopeRecordTableName = TableNamePrefix + "shake_red_envelope_record"
type ShakeRedEnvelopeRecord struct { Id int64 `json:"id" xorm:"not null pk autoincr comment('主键') INT(11)"` IsDelete bool `json:"-" xorm:"default(0)" description:"是否删除"` CreatedAt time.Time `json:"-" xorm:"created" description:"创建时间"` UpdatedAt time.Time `json:"-" xorm:"updated" description:"更新时间"`
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)"` ShakeRedEnvelopeType int `json:"red_envelope_type" xorm:"not null default 0 comment('红包类型[0摇红包1直播红包]')"` ShakeRedEnvelopeRuleId int64 `json:"shake_red_envelope_rule_id,omitempty" xorm:"not null default 0 comment('摇红包规则id') INT(11)"` ShakeRedEnvelopeActivityId int64 `json:"shake_red_envelope_activity_id,omitempty" xorm:"not null default 0 comment('摇红包活动id') INT(11)"` AreaId int64 `json:"area_id" xorm:"not null default 0 comment('地区id') INT(11)"` Name string `json:"name" xorm:"not null default '' comment('红包名字') VARCHAR(255)"` UserId int64 `json:"user_id" xorm:"not null default 0 comment('用户id') INT(11)"` Amount float64 `json:"amount" xorm:"not null default 0.00 comment('金额') DECIMAL(18)"` IsValid bool `json:"is_valid,omitempty" xorm:"-"` IsDraw int `json:"is_draw" xorm:"not null default 0 comment('-1未被摇中,0已被摇中1被提取')"` MchBillno string `json:"mch_billno" xorm:"not null default '' comment('微信红包订单号') VARCHAR(128)"` Version int `json:"version" xorm:"not null version default 0 comment('乐观锁') INT(11)"` }
func (t *ShakeRedEnvelopeRecord) TableName() string { return ShakeRedEnvelopeRecordTableName }
func (t *ShakeRedEnvelopeRecord) ExistRecord(reid, srid, uid int64) (bool, error) { return core.GetXormAuto().Where("is_delete=0 and rehearsal_id=? and "+ "shake_red_envelope_rule_id=? and user_id=?", reid, srid, uid).Exist(t) }
func (t *ShakeRedEnvelopeRecord) Add() (int64, error) { return core.GetXormAuto().InsertOne(t) }
func (t *ShakeRedEnvelopeRecord) Total(aid, rid, said, srid int64) (int64, error) { return core.GetXormAuto().Where("is_delete=0 and activity_id=? and rehearsal_id=? and "+ "shake_red_envelope_activity_id=? and shake_red_envelope_rule_id=?", aid, rid, said, srid).Count(t) }
func (t *ShakeRedEnvelopeRecord) Sum(aid, rid, said, srid int64) (float64, error) { return core.GetXormAuto().Where("is_delete=0 and activity_id=? and rehearsal_id=? and "+ "shake_red_envelope_activity_id=? and shake_red_envelope_rule_id=?", aid, rid, said, srid). Sum(t, "amount")
}
func (t *ShakeRedEnvelopeRecord) Count(aid, rid, said, srid int64, status int64) (int64, error) { return core.GetXormAuto().Where("is_delete=0 and is_draw=? and activity_id=? and rehearsal_id=? and "+ "shake_red_envelope_activity_id=? and shake_red_envelope_rule_id=?", status, aid, rid, said, srid).Count(t) }
func (t *ShakeRedEnvelopeRecord) GetByRuleId(ruleId, rehearsalId, _type interface{}) (bool, error) { return core.GetXormAuto().Where("is_delete=0 and is_draw=-1 and shake_red_envelope_type = ? and "+ "shake_red_envelope_rule_id=? and rehearsal_id=?", _type, ruleId, rehearsalId).Get(t) }
func (t *ShakeRedEnvelopeRecord) UpdateById(id int64, field ...string) (int64, error) { return core.GetXormAuto().Where("is_delete=0 and id=?", id).Cols(field...).Update(t) }
func GetRedEnvelopesByUserId(userId, activityId, rehearsalId int64) ([]*ShakeRedEnvelopeRecord, error) { records := make([]*ShakeRedEnvelopeRecord, 0) err := core.GetXormAuto().Where("user_id=? and rehearsal_id=? and activity_id=? and "+ "is_delete=0 and is_draw<>-1", userId, rehearsalId, activityId).Desc("created_at"). Find(&records) for index := range records { records[index].IsValid = true } return records, err }
|