2019-10-24 19:30:16 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
2019-10-25 16:05:08 +08:00
|
|
|
use App\Http\Requests\Admin\UserUpdate;
|
2019-10-24 19:30:16 +08:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Models\Order;
|
|
|
|
use App\Models\User;
|
|
|
|
|
|
|
|
class UserController extends Controller
|
|
|
|
{
|
|
|
|
public function index (Request $request) {
|
|
|
|
$current = $request->input('current') ? $request->input('current') : 1;
|
|
|
|
$pageSize = $request->input('pageSize') >= 10 ? $request->input('pageSize') : 10;
|
|
|
|
$userModel = User::orderBy('created_at', 'DESC');
|
|
|
|
if ($request->input('email')) {
|
|
|
|
$userModel->where('email', $request->input('email'));
|
|
|
|
}
|
|
|
|
$total = $userModel->count();
|
|
|
|
return response([
|
|
|
|
'data' => $userModel->forPage($current, $pageSize)
|
|
|
|
->get(),
|
|
|
|
'total' => $total
|
|
|
|
]);
|
|
|
|
}
|
2019-10-25 15:10:01 +08:00
|
|
|
|
2019-10-25 16:05:08 +08:00
|
|
|
public function update (UserUpdate $request) {
|
2019-10-25 16:03:30 +08:00
|
|
|
$user = User::find($request->input('id'));
|
|
|
|
if (!$user) {
|
|
|
|
abort(500, '用户不存在');
|
2019-10-25 15:10:01 +08:00
|
|
|
}
|
2019-10-25 16:03:30 +08:00
|
|
|
if (User::where('email', $request->input('email'))->first() && $user->email !== $request->input('email')) {
|
2019-10-25 15:10:01 +08:00
|
|
|
abort(500, '邮箱已被使用');
|
|
|
|
}
|
2019-10-25 15:12:28 +08:00
|
|
|
$user->email = $request->input('email');
|
2019-10-25 16:03:30 +08:00
|
|
|
if ($request->input('password')) {
|
|
|
|
$user->password = password_hash($request->input('password'), PASSWORD_DEFAULT);
|
|
|
|
}
|
2019-10-25 15:12:28 +08:00
|
|
|
$user->transfer_enable = $request->input('transfer_enable') * 1073741824;
|
2019-10-25 16:03:30 +08:00
|
|
|
$user->expired_at = $request->input('expired_at');
|
2019-10-25 15:12:28 +08:00
|
|
|
$user->banned = $request->input('banned');
|
|
|
|
$user->is_admin = $request->input('is_admin');
|
|
|
|
if (!$user->save()) {
|
2019-10-25 15:10:01 +08:00
|
|
|
abort(500, '保存失败');
|
|
|
|
}
|
|
|
|
return response([
|
|
|
|
'data' => true
|
|
|
|
]);
|
|
|
|
}
|
2019-10-24 19:30:16 +08:00
|
|
|
}
|