package models import ( "github.com/ouxuanserver/osmanthuswine/src/core" "time" ) const LiveRedPackTN = TableNamePrefix + "live_red_pack" type LiveRedPack struct { Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"` IsDelete bool `json:"-" 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 default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"` LiveRedPackInfoId int64 `json:"live_red_pack_info_id" xorm:"not null default 0 comment('红包信息id') INT(11)"` ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"` Receiver int64 `json:"receiver" xorm:"not null default 0 comment('[0未领取/非0领取用户id]') INT(11)"` Amount int `json:"amount" xorm:"not null default 0 comment('红包金额, 分') INT(18)"` TransferType int `json:"transfer_type" xorm:"not null default 0 comment('转账方式[0微信红包1微信零钱]')"` TransferNo string `json:"transfer_no" xorm:"not null default '' comment('转账账号') VARCHAR(128) "` Status int `json:"status" xorm:"not null default 0 comment('0 未被领取 1 已被领取 2 已发送')"` Version int `json:"version" xorm:"not null version comment('乐观锁') INT(11)"` } func (t LiveRedPack) TableName() string { return LiveRedPackTN } func (t *LiveRedPack) Add() (int64, error) { return core.GetXormAuto().InsertOne(t) } func (t *LiveRedPack) GetByInfoId(infoId int64) (bool, error) { return core.GetXormAuto().Where("live_red_package_info_id=? and is_delete=0", infoId).Get(t) } func (t *LiveRedPack) Receive(userId int64) (int64, error) { t.Receiver = userId t.Status = 1 return core.GetXormAuto().Where("id=?", t.Id).Cols("user_id, status").Update(t) } func (t *LiveRedPack) UpdateStatusById(id interface{}, status int) (int64, error) { t.Status = status return core.GetXormAuto().Where("id=?", t.Id).Cols("status").Update(t) }