package biz import ( "context" "fmt" "github.com/pkg/errors" "gorm.io/gorm" "time" "voucher/internal/biz/bo" "voucher/internal/biz/vo" "voucher/internal/pkg/lock" "voucher/internal/pkg/uid" ) func (v *VoucherBiz) CmbOrder(ctx context.Context, req *bo.OrderCreateReqBo) (reps *bo.OrderCreateRepBo, err error) { err = lock.NewMutex(v.rdb.Rdb, time.Second*30).Lock(ctx, fmt.Sprintf("cmb_order_%s", req.OutBizNo), func(ctx context.Context) error { order, err := v.OrderRepo.GetByOutBizNo(ctx, req.OutBizNo) if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { return err } if order != nil { // todo return nil } product, err := v.ProductRepo.GetByPNO(ctx, req.ProductNo) if err != nil { return err } orderNo, err := v.GenerateMixRepo.GeneratorString(ctx, uid.Order) if err != nil { return err } o := &bo.OrderBo{ OrderNo: orderNo, OutBizNo: req.OutBizNo, ProductNo: req.ProductNo, Account: req.Account, AppID: product.AppID, MerchantNo: product.MerchantNo, Channel: product.Channel, AccountType: vo.OrderAccountTypeOpenId, Type: vo.OrderTypeCmb, Status: vo.OrderStatusWait, } order, err = v.OrderRepo.Create(ctx, o) if err != nil { return err } return nil }) return } func (v *VoucherBiz) CmbQuery(ctx context.Context, req *bo.OrderCreateReqBo) (reps *bo.OrderCreateRepBo, err error) { err = lock.NewMutex(v.rdb.Rdb, time.Second*30).Lock(ctx, fmt.Sprintf("cmb_order_%s", req.OutBizNo), func(ctx context.Context) error { return nil }) return } func (v *VoucherBiz) CmbNotify(ctx context.Context, order *bo.OrderBo) (err error) { return }