正在显示
14 个修改的文件
包含
163 行增加
和
183 行删除
| @@ -13,12 +13,12 @@ use Throwable; | @@ -13,12 +13,12 @@ use Throwable; | ||
| 13 | */ | 13 | */ |
| 14 | class AsideGlobalException extends Exception | 14 | class AsideGlobalException extends Exception |
| 15 | { | 15 | { |
| 16 | - public function __construct($code = 0, $message = "", Throwable $previous = null) | ||
| 17 | - { | ||
| 18 | - $this->code = $code; | ||
| 19 | - $this->message = $message; | ||
| 20 | - if (empty($this->message)) { | ||
| 21 | - $this->message = Code::fromValue($code)->description; | ||
| 22 | - } | ||
| 23 | - } | 16 | +// public function __construct($code = 0, $message = "", Throwable $previous = null) |
| 17 | +// { | ||
| 18 | +// $this->code = $code; | ||
| 19 | +// $this->message = $message; | ||
| 20 | +// if (empty($this->message)) { | ||
| 21 | +// $this->message = Code::fromValue($code)->description; | ||
| 22 | +// } | ||
| 23 | +// } | ||
| 24 | } | 24 | } |
| @@ -13,12 +13,12 @@ use Throwable; | @@ -13,12 +13,12 @@ use Throwable; | ||
| 13 | */ | 13 | */ |
| 14 | class BsideGlobalException extends Exception | 14 | class BsideGlobalException extends Exception |
| 15 | { | 15 | { |
| 16 | - public function __construct($code = 0, $message = "", Throwable $previous = null) | ||
| 17 | - { | ||
| 18 | - $this->code = $code; | ||
| 19 | - $this->message = $message; | ||
| 20 | - if (empty($this->message)) { | ||
| 21 | - $this->message = Code::fromValue($code)->description; | ||
| 22 | - } | ||
| 23 | - } | 16 | +// public function __construct($code = 0, $message = "", Throwable $previous = null) |
| 17 | +// { | ||
| 18 | +// $this->code = $code; | ||
| 19 | +// $this->message = $message; | ||
| 20 | +// if (empty($this->message)) { | ||
| 21 | +// $this->message = Code::fromValue($code)->description; | ||
| 22 | +// } | ||
| 23 | +// } | ||
| 24 | } | 24 | } |
| @@ -2,17 +2,7 @@ | @@ -2,17 +2,7 @@ | ||
| 2 | 2 | ||
| 3 | namespace App\Exceptions; | 3 | namespace App\Exceptions; |
| 4 | 4 | ||
| 5 | -use App\Enums\Common\Code; | ||
| 6 | -use App\Enums\Common\Common; | ||
| 7 | -use App\Services\DingService; | ||
| 8 | -use App\Utils\EncryptUtils; | ||
| 9 | -use App\Utils\LogUtils; | ||
| 10 | -use Illuminate\Database\Eloquent\ModelNotFoundException; | ||
| 11 | use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; | 5 | use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; |
| 12 | -use Illuminate\Support\Facades\Route; | ||
| 13 | -use Illuminate\Validation\ValidationException; | ||
| 14 | -use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; | ||
| 15 | -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
| 16 | use Throwable; | 6 | use Throwable; |
| 17 | 7 | ||
| 18 | class Handler extends ExceptionHandler | 8 | class Handler extends ExceptionHandler |
| @@ -20,7 +10,7 @@ class Handler extends ExceptionHandler | @@ -20,7 +10,7 @@ class Handler extends ExceptionHandler | ||
| 20 | /** | 10 | /** |
| 21 | * A list of the exception types that are not reported. | 11 | * A list of the exception types that are not reported. |
| 22 | * | 12 | * |
| 23 | - * @var array<int, class-string<Throwable>> | 13 | + * @var array |
| 24 | */ | 14 | */ |
| 25 | protected $dontReport = [ | 15 | protected $dontReport = [ |
| 26 | // | 16 | // |
| @@ -29,123 +19,37 @@ class Handler extends ExceptionHandler | @@ -29,123 +19,37 @@ class Handler extends ExceptionHandler | ||
| 29 | /** | 19 | /** |
| 30 | * A list of the inputs that are never flashed for validation exceptions. | 20 | * A list of the inputs that are never flashed for validation exceptions. |
| 31 | * | 21 | * |
| 32 | - * @var array<int, string> | 22 | + * @var array |
| 33 | */ | 23 | */ |
| 34 | protected $dontFlash = [ | 24 | protected $dontFlash = [ |
| 35 | - 'current_password', | ||
| 36 | 'password', | 25 | 'password', |
| 37 | 'password_confirmation', | 26 | 'password_confirmation', |
| 38 | ]; | 27 | ]; |
| 39 | 28 | ||
| 40 | /** | 29 | /** |
| 41 | - * Register the exception handling callbacks for the application. | ||
| 42 | - * | ||
| 43 | - * @return void | ||
| 44 | - */ | ||
| 45 | - public function register() | ||
| 46 | - { | ||
| 47 | - $this->reportable(function (Throwable $e) { | ||
| 48 | - // | ||
| 49 | - }); | ||
| 50 | - } | ||
| 51 | - /** | ||
| 52 | * Report or log an exception. | 30 | * Report or log an exception. |
| 53 | * | 31 | * |
| 54 | - * @param \Throwable $exception | 32 | + * @param \Throwable $exception |
| 55 | * @return void | 33 | * @return void |
| 56 | * | 34 | * |
| 57 | * @throws \Throwable | 35 | * @throws \Throwable |
| 58 | */ | 36 | */ |
| 59 | public function report(Throwable $exception) | 37 | public function report(Throwable $exception) |
| 60 | { | 38 | { |
| 61 | - | ||
| 62 | - //日志记录 | ||
| 63 | - $exceptionMessage = "错误CODE:" . $exception->getCode() . | ||
| 64 | - "-----错误message:" . $exception->getMessage() . | ||
| 65 | - '------错误文件:' . $exception->getFile() . | ||
| 66 | - '-------错误行数:' . $exception->getLine(); | ||
| 67 | - //A端错误 | ||
| 68 | - if ($exception instanceof AsideGlobalException) { | ||
| 69 | - LogUtils::error("AsideGlobalException", [], $exceptionMessage); | ||
| 70 | - } | ||
| 71 | - //B端错误 | ||
| 72 | - elseif($exception instanceof BsideGlobalException) { | ||
| 73 | - LogUtils::error("BsideGlobalException", [], $exceptionMessage); | ||
| 74 | - } | ||
| 75 | - //验证错误(非手动抛出) | ||
| 76 | - elseif ($exception instanceof ValidationException) { | ||
| 77 | - LogUtils::error("参数验证失败", [], $exceptionMessage); | ||
| 78 | - } | ||
| 79 | - //Redis错误(非手动抛出) | ||
| 80 | - elseif ($exception instanceof \RedisException) { | ||
| 81 | - LogUtils::error("Redis服务异常", [], $exceptionMessage); | ||
| 82 | - } | ||
| 83 | - //Mysql错误(非手动抛出) | ||
| 84 | - elseif ($exception instanceof \PDOException) { | ||
| 85 | - LogUtils::error("数据库服务异常", [], $exceptionMessage); | ||
| 86 | - } | ||
| 87 | - //模型未找到错误(非手动抛出) | ||
| 88 | - elseif ($exception instanceof ModelNotFoundException) { | ||
| 89 | - LogUtils::error("模型资源未找到", [], $exceptionMessage); | ||
| 90 | - } | ||
| 91 | - //其他 | ||
| 92 | - else { | ||
| 93 | - LogUtils::error("全局系统异常", [], $exceptionMessage); | ||
| 94 | - } | 39 | + parent::report($exception); |
| 95 | } | 40 | } |
| 41 | + | ||
| 96 | /** | 42 | /** |
| 97 | * Render an exception into an HTTP response. | 43 | * Render an exception into an HTTP response. |
| 98 | * | 44 | * |
| 99 | - * @param \Illuminate\Http\Request $request | ||
| 100 | - * @param \Throwable $exception | 45 | + * @param \Illuminate\Http\Request $request |
| 46 | + * @param \Throwable $exception | ||
| 101 | * @return \Symfony\Component\HttpFoundation\Response | 47 | * @return \Symfony\Component\HttpFoundation\Response |
| 102 | * | 48 | * |
| 103 | * @throws \Throwable | 49 | * @throws \Throwable |
| 104 | */ | 50 | */ |
| 105 | public function render($request, Throwable $exception) | 51 | public function render($request, Throwable $exception) |
| 106 | { | 52 | { |
| 107 | - $message = $exception->getMessage(); | ||
| 108 | - | ||
| 109 | - if ($exception instanceof AsideGlobalException) { | ||
| 110 | - $code = $exception->getCode(); | ||
| 111 | - }elseif ($exception instanceof BsideGlobalException) { | ||
| 112 | - $code = $exception->getCode(); | ||
| 113 | - } elseif ($exception instanceof ValidationException) { | ||
| 114 | - $code = Code::USER_PARAMS_ERROE(); | ||
| 115 | - } elseif ($exception instanceof \RedisException) { | ||
| 116 | - $code = Code::SERVER_REDIS_ERROR(); | ||
| 117 | - } elseif ($exception instanceof \PDOException) { | ||
| 118 | - $code = Code::SERVER_MYSQL_ERROR(); | ||
| 119 | - } elseif ($exception instanceof ModelNotFoundException) { | ||
| 120 | - $code = Code::USER_MODEL_NOTFOUND_ERROE(); | ||
| 121 | - } elseif ($exception instanceof NotFoundHttpException || $exception instanceof MethodNotAllowedHttpException) { | ||
| 122 | - return response('404 Not Found', 404); | ||
| 123 | - } else { | ||
| 124 | - $code = Code::SYSTEM_ERROR(); | ||
| 125 | - } | ||
| 126 | - //钉钉通知错误信息 | ||
| 127 | - if (in_array(config('app.env'), ['test', 'production']) && (in_array(substr($code, 0, 1), ['B', 'C']))) { | ||
| 128 | - $exceptionMessage = "路由:" . Route::current()->uri . | ||
| 129 | - "-----错误CODE:" . $exception->getCode() . | ||
| 130 | - "-----错误message:" . $exception->getMessage() . | ||
| 131 | - '------错误文件:' . $exception->getFile() . '-------错误行数:' . | ||
| 132 | - $exception->getLine(); | ||
| 133 | - (new DingService())->handle(['keyword' => "ERROR", 'msg' => config('app.env') . '环境报错:' . $exceptionMessage, 'isAtAll' => false]); | ||
| 134 | - } | ||
| 135 | - //开启debug 错误原样输出 | ||
| 136 | - $debub = config('app.debug'); | ||
| 137 | - $message = $debub ? $message : ($code->description ?? $message); | ||
| 138 | - $response = [ | ||
| 139 | - 'code' => $code, | ||
| 140 | - 'message' => $message | ||
| 141 | - ]; | ||
| 142 | - //加密返回 | ||
| 143 | - if (config('app.params_encrypt')) { | ||
| 144 | - $k = config('app.params_encrypt_key'); | ||
| 145 | - $i = config('app.params_encrypt_iv'); | ||
| 146 | - $response = [ | ||
| 147 | - 'p' => (new EncryptUtils())->openssl_en($response, $k, $i)]; | ||
| 148 | - } | ||
| 149 | - return response($response); | 53 | + return parent::render($request, $exception); |
| 150 | } | 54 | } |
| 151 | } | 55 | } |
| @@ -134,7 +134,7 @@ class BaseController extends Controller | @@ -134,7 +134,7 @@ class BaseController extends Controller | ||
| 134 | ]; | 134 | ]; |
| 135 | $this->header['Content-Type'] = $type; | 135 | $this->header['Content-Type'] = $type; |
| 136 | $this->header['token'] = $this->token; | 136 | $this->header['token'] = $this->token; |
| 137 | - $response = Response::create(json_encode($result),$code,$this->header); | 137 | + $response = response($result,$result_code,$this->header);; |
| 138 | throw new HttpResponseException($response); | 138 | throw new HttpResponseException($response); |
| 139 | } | 139 | } |
| 140 | /** | 140 | /** |
| @@ -4,13 +4,12 @@ namespace App\Http\Controllers\Bside; | @@ -4,13 +4,12 @@ namespace App\Http\Controllers\Bside; | ||
| 4 | 4 | ||
| 5 | use App\Enums\Common\Code; | 5 | use App\Enums\Common\Code; |
| 6 | use App\Http\Controllers\Controller; | 6 | use App\Http\Controllers\Controller; |
| 7 | -use App\Utils\EncryptUtils; | ||
| 8 | use \Illuminate\Http\Request; | 7 | use \Illuminate\Http\Request; |
| 9 | use Illuminate\Http\Response; | 8 | use Illuminate\Http\Response; |
| 10 | use Illuminate\Http\Exceptions\HttpResponseException; | 9 | use Illuminate\Http\Exceptions\HttpResponseException; |
| 11 | use Illuminate\Support\Facades\Cache; | 10 | use Illuminate\Support\Facades\Cache; |
| 12 | 11 | ||
| 13 | -class BaseController extends Controller | 12 | +class BaseController extends Controller |
| 14 | { | 13 | { |
| 15 | protected $param = [];//所有请求参数 | 14 | protected $param = [];//所有请求参数 |
| 16 | protected $token = ''; //token | 15 | protected $token = ''; //token |
| @@ -43,39 +42,8 @@ class BaseController extends Controller | @@ -43,39 +42,8 @@ class BaseController extends Controller | ||
| 43 | */ | 42 | */ |
| 44 | public function auth_token(){ | 43 | public function auth_token(){ |
| 45 | $info = Cache::get($this->token); | 44 | $info = Cache::get($this->token); |
| 46 | - if(isset($info) && !empty($info)){ | ||
| 47 | - $this->user = $info; | ||
| 48 | - $this->uid = $info['id']; | ||
| 49 | - } | ||
| 50 | - } | ||
| 51 | - /** | ||
| 52 | - * 成功返回 | ||
| 53 | - * @param array $data | ||
| 54 | - * @param string $code | ||
| 55 | - * @param bool $objectData | ||
| 56 | - * @return JsonResponse | ||
| 57 | - * @throws \Psr\Container\ContainerExceptionInterface | ||
| 58 | - * @throws \Psr\Container\NotFoundExceptionInterface | ||
| 59 | - */ | ||
| 60 | - function success(array $data = [], string $code = Code::SUCCESS, bool $objectData = false): JsonResponse | ||
| 61 | - { | ||
| 62 | - if ($objectData) { | ||
| 63 | - $data = (object)$data; | ||
| 64 | - } | ||
| 65 | - $code = Code::fromValue($code); | ||
| 66 | - $response = [ | ||
| 67 | - 'code' => $code->value, | ||
| 68 | - 'data' => $data, | ||
| 69 | - 'msg' => $code->description, | ||
| 70 | - ]; | ||
| 71 | - //加密-返回数据 | ||
| 72 | - if (config('app.params_encrypt')) { | ||
| 73 | - $k = config('app.params_encrypt_key'); | ||
| 74 | - $i = config('app.params_encrypt_iv'); | ||
| 75 | - $response = [ | ||
| 76 | - 'p' => (new EncryptUtils())->openssl_en($response, $k, $i)]; | ||
| 77 | - } | ||
| 78 | - return response()->json($response,200,$this->header); | 45 | + $this->user = $info; |
| 46 | + $this->uid = $info['id']; | ||
| 79 | } | 47 | } |
| 80 | 48 | ||
| 81 | /** | 49 | /** |
| @@ -124,16 +92,16 @@ class BaseController extends Controller | @@ -124,16 +92,16 @@ class BaseController extends Controller | ||
| 124 | * @author :liyuhang | 92 | * @author :liyuhang |
| 125 | * @method | 93 | * @method |
| 126 | */ | 94 | */ |
| 127 | - public function response($msg,$code = 200,$data = [],$result_code = null,$type = 'application/json'){ | ||
| 128 | - $result_code === null && $result_code = $code; | 95 | + public function response($msg,$code = null,$data = [],$result_code = 200,$type = 'application/json'){ |
| 96 | + $code === null && $code = $result_code; | ||
| 129 | $result = [ | 97 | $result = [ |
| 130 | 'msg' =>$msg, | 98 | 'msg' =>$msg, |
| 131 | - 'code'=>$result_code, | 99 | + 'code'=>$code, |
| 132 | 'data'=>$data | 100 | 'data'=>$data |
| 133 | ]; | 101 | ]; |
| 134 | $this->header['Content-Type'] = $type; | 102 | $this->header['Content-Type'] = $type; |
| 135 | $this->header['token'] = $this->token; | 103 | $this->header['token'] = $this->token; |
| 136 | - $response = Response::create(json_encode($result),$code,$this->header); | 104 | + $response = response($result,$result_code,$this->header);; |
| 137 | throw new HttpResponseException($response); | 105 | throw new HttpResponseException($response); |
| 138 | } | 106 | } |
| 139 | /** | 107 | /** |
| @@ -58,7 +58,7 @@ class ComController extends BaseController | @@ -58,7 +58,7 @@ class ComController extends BaseController | ||
| 58 | $info = $projectRoleModel->read(['id'=>$this->user['role_id']]); | 58 | $info = $projectRoleModel->read(['id'=>$this->user['role_id']]); |
| 59 | $projectMenuModel = new ProjectMenuModel(); | 59 | $projectMenuModel = new ProjectMenuModel(); |
| 60 | $info['role_menu'] = trim($info['role_menu'],','); | 60 | $info['role_menu'] = trim($info['role_menu'],','); |
| 61 | - $lists = $this->where(['status'=>0])->whereIn('id',explode(',',$info['role_menu']))->get(); | 61 | + $lists = $this->where(['status'=>0,'is_role'=>0])->whereIn('id',explode(',',$info['role_menu']))->get(); |
| 62 | $lists = $lists->toArray(); | 62 | $lists = $lists->toArray(); |
| 63 | $menu = array(); | 63 | $menu = array(); |
| 64 | foreach ($lists as $k => $v){ | 64 | foreach ($lists as $k => $v){ |
| @@ -103,4 +103,24 @@ class ComController extends BaseController | @@ -103,4 +103,24 @@ class ComController extends BaseController | ||
| 103 | } | 103 | } |
| 104 | $this->response('success',Code::SUCCESS,[$info]); | 104 | $this->response('success',Code::SUCCESS,[$info]); |
| 105 | } | 105 | } |
| 106 | + | ||
| 107 | + /** | ||
| 108 | + * @name :登录用户编辑资料/修改密码 | ||
| 109 | + * @return void | ||
| 110 | + * @author :liyuhang | ||
| 111 | + * @method | ||
| 112 | + */ | ||
| 113 | + public function edit_info(){ | ||
| 114 | + | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + /** | ||
| 118 | + * @name :退出登录 | ||
| 119 | + * @return void | ||
| 120 | + * @author :liyuhang | ||
| 121 | + * @method :post | ||
| 122 | + */ | ||
| 123 | + public function logout(){ | ||
| 124 | + | ||
| 125 | + } | ||
| 106 | } | 126 | } |
| @@ -25,7 +25,6 @@ class ProjectRoleController extends BaseController | @@ -25,7 +25,6 @@ class ProjectRoleController extends BaseController | ||
| 25 | $this->allCount = $projectRoleModel->allCount; | 25 | $this->allCount = $projectRoleModel->allCount; |
| 26 | $this->result($lists); | 26 | $this->result($lists); |
| 27 | } | 27 | } |
| 28 | - | ||
| 29 | /** | 28 | /** |
| 30 | * @name :添加角色 | 29 | * @name :添加角色 |
| 31 | * @return void | 30 | * @return void |
| @@ -20,7 +20,8 @@ class UserController extends BaseController | @@ -20,7 +20,8 @@ class UserController extends BaseController | ||
| 20 | public function lists(){ | 20 | public function lists(){ |
| 21 | //TODO::搜索参数处理 | 21 | //TODO::搜索参数处理 |
| 22 | $userModel = new UserModel(); | 22 | $userModel = new UserModel(); |
| 23 | - $lists = $userModel->lists($this->map,$this->p,$this->row,$this->order,['id','name','mobile']); | 23 | + $this->map['project_id'] = $this->user['project_id']; |
| 24 | + $lists = $userModel->lists($this->map,$this->p,$this->row,$this->order,['id','name','mobile','created_at']); | ||
| 24 | if(empty($lists)){ | 25 | if(empty($lists)){ |
| 25 | $this->response('请求失败',Code::USER_ERROR,[]); | 26 | $this->response('请求失败',Code::USER_ERROR,[]); |
| 26 | } | 27 | } |
| @@ -39,6 +40,7 @@ class UserController extends BaseController | @@ -39,6 +40,7 @@ class UserController extends BaseController | ||
| 39 | 'mobile'=>'required|string|max:11', | 40 | 'mobile'=>'required|string|max:11', |
| 40 | 'password'=>'required|string|min:5', | 41 | 'password'=>'required|string|min:5', |
| 41 | 'name'=>'required|max:20', | 42 | 'name'=>'required|max:20', |
| 43 | + 'role_id'=>'required' | ||
| 42 | ]; | 44 | ]; |
| 43 | //验证的提示信息 | 45 | //验证的提示信息 |
| 44 | $message = [ | 46 | $message = [ |
| @@ -50,13 +52,15 @@ class UserController extends BaseController | @@ -50,13 +52,15 @@ class UserController extends BaseController | ||
| 50 | 'password.min' => '密码不小于5字符.', | 52 | 'password.min' => '密码不小于5字符.', |
| 51 | 'name.required'=>'名称必须填写', | 53 | 'name.required'=>'名称必须填写', |
| 52 | 'name.min' => '名称不小于5字符.', | 54 | 'name.min' => '名称不小于5字符.', |
| 55 | + 'role_id.required'=>'角色必须填写', | ||
| 53 | ]; | 56 | ]; |
| 54 | $validate = Validator::make($this->param, $rules, $message); | 57 | $validate = Validator::make($this->param, $rules, $message); |
| 55 | if($validate->fails()){ | 58 | if($validate->fails()){ |
| 56 | return $this->response($validate->errors()->first(),Code::USER_LOGIN_ERROE,$this->param); | 59 | return $this->response($validate->errors()->first(),Code::USER_LOGIN_ERROE,$this->param); |
| 57 | } | 60 | } |
| 58 | - $userLogic = new UserLogic(); | ||
| 59 | - $rs = $userLogic->add($this->param); | 61 | + $userModel = new UserModel(); |
| 62 | + $this->param['project_id'] = $this->user['project_id']; | ||
| 63 | + $rs = $userModel->adds($this->param); | ||
| 60 | if($rs === false){ | 64 | if($rs === false){ |
| 61 | $this->response('当前添加用户已存在或参数错误,添加失败',Code::USER_REGISTER_ERROE,[]); | 65 | $this->response('当前添加用户已存在或参数错误,添加失败',Code::USER_REGISTER_ERROE,[]); |
| 62 | } | 66 | } |
| @@ -92,8 +96,14 @@ class UserController extends BaseController | @@ -92,8 +96,14 @@ class UserController extends BaseController | ||
| 92 | if($validate->fails()){ | 96 | if($validate->fails()){ |
| 93 | return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param); | 97 | return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param); |
| 94 | } | 98 | } |
| 95 | - $userLogic = new UserLogic(); | ||
| 96 | - $rs = $userLogic->edits($this->param); | 99 | + $userModel = new UserModel(); |
| 100 | + //TODO::查询当前手机号码是否重复 | ||
| 101 | + $info = $userModel->where('id','<>',$this->param['id']) | ||
| 102 | + ->where(['mobile'=>$this->param['mobile']])->first(); | ||
| 103 | + if(!empty($info)){ | ||
| 104 | + $this->response('当前编辑的手机号码已存在',Code::USER_PARAMS_ERROE); | ||
| 105 | + } | ||
| 106 | + $rs = $userModel->edits($this->param); | ||
| 97 | if($rs === false){ | 107 | if($rs === false){ |
| 98 | $this->response('参数错误或其他服务器原因,编辑失败',Code::USER_ERROR,[]); | 108 | $this->response('参数错误或其他服务器原因,编辑失败',Code::USER_ERROR,[]); |
| 99 | } | 109 | } |
| @@ -2,9 +2,14 @@ | @@ -2,9 +2,14 @@ | ||
| 2 | 2 | ||
| 3 | namespace App\Http\Middleware\Bside; | 3 | namespace App\Http\Middleware\Bside; |
| 4 | 4 | ||
| 5 | +use App\Enums\Common\Code; | ||
| 6 | +use App\Models\ProjectMenu; | ||
| 7 | +use App\Models\ProjectRole as ProjectRoleModel; | ||
| 5 | use Closure; | 8 | use Closure; |
| 6 | use Illuminate\Http\Request; | 9 | use Illuminate\Http\Request; |
| 7 | - | 10 | +use Illuminate\Http\Response; |
| 11 | +use Illuminate\Support\Facades\Cache; | ||
| 12 | +use Illuminate\Http\Exceptions\HttpResponseException; | ||
| 8 | class LoginAuthMiddleware | 13 | class LoginAuthMiddleware |
| 9 | { | 14 | { |
| 10 | /** | 15 | /** |
| @@ -16,6 +21,44 @@ class LoginAuthMiddleware | @@ -16,6 +21,44 @@ class LoginAuthMiddleware | ||
| 16 | */ | 21 | */ |
| 17 | public function handle(Request $request, Closure $next) | 22 | public function handle(Request $request, Closure $next) |
| 18 | { | 23 | { |
| 24 | + $token = $request->header('token'); | ||
| 25 | + if(!isset($token) || empty($token)){ | ||
| 26 | + $this->response('当前用户未登录',Code::USER_ERROR); | ||
| 27 | + } | ||
| 28 | + $info = Cache::get($request->header('token')); | ||
| 29 | + if(empty($info)){ | ||
| 30 | + $this->response('当前用户未登录',Code::USER_ERROR); | ||
| 31 | + } | ||
| 32 | + //操作权限设置 | ||
| 33 | + $projectRoleModel = new ProjectRoleModel(); | ||
| 34 | + $role_info = $projectRoleModel->read(['id'=>$info['role_id']]); | ||
| 35 | + //获取当前操作的控制器与方法 | ||
| 36 | + $action = $request->route()->getAction(); | ||
| 37 | + //查询当前用户是否拥有权限操作 | ||
| 38 | + $projectMenuModel = new ProjectMenu(); | ||
| 39 | + $menu_id = $projectMenuModel->read(['action'=>$action['as']],['id']); | ||
| 40 | + | ||
| 41 | + if(strpos($role_info['role_menu'], $menu_id['id']) < 0){ | ||
| 42 | + $this->response('当前用户没有权限',Code::USER_ERROR); | ||
| 43 | + } | ||
| 19 | return $next($request); | 44 | return $next($request); |
| 20 | } | 45 | } |
| 46 | + /** | ||
| 47 | + * @name 统一返回参数 | ||
| 48 | + * @return void | ||
| 49 | + * @author :liyuhang | ||
| 50 | + * @method | ||
| 51 | + */ | ||
| 52 | + public function response($msg,$code,$data = [],$result_code = 200,$type = 'application/json'){ | ||
| 53 | + $code === null && $code = $result_code; | ||
| 54 | + $result = [ | ||
| 55 | + 'msg' =>$msg, | ||
| 56 | + 'code'=>$code, | ||
| 57 | + 'data'=>$data | ||
| 58 | + ]; | ||
| 59 | + $header['token'] = $type; | ||
| 60 | + $response = response($result,$result_code,$header); | ||
| 61 | + throw new HttpResponseException($response); | ||
| 62 | + } | ||
| 63 | + | ||
| 21 | } | 64 | } |
| @@ -9,6 +9,8 @@ class Base extends Model | @@ -9,6 +9,8 @@ class Base extends Model | ||
| 9 | { | 9 | { |
| 10 | protected $table = ''; | 10 | protected $table = ''; |
| 11 | public $allCount = 0; | 11 | public $allCount = 0; |
| 12 | + //自动维护create_at创建时间 updated_at修改时间 | ||
| 13 | + public $timestamps = true; | ||
| 12 | //统一设置 | 14 | //统一设置 |
| 13 | protected $casts = [ | 15 | protected $casts = [ |
| 14 | 'created_at' => 'datetime:Y-m-d H:i:s', | 16 | 'created_at' => 'datetime:Y-m-d H:i:s', |
| @@ -74,6 +76,8 @@ class Base extends Model | @@ -74,6 +76,8 @@ class Base extends Model | ||
| 74 | * @method post | 76 | * @method post |
| 75 | */ | 77 | */ |
| 76 | public function add($data){ | 78 | public function add($data){ |
| 79 | + $data['created_at'] = date('Y-m-d H:i:s'); | ||
| 80 | + $data['updated_at'] = date('Y-m-d H:i:s'); | ||
| 77 | return $this->insert($data); | 81 | return $this->insert($data); |
| 78 | } | 82 | } |
| 79 | 83 | ||
| @@ -84,9 +88,7 @@ class Base extends Model | @@ -84,9 +88,7 @@ class Base extends Model | ||
| 84 | * @method post | 88 | * @method post |
| 85 | */ | 89 | */ |
| 86 | public function edit($data,$condition){ | 90 | public function edit($data,$condition){ |
| 87 | - if(isset($data['id']) && !empty($data['id'])){ | ||
| 88 | - unset($data['id']); | ||
| 89 | - } | 91 | + $data['updated_at'] = date('Y-m-d H:i:s'); |
| 90 | return $this->where($condition)->update($data); | 92 | return $this->where($condition)->update($data); |
| 91 | } | 93 | } |
| 92 | 94 |
| @@ -4,6 +4,7 @@ namespace App\Models; | @@ -4,6 +4,7 @@ namespace App\Models; | ||
| 4 | 4 | ||
| 5 | //use Illuminate\Contracts\Auth\MustVerifyEmail; | 5 | //use Illuminate\Contracts\Auth\MustVerifyEmail; |
| 6 | use App\Models\ProjectRole as ProjectRoleModel; | 6 | use App\Models\ProjectRole as ProjectRoleModel; |
| 7 | +use App\Models\User as UserModel; | ||
| 7 | use Illuminate\Database\Eloquent\Factories\HasFactory; | 8 | use Illuminate\Database\Eloquent\Factories\HasFactory; |
| 8 | use Illuminate\Database\Eloquent\Model; | 9 | use Illuminate\Database\Eloquent\Model; |
| 9 | //use Illuminate\Foundation\Auth\User as Authenticatable; | 10 | //use Illuminate\Foundation\Auth\User as Authenticatable; |
| @@ -16,7 +17,8 @@ class User extends Base | @@ -16,7 +17,8 @@ class User extends Base | ||
| 16 | use HasApiTokens, HasFactory, Notifiable; | 17 | use HasApiTokens, HasFactory, Notifiable; |
| 17 | 18 | ||
| 18 | protected $table = 'gl_project_user'; | 19 | protected $table = 'gl_project_user'; |
| 19 | - | 20 | + //自动维护create_at创建时间 updated_at修改时间 |
| 21 | + public $timestamps = true; | ||
| 20 | /** | 22 | /** |
| 21 | * The attributes that are mass assignable. | 23 | * The attributes that are mass assignable. |
| 22 | * | 24 | * |
| @@ -34,7 +36,7 @@ class User extends Base | @@ -34,7 +36,7 @@ class User extends Base | ||
| 34 | * @var array<int, string> | 36 | * @var array<int, string> |
| 35 | */ | 37 | */ |
| 36 | protected $hidden = [ | 38 | protected $hidden = [ |
| 37 | - 'password', | 39 | +// 'password', |
| 38 | 'remember_token', | 40 | 'remember_token', |
| 39 | ]; | 41 | ]; |
| 40 | 42 | ||
| @@ -88,4 +90,44 @@ class User extends Base | @@ -88,4 +90,44 @@ class User extends Base | ||
| 88 | } | 90 | } |
| 89 | return $info; | 91 | return $info; |
| 90 | } | 92 | } |
| 93 | + | ||
| 94 | + //新增用户 | ||
| 95 | + public function adds($param){ | ||
| 96 | + //验证当前用户是否存在 | ||
| 97 | + $info = $this->read(['mobile'=>$param['mobile']]); | ||
| 98 | + if(!empty($info)){ | ||
| 99 | + return false; | ||
| 100 | + } | ||
| 101 | + //密码加密 | ||
| 102 | + $param['password'] = base64_encode(md5($param['password'])); | ||
| 103 | + $rs = $this->add($param); | ||
| 104 | + if($rs === false){ | ||
| 105 | + return false; | ||
| 106 | + } | ||
| 107 | + return true; | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + /** | ||
| 111 | + * @param $param | ||
| 112 | + * @name :编辑管理员 | ||
| 113 | + * @return bool | ||
| 114 | + * @author :liyuhang | ||
| 115 | + * @method | ||
| 116 | + */ | ||
| 117 | + public function edits($param){ | ||
| 118 | + //查看密码是否修改 | ||
| 119 | + $info = $this->read(['id'=>$param['id']]); | ||
| 120 | + if($param['password'] == $info['password']){ | ||
| 121 | + unset($param['password']); | ||
| 122 | + } | ||
| 123 | + //密码加密 | ||
| 124 | + $param['password'] = base64_encode(md5($param['password'])); | ||
| 125 | + $rs = $this->edit($param,['id'=>$param['id']]); | ||
| 126 | + if($rs === false){ | ||
| 127 | + return false; | ||
| 128 | + } | ||
| 129 | + //清空当前用户登录缓存 | ||
| 130 | + Cache::pull($info['token']); | ||
| 131 | + return true; | ||
| 132 | + } | ||
| 91 | } | 133 | } |
| @@ -8,7 +8,6 @@ namespace App\Services; | @@ -8,7 +8,6 @@ namespace App\Services; | ||
| 8 | 8 | ||
| 9 | use App\Enums\Common\Code; | 9 | use App\Enums\Common\Code; |
| 10 | use App\Exceptions\BsideGlobalException; | 10 | use App\Exceptions\BsideGlobalException; |
| 11 | -use App\Traits\RedisTrait; | ||
| 12 | 11 | ||
| 13 | class BaseService | 12 | class BaseService |
| 14 | { | 13 | { |
| @@ -7,6 +7,7 @@ use \Illuminate\Support\Facades\Route; | @@ -7,6 +7,7 @@ use \Illuminate\Support\Facades\Route; | ||
| 7 | //必须登录验证的路由组 | 7 | //必须登录验证的路由组 |
| 8 | Route::middleware(['bloginauth'])->group(function () { | 8 | Route::middleware(['bloginauth'])->group(function () { |
| 9 | 9 | ||
| 10 | + Route::any('/user/status', [\App\Http\Controllers\Bside\UserController::class, 'status'])->name('user_status'); | ||
| 10 | }); | 11 | }); |
| 11 | 12 | ||
| 12 | //无需登录验证的路由组 | 13 | //无需登录验证的路由组 |
| @@ -17,7 +18,7 @@ Route::group([], function () { | @@ -17,7 +18,7 @@ Route::group([], function () { | ||
| 17 | //用户相关路由 | 18 | //用户相关路由 |
| 18 | Route::any('/user/add', [\App\Http\Controllers\Bside\UserController::class, 'add'])->name('user_add'); | 19 | Route::any('/user/add', [\App\Http\Controllers\Bside\UserController::class, 'add'])->name('user_add'); |
| 19 | Route::any('/user/edit', [\App\Http\Controllers\Bside\UserController::class, 'edit'])->name('user_edit'); | 20 | Route::any('/user/edit', [\App\Http\Controllers\Bside\UserController::class, 'edit'])->name('user_edit'); |
| 20 | - Route::any('/user/status', [\App\Http\Controllers\Bside\UserController::class, 'status'])->name('user_status'); | 21 | + |
| 21 | Route::any('/user/lists', [\App\Http\Controllers\Bside\UserController::class, 'lists'])->name('user_lists'); | 22 | Route::any('/user/lists', [\App\Http\Controllers\Bside\UserController::class, 'lists'])->name('user_lists'); |
| 22 | Route::any('/user/del', [\App\Http\Controllers\Bside\UserController::class, 'del'])->name('user_del'); | 23 | Route::any('/user/del', [\App\Http\Controllers\Bside\UserController::class, 'del'])->name('user_del'); |
| 23 | //用户角色相关路由 | 24 | //用户角色相关路由 |
-
请 注册 或 登录 后发表评论