request->param()); return json($res); } /** * @auth {{/notice/add}} * @return type */ public function add() { if ($this->request->isPost()) { try { $params = $this->request->param(); validate(NoticeValidate::class)->check($params); if (NoticeApi::edit($params)) return json(["msg" => "文章发布成功"]); throw new \think\exception("文章发布失败"); } catch (\think\exception $e) { return json(["msg" => $e->getMessage()]); } } return view(); } /** * @auth {{/notice/update}} * @return type */ public function edit() { $params = $this->request->param(); if ($this->request->isPost()) { try { validate(NoticeValidate::class)->check($params); if (NoticeApi::edit($params)) return json(["msg" => "文章编辑成功"]); throw new \think\exception("文章编辑失败"); } catch (\think\exception $e) { return json(["msg" => $e->getMessage()]); } } $row = NoticeApi::getOne($params["id"]); return view("", ["row" => $row]); } /** * @auth {{/notice/delete}} * @return type */ public function delete() { if ($this->request->isPost()) { $params = $this->request->param(); $id = $params["id"]; if (NoticeApi::delete($id)) return json(["msg" => "删除成功"]); return json(["msg" => "删除失败"]); } } /** * @auth {{/notice/delete}} * @return type */ public function top() { if ($this->request->isPost()) { $params = $this->request->param(); $id = $params["id"]; $isTop = $params["isTop"] ?: 1; if ($isTop == 1) { if (NoticeApi::setTop($id, 1)) return json(["msg" => "置顶成功"]); return json(["msg" => "置顶失败"]); } else { if (NoticeApi::setTop($id, 2)) return json(["msg" => "取消置顶成功"]); return json(["msg" => "取消置顶失败"]); } } } }