Commit 03afae08 authored by 刘小敏's avatar 刘小敏

fix(commission): 扣减积分抵扣部分的佣金基数

parent 8ef9d665
......@@ -72,9 +72,28 @@ class Commission
// 先记录分佣 再处理记录业绩、升级等情况
$items = $order ? $order['items'] : [];
// 积分抵扣部分需按比例从佣金基数中扣除
// order_item.pay_fee 在创建时未扣减积分抵扣,只有 order.pay_fee 扣减了
$deductScore = isset($order['deduct_score']) ? intval($order['deduct_score']) : 0;
$scoreDeductAmount = $deductScore > 0 ? round($deductScore / 100, 2) : 0;
$totalItemsPayFee = 0;
if ($scoreDeductAmount > 0) {
foreach ($items as $it) {
$totalItemsPayFee = bcadd($totalItemsPayFee, $it['pay_fee'], 2);
}
}
foreach ($items as $item) {
if (isset($item['ext']['is_commission']) && !$item['ext']['is_commission']) continue;
// 按比例从 pay_fee 中扣减积分抵扣金额
if ($scoreDeductAmount > 0 && $totalItemsPayFee > 0) {
$itemPayFee = floatval($item['pay_fee']);
$totalPayFee = floatval($totalItemsPayFee);
$itemScoreDeduction = round($scoreDeductAmount * $itemPayFee / $totalPayFee, 2);
$item['pay_fee'] = round($itemPayFee - $itemScoreDeduction, 2);
}
$commission = new OrderService($item);
// 检查能否分销
if (!$commission->checkAndSetCommission()) continue;
......
......@@ -98,7 +98,7 @@ class FixMissedCommission extends Command
$orders = Db::name('shopro_order')
->where('status', 'completed')
->where('type', '<>', 'score')
->field('id, user_id, order_sn')
->field('id, user_id, order_sn, deduct_score')
->order('id', 'asc')
->page($page, self::PAGE_SIZE)
->select();
......@@ -128,6 +128,16 @@ class FixMissedCommission extends Command
continue;
}
// 积分抵扣部分需按比例从佣金基数中扣除
$deductScore = isset($order['deduct_score']) ? intval($order['deduct_score']) : 0;
$scoreDeductAmount = $deductScore > 0 ? round($deductScore / 100, 2) : 0;
$totalItemsPayFee = 0;
if ($scoreDeductAmount > 0) {
foreach ($items as $it) {
$totalItemsPayFee = bcadd($totalItemsPayFee, $it['pay_fee'], 2);
}
}
// 第一步:为每个缺失分佣记录的商品创建 commission_order + commission_reward(模拟支付成功流程)
foreach ($items as $item) {
$itemId = $item['id'];
......@@ -148,6 +158,14 @@ class FixMissedCommission extends Command
// 补充 user_id(OrderService 需要)
$item['user_id'] = $orderUserId;
// 按比例从 pay_fee 中扣减积分抵扣金额
if ($scoreDeductAmount > 0 && $totalItemsPayFee > 0) {
$itemPayFee = floatval($item['pay_fee']);
$totalPayFee = floatval($totalItemsPayFee);
$itemScoreDeduction = round($scoreDeductAmount * $itemPayFee / $totalPayFee, 2);
$item['pay_fee'] = round($itemPayFee - $itemScoreDeduction, 2);
}
try {
// 模拟订单支付成功后的分佣流程
$commission = new OrderService($item);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment