From 87e3b7a4ca0be043d508a8b1efcfdd93e65df962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AD=90=E9=93=AD?= Date: Mon, 17 Mar 2025 15:03:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=A2=86=E5=8F=96=E6=88=90?= =?UTF-8?q?=E5=8A=9F=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/biz/bo/order_bo.go | 39 ++++++++++++++++---------------- internal/data/model/order.gen.go | 39 ++++++++++++++++---------------- internal/data/repoimpl/order.go | 11 +++++---- internal/service/voucher.go | 6 +++-- 4 files changed, 50 insertions(+), 45 deletions(-) diff --git a/internal/biz/bo/order_bo.go b/internal/biz/bo/order_bo.go index cf4129d..eb20846 100644 --- a/internal/biz/bo/order_bo.go +++ b/internal/biz/bo/order_bo.go @@ -7,25 +7,26 @@ import ( // OrderBo 领域实体Bo结构,字段和模型字段保持一致 type OrderBo struct { - ID uint64 - OrderNo string - OutBizNo string - VoucherNo string - ProductNo string - BatchNo string - Account string - Type vo.OrderType - AccountType vo.OrderAccountType - Status vo.OrderStatus - AppID string - MerchantNo string - NotifyUrl string - Channel vo.Channel - Attach string - Remark string - LastUseTime *time.Time - CreateTime *time.Time - UpdateTime *time.Time + ID uint64 + OrderNo string + OutBizNo string + VoucherNo string + ProductNo string + BatchNo string + Account string + Type vo.OrderType + AccountType vo.OrderAccountType + Status vo.OrderStatus + AppID string + MerchantNo string + NotifyUrl string + Channel vo.Channel + Attach string + Remark string + ReceiveSuccessTime *time.Time + LastUseTime *time.Time + CreateTime *time.Time + UpdateTime *time.Time } type OrderCreateReqBo struct { diff --git a/internal/data/model/order.gen.go b/internal/data/model/order.gen.go index 3608ccf..e0b6ef2 100644 --- a/internal/data/model/order.gen.go +++ b/internal/data/model/order.gen.go @@ -12,25 +12,26 @@ const TableNameOrder = "order" // Order mapped from table type Order 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"` - LastUseTime *time.Time `gorm:"column:last_use_time" json:"last_use_time"` - CreateTime *time.Time `gorm:"column:create_time" json:"create_time"` - UpdateTime *time.Time `gorm:"column:update_time" json:"update_time"` + 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"` + 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 diff --git a/internal/data/repoimpl/order.go b/internal/data/repoimpl/order.go index f03f9d2..5008c73 100644 --- a/internal/data/repoimpl/order.go +++ b/internal/data/repoimpl/order.go @@ -33,9 +33,9 @@ func (p *OrderRepoImpl) FindInBatches(ctx context.Context, w *bo.FindInBatchesUs var results = make([]*model.Order, 0) result := p.db.DB(ctx). - Where("last_use_time BETWEEN ? AND ?", w.StartTime, w.EndTime). + Where("receive_success_time BETWEEN ? AND ?", w.StartTime, w.EndTime). Where("type = ?", w.Type). - Where("status = ?", vo.OrderStatusUse). + Where("status IN (?)", []uint8{vo.OrderStatusSuccess.GetValue(), vo.OrderStatusUse.GetValue()}). FindInBatches(&results, 100, func(tx *gorm.DB, batch int) error { // tx.RowsAffected 提供当前批处理中记录的计数(the count of records in the current batch) // 'batch' 变量表示当前批号(the current batch number) @@ -172,9 +172,10 @@ func (p *OrderRepoImpl) Success(ctx context.Context, id uint64, voucherNo string Status: vo.OrderStatusIng.GetValue(), }). Updates(model.Order{ - Status: vo.OrderStatusSuccess.GetValue(), - VoucherNo: voucherNo, - UpdateTime: &now, + Status: vo.OrderStatusSuccess.GetValue(), + VoucherNo: voucherNo, + ReceiveSuccessTime: &now, + UpdateTime: &now, }) if res.Error != nil { diff --git a/internal/service/voucher.go b/internal/service/voucher.go index 4715a2b..d189357 100644 --- a/internal/service/voucher.go +++ b/internal/service/voucher.go @@ -35,11 +35,13 @@ func (s *VoucherService) OrderNotice(ctx context.Context) error { start := time.Now() - err := s.VoucherBiz.OrderNotice(ctx) + if err := s.VoucherBiz.OrderNotice(ctx); err != nil { + log.Error("订单定时通知,执行失败,err: %v", err) + } end := time.Now() elapsed := end.Sub(start) log.Warnf("订单定时通知,开始执行时间%s,执行结束时间%s,代码块执行耗时: %s", start.Format(time.DateTime), end.Format(time.DateTime), elapsed) - return err + return nil }