去掉枷锁
This commit is contained in:
parent
526634aee3
commit
ab031b6048
|
|
@ -13,49 +13,49 @@ import (
|
||||||
|
|
||||||
func (v *VoucherBiz) CmbOrder(ctx context.Context, req *bo.OrderCreateReqBo) (orderNo string, err error) {
|
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) {
|
order, err := v.OrderRepo.GetByOutBizNo(ctx, vo.OrderTypeCmb, req.OutBizNo)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
if order.Status.IsFail() {
|
||||||
return err
|
|
||||||
}
|
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
|
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) {
|
func (v *VoucherBiz) CmbQuery(ctx context.Context, orderNo string) (resp *v1.CmbQueryReply, err error) {
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
func (p *OrderRepoImpl) GetByOutBizNo(ctx context.Context, t vo.OrderType, outBizNo string) (*bo.OrderBo, error) {
|
||||||
|
|
||||||
info := &model.Order{}
|
info := &model.Order{}
|
||||||
|
|
||||||
db := p.DB(ctx)
|
db := p.DB(ctx)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue