From 4de408c54711af1840952c630d7c66ccf93e590a Mon Sep 17 00:00:00 2001 From: ziming Date: Wed, 21 May 2025 11:05:16 +0800 Subject: [PATCH] kg --- internal/biz/wechat_notify.go | 58 ++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/internal/biz/wechat_notify.go b/internal/biz/wechat_notify.go index f259af2..502cf1d 100644 --- a/internal/biz/wechat_notify.go +++ b/internal/biz/wechat_notify.go @@ -34,30 +34,8 @@ func (v *VoucherBiz) WechatNotifyConsumer(ctx context.Context, tag string, req * return err } - if req.PlainText.ConsumeInformation.ConsumeTime != "" { - - useTime, err2 := time.Parse(time.RFC3339, req.PlainText.ConsumeInformation.ConsumeTime) - if err2 != nil { - return err2 - } - - useLog, err2 := v.UseLogRepo.GetByUseTimeOrder(ctx, order.OrderNo, &useTime) - - if err2 != nil && !errors.Is(err2, gorm.ErrRecordNotFound) { - return err2 - } - - if useLog == nil { - _, err = v.UseLogRepo.Create(ctx, &bo.UseLogBo{ - OrderNo: order.OrderNo, - Amount: req.PlainText.ConsumeInformation.ConsumeAmount, - Type: vo.UseLogTypeUsed, - OperateTime: &useTime, - }) - if err != nil { - return err - } - } + if err = v.useLog(ctx, order, req); err != nil { + return err } return v.wxToBBUse(ctx, order, req) @@ -72,6 +50,38 @@ func (v *VoucherBiz) WechatNotifyConsumer(ctx context.Context, tag string, req * }) } +func (v *VoucherBiz) useLog(ctx context.Context, order *bo.OrderBo, req *bo.WechatVoucherNotifyBo) error { + + if req.PlainText.ConsumeInformation.ConsumeTime == "" { + return nil + } + + useTime, err2 := time.Parse(time.RFC3339, req.PlainText.ConsumeInformation.ConsumeTime) + if err2 != nil { + return err2 + } + + useLog, err2 := v.UseLogRepo.GetByUseTimeOrder(ctx, order.OrderNo, &useTime) + + if err2 != nil && !errors.Is(err2, gorm.ErrRecordNotFound) { + return err2 + } + + if useLog == nil { + _, err := v.UseLogRepo.Create(ctx, &bo.UseLogBo{ + OrderNo: order.OrderNo, + Amount: req.PlainText.ConsumeInformation.ConsumeAmount, + Type: vo.UseLogTypeUsed, + OperateTime: &useTime, + }) + if err != nil { + return err + } + } + + return nil +} + func (v *VoucherBiz) used(ctx context.Context, order *bo.OrderBo) error { if order.Status.IsUse() {