Controller.php
1.58 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesResources;
class Controller extends BaseController
{
use AuthorizesRequests, AuthorizesResources, DispatchesJobs, ValidatesRequests;
protected $data;
protected function errhtml($errCode, $errInfo, $goUrl = '')
{
$data = [
'errcode' => $errCode,
'errinfo' => $errInfo,
'url' => $goUrl
];
return view('errors.error', $data);
}
protected function view($title = '')
{
$this->data['title'] = $title;
$view =request('view', 'web');
return view($view, $this->data);
}
//通用json返回方法
public function response($errCode = 0, $errMsg = '成功', $data = '', $count = 0)
{
if (is_array($errCode)) {
echo json_encode([
'code' => $errCode[0],
'err_code' => $errCode[0],
'err_msg' => $errCode[1],
'data' => !empty($errCode[2]) ? $errCode[2] : '',
'count' => $count,
]);
exit();
} else {
echo json_encode([
'err_code' => $errCode,
'code' => $errCode,
'err_msg' => $errMsg,
'data' => $data,
'count' => $count,
]);
exit();
}
}
}