This commit is contained in:
root 2019-10-25 15:10:01 +08:00
parent 4604e6b053
commit 4de3f9dee4
2 changed files with 64 additions and 0 deletions

View File

@ -2,6 +2,7 @@
namespace App\Http\Controllers\Admin; namespace App\Http\Controllers\Admin;
use App\Http\Requests\Admin\UserSave;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\Order; use App\Models\Order;
@ -23,4 +24,27 @@ class UserController extends Controller
'total' => $total '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
]);
}
} }

View File

@ -0,0 +1,40 @@
<?php
namespace App\Http\Requests\Admin;
use Illuminate\Foundation\Http\FormRequest;
class ServerSave extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'email' => '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' => '是否管理员格式不正确'
];
}
}