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; } }