diff --git a/internal/biz/cmb/notify.go b/internal/biz/cmb/notify.go index 29e8f27..4bc0ebc 100644 --- a/internal/biz/cmb/notify.go +++ b/internal/biz/cmb/notify.go @@ -79,9 +79,9 @@ func (v *Cmb) bizContent(_ context.Context, order *bo.OrderBo, orderNotify *bo.O return string(bizJsonBytes), nil } -func (v *Cmb) NotifyRequest(ctx context.Context, order *bo.OrderBo, req *bo.OrderNotifyBo) (*v1.CmbRequest, error) { +func (v *Cmb) NotifyRequest(ctx context.Context, order *bo.OrderBo, orderNotify *bo.OrderNotifyBo) (*v1.CmbRequest, error) { - bizContent, err := v.bizContent(ctx, order, req) + bizContent, err := v.bizContent(ctx, order, orderNotify) if err != nil { return nil, err } diff --git a/internal/biz/order_notice.go b/internal/biz/order_notice.go index 18cd9c6..3b23f41 100644 --- a/internal/biz/order_notice.go +++ b/internal/biz/order_notice.go @@ -108,18 +108,28 @@ func (v *VoucherBiz) isCanNotice(ctx context.Context) error { func (v *VoucherBiz) cmbOrderNotice(ctx context.Context, order *bo.OrderBo) error { - // 批量通知不做数据存储,量可能会很大很大 + // 批量通知不做数据存储,量会很大 - if err := v.Query(ctx, order); err != nil { - return err - } - - event, err := order.Status.GetOrderNotifyEvent() + status, err := v.WechatCpnRepo.Query(ctx, order) if err != nil { return err } - req := &bo.OrderNotifyBo{ + if order.Status == status { + log.Warnf("notice 券状态未改变:%s,忽略不处理,orderNo:%s", order.Status.GetText(), order.OrderNo) + return nil + } + + if err = v.UpdateOrderStatus(ctx, order.ID, status); err != nil { + return err + } + + event, err := status.GetOrderNotifyEvent() + if err != nil { + return err + } + + orderNotify := &bo.OrderNotifyBo{ OrderNo: order.OrderNo, NotifyUrl: order.NotifyUrl, Channel: order.Channel, @@ -127,7 +137,7 @@ func (v *VoucherBiz) cmbOrderNotice(ctx context.Context, order *bo.OrderBo) erro Type: order.Type, } - request, err := v.Cmb.NotifyRequest(ctx, order, req) + request, err := v.Cmb.NotifyRequest(ctx, order, orderNotify) if err != nil { return err } @@ -138,7 +148,7 @@ func (v *VoucherBiz) cmbOrderNotice(ctx context.Context, order *bo.OrderBo) erro } if reply.RespCode != vo.CmbResponseStatusSuccess.GetValue() { - return fmt.Errorf(reply.RespMsg) + return errors.New(reply.RespMsg) } return nil