From 913de4afe0dcd35b072ab0c434eea60f7a845e6d Mon Sep 17 00:00:00 2001 From: ziming Date: Fri, 1 Aug 2025 11:13:18 +0800 Subject: [PATCH] =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/biz/bo/order_bo.go | 10 ++++ internal/biz/repo/orderBak.go | 10 ++++ internal/biz/wechat_notify.go | 3 +- internal/data/model/order_bak.gen.go | 41 +++++++++++++++++ internal/data/repoimpl/order_bak.go | 64 ++++++++++++++++++++++++++ internal/data/repoimpl/provider_set.go | 1 + 6 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 internal/biz/repo/orderBak.go create mode 100644 internal/data/model/order_bak.gen.go create mode 100644 internal/data/repoimpl/order_bak.go diff --git a/internal/biz/bo/order_bo.go b/internal/biz/bo/order_bo.go index 7643f14..6ef7a03 100644 --- a/internal/biz/bo/order_bo.go +++ b/internal/biz/bo/order_bo.go @@ -45,3 +45,13 @@ type FindInBatchesUseBo struct { StartTime *time.Time EndTime *time.Time } + +type FindInBatchesBo struct { + StartTime *time.Time + EndTime *time.Time + + ProductNo string + OrderNo []string + OutBizNo []string + VoucherNo []string +} diff --git a/internal/biz/repo/orderBak.go b/internal/biz/repo/orderBak.go new file mode 100644 index 0000000..8d865cd --- /dev/null +++ b/internal/biz/repo/orderBak.go @@ -0,0 +1,10 @@ +package repo + +import ( + "context" + "voucher/internal/biz/bo" +) + +type OrderBakRepo interface { + FindInBatches(ctx context.Context, w *bo.FindInBatchesBo, fun func(ctx context.Context, rows []*bo.OrderBo) error) error +} diff --git a/internal/biz/wechat_notify.go b/internal/biz/wechat_notify.go index 603601d..5aee3be 100644 --- a/internal/biz/wechat_notify.go +++ b/internal/biz/wechat_notify.go @@ -112,8 +112,7 @@ func (this *VoucherBiz) expired(ctx context.Context, order *bo.OrderBo) error { return err } - //return this.notify(ctx, order) - return nil // 过期不做通知 + return this.notify(ctx, order) } func (this *VoucherBiz) notify(ctx context.Context, order *bo.OrderBo) error { diff --git a/internal/data/model/order_bak.gen.go b/internal/data/model/order_bak.gen.go new file mode 100644 index 0000000..18a005e --- /dev/null +++ b/internal/data/model/order_bak.gen.go @@ -0,0 +1,41 @@ +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. + +package model + +import ( + "time" +) + +const TableNameOrderBak = "order_bak" + +// Order mapped from table +type OrderBak struct { + ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"` + OrderNo string `gorm:"column:order_no;not null" json:"order_no"` + VoucherNo string `gorm:"column:voucher_no;not null" json:"voucher_no"` + OutBizNo string `gorm:"column:out_biz_no;not null;comment:外部交易号" json:"out_biz_no"` // 外部交易号 + ProductNo string `gorm:"column:product_no;not null;comment:商品编号" json:"product_no"` // 商品编号 + BatchNo string `gorm:"column:batch_no;not null;comment:立减金批次号" json:"batch_no"` // 立减金批次号 + Account string `gorm:"column:account;not null;comment:充值账号" json:"account"` // 充值账号 + AccountType uint8 `gorm:"column:account_type;not null;comment:1:oepnid/userid 2:手机号" json:"account_type"` // 1:oepnid/userid 2:手机号 + Type uint8 `gorm:"column:type;not null;comment:1:招行" json:"type"` + Status uint8 `gorm:"column:status;not null;comment:1:待发放 2:发放中 3:发放成功 4:发放失败" json:"status"` // 1:待发放 2:发放中 3:发放成功 4:发放失败 + AppID string `gorm:"column:app_id;not null;comment:批次所属应用" json:"app_id"` // 批次所属应用 + MerchantNo string `gorm:"column:merchant_no;not null;comment:创建批次号的商户号" json:"merchant_no"` // 创建批次号的商户号 + NotifyUrl string `gorm:"column:notify_url;not null;comment:回调地址" json:"notify_url"` + Channel uint8 `gorm:"column:channel;not null;comment:1:微信 2:支付宝" json:"channel"` // 1:微信 2:支付宝 + Remark string `gorm:"column:remark;not null;comment:remark" json:"remark"` + Attach string `gorm:"column:attach;not null;comment:attach" json:"attach"` + ReceiveSuccessTime *time.Time `gorm:"column:receive_success_time" json:"receive_success_time"` + LastUseTime *time.Time `gorm:"column:last_use_time" json:"last_use_time"` + TransactionId string `gorm:"column:transaction_id;not null" json:"transaction_id"` + CreateTime *time.Time `gorm:"column:create_time" json:"create_time"` + UpdateTime *time.Time `gorm:"column:update_time" json:"update_time"` +} + +// TableName Order's table name +func (*OrderBak) TableName() string { + return TableNameOrderBak +} diff --git a/internal/data/repoimpl/order_bak.go b/internal/data/repoimpl/order_bak.go new file mode 100644 index 0000000..954579b --- /dev/null +++ b/internal/data/repoimpl/order_bak.go @@ -0,0 +1,64 @@ +package repoimpl + +import ( + "context" + "gorm.io/gorm" + "voucher/internal/biz/bo" + "voucher/internal/biz/repo" + "voucher/internal/biz/vo" + "voucher/internal/data" + "voucher/internal/data/model" +) + +// OrderBakRepoImpl . +type OrderBakRepoImpl struct { + Base[model.OrderBak, bo.OrderBo] + db *data.Db +} + +// NewOrderBakRepoImpl . +func NewOrderBakRepoImpl(db *data.Db) repo.OrderBakRepo { + return &OrderBakRepoImpl{db: db} +} + +func (p *OrderBakRepoImpl) DB(ctx context.Context) *gorm.DB { + return p.db.DB(ctx).Model(model.OrderBak{}) +} + +func (p *OrderBakRepoImpl) FindInBatches(ctx context.Context, req *bo.FindInBatchesBo, fun func(ctx context.Context, rows []*bo.OrderBo) error) error { + + tx := p.DB(ctx).Where("status = ?", vo.OrderStatusSuccess.GetValue()) + + if req.ProductNo != "" { + tx = tx.Where("product_no = ?", req.ProductNo) + } + + if req.StartTime != nil && req.EndTime != nil { + tx = tx.Where("receive_success_time BETWEEN ? AND ?", req.StartTime, req.EndTime) + } + + if req.OrderNo != nil { + tx = tx.Where("order_no IN (?)", req.OrderNo) + } + + if req.OutBizNo != nil { + tx = tx.Where("out_biz_no IN (?)", req.OutBizNo) + } + + if req.VoucherNo != nil { + tx = tx.Where("voucher_no IN (?)", req.VoucherNo) + } + + var results = make([]*model.OrderBak, 0) + + result := tx.FindInBatches(&results, 100, func(tx *gorm.DB, batch int) error { + + return fun(ctx, p.ToBos(results)) + }) + + if result.Error != nil { + return result.Error + } + + return nil +} diff --git a/internal/data/repoimpl/provider_set.go b/internal/data/repoimpl/provider_set.go index b02119e..9fd0991 100644 --- a/internal/data/repoimpl/provider_set.go +++ b/internal/data/repoimpl/provider_set.go @@ -10,4 +10,5 @@ var ProviderRepoImplSet = wire.NewSet( NewProductRepoImpl, NewOrderNotifyRepoImpl, NewWechatNotifyRegisterTagRepoImpl, + NewOrderBakRepoImpl, )