From cab7cc9d19806e112d769a5af990f97f78a1e7a1 Mon Sep 17 00:00:00 2001 From: Tokumeikoi Date: Mon, 17 Feb 2020 00:35:21 +0800 Subject: [PATCH] update order change process --- app/Console/Commands/CheckOrder.php | 4 ---- app/Http/Controllers/User/OrderController.php | 19 ++++++++++++++++++- database/update.sql | 3 +++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/Console/Commands/CheckOrder.php b/app/Console/Commands/CheckOrder.php index 3f615d33..557e4a83 100755 --- a/app/Console/Commands/CheckOrder.php +++ b/app/Console/Commands/CheckOrder.php @@ -70,10 +70,6 @@ class CheckOrder extends Command { $plan = Plan::find($order->plan_id); // change plan process - if ((int)$order->type === 3 && (int)config('v2board.try_out_plan_id') !== (int)$user->plan_id) { - $transferEnableDifference = $plan->transfer_enable - ($user->transfer_enable / 1073741824); - $user->expired_at = $user->expired_at - ($transferEnableDifference * config('v2board.plan_transfer_hour', 12) * 3600); - } $user->transfer_enable = $plan->transfer_enable * 1073741824; $user->enable = 1; $user->u = 0; diff --git a/app/Http/Controllers/User/OrderController.php b/app/Http/Controllers/User/OrderController.php index 9ab9be56..d2983749 100755 --- a/app/Http/Controllers/User/OrderController.php +++ b/app/Http/Controllers/User/OrderController.php @@ -72,6 +72,21 @@ class OrderController extends Controller return true; } + private function getDiffPrice(User $user, Plan $plan) + { + if ($plan->month_price) { + $dayPrice = $plan->month_price / 30; + } else if ($plan->quarter_price) { + $dayPrice = $plan->quarter_price / 62; + } else if ($plan->half_year_price) { + $dayPrice = $plan->half_year_price / 182.5; + } else if ($plan->year_price) { + $dayPrice = $plan->year_price / 365; + } + $remainingDay = ($user->expired_at - time()) / 86400; + return $remainingDay * $dayPrice; + } + public function save(OrderSave $request) { if ($this->isNotCompleteOrderByUserId($request->session()->get('id'))) { @@ -122,8 +137,10 @@ class OrderController extends Controller $order->total_amount = $plan[$request->input('cycle')]; // renew and change subscribe process if ($user->expired_at > time() && $order->plan_id !== $user->plan_id) { - $order->type = 3; if (!(int)config('v2board.plan_change_enable', 1)) abort(500, '目前不允许更改订阅,请联系管理员'); + $order->type = 3; + $order->diff_amount = $this->getDiffPrice($user, $plan); + $order->total_amount = $order->diff_amount; } else if ($user->expired_at > time() && $order->plan_id == $user->plan_id) { $order->type = 2; } else { diff --git a/database/update.sql b/database/update.sql index 686c9fea..959148fd 100644 --- a/database/update.sql +++ b/database/update.sql @@ -156,3 +156,6 @@ CREATE TABLE `failed_jobs` ( ALTER TABLE `v2_user` ADD `discount` int(11) NULL AFTER `balance`; + +ALTER TABLE `v2_order` +ADD `diff_amount` int(11) NULL COMMENT '差价' AFTER `discount_amount`;