作者 Your Name

gx

... ... @@ -110,14 +110,6 @@ class Handler extends ExceptionHandler
$code = $exception->getCode();
}elseif ($exception instanceof BsideGlobalException) {
$code = $exception->getCode();
} elseif ($exception instanceof ValidationException) {
$code = Code::USER_PARAMS_ERROE();
} elseif ($exception instanceof \RedisException) {
$code = Code::SERVER_REDIS_ERROR();
} elseif ($exception instanceof \PDOException) {
$code = Code::SERVER_MYSQL_ERROR();
} elseif ($exception instanceof ModelNotFoundException) {
$code = Code::USER_MODEL_NOTFOUND_ERROE();
} elseif ($exception instanceof NotFoundHttpException || $exception instanceof MethodNotAllowedHttpException) {
return response('404 Not Found', 404);
} else {
... ...
... ... @@ -31,25 +31,12 @@ class BaseController extends Controller
$this->request = $request;
$this->param = $this->request->all();
$this->token = $this->request->header('token');
$this->get_param();
$this->auth_token();
}
/**
* @name
* @return void
* @author :liyuhang
* @method
*/
public function auth_token(){
$info = Cache::get($this->token);
if(!empty($info)){
if(!empty($this->token) && !empty(Cache::get($this->token))){
$info = Cache::get($this->token);
$this->user = $info;
$this->uid = $info['id'];
}else{
$this->response('当前用户未登录',Code::USER_ERROR);
}
$this->get_param();
}
/**
* 成功返回
... ...
... ... @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Bside;
use App\Enums\Common\Code;
use App\Http\Logic\Bside\UserLogic;
use App\Models\User as UserModel;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Validator;
use Symfony\Component\HttpFoundation;
... ... @@ -25,8 +26,7 @@ class UserController extends BaseController
if(empty($lists)){
$this->response('请求失败',Code::USER_ERROR,[]);
}
$this->allCount = $userModel->allCount;
$this->result($lists);
$this->response('列表',Code::SUCCESS,$lists);
}
/**
... ...
... ... @@ -23,11 +23,15 @@ class LoginAuthMiddleware
{
$token = $request->header('token');
if(!isset($token) || empty($token)){
$this->response('当前用户未登录',Code::USER_ERROR);
$res = [
'code'=>'A00010',
'msg' =>'当前用户未登录'
];
return response(['code'=>Code::USER_ERROR,'msg'=>'当前用户未登录']);
}
$info = Cache::get($token);
if(empty($info)){
$this->response('当前用户未登录',Code::USER_ERROR);
return response(['code'=>Code::USER_ERROR,'msg'=>'当前用户未登录']);
}
//操作权限设置
$projectRoleModel = new ProjectRoleModel();
... ... @@ -39,27 +43,10 @@ class LoginAuthMiddleware
$menu_id = $projectMenuModel->read(['action'=>$action['as']],['id']);
if($menu_id !== false){
if(strpos($role_info['role_menu'], $menu_id['id']) < 0){
$this->response('当前用户没有权限',Code::USER_ERROR);
return response(['code'=>Code::USER_ERROR,'msg'=>'当前用户没有权限']);
}
}
return $next($request);
}
/**
* @name 统一返回参数
* @return void
* @author :liyuhang
* @method
*/
public function response($msg,$code,$data = [],$result_code = 200,$type = 'application/json'){
$code === null && $code = $result_code;
$result = [
'msg' =>$msg,
'code'=>$code,
'data'=>$data
];
$header['token'] = $type;
$response = response($result,$result_code,$header);
throw new HttpResponseException($response);
}
}
... ...
... ... @@ -37,7 +37,7 @@ class Base extends Model
*/
public function lists($map, $p, $row, $order = 'id', $fields = ['*']){
//TODO::where(['id'=>'','name'=>''])
$lists = $this->select($fields)->where($map)->forPage($p,$row)->orderBy($order)->get();
$lists = DB::table($this->table)->select($fields)->where($map)->orderBy($order)->paginate($row, ['*'], 'page', $p);
if (empty($lists)) {
return false;
}
... ...
... ... @@ -14,5 +14,5 @@ use Illuminate\Support\Facades\Route;
*/
Route::get('/', function () {
return view('welcome');
// return view('welcome');
});
... ...