From c09e2873b65505557d01739bfe84ab653986777a Mon Sep 17 00:00:00 2001 From: yaooo <272523191@qq.com> Date: Sat, 28 Oct 2023 18:03:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=B3=BB=E7=BB=9F=E5=85=AC?= =?UTF-8?q?=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/NoteIndex.php | 58 ++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 app/api/controller/NoteIndex.php diff --git a/app/api/controller/NoteIndex.php b/app/api/controller/NoteIndex.php new file mode 100644 index 0000000..7f9a76b --- /dev/null +++ b/app/api/controller/NoteIndex.php @@ -0,0 +1,58 @@ + ['except' => []] + ]; + + public function index() + { + $this->checkAuth(); + $param = get_params(); + $where = array(); + if (!empty($param['keywords'])) { + $where[] = ['a.title', 'like', '%' . $param['keywords'] . '%']; + } + $where[] = ['a.status', '=', 1]; + $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit']; + $note = NoteList::where($where) + ->field('a.id,a.cate_id,a.title,a.content,a.status,a.create_time,a.start_time,a.end_time,c.title as cate_title') + ->alias('a') + ->join('NoteCate c', 'a.cate_id = c.id', 'LEFT') + ->order('a.end_time desc,a.sort desc,a.create_time desc') + ->paginate($rows, false, ['query' => $param]) + ->each(function ($item, $key) { + $item->start_time = empty($item->start_time) ? '-' : date('Y-m-d', $item->start_time); + $item->end_time = empty($item->end_time) ? '-' : date('Y-m-d', $item->end_time); + }); + $this->apiSuccess('获取成功', $note); + } + + public function view() + { + $this->checkAuth(); + $id = empty(get_params('id')) ? 0 : get_params('id'); + $note = Db::name('Note')->where(['id' => $id])->find(); + $note['cate_title'] = Db::name('NoteCate')->where(['id' => $note['cate_id']])->value('title'); + $this->apiSuccess('获取成功', $note); + } + +}