mirror of
https://github.com/v2board/v2board.git
synced 2024-11-13 02:59:10 +08:00
update: fix order service
This commit is contained in:
parent
ad619b6a3a
commit
9f574a6208
@ -186,27 +186,28 @@ class OrderService
|
|||||||
|
|
||||||
private function getSurplusValueByPeriod(User $user, Order $order)
|
private function getSurplusValueByPeriod(User $user, Order $order)
|
||||||
{
|
{
|
||||||
$orderModel = Order::where('user_id', $user->id)
|
$orders = Order::where('user_id', $user->id)
|
||||||
->where('period', '!=', 'reset_price')
|
->where('period', '!=', 'reset_price')
|
||||||
->where('status', 3);
|
->where('status', 3)
|
||||||
$orders = $orderModel->get();
|
->get()
|
||||||
|
->toArray();
|
||||||
if (!$orders) return;
|
if (!$orders) return;
|
||||||
$orderAmountSum = 0;
|
$orderAmountSum = 0;
|
||||||
$orderMonthSum = 0;
|
$orderMonthSum = 0;
|
||||||
foreach ($orders as $k => $item) {
|
foreach ($orders as $item) {
|
||||||
if ($item->period === 'onetime_price') continue;
|
if ($item['period'] === 'onetime_price') continue;
|
||||||
$orderMonthSum = self::STR_TO_TIME[$item->period] + $orderMonthSum;
|
$orderMonthSum = self::STR_TO_TIME[$item['period']] + $orderMonthSum;
|
||||||
$orderAmountSum = $orderAmountSum + ($item['total_amount'] + $item['balance_amount'] + $item['surplus_amount'] - $item['refund_amount']);
|
$orderAmountSum = $orderAmountSum + ($item['total_amount'] + $item['balance_amount'] + $item['surplus_amount'] - $item['refund_amount']);
|
||||||
}
|
}
|
||||||
$expiredAtByOrder = strtotime("+{$orderMonthSum} month", $orders[0]->created_at);
|
$expiredAtByOrder = strtotime("+{$orderMonthSum} month", $orders[0]['created_at']);
|
||||||
if ($expiredAtByOrder < time()) return;
|
if ($expiredAtByOrder < time()) return;
|
||||||
$orderSurplusSecond = $expiredAtByOrder - time();
|
$orderSurplusSecond = $expiredAtByOrder - time();
|
||||||
$orderRangeSecond = $expiredAtByOrder - $orders[0]->created_at;
|
$orderRangeSecond = $expiredAtByOrder - $orders[0]['created_at'];
|
||||||
$avgPrice = $orderAmountSum / $orderRangeSecond;
|
$avgPrice = $orderAmountSum / $orderRangeSecond;
|
||||||
$orderSurplusAmount = $avgPrice * $orderSurplusSecond;
|
$orderSurplusAmount = $avgPrice * $orderSurplusSecond;
|
||||||
if (!$orderSurplusSecond || !$orderSurplusAmount) return;
|
if (!$orderSurplusSecond || !$orderSurplusAmount) return;
|
||||||
$order->surplus_amount = $orderSurplusAmount > 0 ? $orderSurplusAmount : 0;
|
$order->surplus_amount = $orderSurplusAmount > 0 ? $orderSurplusAmount : 0;
|
||||||
$order->surplus_order_ids = array_column($orders->toArray(), 'id');
|
$order->surplus_order_ids = array_column($orders, 'id');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function paid(string $callbackNo)
|
public function paid(string $callbackNo)
|
||||||
|
Loading…
Reference in New Issue
Block a user