@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\service\partner;
|
||||
|
||||
/**
|
||||
* 团队拆 100:无馆有县=100;有馆有县=50+50;有馆无县=50
|
||||
*/
|
||||
class TeamSplitReward
|
||||
{
|
||||
public function run($order, $buyerId, $chain, ActiveService $active)
|
||||
{
|
||||
$venueSplit = (float) PartnerConfig::get('partner_venue_split', 50);
|
||||
$countyFull = (float) PartnerConfig::get('partner_county_full', 100);
|
||||
$result = ['venue' => null, 'county' => null];
|
||||
|
||||
$venue = $this->nearest($chain, 'is_venue', $active);
|
||||
$county = $this->nearestCounty($chain, $venue, $active);
|
||||
|
||||
if (!$venue && !$county) {
|
||||
PartnerRewardService::writeSkip($order, $buyerId, 0, 'team_venue', 'system', 'not_venue', '链上无酒道馆且无区县');
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ($venue) {
|
||||
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']];
|
||||
}
|
||||
}
|
||||
|
||||
if ($county) {
|
||||
$amount = $venue ? $venueSplit : $countyFull;
|
||||
if ($county['inactive']) {
|
||||
PartnerRewardService::writeSkip($order, $buyerId, $county['user_id'], 'team_county', 'county', 'inactive_30d', '区县 30 日无自购');
|
||||
} else {
|
||||
PartnerRewardService::account($order, $buyerId, $county['user_id'], 'team_county', 'county', $amount, $amount, [
|
||||
'formula' => $venue ? "区县团队拆分 {$amount}(馆上)" : "无馆区县全额 {$amount}",
|
||||
]);
|
||||
$result['county'] = ['user_id' => $county['user_id'], 'amount' => $amount, 'index' => $county['index']];
|
||||
}
|
||||
} elseif ($venue && !$county) {
|
||||
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;
|
||||
}
|
||||
|
||||
protected function nearestCounty($chain, $venue, ActiveService $active)
|
||||
{
|
||||
$start = $venue ? ($venue['index'] + 1) : 0;
|
||||
for ($i = $start; $i < count($chain); $i++) {
|
||||
if (!intval($chain[$i]['is_county'] ?? 0)) {
|
||||
continue;
|
||||
}
|
||||
return [
|
||||
'user_id' => $chain[$i]['user_id'],
|
||||
'index' => $i,
|
||||
'inactive' => !$active->isActive($chain[$i]['agent'] ?? $chain[$i]),
|
||||
'node' => $chain[$i],
|
||||
];
|
||||
}
|
||||
// 无馆时从链头找区县(含自购区县)
|
||||
if (!$venue) {
|
||||
return $this->nearest($chain, 'is_county', $active);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户