正在显示
1 个修改的文件
包含
26 行增加
和
23 行删除
| @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Bside; | @@ -4,6 +4,7 @@ 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; | ||
| 7 | use Illuminate\Http\JsonResponse; | 8 | use Illuminate\Http\JsonResponse; |
| 8 | use Illuminate\Http\Request; | 9 | use Illuminate\Http\Request; |
| 9 | use Illuminate\Http\Exceptions\HttpResponseException; | 10 | use Illuminate\Http\Exceptions\HttpResponseException; |
| @@ -46,6 +47,28 @@ class BaseController extends Controller | @@ -46,6 +47,28 @@ class BaseController extends Controller | ||
| 46 | $this->uid = $info['id']; | 47 | $this->uid = $info['id']; |
| 47 | } | 48 | } |
| 48 | /** | 49 | /** |
| 50 | + * 成功返回 | ||
| 51 | + * @param array $data | ||
| 52 | + * @param string $code | ||
| 53 | + * @param bool $objectData | ||
| 54 | + * @return JsonResponse | ||
| 55 | + * @throws \Psr\Container\ContainerExceptionInterface | ||
| 56 | + * @throws \Psr\Container\NotFoundExceptionInterface | ||
| 57 | + */ | ||
| 58 | + function success(array $data = [], string $code = Code::SUCCESS, bool $objectData = false): JsonResponse | ||
| 59 | + { | ||
| 60 | + if ($objectData) { | ||
| 61 | + $data = (object)$data; | ||
| 62 | + } | ||
| 63 | + $code = Code::fromValue($code); | ||
| 64 | + $response = [ | ||
| 65 | + 'code' => $code->value, | ||
| 66 | + 'data' => $data, | ||
| 67 | + 'msg' => $code->description, | ||
| 68 | + ]; | ||
| 69 | + return response()->json($response,200,$this->header); | ||
| 70 | + } | ||
| 71 | + /** | ||
| 49 | * @name 参数过滤 | 72 | * @name 参数过滤 |
| 50 | * @return void | 73 | * @return void |
| 51 | * @author :liyuhang | 74 | * @author :liyuhang |
| @@ -91,10 +114,10 @@ class BaseController extends Controller | @@ -91,10 +114,10 @@ class BaseController extends Controller | ||
| 91 | * @author :liyuhang | 114 | * @author :liyuhang |
| 92 | * @method | 115 | * @method |
| 93 | */ | 116 | */ |
| 94 | - public function response($msg,string $code = Code::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'){ | 117 | + public function response($msg = null,string $code = Code::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'){ |
| 95 | $code = Code::fromValue($code); | 118 | $code = Code::fromValue($code); |
| 96 | $result = [ | 119 | $result = [ |
| 97 | - 'msg' => $msg == null ? $msg : $code->description, | 120 | + 'msg' => $msg == ' ' ? $msg : $code->description, |
| 98 | 'code' => $code->value, | 121 | 'code' => $code->value, |
| 99 | 'data' => $data, | 122 | 'data' => $data, |
| 100 | ]; | 123 | ]; |
| @@ -103,29 +126,9 @@ class BaseController extends Controller | @@ -103,29 +126,9 @@ class BaseController extends Controller | ||
| 103 | $response = response($result,$result_code,$this->header);; | 126 | $response = response($result,$result_code,$this->header);; |
| 104 | throw new HttpResponseException($response); | 127 | throw new HttpResponseException($response); |
| 105 | } | 128 | } |
| 106 | - /** | ||
| 107 | - * 方法请求输出数据(带分页参数) | ||
| 108 | - * @param $data | ||
| 109 | - * @return | ||
| 110 | - */ | ||
| 111 | - protected function result($lists) { | ||
| 112 | - $data['data'] = $lists; | ||
| 113 | - $data['page'] = $this->setPages(); | ||
| 114 | - $this->response('success', 200, $data); | ||
| 115 | 129 | ||
| 116 | - } | ||
| 117 | 130 | ||
| 118 | - /** | ||
| 119 | - * 设置分页返回参数() | ||
| 120 | - */ | ||
| 121 | - protected function setPages() { | ||
| 122 | - $page_count = $this->allCount > $this->row ? ceil($this->allCount / $this->row) : 1; | ||
| 123 | - $this->header['Total-Count'] = $this->allCount; //总条数 | ||
| 124 | - $this->header['Page-Count'] = $page_count; //总页数 | ||
| 125 | - $this->header['Current-Page'] = $this->p; //当前页数 | ||
| 126 | - $this->header['Per-Page'] = $this->row; //每页条数 | ||
| 127 | - return $this->header; | ||
| 128 | - } | 131 | + |
| 129 | 132 | ||
| 130 | /** | 133 | /** |
| 131 | * @name :上传图片 | 134 | * @name :上传图片 |
-
请 注册 或 登录 后发表评论