all(), [ "name" => "required|between:1,64", "description" => "max:255", ]); if ($validator->fails()) { return $this->fail(REQUEST_PARAM_ERROR, $this->error[REQUEST_PARAM_ERROR], $validator->errors()); } $params = []; $params["name"] = $request->input("name"); $params["description"] = $request->input("description"); $role = new Models\Role(); $result = $role->CreateRole($params); if ($result["code"] == 0) { return $this->success($result["data"]); } return $this->fail($result["code"], $this->error[$result["code"]]);; } /** * 修改某个角色的信息 * * @param Request $request * @return \Illuminate\Http\JsonResponse */ public function ModifyRole(Request $request) { $validator = Validator::make($request->all(), [ "id" => "required|integer|min:1", "name" => "between:1,64", "description" => "max:255", ]); if ($validator->fails()) { return $this->fail(REQUEST_PARAM_ERROR, $this->error[REQUEST_PARAM_ERROR], $validator->errors()); } $params = []; $params["id"] = $request->input("id"); $params["name"] = $request->input("name"); $params["description"] = $request->input("description"); $role = new Models\Role(); $result = $role->ModifyRole($params); $code = $result["code"]; if ($code == 0) { return $this->success($result["data"]); } return $this->fail($code, $this->error[$code]); } /** * 删除某个角色 * * @param Request $request * @return \Illuminate\Http\JsonResponse */ public function DeleteRole(Request $request) { $validator = Validator::make($request->all(), [ "id" => "required|integer|min:1", ]); if ($validator->fails()) { return $this->fail(REQUEST_PARAM_ERROR, $this->error[REQUEST_PARAM_ERROR], $validator->errors()); } $params = []; $params["id"] = $request->input("id"); $role = new Models\Role(); $code = $role->DeleteRole($params); if ($code == 0) { return $this->success("success"); } return $this->fail($code, $this->error[$code]); } /** * 列出所有的角色信息 * * @param Request $request * @return \Illuminate\Http\JsonResponse|mixed */ public function ListRole(Request $request) { $validator = Validator::make($request->all(), [ "page" => "integer|min:1", "pageCount" => "integer|min:1" ]); if ($validator->fails()) { return $this->fail(REQUEST_PARAM_ERROR, $this->error[REQUEST_PARAM_ERROR], $validator->errors()); } $params = []; $params["page"] = (int)$request->input("page"); $params["pageCount"] = (int)$request->input("pageCount"); $params["keyword"] = $request->input("keyword"); $role = new Models\Role(); $roleData = $role->ListRole($params); return $this->success($roleData); } /** * 加载当前用户的角色信息 * * @param Request $request * @return \Illuminate\Http\JsonResponse */ public function LoadRole(Request $request) { $uid = (int)$request->input("currentUid"); if ($uid < 1) { $this->fail(INVALID_USER_ID, $this->error[INVALID_USER_ID]); } $role = new Models\UserRole(); $data = $role->LoadRole($uid); if ($data["code"] == 0){ return $this->success($data["data"]); } return $this->fail($data["code"], $this->error[$data["code"]]); } /** * 管理员加载用户的角色信息 * * @param Request $request * @return \Illuminate\Http\JsonResponse */ public function AdminLoadRole(Request $request) { $uid = (int)$request->input("userId"); if ($uid < 1) { $this->fail(INVALID_USER_ID, $this->error[INVALID_USER_ID]); } $role = new Models\UserRole(); $data = $role->LoadRole($uid); if ($data["code"] == 0){ return $this->success($data["data"]); } return $this->fail($data["code"], $this->error[$data["code"]]); } /** * 列出角色下的用户 * * @param Request $request * @return array|\Illuminate\Http\JsonResponse */ public function LoadRoleUsers(Request $request) { $validator = Validator::make($request->all(), [ "keyword" => "max: 255", "page" => "integer|min:1", "pageCount" => "integer|min:1", "ukeyword" => "max: 255", "upage" => "integer|min:1", "upageCount" => "integer|min:1" ]); if ($validator->fails()) { return $this->fail(REQUEST_PARAM_ERROR, $this->error[REQUEST_PARAM_ERROR], $validator->errors()); } $keyword = $request->input("keyword"); $page = (int)$request->input("page"); $pageCount = (int)$request->input("pageCount"); $ukeyword = $request->input("ukeyword"); $upage = (int)$request->input("page"); $upageCount = (int)$request->input("pageCount"); $role = new Models\Role(); $data = $role->LoadRoleUsers($keyword, $page, $pageCount, $ukeyword, $upage, $upageCount); return $this->success($data); } }