['except' => []] ]; public function index() { $this->checkAuth(); $param = get_params(); $where = array(); if (!empty($param['keyword'])) { $where[] = ['a.title', 'like', '%' . $param['keyword'] . '%']; } $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(); if (empty($note)) { $this->apiError('公告不存在'); } $note['cate_title'] = Db::name('NoteCate')->where(['id' => $note['cate_id']])->value('title'); $this->apiSuccess('获取成功', $note); } }