This commit is contained in:
Tokumeikoi 2020-04-20 16:18:21 +08:00
parent 9e07861c9b
commit 2076dded41

View File

@ -77,17 +77,16 @@ class OrderController extends Controller
// surplus value // surplus value
private function getSurplusValue(User $user, Order $order) private function getSurplusValue(User $user, Order $order)
{ {
// $plan = Plan::find($user->plan_id); if ($user->expired_at === NULL) {
// if ($user->expired_at === NULL) { $this->getSurplusValueByOneTime($user);
// $this->getSurplusValueByOneTime($user, $plan); } else {
// } else { $this->getSurplusValueByCycle($user, $order);
// $this->getSurplusValueByCycle($user, $order); }
// }
$this->getSurplusValueByCycle($user, $order);
} }
private function getSurplusValueByOneTime(User $user, Plan $plan) private function getSurplusValueByOneTime(User $user)
{ {
$plan = Plan::find($user->plan_id);
$trafficUnitPrice = $plan->onetime_price / $plan->transfer_enable; $trafficUnitPrice = $plan->onetime_price / $plan->transfer_enable;
if ($user->discount && $trafficUnitPrice) { if ($user->discount && $trafficUnitPrice) {
$trafficUnitPrice = $trafficUnitPrice - ($trafficUnitPrice * $user->discount / 100); $trafficUnitPrice = $trafficUnitPrice - ($trafficUnitPrice * $user->discount / 100);
@ -108,14 +107,14 @@ class OrderController extends Controller
$orderModel = Order::where('user_id', $user->id)->where('status', 3); $orderModel = Order::where('user_id', $user->id)->where('status', 3);
$totalValue = $orderModel->sum('total_amount') + $orderModel->sum('balance_amount'); $totalValue = $orderModel->sum('total_amount') + $orderModel->sum('balance_amount');
info('剩余价值' . $totalValue); if ($totalValue <= 0) {
return;
}
$totalMonth = 0; $totalMonth = 0;
foreach ($orderModel->get() as $item) { foreach ($orderModel->get() as $item) {
$totalMonth = $totalMonth + $strToMonth[$item->cycle]; $totalMonth = $totalMonth + $strToMonth[$item->cycle];
} }
info('剩余月份' . $totalMonth);
$unitPrice = $totalValue / $totalMonth; $unitPrice = $totalValue / $totalMonth;
info('单价' . $unitPrice);
$remainingMonth = ($user->expired_at - time()) / 2678400; $remainingMonth = ($user->expired_at - time()) / 2678400;
$result = $unitPrice * $remainingMonth; $result = $unitPrice * $remainingMonth;
$order->surplus_amount = $result > 0 ? $result : 0; $order->surplus_amount = $result > 0 ? $result : 0;