123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- namespace App\Http\Controllers;
- use App\Models;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Validator;
- // todo 返回值为 数字代码还是json还是其他格式待定
- class UserController extends Controller
- {
- public function CreateUser(Request $request)
- {
- $validator = Validator::make($request->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;
- }
- }
|