平台应当要可以用代理的钱包支付
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m6s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m6s
This commit is contained in:
@@ -152,17 +152,9 @@ func (s *Service) CreateAdminOrder(ctx context.Context, req *dto.CreateAdminOrde
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if resolvedCard != nil {
|
if resolvedCard != nil {
|
||||||
if buyerType == model.BuyerTypeAgent {
|
validationResult, err = s.purchaseValidationService.ValidateCardPurchase(ctx, resolvedCard.ID, req.PackageIDs)
|
||||||
validationResult, err = s.purchaseValidationService.ValidateCardPurchase(ctx, resolvedCard.ID, req.PackageIDs)
|
|
||||||
} else {
|
|
||||||
validationResult, err = s.purchaseValidationService.ValidateAdminOfflineCardPurchase(ctx, resolvedCard.ID, req.PackageIDs)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if buyerType == model.BuyerTypeAgent {
|
validationResult, err = s.purchaseValidationService.ValidateDevicePurchase(ctx, resolvedDevice.ID, req.PackageIDs)
|
||||||
validationResult, err = s.purchaseValidationService.ValidateDevicePurchase(ctx, resolvedDevice.ID, req.PackageIDs)
|
|
||||||
} else {
|
|
||||||
validationResult, err = s.purchaseValidationService.ValidateAdminOfflineDevicePurchase(ctx, resolvedDevice.ID, req.PackageIDs)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,70 +270,90 @@ func (s *Service) CreateAdminOrder(ctx context.Context, req *dto.CreateAdminOrde
|
|||||||
|
|
||||||
} else if req.PaymentMethod == model.PaymentMethodWallet {
|
} else if req.PaymentMethod == model.PaymentMethodWallet {
|
||||||
// ==== 场景 2:代理钱包支付(wallet)====
|
// ==== 场景 2:代理钱包支付(wallet)====
|
||||||
// 只有代理账号可以使用钱包支付
|
if resourceShopID == nil || *resourceShopID == 0 {
|
||||||
if buyerType != model.BuyerTypeAgent {
|
return nil, errors.New(errors.CodeInvalidParam, "资源未分配给代理商,无法使用代理钱包支付")
|
||||||
return nil, errors.New(errors.CodeInvalidParam, "只有代理账号可以使用钱包支付")
|
|
||||||
}
|
|
||||||
operatorShopID := buyerID
|
|
||||||
|
|
||||||
// 判断资源是否属于操作者
|
|
||||||
if resourceShopID == nil {
|
|
||||||
return nil, errors.New(errors.CodeInternalError, "资源店铺ID为空")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if *resourceShopID == operatorShopID {
|
if buyerType == model.BuyerTypeAgent {
|
||||||
// ==== 子场景 2.1:代理自购 ====
|
operatorShopID := buyerID
|
||||||
operatorCostPriceMap, operatorTotalCost, err := s.buildCostPriceMap(ctx, validationResult.Packages, operatorShopID)
|
|
||||||
|
if *resourceShopID == operatorShopID {
|
||||||
|
// ==== 子场景 2.1:代理自购 ====
|
||||||
|
operatorCostPriceMap, operatorTotalCost, err := s.buildCostPriceMap(ctx, validationResult.Packages, operatorShopID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
orderBuyerType = model.BuyerTypeAgent
|
||||||
|
orderBuyerID = operatorShopID
|
||||||
|
itemUnitPriceMap = operatorCostPriceMap
|
||||||
|
totalAmount = operatorTotalCost
|
||||||
|
paymentMethod = model.PaymentMethodWallet
|
||||||
|
paymentStatus = model.PaymentStatusPaid
|
||||||
|
paidAt = &now
|
||||||
|
isPurchaseOnBehalf = false
|
||||||
|
|
||||||
|
operatorID = &operatorShopID
|
||||||
|
operatorType = "agent"
|
||||||
|
actualPaidAmountVal := operatorTotalCost
|
||||||
|
actualPaidAmount = &actualPaidAmountVal
|
||||||
|
purchaseRole = model.PurchaseRoleSelfPurchase
|
||||||
|
sellerCostPrice = operatorTotalCost
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// ==== 子场景 2.2:代理代购(给下级购买)====
|
||||||
|
// 获取买家成本价
|
||||||
|
buyerCostPriceMap, buyerTotalCost, err := s.buildCostPriceMap(ctx, validationResult.Packages, *resourceShopID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取操作者成本价
|
||||||
|
_, operatorTotalCost, err := s.buildCostPriceMap(ctx, validationResult.Packages, operatorShopID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
orderBuyerType = model.BuyerTypeAgent
|
||||||
|
orderBuyerID = *resourceShopID
|
||||||
|
itemUnitPriceMap = buyerCostPriceMap
|
||||||
|
totalAmount = buyerTotalCost
|
||||||
|
paymentMethod = model.PaymentMethodWallet
|
||||||
|
paymentStatus = model.PaymentStatusPaid
|
||||||
|
paidAt = &now
|
||||||
|
isPurchaseOnBehalf = true
|
||||||
|
|
||||||
|
operatorID = &operatorShopID
|
||||||
|
operatorType = "agent"
|
||||||
|
actualPaidAmountVal := operatorTotalCost
|
||||||
|
actualPaidAmount = &actualPaidAmountVal
|
||||||
|
purchaseRole = model.PurchaseRolePurchaseForSubordinate
|
||||||
|
// 代理代购下级时,佣金差额基准应是操作方(代理自己)的成本价,而非下级的成本价
|
||||||
|
sellerCostPrice = operatorTotalCost
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// ==== 子场景 2.3:平台/超管代扣目标代理钱包 ====
|
||||||
|
targetShopID := *resourceShopID
|
||||||
|
targetCostPriceMap, targetTotalCost, err := s.buildCostPriceMap(ctx, validationResult.Packages, targetShopID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
orderBuyerType = model.BuyerTypeAgent
|
orderBuyerType = model.BuyerTypeAgent
|
||||||
orderBuyerID = operatorShopID
|
orderBuyerID = targetShopID
|
||||||
itemUnitPriceMap = operatorCostPriceMap
|
itemUnitPriceMap = targetCostPriceMap
|
||||||
totalAmount = operatorTotalCost
|
totalAmount = targetTotalCost
|
||||||
paymentMethod = model.PaymentMethodWallet
|
paymentMethod = model.PaymentMethodWallet
|
||||||
paymentStatus = model.PaymentStatusPaid
|
paymentStatus = model.PaymentStatusPaid
|
||||||
paidAt = &now
|
paidAt = &now
|
||||||
isPurchaseOnBehalf = false
|
isPurchaseOnBehalf = false
|
||||||
|
|
||||||
operatorID = &operatorShopID
|
operatorID = nil
|
||||||
operatorType = "agent"
|
operatorType = constants.OwnerTypePlatform
|
||||||
actualPaidAmountVal := operatorTotalCost
|
actualPaidAmountVal := targetTotalCost
|
||||||
actualPaidAmount = &actualPaidAmountVal
|
actualPaidAmount = &actualPaidAmountVal
|
||||||
purchaseRole = model.PurchaseRoleSelfPurchase
|
purchaseRole = model.PurchaseRoleSelfPurchase
|
||||||
sellerCostPrice = operatorTotalCost
|
sellerCostPrice = targetTotalCost
|
||||||
|
|
||||||
} else {
|
|
||||||
// ==== 子场景 2.2:代理代购(给下级购买)====
|
|
||||||
// 获取买家成本价
|
|
||||||
buyerCostPriceMap, buyerTotalCost, err := s.buildCostPriceMap(ctx, validationResult.Packages, *resourceShopID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取操作者成本价
|
|
||||||
_, operatorTotalCost, err := s.buildCostPriceMap(ctx, validationResult.Packages, operatorShopID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
orderBuyerType = model.BuyerTypeAgent
|
|
||||||
orderBuyerID = *resourceShopID
|
|
||||||
itemUnitPriceMap = buyerCostPriceMap
|
|
||||||
totalAmount = buyerTotalCost
|
|
||||||
paymentMethod = model.PaymentMethodWallet
|
|
||||||
paymentStatus = model.PaymentStatusPaid
|
|
||||||
paidAt = &now
|
|
||||||
isPurchaseOnBehalf = true
|
|
||||||
|
|
||||||
operatorID = &operatorShopID
|
|
||||||
operatorType = "agent"
|
|
||||||
actualPaidAmountVal := operatorTotalCost
|
|
||||||
actualPaidAmount = &actualPaidAmountVal
|
|
||||||
purchaseRole = model.PurchaseRolePurchaseForSubordinate
|
|
||||||
// 代理代购下级时,佣金差额基准应是操作方(代理自己)的成本价,而非下级的成本价
|
|
||||||
sellerCostPrice = operatorTotalCost
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 兜底检查:后台不支持其他支付方式(DTO 验证已拒绝,此为防御性编程)
|
// 兜底检查:后台不支持其他支付方式(DTO 验证已拒绝,此为防御性编程)
|
||||||
@@ -432,10 +444,10 @@ func (s *Service) CreateAdminOrder(ctx context.Context, req *dto.CreateAdminOrde
|
|||||||
|
|
||||||
} else if req.PaymentMethod == model.PaymentMethodWallet {
|
} else if req.PaymentMethod == model.PaymentMethodWallet {
|
||||||
// 钱包支付:创建订单、扣款、激活套餐(在事务中完成)
|
// 钱包支付:创建订单、扣款、激活套餐(在事务中完成)
|
||||||
if operatorID == nil {
|
operatorShopID := orderBuyerID
|
||||||
return nil, errors.New(errors.CodeInternalError, "钱包支付场景下 operatorID 不能为空")
|
if operatorID != nil {
|
||||||
|
operatorShopID = *operatorID
|
||||||
}
|
}
|
||||||
operatorShopID := *operatorID
|
|
||||||
buyerShopID := orderBuyerID
|
buyerShopID := orderBuyerID
|
||||||
|
|
||||||
if err := s.createOrderWithWalletPayment(ctx, order, items, operatorShopID, buyerShopID); err != nil {
|
if err := s.createOrderWithWalletPayment(ctx, order, items, operatorShopID, buyerShopID); err != nil {
|
||||||
@@ -1013,8 +1025,8 @@ func (s *Service) createOrderWithWalletPayment(ctx context.Context, order *model
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 3. 事务外:佣金计算(异步)
|
// 3. 事务外:佣金计算(异步)
|
||||||
// 只有平台代购才入队佣金计算(operator_id == nil)
|
// 仅兼容极少数“平台代购但走钱包事务”的特殊场景,普通钱包订单不在此处入队佣金
|
||||||
if order.OperatorID == nil {
|
if order.PurchaseRole == model.PurchaseRolePurchasedByPlatform {
|
||||||
s.enqueueCommissionCalculation(ctx, order.ID)
|
s.enqueueCommissionCalculation(ctx, order.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user