app = $app; $this->request = $this->app->request; } /** * 返回JSON响应 * @param mixed $data 数据 * @param int $code 状态码 * @param string $msg 消息 * @return \think\Response */ protected function json($data = [], $code = 0, $msg = 'success') { return json([ 'code' => $code, 'msg' => $msg, 'data' => $data ]); } /** * 返回成功响应 * @param mixed $data 数据 * @param string $msg 消息 * @return \think\Response */ protected function success($data = [], $msg = 'success') { return $this->json($data, 0, $msg); } /** * 返回错误响应 * @param string $msg 错误消息 * @param int $code 错误码 * @param mixed $data 数据 * @return \think\Response */ protected function error($msg = 'error', $code = 1, $data = []) { return $this->json($data, $code, $msg); } }