文件
Henglianshutong/addons/shopro/service/partner/PeerShareReward.php

51 行
1.8 KiB
PHP

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<?php
namespace addons\shopro\service\partner;
/**
* 酒道馆 / 区县平级 10%,基数为本单该下级的团队奖
*/
class PeerShareReward
{
public function run($order, $buyerId, $chain, $teamResult, ActiveService $active)
{
$venueRate = (float) PartnerConfig::get('partner_venue_peer_rate', 0.10);
$countyRate = (float) PartnerConfig::get('partner_county_peer_rate', 0.10);
if (!empty($teamResult['venue'])) {
$this->peer($order, $buyerId, $chain, $teamResult['venue'], 'is_venue', 'venue_peer', 'venue', $venueRate, $active, '酒道馆');
}
if (!empty($teamResult['county'])) {
$this->peer($order, $buyerId, $chain, $teamResult['county'], 'is_county', 'county_peer', 'county', $countyRate, $active, '区县');
}
}
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];
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'],
]);
}
}