BaseController.php
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace App\Http\Controllers\Cside;
use App\Http\Controllers\Controller;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Http\JsonResponse;
class BaseController extends Controller
{
const SUCCESS = 200;
const ERROR = 400;
protected $param = [];//所有请求参数
protected $token = ''; //token
protected $request = [];//助手函数
protected $page = 1;//当前页
protected $row = 20;//每页条数
protected $header = [];//设置请求头参数
protected $order = 'id';
protected $map = [];//处理后的参数
protected $uid = 0;
protected $user = [];//当前登录用户详情
public function __construct(){
}
/**
* 响应
* @throws HttpResponseException
*/
public function response($msg = null,string $code = self::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'): JsonResponse
{
$result = [
'msg' => $msg,
'code' => $code,
'data' => $data,
];
$this->header['Content-Type'] = $type;
$this->header['token'] = $this->token;
$response = response($result,$result_code,$this->header);
throw new HttpResponseException($response);
}
}