Browse Source

red pack

master
黄梓健 5 years ago
parent
commit
b32eb2b13d
  1. 83
      controllers/client/live.go
  2. 12
      controllers/client/order.go
  3. 29
      controllers/client/shake_red_envelope.go
  4. 8
      controllers/pc/shake_red_envelope.go
  5. 32
      models/customer_goods.go
  6. 46
      models/customer_order.go
  7. 2
      models/init_models.go
  8. 32
      models/live_red_pack_info.go
  9. 47
      models/shake_red_envelope_record.go

83
controllers/client/live.go

@ -82,56 +82,71 @@ func (t *LiveCtl) LoopQuery() {
// 下单发送红包
// 维护一个队列进行循环, 遍历是否付款成功
func (t *LiveCtl) SendLiveRedPack() {
userId := t.MustGetUID() // 用户 uid
activityId := t.MustGetInt64("activity_id") // activity_id
num := t.MustGetInt("num") // 红包数量
amount := t.MustGetInt64("amount") // 金额
prompt := t.MustGet("prompt") // 提示
userId := t.MustGetUID() // 用户 uid
activityId := t.MustGetInt64("activity_id") // activity_id
num := t.MustGetInt("num") // 红包数量
prompt := t.MustGet("prompt") // 提示
amount := utils.Float64CusDecimal(t.MustGetDouble("amount"), 2) // 金额
areaId := t.MustGetInt64("area_id")
activity := new(models.Activity)
exist, err := models.GetById(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
area := new(models.AreaStore)
exist, err = models.GetById(area, areaId)
t.CheckErr(err)
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
user := models.User{}
exist, err := models.GetById(&user, userId)
exist, err = models.GetById(&user, userId)
t.CheckErr(err)
t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
ip := strings.Split(t.Request.OriginRequest.RemoteAddr, ":")
res, err := pay_service.UnifiedOrder("欧轩互动-直播红包", ip[0], user.Openid, amount, 3, activityId, userId)
t.CheckErr(err)
info := models.LiveRedPackInfo{}
info.OutTradeNo = res["out_trade_no"].(string)
info.Amount = amount
info.UserId = userId
info.ActivityId = activityId
info.Prompt = filter.Replace(prompt)
info.IsDelete = false
info.UpdatedAt = time.Now()
info.CreatedAt = time.Now()
_, err = info.Add()
t.CheckErr(err)
redPacks := red_envelope_service.GenRedPack(int(amount), num)
for _, v := range redPacks {
redPack := new(models.LiveRedPack)
redPack.LiveRedPackInfoId = info.Id
redPack.ActivityId = activityId
redPack.Receiver = 0
redPack.Amount = v
redPack.CreatedAt = time.Now()
redPack.UpdatedAt = time.Now()
_, err = redPack.Add()
res, err := pay_service.UnifiedOrder("欧轩互动-直播红包", ip[0], user.Openid, int64(amount*100), 3, activityId, userId)
t.CheckErr(err)
rule := models.LiveRedEnvelopeRule{}
rule.OutTradeNo = res["out_trade_no"].(string)
rule.Amount = amount
rule.UserId = userId
rule.ActivityId = activityId
rule.Prompt = filter.Replace(prompt)
rule.IsDelete = false
rule.UpdatedAt = time.Now()
rule.CreatedAt = time.Now()
_, err = rule.Add()
t.CheckErr(err)
records := red_envelope_service.GenRedPack(int(amount*100), num)
for _, v := range records {
record := new(models.ShakeRedEnvelopeRecord)
record.AreaId = area.Id
record.AreaName = area.Name
record.LiveRedEnvelopeRuleId = rule.Id
record.ActivityId = activityId
record.Name = activity.Name
record.UserId = 0
record.Amount = utils.Float64CusDecimal(float64(v)/float64(100), 2)
record.CreatedAt = time.Now()
record.UpdatedAt = time.Now()
_, err = record.Add()
t.CheckErr(err)
}
res["red_pack_info_id"] = info.Id
res["red_pack_info_id"] = rule.Id
t.JSON(res)
}
// 支付之后可以遍历查询是否成功 -- 前端发送消息
// 不建议, 通过im 系统进行通知
func (t *LiveCtl) QueryLiveRedPack() {
outTradeNo := t.MustGet("out_trade_no")
res, err := pay_service.OrderQuery(outTradeNo)
t.CheckErr(err)
info := new(models.LiveRedPackInfo)
info := new(models.LiveRedEnvelopeRule)
exist, err := info.GetByOutTradeNo(outTradeNo)
t.CheckErr(err)
t.Assert(exist, code.MSG_LIVE_RED_PACK_INFO_NOT_EXIST, "直播红包信息不存在")
@ -160,7 +175,7 @@ func (t *LiveCtl) GetLiveRedPack() {
t.CheckErr(err)
t.Assert(exist, code.MSG_USER_NOT_EXIST, "不存在用户")
redPack := new(models.LiveRedPack)
redPack := new(models.ShakeRedEnvelopeRecord)
exist, err = redPack.GetByInfoId(liveRedPackInfoId)
t.CheckErr(err)
if !exist {

12
controllers/client/order.go

@ -0,0 +1,12 @@
package client
import "hudongzhuanjia/controllers"
// 订单活动
type OrderCtl struct {
controllers.BaseCtl
}
func (t *OrderCtl) ListGood() {
}

29
controllers/client/shake_red_envelope.go

@ -7,10 +7,10 @@ import (
activity_service "hudongzhuanjia/services/activity"
pay_service "hudongzhuanjia/services/pay"
ws_send_service "hudongzhuanjia/services/ws_send"
"hudongzhuanjia/utils"
"hudongzhuanjia/utils/code"
"hudongzhuanjia/utils/define"
"math/rand"
"strings"
"time"
)
@ -65,7 +65,7 @@ func (t *ShakeRedEnvelopeCtl) Shake() {
record := new(models.ShakeRedEnvelopeRecord) /// 之后使用, 存入乐观锁
if moduleService.BesideRepeat == define.MODULE_BESIDE_REPEAT { // 剔除摇过红包的用户
exist, err := record.ExistRecord(activity.RehearsalId, activity.Id, rule.Id, envelope.Id, userId)
exist, err = record.ExistRecord(activity.RehearsalId, activity.Id, rule.Id, envelope.Id, userId)
t.CheckErr(err)
t.Assert(!exist, code.MSG_SHAKERB_RECORD_NOT_EXIST, "您已经摇过红包了,请等待下一轮.") // 不存在继续往下走
}
@ -84,24 +84,18 @@ func (t *ShakeRedEnvelopeCtl) Shake() {
t.CheckErr(err)
t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
record.IsDraw = 0
// 记录红包 ---> 非彩排才能
if activity.RehearsalId == 0 {
//res, err := pay_service.SendRedPack("欧轩互动", user.Openid, fmt.Sprintf("感谢您参加%s", activity.Name),
// "", rule.Model, "摇得越快抢得越多", int(record.Amount*100), 1, 1)
ip := strings.Split(t.Request.OriginRequest.RemoteAddr, ":")
res, err := pay_service.Transfer("欧轩互动-红包活动", ip[0], user.Openid, int(record.Amount*100))
if err != nil {
t.ERROR("您与红包擦肩而过", code.MSG_SHAKERB_NOT_HIT)
return
}
record.TransferType = 1
record.TransferNo = res.PartnerTradeNo
record.IsDraw = 1
record.TransferType = 1 // 微信转账
record.PartnerTradeNo = utils.RandomStr(32)
// 加入延迟队列
pay_service.PutTransferDelayQueue("欧轩互动-红包活动", record.PartnerTradeNo, user.Openid, int(record.Amount*100), 5, 5*60)
}
record.IsDraw = 1
record.UserId = user.Id
record.AreaName = area.Name
record.Name = activity.Name
@ -114,14 +108,9 @@ func (t *ShakeRedEnvelopeCtl) Shake() {
remaining, err := new(models.ShakeRedEnvelopeRecord).Count(activity.Id, activity.RehearsalId, envelope.Id, rule.Id, -1)
t.CheckErr(err)
customer := new(models.Customer)
exist, err = models.GetById(customer, customerId)
t.CheckErr(err)
t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
go ws_send_service.SendShakeRedEnvelope(fmt.Sprintf("%d", activity.Id),
define.TYPE_H5USER, userId, map[string]interface{}{
"customer_id": customer.Id,
"customer_id": customerId,
"user_id": user.Id,
"type": "shake_rb",
"data": map[string]interface{}{
@ -135,7 +124,7 @@ func (t *ShakeRedEnvelopeCtl) Shake() {
go ws_send_service.SendShakeRedEnvelope(fmt.Sprintf("%d", activity.Id),
define.TYPE_CUSTOMER, customerId, map[string]interface{}{
"customer_id": customer.Id,
"customer_id": customerId,
"user_id": user.Id,
"type": "shake_rb",
"data": map[string]interface{}{

8
controllers/pc/shake_red_envelope.go

@ -159,13 +159,15 @@ func (t *ShakeRedEnvelopeCtl) List() {
func (t *ShakeRedEnvelopeCtl) Qrcode() {
activityId := t.MustGetInt64("activity_id")
customerId := t.MustGetUID()
rehearsalId := t.MustGetInt64("rehearsal_id")
ruleId := t.MustGetInt64("shake_red_envelope_rule_id")
//将服务器得地址和activity_id,动态生成二维码
qrcode, err := utils.GenH5Qrcode(define.H5ShakeRb, map[string]interface{}{
"activity_id": activityId,
"customer_id": customerId,
"rule_id": ruleId,
"activity_id": activityId,
"customer_id": customerId,
"rule_id": ruleId,
"rehearsal_id": rehearsalId,
})
t.CheckErr(err)
t.JSON(map[string]interface{}{

32
models/customer_goods.go

@ -1,22 +1,28 @@
package models
import (
"time"
)
import "time"
const CustomerGoodsTableName = TableNamePrefix + "customer_goods"
type CustomerGoods struct {
Id int64 `json:"id"`
ActivityId int64 `json:"activity_id"`
GoodsPicUrl string `json:"goods_pic_url"`
Name string `json:"name" description:"商品名字"`
Qrcode string `json:"qrcode" xorm:"-"`
Price float64 `json:"price" description:"价格"`
Desc string `json:"desc" description:"介绍"`
IsDelete bool `json:"is_delete" xorm:"default(0)"`
CreatedAt time.Time `json:"created_at" xorm:"created"`
UpdatedAt time.Time `json:"updated_at" xorm:"updated"`
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:"created_at" xorm:"created comment('创建时间') TIMESTAMP"`
UpdatedAt time.Time `json:"updated_at" xorm:"not null default 'CURRENT_TIMESTAMP' updated comment('更新时间') TIMESTAMP"`
ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"`
AreaId int64 `json:"area_id" xorm:"not null default 0 comment('地区id') INT(11)"`
GoodsPicUrl string `json:"goods_pic_url" xorm:"not null default '' comment('商品图片') VARCHAR(255)"`
IsForceAdded int `json:"is_force_added" xorm:"not null default 0 comment('是否强制上架0不强制1强制') TINYINT(1)"`
GoodType int `json:"good_type" xorm:"not null default 0 comment('商品类型0不需要邮寄1需要邮寄') TINYINT(1)"`
FixedField string `json:"fixed_field" xorm:"not null default '' comment('固定不可改字段,|分隔') VARCHAR(255)"`
Stock int `json:"stock" xorm:"not null default 0 comment('库存-1的时候无上限') INT(18)"`
Name string `json:"name" xorm:"not null default '' comment('商品名称') VARCHAR(255)"`
Price float64 `json:"price" xorm:"not null default '' comment('商品单价') DECIMAL(18,2)"`
Desc string `json:"desc" xorm:"not null default '' comment('商品介绍') VARCHAR(255)"`
// 无关变量
Qrcode string `json:"qrcode" xorm:"-"`
}
func (t *CustomerGoods) TableName() string {

46
models/customer_order.go

@ -8,25 +8,35 @@ import (
const CustomerOrderTableName = TableNamePrefix + "customer_order"
type CustomerOrder struct {
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"`
UserPrizeId int64 `json:"user_prize_id" xorm:"not null default 0 comment('用户奖品id') INT(11)"`
ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('主活动id') INT(11)"`
AreaId int64 `json:"area_id" xorm:"not null default 0 comment('地区id') BIGINT(20)"`
AreaName string `json:"area_name" xorm:"not null default('') comment('地区名字') VARCHAR(255)"`
RehearsalId int64 `json:"rehearsal_id" xorm:"not null default(0) comment('彩排id/0正式') BIGINT(20)"`
OutTradeNo string `json:"out_trade_no" xorm:"not null default('') comment('订单流水号') VARCHAR(255)"`
OrderEntryPersonId int64 `json:"order_enter_person_id" xorm:"not null default 0 comment('订单录入人员id') BIGINT(20)"`
OrderEntryPersonName string `json:"order_entry_person_name" xorm:"-"`
BuyerId int64 `json:"buyer_id" xorm:"not null default 0 comment('user表id') BIGINT(20)"`
User *User `json:"user" xorm:"-"`
GoodsId int64 `json:"goods_id" xorm:"not null default 0 comment('customer_goods表id') BIGINT(20)"`
Good *CustomerGoods `json:"good" xorm:"-"`
GoodsName string `json:"goods_name" xorm:"not null default('') comment('商品名字') VARCHAR(255)"`
TotalAmount float64 `json:"total_amount" xorm:"not null default 0.00 comment('订单总额') DECIMAL"`
Id int64 `json:"id" xorm:"not null pk autoincr comment('主键') INT(11)"`
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"`
UserPrizeId int64 `json:"user_prize_id" xorm:"not null default 0 comment('用户奖品id') INT(11)"`
ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('主活动id') INT(11)"`
AreaId int64 `json:"area_id" xorm:"not null default 0 comment('地区id') INT(11)"`
AreaName string `json:"area_name" xorm:"not null default '' comment('地区名字') VARCHAR(255)"`
RehearsalId int64 `json:"rehearsal_id" xorm:"not null default 0 comment('彩排id/0正式') BIGINT(20)"`
OutTradeNo string `json:"out_trade_no" xorm:"not null default '' comment('订单流水号') VARCHAR(255)"`
OrderEntryPersonId int64 `json:"order_enter_person_id" xorm:"not null default 0 comment('订单录入人员id') BIGINT(20)"`
BuyerId int64 `json:"buyer_id" xorm:"not null default 0 comment('user表id') BIGINT(20)"`
GoodsId int64 `json:"goods_id" xorm:"not null default 0 comment('customer_goods表id') BIGINT(20)"`
GoodsName string `json:"goods_name" xorm:"not null default '' comment('商品名字') VARCHAR(255)"`
GoodsNum int `json:"goods_num" xorm:"not null default 0 comment('商品数量') INT(11)"`
TotalAmount float64 `json:"total_amount" xorm:"not null default 0.00 comment('订单总额') DECIMAL(18,2)"`
Postage float64 `json:"postage" xorm:"not null default 0.00 comment('邮费[0免邮]') DECIMAL(18,2)"`
Status int `json:"status" xorm:"not null default 0 comment('订单状态[0未支付1已支付2待发货3已发货4确认收货5申请退款6已退款]')"`
// 快递信息
Receiver string `json:"receiver" xorm:"not null default '' comment('收件人') VARCHAR(128)"`
Address string `json:"address" xorm:"not null default '' comment('收件人地址') VARCHAR(255)"`
Phone string `json:"phone" xorm:"not null default '' comment('收件人电话') VARCHAR(128)"`
// 无关变量
OrderTime string `json:"order_time" xorm:"-"`
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"`
Good *CustomerGoods `json:"good" xorm:"-"`
User *User `json:"user" xorm:"-"`
OrderEntryPersonName string `json:"order_entry_person_name" xorm:"-"`
}
func (t *CustomerOrder) TableName() string {

2
models/init_models.go

@ -86,7 +86,7 @@ func init() {
new(RealSignHistory),
new(LiveViewer),
new(LiveConfig),
new(LiveRedPackInfo),
new(LiveRedEnvelopeRule),
new(LiveRedPack),
new(UserTransfer),
)

32
models/live_red_pack_info.go

@ -7,45 +7,45 @@ import (
const LiveRedPackInfoTN = TableNamePrefix + "live_red_pack_info"
type LiveRedPackInfo struct {
type LiveRedEnvelopeRule struct {
Id int64 `json:"live_red_pack_info_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"`
UserId int64 `json:"user_id" xorm:"not null default 0 comment('用户id') INT(11)"`
ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"`
GroupId string `json:"group_id" xorm:"not null default '' comment('聊天室地址') VARCHAR(128)"`
Prompt string `json:"prompt" xorm:"not null default 0 comment('祝福语') VARCHAR(255)"`
Amount int64 `json:"amount" xorm:"not null default 0 comment('红包金额, 分') INT(18)"`
OutTradeNo string `json:"out_trade_no" xorm:"not null default '' comment('订单号') VARCHAR(128)"`
Error string `json:"error" xorm:"not null default '' comment('出现错误') VARCHAR(255)"`
Status int `json:"status" xorm:"not null default 0 comment('-1尚未支付0支付成功1已推送2已作废')"`
UserId int64 `json:"user_id" xorm:"not null default 0 comment('用户id') INT(11)"`
ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"`
GroupId string `json:"group_id" xorm:"not null default '' comment('聊天室地址') VARCHAR(128)"`
Prompt string `json:"prompt" xorm:"not null default 0 comment('祝福语') VARCHAR(255)"`
Amount float64 `json:"amount" xorm:"not null default 0 comment('红包金额') DECIMAL(18,2)"`
OutTradeNo string `json:"out_trade_no" xorm:"not null default '' comment('订单号') VARCHAR(128)"`
Error string `json:"error" xorm:"not null default '' comment('出现错误') VARCHAR(255)"`
Status int `json:"status" xorm:"not null default 0 comment('-1尚未支付0支付成功1已推送2已作废')"`
}
func (t *LiveRedPackInfo) TableName() string {
func (t *LiveRedEnvelopeRule) TableName() string {
return LiveRedPackInfoTN
}
func (t *LiveRedPackInfo) Add() (int64, error) {
func (t *LiveRedEnvelopeRule) Add() (int64, error) {
return core.GetXormAuto().InsertOne(t)
}
func GetLiveRedPackInfos(status int) ([]*LiveRedPackInfo, error) {
infos := make([]*LiveRedPackInfo, 0)
func GetLiveRedPackInfos(status int) ([]*LiveRedEnvelopeRule, error) {
infos := make([]*LiveRedEnvelopeRule, 0)
err := core.GetXormAuto().Where("is_delete=0 and status=?", status).Find(&infos)
return infos, err
}
func (t *LiveRedPackInfo) GetByOutTradeNo(outTradeNo string) (bool, error) {
func (t *LiveRedEnvelopeRule) GetByOutTradeNo(outTradeNo string) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and out_trade_no=?", outTradeNo).Get(t)
}
func (t *LiveRedPackInfo) UpdateStatusById(id interface{}, status int) (int64, error) {
func (t *LiveRedEnvelopeRule) UpdateStatusById(id interface{}, status int) (int64, error) {
return core.GetXormAuto().Where("id=?", id).Cols("status").Update(&LiveRedPack{Status: status})
}
func (t *LiveRedPackInfo) UpdateStatusByOutTradeNo(outTradeNo string, status int) (int64, error) {
func (t *LiveRedEnvelopeRule) UpdateStatusByOutTradeNo(outTradeNo string, status int) (int64, error) {
t.Status = status
return core.GetXormAuto().Where("is_delete=0 and status=0 and out_trade_no=?", outTradeNo).Update(t)
}

47
models/shake_red_envelope_record.go

@ -8,25 +8,30 @@ import (
const ShakeRedEnvelopeRecordTableName = TableNamePrefix + "shake_red_envelope_record"
type ShakeRedEnvelopeRecord struct {
Id int64 `json:"id" xorm:"not null pk autoincr comment('主键') 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)"`
ShakeRedEnvelopeActivityId int64 `json:"shake_red_envelope_activity_id" xorm:"not null default 0 comment('摇红包活动id') INT(11)"`
ShakeRedEnvelopeRuleId int64 `json:"shake_red_envelope_rule_id" xorm:"not null default 0 comment('摇红包规则id') INT(11)"`
UserId int64 `json:"user_id" xorm:"not null default 0 comment('用户id') INT(11)"`
IsValid bool `json:"is_valid" xorm:"-"`
Name string `json:"name" xorm:"not null default '' comment('红包名字') VARCHAR(255)"`
Amount float64 `json:"amount" xorm:"not null default '0' comment('金额') VARCHAR(18)"`
AreaId int64 `json:"area_id" xorm:"not null default 0 comment('地区id') INT(11)"`
AreaName string `json:"area_name" xorm:"not null default '' comment('地区名字') VARCHAR(18)"`
IsDraw int `json:"is_draw" xorm:"not null default(0) comment('-1未被摇中,0已被摇中,1已被提现')"`
TransferType int `json:"transfer_type" xorm:"not null default 0 comment('0微信红包 1 微信转账') TINYINT(1)"`
TransferNo string `json:"transfer_no" xorm:"not null default '' comment('转账账单no') VARCHAR(128)"`
Status string `json:"status" xorm:"not null default '' comment('红包状态') VARCHAR(16)"`
Version int `json:"version" xorm:"not null version comment('乐观锁') INT(11)"`
IsDelete bool `json:"-" xorm:"default(0)" description:"是否删除"`
CreatedAt time.Time `json:"-" xorm:"created" description:"创建时间"`
UpdatedAt time.Time `json:"-" xorm:"updated" description:"更新时间"`
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)"`
RedEnvelopeType int `json:"red_envelope_type" xorm:"not null default 0 comment('红包类型[0摇红包1直播红包]')"`
LiveRedEnvelopeRuleId int64 `json:"live_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)"`
ShakeRedEnvelopeRuleId int64 `json:"shake_red_envelope_rule_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)"`
AreaName string `json:"area_name" xorm:"not null default '' comment('地区名字') VARCHAR(18)"`
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' comment('金额') DECIMAL(18,2)"`
IsDraw int `json:"is_draw" xorm:"not null default(0) comment('-1未被摇中,0已被摇中,1已被提现,2提现失败')"`
TransferType int `json:"transfer_type" xorm:"not null default 0 comment('0微信红包 1 微信转账') TINYINT(1)"`
PartnerTradeNo string `json:"partner_trade_no" xorm:"not null default '' comment('转账账单no') VARCHAR(128)"`
Version int `json:"version" xorm:"not null version comment('乐观锁') INT(11)"`
// 无关变量
// Status string `json:"status" xorm:"not null default '' comment('红包状态') VARCHAR(16)"`
IsValid bool `json:"is_valid,omitempty" xorm:"-"`
}
func (t *ShakeRedEnvelopeRecord) TableName() string {
@ -39,6 +44,10 @@ func (t *ShakeRedEnvelopeRecord) ExistRecord(reid, aid, srid, said, uid int64) (
reid, aid, srid, said, 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)

Loading…
Cancel
Save