feat(partner): 全网平级奖支持逐代10%级联递减至0.01元截断机制
这个提交包含在:
@@ -3,7 +3,7 @@
|
||||
namespace addons\shopro\service\partner;
|
||||
|
||||
/**
|
||||
* 酒道馆 / 区县平级 10%,基数为本单该下级的团队奖
|
||||
* 酒道馆 / 区县平级 10% 逐代递减级联,最低发放 0.01 元截断
|
||||
*/
|
||||
class PeerShareReward
|
||||
{
|
||||
@@ -22,29 +22,67 @@ class PeerShareReward
|
||||
|
||||
protected function peer($order, $buyerId, $chain, $from, $flag, $type, $role, $rate, ActiveService $active, $label)
|
||||
{
|
||||
$start = intval($from['index']) + 1;
|
||||
$peer = null;
|
||||
for ($i = $start; $i < count($chain); $i++) {
|
||||
if (intval($chain[$i][$flag] ?? 0)) {
|
||||
$peer = $chain[$i];
|
||||
$maxGenerations = intval(PartnerConfig::get("partner_{$role}_peer_max_generations", 50));
|
||||
if ($maxGenerations <= 0) {
|
||||
$maxGenerations = 50;
|
||||
}
|
||||
|
||||
$currentFrom = intval($from['index']);
|
||||
$currentBase = (float) $from['amount'];
|
||||
$sourceUserId = $from['user_id'];
|
||||
|
||||
for ($gen = 1; $gen <= $maxGenerations; $gen++) {
|
||||
$peerIdx = -1;
|
||||
for ($i = $currentFrom + 1; $i < count($chain); $i++) {
|
||||
if (intval($chain[$i][$flag] ?? 0)) {
|
||||
$peerIdx = $i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($peerIdx < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
$peer = $chain[$peerIdx];
|
||||
$amount = round($currentBase * $rate, 2);
|
||||
if ($amount < 0.01) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!$active->isActive($peer['agent'] ?? $peer)) {
|
||||
PartnerRewardService::writeSkip(
|
||||
$order,
|
||||
$buyerId,
|
||||
$peer['user_id'],
|
||||
$type,
|
||||
$role,
|
||||
'inactive_30d',
|
||||
"{$label}平级(第{$gen}代) 30 日无自购"
|
||||
);
|
||||
} else {
|
||||
PartnerRewardService::account(
|
||||
$order,
|
||||
$buyerId,
|
||||
$peer['user_id'],
|
||||
$type,
|
||||
$role,
|
||||
$amount,
|
||||
$currentBase,
|
||||
[
|
||||
'generation' => $gen,
|
||||
'formula' => "{$label}平级(第{$gen}代) {$currentBase} × " . ($rate * 100) . "% = {$amount}",
|
||||
'from_user_id' => $sourceUserId,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
$currentFrom = $peerIdx;
|
||||
$currentBase = $amount;
|
||||
$sourceUserId = $peer['user_id'];
|
||||
|
||||
if ($currentBase < 0.01) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$peer) {
|
||||
return;
|
||||
}
|
||||
$base = (float) $from['amount'];
|
||||
$amount = round($base * $rate, 2);
|
||||
if (!$active->isActive($peer['agent'] ?? $peer)) {
|
||||
PartnerRewardService::writeSkip($order, $buyerId, $peer['user_id'], $type, $role, 'inactive_30d', "{$label}平级 30 日无自购");
|
||||
return;
|
||||
}
|
||||
if ($amount <= 0) {
|
||||
return;
|
||||
}
|
||||
PartnerRewardService::account($order, $buyerId, $peer['user_id'], $type, $role, $amount, $base, [
|
||||
'formula' => "{$label}平级 {$base} × " . ($rate * 100) . "% = {$amount}",
|
||||
'from_user_id' => $from['user_id'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户