From 3b9e9cbe7fae28fceb099fa9824f1f8b75d54ecb Mon Sep 17 00:00:00 2001 From: Tokumeikoi Date: Fri, 28 Feb 2020 14:51:06 +0800 Subject: [PATCH] add onetime plan --- app/Http/Controllers/User/OrderController.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/Http/Controllers/User/OrderController.php b/app/Http/Controllers/User/OrderController.php index 3617d8c0..25669d1a 100755 --- a/app/Http/Controllers/User/OrderController.php +++ b/app/Http/Controllers/User/OrderController.php @@ -75,6 +75,25 @@ class OrderController extends Controller private function getSurplusValue(User $user) { $plan = Plan::find($user->plan_id); + switch ($plan->type) { + case 0: return $this->getSurplusValueByCycle($user, $plan); + case 1: return $this->getSurplusValueByOneTime($user, $plan); + } + } + + private function getSurplusValueByOneTime(User $user, Plan $plan) + { + $trafficUnitPrice = 0; + $trafficUnitPrice = $plan->onetime_price / $plan->transfer_enable; + if ($user->discount && $trafficUnitPrice) { + $trafficUnitPrice = $trafficUnitPrice - ($trafficUnitPrice * $user->discount / 100); + } + $notUsedTrafficPrice = $plan->transfer_enable - (($user->u + $user->d) / 1073741824); + return $trafficUnitPrice * $notUsedTrafficPrice; + } + + private function getSurplusValueByCycle(User $user, Plan $plan) + { $dayPrice = 0; if ($plan->month_price) { $dayPrice = $plan->month_price / 2592000;