From deba5a101b32995dcdf0ced2369df161482aadc7 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 27 Oct 2019 20:43:32 +0800 Subject: [PATCH] update --- app/Http/Controllers/Admin/PlanController.php | 25 ++++++------------- app/Http/Controllers/Admin/UserController.php | 14 +++++------ routes/api.php | 2 +- 3 files changed, 16 insertions(+), 25 deletions(-) diff --git a/app/Http/Controllers/Admin/PlanController.php b/app/Http/Controllers/Admin/PlanController.php index 1c7a9682..a95e8785 100755 --- a/app/Http/Controllers/Admin/PlanController.php +++ b/app/Http/Controllers/Admin/PlanController.php @@ -63,29 +63,20 @@ class PlanController extends Controller ]); } - public function show (Request $request) { - $plan = Plan::find($request->input('id')); - if (!$plan) { - abort(500, '该订阅不存在'); - } - $plan->show = $plan->show ? 0 : 1; - if (!$plan->save()) { - abort(500, '更改失败'); - } - return response([ - 'data' => true + public function update (Request $request) { + $updateData = $request->only([ + 'show', + 'renew' ]); - } - - public function renew (Request $request) { + $plan = Plan::find($request->input('id')); if (!$plan) { abort(500, '该订阅不存在'); } - $plan->renew = $plan->renew ? 0 : 1; - if (!$plan->save()) { - abort(500, '更改失败'); + if (!$plan->update($updateData)) { + abort(500, '保存失败'); } + return response([ 'data' => true ]); diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index d948bdeb..a787a000 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -26,7 +26,7 @@ class UserController extends Controller } public function update (UserUpdate $request) { - $fetchData = $request->only([ + $updateData = $request->only([ 'email', 'password', 'transfer_enable', @@ -38,16 +38,16 @@ class UserController extends Controller if (!$user) { abort(500, '用户不存在'); } - if (User::where('email', $fetchData['email'])->first() && $user->email !== $fetchData['email']) { + if (User::where('email', $update['email'])->first() && $user->email !== $updateData['email']) { abort(500, '邮箱已被使用'); } - if ($fetchData['password']) { - $fetchData['password'] = password_hash($fetchData['password'], PASSWORD_DEFAULT); + if ($updateData['password']) { + $updateData['password'] = password_hash($updateData['password'], PASSWORD_DEFAULT); } else { - unset($fetchData['password']); + unset($updateData['password']); } - $fetchData['transfer_enable'] = $fetchData['transfer_enable'] * 1073741824; - if (!$user->update($fetchData)) { + $updateData['transfer_enable'] = $updateData['transfer_enable'] * 1073741824; + if (!$user->update($updateData)) { abort(500, '保存失败'); } return response([ diff --git a/routes/api.php b/routes/api.php index e40a58d2..e4d203a8 100755 --- a/routes/api.php +++ b/routes/api.php @@ -26,7 +26,7 @@ Route::prefix('v1') Route::get('plan', 'Admin\\PlanController@index'); Route::post('plan/save', 'Admin\\PlanController@save'); Route::post('plan/drop', 'Admin\\PlanController@drop'); - Route::post('plan/show', 'Admin\\PlanController@show'); + Route::post('plan/update', 'Admin\\PlanController@update'); // Server Route::get('server', 'Admin\\ServerController@index'); Route::post('server/save', 'Admin\\ServerController@save');