mirror of
https://github.com/v2board/v2board.git
synced 2025-02-11 16:00:27 +08:00
order process fix
This commit is contained in:
parent
25d4c5b31d
commit
51fee8892e
@ -126,25 +126,18 @@ class OrderService
|
|||||||
$orderModel = Order::where('user_id', $user->id)
|
$orderModel = Order::where('user_id', $user->id)
|
||||||
->where('cycle', '!=', 'reset_price')
|
->where('cycle', '!=', 'reset_price')
|
||||||
->where('status', 3);
|
->where('status', 3);
|
||||||
|
$surplusAmount = 0;
|
||||||
$totalValue = $orderModel->sum('total_amount') + $orderModel->sum('balance_amount');
|
|
||||||
$totalValue = 0;
|
|
||||||
$totalMonth = 0;
|
|
||||||
foreach ($orderModel->get() as $item) {
|
foreach ($orderModel->get() as $item) {
|
||||||
$surplusMonth = strtotime("+ {$strToMonth[$item->cycle]}month", $item->updated_at->format('U'));
|
$surplusMonth = strtotime("+ {$strToMonth[$item->cycle]}month", $item->updated_at->format('U'));
|
||||||
$surplusMonth = ($surplusMonth - time()) / 2678400;
|
$surplusMonth = ($surplusMonth - time()) / 2678400 / $strToMonth[$item->cycle];
|
||||||
if ($surplusMonth) {
|
if ($surplusMonth > 0) {
|
||||||
$totalMonth = $totalMonth + $surplusMonth;
|
$surplusAmount = $surplusAmount + ($item['total_amount'] + $item['balance_amount']) * $surplusMonth;
|
||||||
$totalValue = ($item['total_amount'] + $item['balance_amount']) * $surplusMonth;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!$totalValue || !$totalMonth) {
|
if (!$surplusAmount) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$unitPrice = $totalValue / $totalMonth;
|
$order->surplus_amount = $surplusAmount > 0 ? $surplusAmount : 0;
|
||||||
$remainingMonth = ($user->expired_at - time()) / 2678400;
|
|
||||||
$result = $unitPrice * $remainingMonth;
|
|
||||||
$order->surplus_amount = $result > 0 ? $result : 0;
|
|
||||||
$order->surplus_order_ids = json_encode(array_map(function ($v) { return $v['id'];}, $orderModel->get()->toArray()));
|
$order->surplus_order_ids = json_encode(array_map(function ($v) { return $v['id'];}, $orderModel->get()->toArray()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user