|
|
@ -3,7 +3,6 @@ |
|
|
namespace App\Http\Controllers\Admin; |
|
|
namespace App\Http\Controllers\Admin; |
|
|
|
|
|
|
|
|
use App\Exceptions\CustomException; |
|
|
use App\Exceptions\CustomException; |
|
|
use App\Http\Controllers\Controller; |
|
|
|
|
|
use App\Models\AdminRoles; |
|
|
use App\Models\AdminRoles; |
|
|
use App\Models\AdminUsers; |
|
|
use App\Models\AdminUsers; |
|
|
use App\Services\ApiResponseService; |
|
|
use App\Services\ApiResponseService; |
|
|
@ -14,7 +13,7 @@ use Illuminate\Http\Request; |
|
|
use Illuminate\Support\Facades\Validator; |
|
|
use Illuminate\Support\Facades\Validator; |
|
|
use Illuminate\Validation\ValidationException; |
|
|
use Illuminate\Validation\ValidationException; |
|
|
|
|
|
|
|
|
class UserController extends Controller |
|
|
class UserController extends BaseController |
|
|
{ |
|
|
{ |
|
|
/** |
|
|
/** |
|
|
* @var ApiResponseService |
|
|
* @var ApiResponseService |
|
|
@ -59,11 +58,7 @@ class UserController extends Controller |
|
|
$total = $query->count(); |
|
|
$total = $query->count(); |
|
|
$items = $query->latest()->forPage($page, $perPage)->get()->each( |
|
|
$items = $query->latest()->forPage($page, $perPage)->get()->each( |
|
|
function ($item) { |
|
|
function ($item) { |
|
|
$item['status_str'] = $item['status'] ? __('admin.normal') |
|
|
return $this->AdminUserModelService->optionItem($item); |
|
|
: __('admin.freeze'); |
|
|
|
|
|
$item['role_name'] = $item->roles->value('name'); |
|
|
|
|
|
unset($item['roles']); |
|
|
|
|
|
return $item; |
|
|
|
|
|
} |
|
|
} |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
@ -89,9 +84,8 @@ class UserController extends Controller |
|
|
{ |
|
|
{ |
|
|
try { |
|
|
try { |
|
|
$data = [ |
|
|
$data = [ |
|
|
'roles_list' => [], |
|
|
'roles_list' => AdminRoles::getRolesList(), |
|
|
'permissions_list' => [], |
|
|
'packing_list' => $this->getPackingList() |
|
|
'packing_list' => [] |
|
|
|
|
|
]; |
|
|
]; |
|
|
return $this->responseService->success($data); |
|
|
return $this->responseService->success($data); |
|
|
} catch (Exception $e) { |
|
|
} catch (Exception $e) { |
|
|
@ -101,6 +95,21 @@ class UserController extends Controller |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected function getPackingList(): array |
|
|
|
|
|
{ |
|
|
|
|
|
return [ |
|
|
|
|
|
[ |
|
|
|
|
|
'id' => 1, |
|
|
|
|
|
'name' => '停车场1' |
|
|
|
|
|
], |
|
|
|
|
|
|
|
|
|
|
|
[ |
|
|
|
|
|
'id' => 2, |
|
|
|
|
|
'name' => '停车场1' |
|
|
|
|
|
] |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @param Request $request |
|
|
* @param Request $request |
|
|
* @return JsonResponse |
|
|
* @return JsonResponse |
|
|
@ -111,10 +120,11 @@ class UserController extends Controller |
|
|
{ |
|
|
{ |
|
|
try { |
|
|
try { |
|
|
$this->saveValidator($request->all()); |
|
|
$this->saveValidator($request->all()); |
|
|
|
|
|
$this->AdminUserModelService->createModel($request->all()); |
|
|
$model = $this->AdminUserModelService->createModel($request->all()); |
|
|
return $this->responseService->success( |
|
|
|
|
|
null, |
|
|
return $this->responseService->success($model, '创建用户成功'); |
|
|
__('admin.save_succeeded') |
|
|
|
|
|
); |
|
|
} catch (ValidationException|CustomException $e) { |
|
|
} catch (ValidationException|CustomException $e) { |
|
|
throw $e; |
|
|
throw $e; |
|
|
} catch (Exception $e) { |
|
|
} catch (Exception $e) { |
|
|
@ -138,6 +148,7 @@ class UserController extends Controller |
|
|
'role_id' => 'required|numeric', |
|
|
'role_id' => 'required|numeric', |
|
|
'packing_id' => 'required|numeric', |
|
|
'packing_id' => 'required|numeric', |
|
|
'password' => 'required|between:12,30', |
|
|
'password' => 'required|between:12,30', |
|
|
|
|
|
'email' => 'email' |
|
|
]; |
|
|
]; |
|
|
$messages = [ |
|
|
$messages = [ |
|
|
'username.required' => __('validation.admin_user.l_a_empty'), |
|
|
'username.required' => __('validation.admin_user.l_a_empty'), |
|
|
@ -147,12 +158,13 @@ class UserController extends Controller |
|
|
'packing_id.required' => __('validation.admin_user.s_p_empty'), |
|
|
'packing_id.required' => __('validation.admin_user.s_p_empty'), |
|
|
'password.required' => __('validation.admin_user.p_empty'), |
|
|
'password.required' => __('validation.admin_user.p_empty'), |
|
|
'password.between' => __('validation.admin_user.p_between'), |
|
|
'password.between' => __('validation.admin_user.p_between'), |
|
|
|
|
|
'email.email' => __('validation.admin_user.email'), |
|
|
]; |
|
|
]; |
|
|
if ($id) { |
|
|
if ($id) { |
|
|
$data['id'] = $id; |
|
|
$this->validateId($id, AdminUsers::class); |
|
|
$rules['id'] = 'required|numeric'; |
|
|
$rules['status'] = 'required|in:0,1'; |
|
|
$messages['id.required'] = __('validation.admin_user.id_empty'); |
|
|
$messages['status.required'] = __('validation.admin_user.s_empty'); |
|
|
$messages['id.numeric'] = __('validation.admin_user.id_numeric'); |
|
|
$messages['status.in'] = __('validation.admin_user.s_in'); |
|
|
} |
|
|
} |
|
|
$validator = Validator::make($data, $rules, $messages); |
|
|
$validator = Validator::make($data, $rules, $messages); |
|
|
|
|
|
|
|
|
@ -167,8 +179,10 @@ class UserController extends Controller |
|
|
public function show(string $id): JsonResponse |
|
|
public function show(string $id): JsonResponse |
|
|
{ |
|
|
{ |
|
|
try { |
|
|
try { |
|
|
|
|
|
$this->validateId($id, AdminUsers::class); |
|
|
$model = AdminUsers::findOrFail($id); |
|
|
$model = AdminUsers::findOrFail($id); |
|
|
return $this->responseService->success($model); |
|
|
$item = $this->AdminUserModelService->optionItem($model); |
|
|
|
|
|
return $this->responseService->success($item); |
|
|
} catch (Exception $e) { |
|
|
} catch (Exception $e) { |
|
|
return $this->responseService->systemError( |
|
|
return $this->responseService->systemError( |
|
|
__('exception.get_data_failed') . ':' . $e->getMessage() |
|
|
__('exception.get_data_failed') . ':' . $e->getMessage() |
|
|
@ -182,12 +196,12 @@ class UserController extends Controller |
|
|
public function edit(string $id): JsonResponse |
|
|
public function edit(string $id): JsonResponse |
|
|
{ |
|
|
{ |
|
|
try { |
|
|
try { |
|
|
|
|
|
$item = AdminUsers::findOrFail($id); |
|
|
|
|
|
$item = $this->AdminUserModelService->optionItem($item, 1); |
|
|
$data = [ |
|
|
$data = [ |
|
|
'item' => AdminUsers::query() |
|
|
'item' => $item, |
|
|
->where('id', $id) |
|
|
'role_list' => AdminRoles::getRolesList(), |
|
|
->get() |
|
|
'packing_list' => $this->getPackingList() |
|
|
->toArray(), |
|
|
|
|
|
'roles' => AdminRoles::getRolesList() |
|
|
|
|
|
]; |
|
|
]; |
|
|
return $this->responseService->success($data); |
|
|
return $this->responseService->success($data); |
|
|
} catch (Exception $e) { |
|
|
} catch (Exception $e) { |
|
|
@ -213,7 +227,7 @@ class UserController extends Controller |
|
|
|
|
|
|
|
|
return $this->responseService->success( |
|
|
return $this->responseService->success( |
|
|
null, |
|
|
null, |
|
|
__('controller.rule.update_success') |
|
|
__('admin.update_succeeded') |
|
|
); |
|
|
); |
|
|
} catch (ValidationException|CustomException $e) { |
|
|
} catch (ValidationException|CustomException $e) { |
|
|
throw $e; |
|
|
throw $e; |
|
|
@ -234,8 +248,10 @@ class UserController extends Controller |
|
|
{ |
|
|
{ |
|
|
try { |
|
|
try { |
|
|
$this->AdminUserModelService->deleteModel($id); |
|
|
$this->AdminUserModelService->deleteModel($id); |
|
|
|
|
|
return $this->responseService->success( |
|
|
return $this->responseService->success(null, '删除数据模型成功'); |
|
|
null, |
|
|
|
|
|
__('admin.delete_succeeded') |
|
|
|
|
|
); |
|
|
} catch (CustomException $e) { |
|
|
} catch (CustomException $e) { |
|
|
throw $e; |
|
|
throw $e; |
|
|
} catch (Exception $e) { |
|
|
} catch (Exception $e) { |
|
|
|