all(), [ "username" => "required|between:1,32", "password" => "required|between:8,16", "nickname" => "max:32", "icon" => "max:255", "tel" => "max:32", "email" => "max:64", ]); if ($validator->fails()) { return $this->fail(REQUEST_PARAM_ERROR, $this->error[REQUEST_PARAM_ERROR], $validator->errors()); } $params = []; $params["username"] = $request->input("username"); $params["password"] = $request->input("password"); $params["nickname"] = $request->input("nickname"); $params["icon"] = $request->input("icon"); $params["tel"] = $request->input("tel"); $params["email"] = $request->input("email"); $user = new Models\User(); $result = $user->CreateUser($params); if ($result["code"] == 0) { return $this->success($result["data"]); } return $this->fail($result["code"], $this->error[$result["code"]]); } public function ModifyUser(Request $request) { $validator = Validator::make($request->all(), [ "id" => "required|integer|min:1", "nickname" => "max:32", "icon" => "max:255", "tel" => "max:32", "email" => "max:64", ]); if ($validator->fails()) { return $this->fail(REQUEST_PARAM_ERROR, $this->error[REQUEST_PARAM_ERROR], $validator->errors()); } $params = []; $params["id"] = $request->input("id"); $params["username"] = $request->input("username"); $params["password"] = $request->input("password"); $params["nickname"] = $request->input("nickname"); $params["icon"] = $request->input("icon"); $params["tel"] = $request->input("tel"); $params["email"] = $request->input("email"); $user = new Models\User(); $code = $user->ModifyUser($params); if ($code == 0) { return $this->success("success"); } else { return $this->fail($code, $this->error[$code]); } } public function DeleteUser(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()); } $uid = $request->input("id"); $user = new Models\User(); $code = $user->DeleteUser($uid); if ($code == 0) { return $this->success("success"); } return $this->fail($code, $this->error[$code]); } // todo, 列出用户要根据业务在中间件添加权限拦截 public function ListUser(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()); } $page = $request->input("page"); $pageCount = $request->input("pageCount"); $keyword = $request->input("keyword"); $user = new Models\User(); $result = $user->ListUser($page, $pageCount, $keyword); return $result; } }