request->get('page/d', 1); $key = $this->request->get('key', ''); $type = $this->request->get('type', 1); $result = $noticeModel->getLists([ 'search' => [ 'title' => $key, 'type' => $type ], ], 10, $page, [ 'id', 'title', 'cover', 'desc', 'views' ]); $this->success('获取成功', [ 'total' => $result['total'], 'pageSize' => $result['pageSize'], 'totalSize' => $result['totalSize'], 'list' => $result['list'], ]); } /** * 公告详情 * @param NoticeModel $noticeModel * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function detail(NoticeModel $noticeModel) { $id = $this->request->get('id/d'); if (empty($id)) { $this->success('参数错误', [], 501); } $detail = $noticeModel->getItem($id, [ 'id', 'title', 'views', 'content', 'create_time', 'status' ]); if (empty($detail)) { $this->success('内容不存在', [], 502); } if ($detail->status == 2) { $this->success('内容以下架', [], 502); } // 浏览量+1 $detail->views += 1; $noticeModel->where(['id' => $id])->setInc('views'); $detail->create_time = date('Y-m-d H:i:s', $detail->create_time); $this->success('获取成功', [ 'detail' => $detail ]); } }