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() {