From 3eaffae096d76188c83771e338250a12408f74bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AD=90=E9=93=AD?= Date: Wed, 19 Mar 2025 09:30:53 +0800 Subject: [PATCH] =?UTF-8?q?orderNotice=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/biz/wechat_notify_consume.go | 93 +++++++++++++++------------ internal/service/cron.go | 5 ++ 2 files changed, 58 insertions(+), 40 deletions(-) diff --git a/internal/biz/wechat_notify_consume.go b/internal/biz/wechat_notify_consume.go index 8ec9a51..79ed0a0 100644 --- a/internal/biz/wechat_notify_consume.go +++ b/internal/biz/wechat_notify_consume.go @@ -39,19 +39,64 @@ func (v *VoucherBiz) WechatNotifyConsumer(ctx context.Context, tag string, req * return err } - } else { - return fmt.Errorf("未知通知类型:%s", req.PlainText.Status.GetText()) } - if order.Type.IsCmb() { - - return v.cmbNotify(ctx, order.ID) - } - - return nil + return fmt.Errorf("未知通知类型:%s", req.PlainText.Status.GetText()) }) } +func (v *VoucherBiz) used(ctx context.Context, order *bo.OrderBo) error { + + if order.Status.IsUse() { + log.Warnf("券状态已是已使用,忽略不处理,orderNo:%s", order.OrderNo) + return nil + } + + if err := v.OrderRepo.Used(ctx, order.ID); err != nil { + return err + } + + return v.notify(ctx, order) +} + +func (v *VoucherBiz) available(ctx context.Context, order *bo.OrderBo) error { + + if order.Status.IsSuccess() { + log.Warnf("券状态已是可使用,忽略不处理,orderNo:%s", order.OrderNo) + return nil + } + + if err := v.OrderRepo.Available(ctx, order.ID); err != nil { + return err + } + + return v.notify(ctx, order) +} + +func (v *VoucherBiz) expired(ctx context.Context, order *bo.OrderBo) error { + + if order.Status.IsExpired() { + log.Warnf("券状态已是已过期,忽略不处理,orderNo:%s", order.OrderNo) + return nil + } + + if err := v.OrderRepo.Expired(ctx, order.ID); err != nil { + return err + } + + return v.notify(ctx, order) +} + +func (v *VoucherBiz) notify(ctx context.Context, order *bo.OrderBo) error { + + if order.Type.IsCmb() { + + return v.cmbNotify(ctx, order.ID) + } + + return fmt.Errorf("未知渠道订单类型:%s", order.Type.GetText()) +} + func (v *VoucherBiz) cmbNotify(ctx context.Context, orderId uint64) error { order, err := v.OrderRepo.GetByID(ctx, orderId) @@ -72,35 +117,3 @@ func (v *VoucherBiz) cmbNotify(ctx context.Context, orderId uint64) error { return nil } - -func (v *VoucherBiz) used(ctx context.Context, order *bo.OrderBo) error { - - if order.Status.IsUse() { - log.Warnf("券状态已是已使用,忽略不处理,orderNo:%s", order.OrderNo) - return nil - } - - return v.OrderRepo.Used(ctx, order.ID) -} - -func (v *VoucherBiz) available(ctx context.Context, order *bo.OrderBo) error { - - if order.Status.IsSuccess() { - log.Warnf("券状态已是可使用,忽略不处理,orderNo:%s", order.OrderNo) - return nil - } - - log.Warnf("券状态重置为可使用,orderNo:%s", order.OrderNo) - - return v.OrderRepo.Available(ctx, order.ID) -} - -func (j *VoucherBiz) expired(ctx context.Context, order *bo.OrderBo) error { - - if order.Status.IsExpired() { - log.Warnf("券状态已是已过期,忽略不处理,orderNo:%s", order.OrderNo) - return nil - } - - return j.OrderRepo.Expired(ctx, order.ID) -} diff --git a/internal/service/cron.go b/internal/service/cron.go index a739ba6..492b428 100644 --- a/internal/service/cron.go +++ b/internal/service/cron.go @@ -11,6 +11,11 @@ func (s *VoucherService) CronNotice(ctx context.Context) error { c, ok := s.bc.Cron.CommandMap["orderNotice"] if !ok { + log.Warn("orderNotice定时任务未找到") + return nil + } + + if !c.IsOpen { log.Warn("orderNotice定时任务未开启") return nil }