12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?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 \app\admin\controller\Base
- {
- public $white=[];
- 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);
- }
- }
|