6
0
Fork 0

优化管理津贴分配规则

release
李静 2022-02-14 15:57:59 +08:00
parent 24439c851b
commit 050927ffbc
1 changed files with 25 additions and 0 deletions

View File

@ -393,6 +393,10 @@ class OrderProcessCommand extends Command
$ranking = 0;
foreach ($dealers as $dealer) {
if (! in_array($dealer->lvl, [DealerLvl::Secondary, DealerLvl::Top])) {
continue;
}
// 如果当前经销商等级没有对应的管理津贴分配规则,则忽略
if (is_null($rule = $rules->get($dealer->lvl->value))) {
continue;
@ -400,6 +404,27 @@ class OrderProcessCommand extends Command
// 同等级管理津贴最多给三次
if ($last === null || $dealer->lvl->value > $last->lvl->value) {
if ($ranking < 3 && $dealer->lvl === DealerLvl::Top) {
if ($secondarySubsidyRule = $rules->get(DealerLvl::Secondary)) {
$key = 'price_'.(1 + $ranking).'st';
$secondarySubsidy = $secondarySubsidyRule->{$key};
if (bccomp($secondarySubsidy, '0') === 1) {
$logs[] = [
'user_id' => $dealer->user_id,
'order_id' => $product->order_id,
'product_id' => $product->product_id,
'lvl' => $dealer->lvl,
'sales_volume' => $product->qty,
'total_amount' => bcmul($product->qty, $secondarySubsidy, 2),
'created_at' => $tz,
'updated_at' => $tz,
];
}
}
}
$ranking = 1;
} elseif ($ranking < 3 && $dealer->lvl->value === $last->lvl->value) {
$ranking++;