update: order service

This commit is contained in:
tokumeikoi 2022-03-04 22:48:44 +08:00
parent b85eb72d1a
commit d0cab99ae4
2 changed files with 22 additions and 24 deletions

View File

@ -117,30 +117,28 @@ class OrderService
public function setInvite(User $user):void
{
$order = $this->order;
if ($user->invite_user_id && $order->total_amount > 0) {
$order->invite_user_id = $user->invite_user_id;
$inviter = User::find($user->invite_user_id);
$isCommission = false;
switch ((int)$inviter->commission_type) {
case 0:
$commissionFirstTime = (int)config('v2board.commission_first_time_enable', 1);
$isCommission = (!$commissionFirstTime || ($commissionFirstTime && !$this->haveValidOrder($user)));
break;
case 1:
$isCommission = true;
break;
case 2:
$isCommission = !$this->haveValidOrder($user);
break;
}
if ($user->invite_user_id && ($order->total_amount <= 0)) return;
$order->invite_user_id = $user->invite_user_id;
$inviter = User::find($user->invite_user_id);
$isCommission = false;
switch ((int)$inviter->commission_type) {
case 0:
$commissionFirstTime = (int)config('v2board.commission_first_time_enable', 1);
$isCommission = (!$commissionFirstTime || ($commissionFirstTime && !$this->haveValidOrder($user)));
break;
case 1:
$isCommission = true;
break;
case 2:
$isCommission = !$this->haveValidOrder($user);
break;
}
if ($isCommission) {
if ($inviter && $inviter->commission_rate) {
$order->commission_balance = $order->total_amount * ($inviter->commission_rate / 100);
} else {
$order->commission_balance = $order->total_amount * (config('v2board.invite_commission', 10) / 100);
}
}
if ($isCommission) return;
if ($inviter && $inviter->commission_rate) {
$order->commission_balance = $order->total_amount * ($inviter->commission_rate / 100);
} else {
$order->commission_balance = $order->total_amount * (config('v2board.invite_commission', 10) / 100);
}
}

File diff suppressed because one or more lines are too long