responseService = $responseService; } /** * 验证ID * @param $id * @param $model * @return void * @throws ValidationException|Exception */ protected function validateId($id, $model): void { $data = ['id' => $id]; $validator = Validator::make($data, [ 'id' => 'required|numeric' ], [ 'id.required' => __('validation.id_empty'), 'id.numeric' => __('validation.id_numeric') ]); if ($validator->fails()) { throw new ValidationException($validator); } if (!$model::query()->where('id', $id)->exists()) { throw new Exception(__('exception.exception_handler.resource')); }; } /** * 功能显示权限 * @return int[] * @throws InvalidArgumentException */ protected function methodShow(): array { $methodAuthArr = AdminMenuService::auth($this->adminUserId); $roleMenuArr = AdminMenuService::getRoleMenuList($this->menuUri); $authArr = []; foreach ($roleMenuArr as $value) { $authArr[$value] = 0; } $newArr = []; foreach ($authArr as $authKey => $value) { if (in_array($authKey, $methodAuthArr)) { $authArr[$authKey] = 1; } $key = explode('.',$authKey); $newArr[$key[1]] = $authArr[$authKey]; } return $newArr; } /** * @return JsonResponse * @throws InvalidArgumentException */ public function rule(): JsonResponse { try { if (!$this->menuUri) { throw new Exception(''); } return $this->responseService->success($this->methodShow()); } catch (Exception $e) { return $this->responseService->systemError( __('exception.get_data_failed') . ':' . $e->getMessage() ); } } }