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