From ab031b6048bcb3fdedf483d2533dd483a304baef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AD=90=E9=93=AD?= Date: Fri, 21 Mar 2025 10:13:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E6=9E=B7=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/biz/cmb.go | 62 ++++++++++++++++----------------- internal/data/repoimpl/order.go | 1 + 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/internal/biz/cmb.go b/internal/biz/cmb.go index cf03c97..cdd40a4 100644 --- a/internal/biz/cmb.go +++ b/internal/biz/cmb.go @@ -13,49 +13,49 @@ import ( func (v *VoucherBiz) CmbOrder(ctx context.Context, req *bo.OrderCreateReqBo) (orderNo string, err error) { - c := vo.CmbOrderLockKey.BuildCache([]string{req.OutBizNo, req.Type.String()}) + ctx, cancel := context.WithTimeout(ctx, 25*time.Second) + defer cancel() - err = lock.NewMutex(v.rdb.Rdb, c.TTL).Lock(ctx, c.Key, func(ctx context.Context) error { + //c := vo.CmbOrderLockKey.BuildCache([]string{req.OutBizNo, req.Type.String()}) - order, err := v.OrderRepo.GetByOutBizNo(ctx, vo.OrderTypeCmb, req.OutBizNo) + //err = lock.NewMutex(v.rdb.Rdb, c.TTL).Lock(ctx, c.Key, func(ctx context.Context) error { - if err != nil && !err2.IsDbNotFound(err) { - return err - } + order, err := v.OrderRepo.GetByOutBizNo(ctx, vo.OrderTypeCmb, req.OutBizNo) - if order != nil { + if err != nil && !err2.IsDbNotFound(err) { + return orderNo, err + } - if order.Status.IsFail() { + if order != nil { - if err = v.orderRetry(ctx, order); err != nil { - return err - } + if order.Status.IsFail() { + + if err = v.orderRetry(ctx, order); err != nil { + return orderNo, err } - - orderNo = order.OrderNo - return nil - } - - product, err := v.ProductRepo.GetByProductNo(ctx, req.ProductNo) - if err != nil { - return err - } - - if !product.Channel.IsWeChat() { - return err2.ErrorCmbProductNotSupported("只支持微信") - } - - order, err = v.order(ctx, req, product) - if err != nil { - return err } orderNo = order.OrderNo + return orderNo, err + } - return nil - }) + product, err := v.ProductRepo.GetByProductNo(ctx, req.ProductNo) + if err != nil { + return orderNo, err + } - return + if !product.Channel.IsWeChat() { + return orderNo, err2.ErrorCmbProductNotSupported("只支持微信") + } + + order, err = v.order(ctx, req, product) + if err != nil { + return orderNo, err + } + + orderNo = order.OrderNo + + return orderNo, nil } func (v *VoucherBiz) CmbQuery(ctx context.Context, orderNo string) (resp *v1.CmbQueryReply, err error) { diff --git a/internal/data/repoimpl/order.go b/internal/data/repoimpl/order.go index 074c2f7..ab8083a 100644 --- a/internal/data/repoimpl/order.go +++ b/internal/data/repoimpl/order.go @@ -84,6 +84,7 @@ func (p *OrderRepoImpl) Create(ctx context.Context, req *bo.OrderBo) (*bo.OrderB } func (p *OrderRepoImpl) GetByOutBizNo(ctx context.Context, t vo.OrderType, outBizNo string) (*bo.OrderBo, error) { + info := &model.Order{} db := p.DB(ctx)