From 0de4d12b8559920b97a53e76925a1ac702cc13aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AD=90=E9=93=AD?= Date: Thu, 13 Mar 2025 11:21:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/biz/cmb/notify.go | 5 +++++ internal/biz/vo/order_status.go | 2 +- internal/biz/wechat_notify_consume.go | 32 ++++++++++++++++++--------- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/internal/biz/cmb/notify.go b/internal/biz/cmb/notify.go index 6e2d6e2..45038a5 100644 --- a/internal/biz/cmb/notify.go +++ b/internal/biz/cmb/notify.go @@ -3,6 +3,7 @@ package cmb import ( "context" "encoding/json" + "fmt" "github.com/go-kratos/kratos/v2/log" "time" err2 "voucher/api/err" @@ -13,6 +14,10 @@ import ( func (v *Cmb) Notify(ctx context.Context, order *bo.OrderBo) (*bo.OrderNotifyBo, error) { + if order.Status.IsCanNotify() { + return nil, fmt.Errorf("订单状态不允许通知,orderNo:%s,orderStatusText:%s", order.OrderNo, order.Status.GetText()) + } + event, err := order.Status.GetOrderNotifyEvent() if err != nil { return nil, err diff --git a/internal/biz/vo/order_status.go b/internal/biz/vo/order_status.go index 55ae7ba..152fb6f 100644 --- a/internal/biz/vo/order_status.go +++ b/internal/biz/vo/order_status.go @@ -57,7 +57,7 @@ func (s OrderStatus) IsExpired() bool { return s == OrderStatusExpired } -func (s OrderStatus) CanNotify() bool { +func (s OrderStatus) IsCanNotify() bool { return s.IsSuccess() || s.IsUse() || s.IsExpired() } diff --git a/internal/biz/wechat_notify_consume.go b/internal/biz/wechat_notify_consume.go index 9ed5d87..8ec9a51 100644 --- a/internal/biz/wechat_notify_consume.go +++ b/internal/biz/wechat_notify_consume.go @@ -45,22 +45,34 @@ func (v *VoucherBiz) WechatNotifyConsumer(ctx context.Context, tag string, req * if order.Type.IsCmb() { - if orderNotify, err2 := v.Cmb.Notify(ctx, order); err2 != nil { - - if !errPb.IsNeedRetryNotify(err2) { - return err2 - } - // 第一次通知失败重试入队 - // 状态回调接口失败需要支持重试 重试间隔为1分钟、2分钟、12分钟、60分钟、360分钟 - return v.PushNotifyRetryDelayMQ(ctx, 60, orderNotify.ID) - - } + return v.cmbNotify(ctx, order.ID) } return nil }) } +func (v *VoucherBiz) cmbNotify(ctx context.Context, orderId uint64) error { + + order, err := v.OrderRepo.GetByID(ctx, orderId) + if err != nil { + return err + } + + if orderNotify, err := v.Cmb.Notify(ctx, order); err != nil { + + if !errPb.IsNeedRetryNotify(err) { + return err + } + + // 第一次通知失败重试入队 + // 状态回调接口失败需要支持重试 重试间隔为1分钟、2分钟、12分钟、60分钟、360分钟 + return v.PushNotifyRetryDelayMQ(ctx, 60, orderNotify.ID) + } + + return nil +} + func (v *VoucherBiz) used(ctx context.Context, order *bo.OrderBo) error { if order.Status.IsUse() {