还原代码

This commit is contained in:
李子铭 2025-03-21 14:35:59 +08:00
parent 9d0e5e6f76
commit 1a8343cda8
2 changed files with 31 additions and 24 deletions

View File

@ -8,16 +8,19 @@ import (
v1 "voucher/api/v1"
"voucher/internal/biz/bo"
"voucher/internal/biz/vo"
"voucher/internal/pkg/helper"
"voucher/internal/pkg/lock"
)
func (v *VoucherBiz) CmbOrder(ctx context.Context, req *bo.OrderCreateReqBo) (orderNo string, err error) {
bizCtx := helper.CopyValueCtx(ctx)
c := vo.CmbOrderLockKey.BuildCache([]string{req.OutBizNo, req.Type.String()})
err = lock.NewMutex(v.rdb.Rdb, c.TTL).Lock(ctx, c.Key, func(ctx context.Context) error {
err = lock.NewMutex(v.rdb.Rdb, c.TTL).Lock(bizCtx, c.Key, func(bizCtx context.Context) error {
order, err := v.OrderRepo.GetByOutBizNo(ctx, vo.OrderTypeCmb, req.OutBizNo)
order, err := v.OrderRepo.GetByOutBizNo(bizCtx, vo.OrderTypeCmb, req.OutBizNo)
if err != nil && !err2.IsDbNotFound(err) {
return err
@ -27,7 +30,7 @@ func (v *VoucherBiz) CmbOrder(ctx context.Context, req *bo.OrderCreateReqBo) (or
if order.Status.IsFail() {
if err = v.orderRetry(ctx, order); err != nil {
if err = v.orderRetry(bizCtx, order); err != nil {
return err
}
}
@ -36,7 +39,7 @@ func (v *VoucherBiz) CmbOrder(ctx context.Context, req *bo.OrderCreateReqBo) (or
return nil
}
product, err := v.ProductRepo.GetByProductNo(ctx, req.ProductNo)
product, err := v.ProductRepo.GetByProductNo(bizCtx, req.ProductNo)
if err != nil {
return err
}
@ -45,7 +48,7 @@ func (v *VoucherBiz) CmbOrder(ctx context.Context, req *bo.OrderCreateReqBo) (or
return err2.ErrorCmbProductNotSupported("只支持微信")
}
order, err = v.order(ctx, req, product)
order, err = v.order(bizCtx, req, product)
if err != nil {
return err
}

View File

@ -18,26 +18,23 @@ func (v *VoucherBiz) order(ctx context.Context, req *bo.OrderCreateReqBo, produc
return nil, err
}
voucherNo := ""
if product.ProductNo == "001" {
// 压测商品
voucherNo = order.OrderNo
} else {
// 压测商品-直接返回
return order, nil
}
// 注册通知标签 order.MerchantNo 批次创建商户, order.BatchNo 商品批次号
if err = v.registerNotifyTag(ctx, order.MerchantNo, order.BatchNo); err != nil {
return nil, err
// 注册通知标签 order.MerchantNo 批次创建商户, order.BatchNo 商品批次号
if err = v.registerNotifyTag(ctx, order.MerchantNo, order.BatchNo); err != nil {
return nil, err
}
// 真实发放
voucherNo, err := v.WechatCpnRepo.Order(ctx, order)
if err != nil {
if err3 := v.fail(ctx, order, err.Error()); err3 != nil {
return nil, err3
}
// 真实发放
voucherNo, err = v.WechatCpnRepo.Order(ctx, order)
if err != nil {
if err3 := v.fail(ctx, order, err.Error()); err3 != nil {
return nil, err3
}
return nil, err
}
return nil, err
}
if err = v.success(ctx, order, voucherNo); err != nil {
@ -63,7 +60,7 @@ func (v *VoucherBiz) orderRetry(ctx context.Context, order *bo.OrderBo) error {
func (v *VoucherBiz) create(ctx context.Context, req *bo.OrderCreateReqBo, product *bo.ProductBo) (*bo.OrderBo, error) {
return v.OrderRepo.Create(ctx, &bo.OrderBo{
o := &bo.OrderBo{
OrderNo: v.GenerateMixRepo.GeneratorString(ctx, fmt.Sprintf("%d%s", req.Type, req.OutBizNo)),
OutBizNo: req.OutBizNo,
ProductNo: req.ProductNo,
@ -77,7 +74,14 @@ func (v *VoucherBiz) create(ctx context.Context, req *bo.OrderCreateReqBo, produ
Type: req.Type,
Status: vo.OrderStatusIng, // 同步发放,状态至为发放中
Attach: req.Attach,
})
}
if product.ProductNo == "001" {
// 压测商品
o.Status = vo.OrderStatusSuccess
}
return v.OrderRepo.Create(ctx, o)
}
func (v *VoucherBiz) registerNotifyTag(ctx context.Context, stockCreatorMchID, stockID string) error {