From e9c99d75426fb462ee027ab928f3a058ca897f85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AD=90=E9=93=AD?= Date: Thu, 13 Mar 2025 11:14:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/biz/repo/order.go | 1 + internal/biz/wechat_notify_consume.go | 20 +++++++++++++++++++- internal/data/repoimpl/order.go | 20 ++++++++++++++++++++ internal/service/wechat_notify_consume.go | 10 ---------- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/internal/biz/repo/order.go b/internal/biz/repo/order.go index 008c5b4..310a88f 100644 --- a/internal/biz/repo/order.go +++ b/internal/biz/repo/order.go @@ -16,5 +16,6 @@ type OrderRepo interface { Success(ctx context.Context, id uint64, voucherNo string) error Fail(ctx context.Context, id uint64, remark string) error Used(ctx context.Context, id uint64) error + Available(ctx context.Context, id uint64) error Expired(ctx context.Context, id uint64) error } diff --git a/internal/biz/wechat_notify_consume.go b/internal/biz/wechat_notify_consume.go index b25ba9b..9ed5d87 100644 --- a/internal/biz/wechat_notify_consume.go +++ b/internal/biz/wechat_notify_consume.go @@ -21,7 +21,13 @@ func (v *VoucherBiz) WechatNotifyConsumer(ctx context.Context, tag string, req * return err } - if req.PlainText.Status.IsUsed() { + if req.PlainText.Status.IsSended() { + + if err = v.available(ctx, order); err != nil { + return err + } + + } else if req.PlainText.Status.IsUsed() { if err = v.used(ctx, order); err != nil { return err @@ -65,6 +71,18 @@ func (v *VoucherBiz) used(ctx context.Context, order *bo.OrderBo) error { 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() { diff --git a/internal/data/repoimpl/order.go b/internal/data/repoimpl/order.go index 6161699..13535fe 100644 --- a/internal/data/repoimpl/order.go +++ b/internal/data/repoimpl/order.go @@ -160,6 +160,26 @@ func (p *OrderRepoImpl) Success(ctx context.Context, id uint64, voucherNo string return nil } +func (p *OrderRepoImpl) Available(ctx context.Context, id uint64) error { + now := time.Now() + + res := p.db.DB(ctx). + Where(model.Order{ + ID: id, + Status: vo.OrderStatusUse.GetValue(), + }). + Updates(model.Order{ + Status: vo.OrderStatusSuccess.GetValue(), + UpdateTime: &now, + }) + + if res.Error != nil { + return res.Error + } + + return nil +} + func (p *OrderRepoImpl) Fail(ctx context.Context, id uint64, remark string) error { now := time.Now() diff --git a/internal/service/wechat_notify_consume.go b/internal/service/wechat_notify_consume.go index 912676c..84cbcb6 100644 --- a/internal/service/wechat_notify_consume.go +++ b/internal/service/wechat_notify_consume.go @@ -3,7 +3,6 @@ package service import ( "context" "encoding/json" - "github.com/go-kratos/kratos/v2/log" "voucher/internal/biz/bo" ) @@ -15,14 +14,5 @@ func (v *VoucherService) WechatNotifyConsumer(ctx context.Context, tag, msg stri return err } - if req.PlainText.Status.IsSended() { - log.Warnf("券状态可用,忽略不处理,couponId:%s,stockId:%s,status:%s", - req.PlainText.CouponID, - req.PlainText.StockID, - req.PlainText.Status.GetText(), - ) - return nil - } - return v.VoucherBiz.WechatNotifyConsumer(ctx, tag, req) }