修复佣金错误计算的问题
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m15s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m15s
This commit is contained in:
@@ -141,13 +141,17 @@ func (s *Service) CalculateCostDiffCommission(ctx context.Context, order *model.
|
||||
return nil, errors.Wrap(errors.CodeDatabaseError, err, "获取销售店铺失败")
|
||||
}
|
||||
|
||||
// 卖家利润 = 实际收款 - 成本价,必须用 ActualPaidAmount 而非 TotalAmount
|
||||
// TotalAmount 在 fix-order-price-semantics 后始终存零售价,代理自购时会错误产生佣金
|
||||
var sellerProfit int64
|
||||
if order.ActualPaidAmount != nil {
|
||||
sellerProfit = *order.ActualPaidAmount - order.SellerCostPrice
|
||||
} else {
|
||||
sellerProfit = order.TotalAmount - order.SellerCostPrice
|
||||
sellerProfit, shouldCalculateSellerProfit := calculateSellerProfit(order)
|
||||
if !shouldCalculateSellerProfit {
|
||||
s.logger.Warn("订单缺少实际支付金额,跳过终端销售代理成本价差佣金计算",
|
||||
zap.Uint("order_id", order.ID),
|
||||
zap.String("source", order.Source),
|
||||
zap.String("payment_method", order.PaymentMethod),
|
||||
zap.String("buyer_type", order.BuyerType),
|
||||
zap.String("purchase_role", order.PurchaseRole),
|
||||
zap.Int64("total_amount", order.TotalAmount),
|
||||
zap.Int64("seller_cost_price", order.SellerCostPrice),
|
||||
)
|
||||
}
|
||||
if sellerProfit > 0 {
|
||||
records = append(records, &model.CommissionRecord{
|
||||
@@ -232,6 +236,28 @@ func (s *Service) CalculateCostDiffCommission(ctx context.Context, order *model.
|
||||
return records, nil
|
||||
}
|
||||
|
||||
// calculateSellerProfit 计算终端销售代理的成本价差收益。
|
||||
// 代理钱包/代购链路必须以 actual_paid_amount 为准,禁止回退到 total_amount,
|
||||
// 否则在 total_amount 已改成零售价后会再次产生“建议售价-成本价”的错误佣金。
|
||||
func calculateSellerProfit(order *model.Order) (int64, bool) {
|
||||
if order == nil {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
if order.ActualPaidAmount != nil {
|
||||
return *order.ActualPaidAmount - order.SellerCostPrice, true
|
||||
}
|
||||
|
||||
if order.BuyerType == model.BuyerTypeAgent ||
|
||||
order.PaymentMethod == model.PaymentMethodWallet ||
|
||||
order.IsPurchaseOnBehalf ||
|
||||
order.Source == constants.OrderSourceAdmin {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
return order.TotalAmount - order.SellerCostPrice, true
|
||||
}
|
||||
|
||||
func (s *Service) triggerOneTimeCommissionForCardInTx(ctx context.Context, tx *gorm.DB, order *model.Order, cardID uint) error {
|
||||
if order.IsPurchaseOnBehalf || order.Source != constants.OrderSourceClient {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user