|
...
|
...
|
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Bside; |
|
|
|
|
|
|
|
use App\Enums\Common\Code;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Utils\EncryptUtils;
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
|
...
|
...
|
@@ -46,6 +47,28 @@ class BaseController extends Controller |
|
|
|
$this->uid = $info['id'];
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* 成功返回
|
|
|
|
* @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
|
|
|
|
{
|
|
|
|
if ($objectData) {
|
|
|
|
$data = (object)$data;
|
|
|
|
}
|
|
|
|
$code = Code::fromValue($code);
|
|
|
|
$response = [
|
|
|
|
'code' => $code->value,
|
|
|
|
'data' => $data,
|
|
|
|
'msg' => $code->description,
|
|
|
|
];
|
|
|
|
return response()->json($response,200,$this->header);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @name 参数过滤
|
|
|
|
* @return void
|
|
|
|
* @author :liyuhang
|
|
...
|
...
|
@@ -91,10 +114,10 @@ class BaseController extends Controller |
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function response($msg,string $code = Code::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'){
|
|
|
|
public function response($msg = null,string $code = Code::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'){
|
|
|
|
$code = Code::fromValue($code);
|
|
|
|
$result = [
|
|
|
|
'msg' => $msg == null ? $msg : $code->description,
|
|
|
|
'msg' => $msg == ' ' ? $msg : $code->description,
|
|
|
|
'code' => $code->value,
|
|
|
|
'data' => $data,
|
|
|
|
];
|
|
...
|
...
|
@@ -103,29 +126,9 @@ class BaseController extends Controller |
|
|
|
$response = response($result,$result_code,$this->header);;
|
|
|
|
throw new HttpResponseException($response);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* 方法请求输出数据(带分页参数)
|
|
|
|
* @param $data
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
protected function result($lists) {
|
|
|
|
$data['data'] = $lists;
|
|
|
|
$data['page'] = $this->setPages();
|
|
|
|
$this->response('success', 200, $data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 设置分页返回参数()
|
|
|
|
*/
|
|
|
|
protected function setPages() {
|
|
|
|
$page_count = $this->allCount > $this->row ? ceil($this->allCount / $this->row) : 1;
|
|
|
|
$this->header['Total-Count'] = $this->allCount; //总条数
|
|
|
|
$this->header['Page-Count'] = $page_count; //总页数
|
|
|
|
$this->header['Current-Page'] = $this->p; //当前页数
|
|
|
|
$this->header['Per-Page'] = $this->row; //每页条数
|
|
|
|
return $this->header;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name :上传图片
|
...
|
...
|
|