From ef9fc48b44d4f3352c819e4b920d1ae1263bb02a Mon Sep 17 00:00:00 2001 From: "453530270@qq.com" Date: Sun, 6 Oct 2024 20:56:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=9F=BA=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/ApiController.php | 67 ++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 app/api/controller/ApiController.php diff --git a/app/api/controller/ApiController.php b/app/api/controller/ApiController.php new file mode 100644 index 0000000..58aab9c --- /dev/null +++ b/app/api/controller/ApiController.php @@ -0,0 +1,67 @@ +renderJson(config('status.success'), $message, $data); + } + + /** + * 返回操作失败json + * @param string $message + * @param array $data + * @return Json + */ + protected final function renderError(string $message = 'error', array $data = []): Json + { + return $this->renderJson(config('status.error'), $message, $data); + } + + /** + * 获取post数据 (数组) + * @param null $key + * @param bool $filter + * @return mixed + */ + protected final function postData($key = null, bool $filter = false) + { + return $this->request->post(empty($key) ? '' : "{$key}/a", null, $filter ? '' : null); + } + + /** + * 获取post数据 (数组) + * @param string|null $key + * @param bool $filter + * @return mixed + */ + protected final function postForm(?string $key = 'form', bool $filter = true) + { + return $this->postData(empty($key) ? 'form' : $key, $filter); + } +} \ No newline at end of file