|
...
|
...
|
@@ -7,6 +7,7 @@ use App\Http\Controllers\Controller; |
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
use Illuminate\Support\Facades\Session;
|
|
|
|
|
|
|
|
class BaseController extends Controller
|
|
...
|
...
|
@@ -14,7 +15,6 @@ class BaseController extends Controller |
|
|
|
protected $param = [];//所有请求参数
|
|
|
|
protected $token = ''; //token
|
|
|
|
protected $request = [];//助手函数
|
|
|
|
protected $allCount = 0;//总条数
|
|
|
|
protected $page = 1;//当前页
|
|
|
|
protected $row = 20;//每页条数
|
|
|
|
protected $header = [];//设置请求头参数
|
|
...
|
...
|
@@ -22,7 +22,6 @@ class BaseController extends Controller |
|
|
|
protected $map = [];//处理后的参数
|
|
|
|
protected $uid = 0;
|
|
|
|
protected $user = [];//当前登录用户详情
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取所有参数
|
|
|
|
*/
|
|
...
|
...
|
@@ -30,24 +29,24 @@ class BaseController extends Controller |
|
|
|
{
|
|
|
|
$this->request = $request;
|
|
|
|
$this->param = $this->request->all();
|
|
|
|
$this->token = $this->request->header('token');
|
|
|
|
if(!empty($this->token) && !empty(Cache::get($this->token))){
|
|
|
|
$info = Cache::get($this->token);
|
|
|
|
$this->user = $info;
|
|
|
|
$this->uid = $info['id'];
|
|
|
|
}else{
|
|
|
|
return response(['code'=>Code::USER_ERROR,'msg'=>'当前用户未登录']);
|
|
|
|
}
|
|
|
|
$this->get_param();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
* @author zbj
|
|
|
|
* @date 2023/4/19
|
|
|
|
*/
|
|
|
|
public function manage(){
|
|
|
|
return Session::get('manage');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 成功返回
|
|
|
|
* @param array $data
|
|
|
|
* @param string $code
|
|
|
|
* @param bool $objectData
|
|
|
|
* @return JsonResponse
|
|
|
|
* @throws \Psr\Container\ContainerExceptionInterface
|
|
|
|
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
|
|
*/
|
|
|
|
function success(array $data = [], string $code = Code::SUCCESS, bool $objectData = false): JsonResponse
|
|
|
|
{
|
|
...
|
...
|
@@ -60,6 +59,7 @@ class BaseController extends Controller |
|
|
|
'data' => $data,
|
|
|
|
'msg' => $code->description,
|
|
|
|
];
|
|
|
|
$this->header['token'] = $this->token;
|
|
|
|
return response()->json($response,200,$this->header);
|
|
|
|
}
|
|
|
|
/**
|
|
...
|
...
|
@@ -116,11 +116,53 @@ class BaseController extends Controller |
|
|
|
$result = [
|
|
|
|
'msg' => $msg == ' ' ? $code->description : $msg,
|
|
|
|
'code' => $code->value,
|
|
|
|
'data' => $data,
|
|
|
|
'data' => $this->_extents($data),
|
|
|
|
];
|
|
|
|
$this->header['Content-Type'] = $type;
|
|
|
|
$this->header['token'] = $this->token;
|
|
|
|
$response = response($result,$result_code,$this->header);;
|
|
|
|
throw new HttpResponseException($response);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 菜单权限->得到子级数组
|
|
|
|
* @param int
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function _get_child($my_id, $arr)
|
|
|
|
{
|
|
|
|
$new_arr = array();
|
|
|
|
foreach ($arr as $k => $v) {
|
|
|
|
$v = (array)$v;
|
|
|
|
if ($v['pid'] == $my_id) {
|
|
|
|
$v['sub'] = $this->_get_child($v['id'],$arr);
|
|
|
|
$new_arr[] = $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $new_arr ? $new_arr : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function _extents($data) {
|
|
|
|
|
|
|
|
if (empty($data) || !is_array($data)) {
|
|
|
|
return empty($data) ? is_array($data) ? [] : '' : $data;
|
|
|
|
}
|
|
|
|
foreach ($data as $k => $v) {
|
|
|
|
if (is_array($v)) {
|
|
|
|
$data[$k] = $this->_extents($v);
|
|
|
|
} else {
|
|
|
|
if (is_null($v)) {
|
|
|
|
$data[$k] = '';
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch ((string) $k) {
|
|
|
|
case 'image':
|
|
|
|
$v['image_link'] = file_get_contents($v);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|