1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- declare (strict_types = 1);
- namespace app\txx\controller;
- use app\BaseController;use think\App;
- use think\exception\HttpResponseException;
- use think\Response;
- class Base extends BaseController
- {
- public $white=[];
- protected $uid=0;
- protected $uname='';
- public function __construct(App $app) {
- parent::__construct($app);
- }
-
- /**
- * @param string $message
- * @param int $code
- * @param null $data
- */
- public function error($message='',$code=1003,$data=null){
- $this->result($message,$data,$code);
- }
- /**
- * @param string $message
- * @param int $code
- * @param null $data
- */
- public function success($message='',$data=null,$code=0){
- $this->result($message,$data,$code);
- }
-
- /**
- * @param string $msg
- * @param null $data
- * @param int $code
- * @param string|null $type
- * @param array $header
- * @param array $options
- */
- private function result(string $msg, $data = null, int $code = 0, string $type = 'json', array $header = [], array
- $options = [])
- {
- $result = [
- 'code' => $code,
- 'message' => $msg,
- 'data' => $data,
- ];
- $code = 200;
- if (isset($header['statuscode'])) {
- $code = $header['statuscode'];
- unset($header['statuscode']);
- }
- $response = Response::create($result, $type, $code)->header($header)->options($options);
- throw new HttpResponseException($response);
- }
- }
|