diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index 5e825053..cabde760 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\Admin; +use App\Http\Requests\Admin\UserSave; use Illuminate\Http\Request; use App\Http\Controllers\Controller; use App\Models\Order; @@ -23,4 +24,27 @@ class UserController extends Controller 'total' => $total ]); } + + public function save (UserSave $request) { + if ($request->input('id')) { + $userModel = User::find($request->input('id')); + } else { + $userModel = new User(); + } + if (User::where('email', $request->input('email')->first())) { + abort(500, '邮箱已被使用'); + } + $userModel->email = $request->input('email'); + $userModel->password = password_hash($request->input('password'), PASSWORD_DEFAULT); + $userModel->transfer_enable = $request->input('transfer_enable') * 1073741824; + $userModel->expired_at = $request->input('expired_at'); + $userModel->banned = $request->input('banned'); + $userModel->is_admin = $request->input('is_admin'); + if (!$userModel->save()) { + abort(500, '保存失败'); + } + return response([ + 'data' => true + ]); + } } diff --git a/app/Http/Requests/Admin/UserSave.php b/app/Http/Requests/Admin/UserSave.php new file mode 100644 index 00000000..81f52fae --- /dev/null +++ b/app/Http/Requests/Admin/UserSave.php @@ -0,0 +1,40 @@ + 'required|email', + 'password' => 'required', + 'transfer_enable' => 'numeric', + 'expired_at' => 'integer', + 'banned' => 'required|in:0,1', + 'is_admin' => 'required|in:0,1' + ]; + } + + public function messages() + { + return [ + 'email.required' => '邮箱不能为空', + 'email.email' => '邮箱格式不正确', + 'password.required' => '密码不能为空', + 'transfer_enable.numeric' => '流量格式不正确', + 'expired_at.integer' => '到期时间格式不正确', + 'banned.required' => '是否封禁不能为空', + 'banned.in' => '是否封禁格式不正确', + 'is_admin.required' => '是否管理员不能为空', + 'is_admin.in' => '是否管理员格式不正确' + ]; + } +}