平台应当要可以用代理的钱包支付
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m6s

This commit is contained in:
2026-04-27 10:01:38 +08:00
parent 60debb7505
commit 02ccf57aa3

View File

@@ -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 { } else {
validationResult, err = s.purchaseValidationService.ValidateAdminOfflineCardPurchase(ctx, resolvedCard.ID, req.PackageIDs)
}
} 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,16 +270,12 @@ 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 buyerType == model.BuyerTypeAgent {
if resourceShopID == nil { operatorShopID := buyerID
return nil, errors.New(errors.CodeInternalError, "资源店铺ID为空")
}
if *resourceShopID == operatorShopID { if *resourceShopID == operatorShopID {
// ==== 子场景 2.1:代理自购 ==== // ==== 子场景 2.1:代理自购 ====
@@ -343,6 +331,30 @@ func (s *Service) CreateAdminOrder(ctx context.Context, req *dto.CreateAdminOrde
// 代理代购下级时,佣金差额基准应是操作方(代理自己)的成本价,而非下级的成本价 // 代理代购下级时,佣金差额基准应是操作方(代理自己)的成本价,而非下级的成本价
sellerCostPrice = operatorTotalCost sellerCostPrice = operatorTotalCost
} }
} else {
// ==== 子场景 2.3:平台/超管代扣目标代理钱包 ====
targetShopID := *resourceShopID
targetCostPriceMap, targetTotalCost, err := s.buildCostPriceMap(ctx, validationResult.Packages, targetShopID)
if err != nil {
return nil, err
}
orderBuyerType = model.BuyerTypeAgent
orderBuyerID = targetShopID
itemUnitPriceMap = targetCostPriceMap
totalAmount = targetTotalCost
paymentMethod = model.PaymentMethodWallet
paymentStatus = model.PaymentStatusPaid
paidAt = &now
isPurchaseOnBehalf = false
operatorID = nil
operatorType = constants.OwnerTypePlatform
actualPaidAmountVal := targetTotalCost
actualPaidAmount = &actualPaidAmountVal
purchaseRole = model.PurchaseRoleSelfPurchase
sellerCostPrice = targetTotalCost
}
} else { } else {
// 兜底检查后台不支持其他支付方式DTO 验证已拒绝,此为防御性编程) // 兜底检查后台不支持其他支付方式DTO 验证已拒绝,此为防御性编程)
return nil, errors.New(errors.CodeInvalidParam, "后台仅支持钱包支付或线下支付") return nil, errors.New(errors.CodeInvalidParam, "后台仅支持钱包支付或线下支付")
@@ -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)
} }