From 0d1870f5c8c9b5ce9ba72ed2cd509022c5c6470e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AD=90=E9=93=AD?= Date: Fri, 14 Mar 2025 11:51:49 +0800 Subject: [PATCH] notice --- internal/biz/cmb.go | 4 ++++ internal/biz/order.go | 35 +++++++++++++++++++++++++++++++++++ internal/biz/order_notice.go | 27 ++------------------------- 3 files changed, 41 insertions(+), 25 deletions(-) diff --git a/internal/biz/cmb.go b/internal/biz/cmb.go index 4d8e125..c7ff300 100644 --- a/internal/biz/cmb.go +++ b/internal/biz/cmb.go @@ -69,6 +69,10 @@ func (v *VoucherBiz) CmbQuery(ctx context.Context, orderNo string) (resp *v1.Cmb return err } + if err = v.Query(ctx, order); err != nil { + return err + } + status, err := order.Status.GetCmbStatusText() if err != nil { return err diff --git a/internal/biz/order.go b/internal/biz/order.go index 7873f11..d69f49f 100644 --- a/internal/biz/order.go +++ b/internal/biz/order.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "github.com/go-kratos/kratos/v2/log" "github.com/redis/go-redis/v9" "gorm.io/gorm" "voucher/internal/biz/bo" @@ -236,3 +237,37 @@ func (v *VoucherBiz) alarmText(_ context.Context, order *bo.OrderBo, errMsg stri return fmt.Sprintf(msg, remarks) } + +func (v *VoucherBiz) Query(ctx context.Context, order *bo.OrderBo) error { + + status, err := v.WechatCpnRepo.Query(ctx, order) + if err != nil { + return err + } + + if order.Status == status { + log.Warnf("券状态未改变:%s,忽略不处理,orderNo:%s", order.Status.GetText(), order.OrderNo) + return nil + } + + if err = v.UpdateOrderStatus(ctx, order.ID, status); err != nil { + return err + } + + order.Status = status + + return nil +} + +func (v *VoucherBiz) UpdateOrderStatus(ctx context.Context, orderId uint64, status vo.OrderStatus) error { + + if status.IsSuccess() { + return v.OrderRepo.Available(ctx, orderId) + } else if status.IsUse() { + return v.OrderRepo.Used(ctx, orderId) + } else if status.IsExpired() { + return v.OrderRepo.Expired(ctx, orderId) + } + + return fmt.Errorf("notice 未知券状态,orderId:%d,statuText:%s", orderId, status.GetText()) +} diff --git a/internal/biz/order_notice.go b/internal/biz/order_notice.go index 89ae1a2..513e2f2 100644 --- a/internal/biz/order_notice.go +++ b/internal/biz/order_notice.go @@ -104,34 +104,11 @@ func (v *VoucherBiz) isCanNotice(ctx context.Context) error { func (v *VoucherBiz) cmbOrderNotice(ctx context.Context, order *bo.OrderBo) error { // 批量通知不做数据存储,量可能会很大很大 - status, err := v.WechatCpnRepo.Query(ctx, order) - if err != nil { + + if err := v.Query(ctx, order); err != nil { return err } - if order.Status == status { - log.Warnf("notice 券状态未改变:%s,忽略不处理,orderNo:%s", order.Status.GetText(), order.OrderNo) - return nil - } - - if status.IsSuccess() { - if err = v.OrderRepo.Available(ctx, order.ID); err != nil { - return err - } - } else if status.IsUse() { - if err = v.OrderRepo.Used(ctx, order.ID); err != nil { - return err - } - } else if status.IsExpired() { - if err = v.OrderRepo.Expired(ctx, order.ID); err != nil { - return err - } - } else { - return fmt.Errorf("notice 未知券状态,orderNo:%s,statuText:%s", order.OrderNo, status.GetText()) - } - - order.Status = status - event, err := order.Status.GetOrderNotifyEvent() if err != nil { return err