后续订单按离买家最近的县结算;馆在县下或同一人时仍按 50+50。已入账订单不重算。 Co-authored-by: Cursor <cursoragent@cursor.com>
91 行
4.0 KiB
PHP
91 行
4.0 KiB
PHP
<?php
|
|
|
|
namespace addons\shopro\service\partner;
|
|
|
|
/**
|
|
* 渠道管理奖(馆/县拆分),链下标越小越靠近买家:
|
|
* - 无馆有县:县 100
|
|
* - 有馆无县:馆 50
|
|
* - 最近的馆在最近的县下方,或馆与县是同一人:馆 50 + 县 50
|
|
* - 最近的县在最近的馆下方:县 100,县以上的馆不发
|
|
*/
|
|
class TeamSplitReward
|
|
{
|
|
public function run($order, $buyerId, $chain, ActiveService $active, $rules = null)
|
|
{
|
|
$venueSplit = (isset($rules['venue_split']) && is_numeric($rules['venue_split']))
|
|
? (float) $rules['venue_split']
|
|
: (float) PartnerConfig::get('partner_venue_split', 50);
|
|
$countyFull = (isset($rules['county_full']) && is_numeric($rules['county_full']))
|
|
? (float) $rules['county_full']
|
|
: (float) PartnerConfig::get('partner_county_full', 100);
|
|
$result = ['venue' => null, 'county' => null];
|
|
|
|
$venue = $this->nearest($chain, 'is_venue', $active);
|
|
$county = $this->nearest($chain, 'is_county', $active);
|
|
|
|
if (!$venue && !$county) {
|
|
PartnerRewardService::writeSkip($order, $buyerId, 0, 'team_venue', 'system', 'not_venue', '链上无酒道馆且无区县');
|
|
return $result;
|
|
}
|
|
|
|
// 县比馆更靠近买家时,馆在县之上,不发酒道馆管理奖
|
|
$venueAboveCounty = $venue && $county && intval($venue['index']) > intval($county['index']);
|
|
$venueEarns = $venue && !$venueAboveCounty;
|
|
|
|
if ($venueEarns) {
|
|
if ($venue['inactive']) {
|
|
PartnerRewardService::writeSkip($order, $buyerId, $venue['user_id'], 'team_venue', 'venue', 'inactive_30d', '酒道馆 30 日无自购');
|
|
} else {
|
|
PartnerRewardService::account($order, $buyerId, $venue['user_id'], 'team_venue', 'venue', $venueSplit, $venueSplit, [
|
|
'formula' => "酒道馆管理奖 {$venueSplit}",
|
|
]);
|
|
$result['venue'] = ['user_id' => $venue['user_id'], 'amount' => $venueSplit, 'index' => $venue['index']];
|
|
}
|
|
} elseif ($venueAboveCounty) {
|
|
PartnerRewardService::writeSkip($order, $buyerId, $venue['user_id'], 'team_venue', 'venue', 'venue_above_county', '县以上酒道馆无收益');
|
|
}
|
|
|
|
if ($county) {
|
|
$amount = $venueEarns ? $venueSplit : $countyFull;
|
|
if ($county['inactive']) {
|
|
PartnerRewardService::writeSkip($order, $buyerId, $county['user_id'], 'team_county', 'county', 'inactive_30d', '区县 30 日无自购');
|
|
} else {
|
|
if ($venue && intval($venue['user_id']) === intval($county['user_id'])) {
|
|
$formulaText = "区县管理奖 {$amount}(馆兼县)";
|
|
} elseif ($venueEarns) {
|
|
$formulaText = "区县管理奖 {$amount}(馆上)";
|
|
} elseif ($venueAboveCounty) {
|
|
$formulaText = "区县管理奖 {$amount}(县在馆下)";
|
|
} else {
|
|
$formulaText = "区县管理奖 {$amount}(直达)";
|
|
}
|
|
PartnerRewardService::account($order, $buyerId, $county['user_id'], 'team_county', 'county', $amount, $amount, [
|
|
'formula' => $formulaText,
|
|
]);
|
|
$result['county'] = ['user_id' => $county['user_id'], 'amount' => $amount, 'index' => $county['index']];
|
|
}
|
|
} elseif ($venue) {
|
|
PartnerRewardService::writeSkip($order, $buyerId, 0, 'team_county', 'system', 'not_county', '有馆无区县');
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
protected function nearest($chain, $flag, ActiveService $active)
|
|
{
|
|
foreach ($chain as $i => $node) {
|
|
if (!intval($node[$flag] ?? 0)) {
|
|
continue;
|
|
}
|
|
return [
|
|
'user_id' => $node['user_id'],
|
|
'index' => $i,
|
|
'inactive' => !$active->isActive($node['agent'] ?? $node),
|
|
'node' => $node,
|
|
];
|
|
}
|
|
return null;
|
|
}
|
|
}
|