From 68b95dc87c6dd74a652971e34623658c9c53e16f Mon Sep 17 00:00:00 2001 From: ziming Date: Tue, 10 Jun 2025 10:39:17 +0800 Subject: [PATCH] query --- internal/biz/wechat_notify.go | 7 +------ internal/biz/wechat_query.go | 20 +++++++++++--------- internal/pkg/helper/utils_test.go | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/internal/biz/wechat_notify.go b/internal/biz/wechat_notify.go index 833ca14..8c288f4 100644 --- a/internal/biz/wechat_notify.go +++ b/internal/biz/wechat_notify.go @@ -118,12 +118,7 @@ func (v *VoucherBiz) expired(ctx context.Context, order *bo.OrderBo) error { 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()) + return v.cmbNotify(ctx, order.ID) } func (v *VoucherBiz) cmbNotify(ctx context.Context, orderId uint64) error { diff --git a/internal/biz/wechat_query.go b/internal/biz/wechat_query.go index a7711aa..37db077 100644 --- a/internal/biz/wechat_query.go +++ b/internal/biz/wechat_query.go @@ -63,31 +63,32 @@ func (v *VoucherBiz) WechatQuery(ctx context.Context, msg string) error { n := 0 num := 0 + notifyNum := 0 err := v.OrderRepo.FinSucByStockIdInBatches(ctx, req, func(ctx context.Context, rows []*bo.OrderBo) error { n += 1 for _, order := range rows { num += 1 - if err := v.wechatQuery(ctx, order); err != nil { + if err := v.wechatQuery(ctx, order, ¬ifyNum); err != nil { log.Errorf("微信查询券订单状态发生错误,msg:%s,orderNo:%s,couponId:%s,appId:%s,openId:%s,err:%v", msg, order.OrderNo, order.VoucherNo, order.AppID, order.Account, err) } } - log.Warnf("微信券查询处理第:%d组,已执行条数:%d,执行开始时间:%s,已耗时:%s", n, num, startStr, time.Now().Sub(start).String()) + log.Warnf("微信券查询处理第:%d组,已执行条数:%d,核销通知条数:%d,执行开始时间:%s,已耗时:%s", n, num, notifyNum, startStr, time.Now().Sub(start).String()) return nil }) - log.Warnf("微信券查询处理耗时:%s,处理%d组,处理%d单,msg:%s", time.Now().Sub(start).String(), n, num, msg) - fmt.Printf("微信券查询处理耗时:%s,处理%d组,处理%d单,msg:%s", time.Now().Sub(start).String(), n, num, msg) + log.Warnf("微信券查询处理耗时:%s,处理%d组,处理%d单,核销通知条数:%d,msg:%s", time.Now().Sub(start).String(), n, num, notifyNum, msg) + fmt.Printf("微信券查询处理耗时:%s,处理%d组,处理%d单,核销通知条数:%d,msg:%s", time.Now().Sub(start).String(), n, num, notifyNum, msg) return err } -func (v *VoucherBiz) wechatQuery(ctx context.Context, order *bo.OrderBo) error { +func (v *VoucherBiz) wechatQuery(ctx context.Context, order *bo.OrderBo, notifyNum *int) error { status, err := v.WechatCpnRepo.Query(ctx, order) if err != nil { @@ -95,7 +96,7 @@ func (v *VoucherBiz) wechatQuery(ctx context.Context, order *bo.OrderBo) error { } if status.IsUse() { - return v.queryUsed(ctx, order) + return v.queryUsed(ctx, order, notifyNum) } else if status.IsExpired() { return v.expired(ctx, order) } @@ -103,11 +104,12 @@ func (v *VoucherBiz) wechatQuery(ctx context.Context, order *bo.OrderBo) error { return nil } -func (v *VoucherBiz) queryUsed(ctx context.Context, order *bo.OrderBo) error { +func (v *VoucherBiz) queryUsed(ctx context.Context, order *bo.OrderBo, notifyNum *int) error { + + *notifyNum += 1 if order.Status.IsUse() { - log.Warnf("券状态已是已使用,忽略不处理,orderNo:%s", order.OrderNo) - return nil + return v.notify(ctx, order) } if err := v.OrderRepo.Used(ctx, order.ID); err != nil { diff --git a/internal/pkg/helper/utils_test.go b/internal/pkg/helper/utils_test.go index 8f14839..e596e66 100644 --- a/internal/pkg/helper/utils_test.go +++ b/internal/pkg/helper/utils_test.go @@ -25,3 +25,19 @@ func TestNoticeTime(t *testing.T) { t.Logf("startTime:%s,endTime:%s", startTime, endTime) } + +func TestNum(t *testing.T) { + useNum := 0 + used(&useNum) + t.Log(useNum) +} + +func used(useNum *int) { + queryUsed(useNum) + queryUsed(useNum) + *useNum += 1 +} + +func queryUsed(useNum *int) { + *useNum += 1 +}