This commit is contained in:
ziming 2025-08-01 11:13:18 +08:00
parent ad380958a0
commit 913de4afe0
6 changed files with 127 additions and 2 deletions

View File

@ -45,3 +45,13 @@ type FindInBatchesUseBo struct {
StartTime *time.Time StartTime *time.Time
EndTime *time.Time EndTime *time.Time
} }
type FindInBatchesBo struct {
StartTime *time.Time
EndTime *time.Time
ProductNo string
OrderNo []string
OutBizNo []string
VoucherNo []string
}

View File

@ -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
}

View File

@ -112,8 +112,7 @@ func (this *VoucherBiz) expired(ctx context.Context, order *bo.OrderBo) error {
return err return err
} }
//return this.notify(ctx, order) return this.notify(ctx, order)
return nil // 过期不做通知
} }
func (this *VoucherBiz) notify(ctx context.Context, order *bo.OrderBo) error { func (this *VoucherBiz) notify(ctx context.Context, order *bo.OrderBo) error {

View File

@ -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 <order>
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
}

View File

@ -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
}

View File

@ -10,4 +10,5 @@ var ProviderRepoImplSet = wire.NewSet(
NewProductRepoImpl, NewProductRepoImpl,
NewOrderNotifyRepoImpl, NewOrderNotifyRepoImpl,
NewWechatNotifyRegisterTagRepoImpl, NewWechatNotifyRegisterTagRepoImpl,
NewOrderBakRepoImpl,
) )