123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- namespace app\common\controller;
- use app\common\model\User;
- use think\exception\HttpResponseException;
- use think\facade\Request;
- use think\Response;
- class Api
- {
-
- protected $request;
-
- protected $failException = true;
-
- protected $responseType = 'json';
-
- protected function success($msg = '', $data = null , $is_login = 1, $code = 1, $type = null, array $header = [])
- {
- $this->result($msg, $data, $is_login, $code, $type, $header);
- }
-
- protected function error($msg = '', $data = null, $is_login = 1, $code = 0, $type = null, array $header = [])
- {
- $this->result($msg, $data, $is_login, $code, $type, $header);
- }
-
- protected function result($msg, $data = null, $is_login, $code = 0, $type = null, array $header = [])
- {
- $result = [
- 'code' => $code,
- 'is_login' => $is_login,
- 'msg' => $msg,
- 'time' => Request::instance()->server('REQUEST_TIME'),
- 'data' => $data,
- ];
-
- $type = $type ? $type : 'json';
- if (isset($header['statuscode']))
- {
- $code = $header['statuscode'];
- unset($header['statuscode']);
- }
- else
- {
-
- $code = $code >= 1000 || $code < 200 ? 200 : $code;
- }
- $response = Response::create($result, $type, $code)->header($header);
- throw new HttpResponseException($response);
- }
-
- protected function check_login(){
- $user = app()->session->get('us');
- if (!$user){
- $this->error('请先登录','',0);
- }
- $userinfo = User::where('id',$user['id'])->find();
- if ($userinfo['status']!=1){
- app()->session->clear();
- app()->session->destroy();
- $this->error('账号被禁用','',0);
- }
- return true;
- }
- }
|