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)