From c005714ea848f898df6df590923443117c562652 Mon Sep 17 00:00:00 2001 From: tensent Date: Thu, 16 Apr 2020 16:53:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=85=E5=AE=B9=E6=A8=A1=E5=9D=97=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/front/Content.php | 96 +++++++++++++++++-- .../default/front/content_detail.html | 37 +++++++ .../template/default/front/content_index.html | 37 +++++++ .../template/default/front/content_lists.html | 40 ++++++++ .../default/front/content_search.html | 35 +++++++ route/app.php | 2 +- 6 files changed, 239 insertions(+), 8 deletions(-) create mode 100644 public/template/default/front/content_detail.html create mode 100644 public/template/default/front/content_index.html create mode 100644 public/template/default/front/content_lists.html create mode 100644 public/template/default/front/content_search.html diff --git a/app/controller/front/Content.php b/app/controller/front/Content.php index 27721252..6c24aaef 100644 --- a/app/controller/front/Content.php +++ b/app/controller/front/Content.php @@ -8,17 +8,39 @@ // +---------------------------------------------------------------------- namespace app\controller\front; +use think\facade\Db; use \app\model\Category; use \app\model\Model; use \app\model\Content as ContentModel; class Content extends Base { + + public $modelInfo = []; + public $model = null; /** * @title 内容频道页 * @return [type] [description] */ public function index() { + $param = $this->request->param(); + $this->setModel(); + $order = "id desc"; + $map = []; + + if (isset($param['keyword']) && $param['keyword'] != '') { + $map[] = ['title', 'LIKE', '%'.$param['keyword'].'%']; + } + + $category = Category::where('model_id', $this->modelInfo['id'])->column("*", "id"); + + $list = $this->model->where($map)->order($order)->paginate($this->request->pageConfig); + $this->data = [ + 'model' => $this->modelInfo, + 'category' => $category, + 'list' => $list, + 'page' => $list->render() + ]; return $this->fetch(); } @@ -27,6 +49,60 @@ class Content extends Base { * @return [type] [description] */ public function lists() { + $param = $this->request->param(); + $this->setModel(); + $order = "id desc"; + $map = []; + + $category = Category::where('model_id', $this->modelInfo['id'])->column("*", "id"); + + $ids = (new \sent\tree\Tree())->getChilds($category, (int) $param['id']); + array_push($ids, (int) $param['id']); + + $map[] = ['category_id', "IN", $ids]; + if (isset($param['keyword']) && $param['keyword'] != '') { + $map[] = ['title', 'LIKE', '%'.$param['keyword'].'%']; + } + + $list = $this->model->where($map)->order($order)->paginate($this->request->pageConfig); + $this->data = [ + 'model' => $this->modelInfo, + 'id' => (int) $param['id'], + 'category' => $category, + 'list' => $list, + 'page' => $list->render() + ]; + return $this->fetch(); + } + + /** + * @title 内容详情 + * @return [type] [description] + */ + public function detail() { + $param = $this->request->param(); + $this->setModel(); + + $map[] = ['id', "=", $param['id']]; + $detail = $this->model->where($map)->find(); + + $pmap = [ + ['category_id', '=', $detail['category_id']], + ['id', '<', $param['id']] + ]; + $prev = Db::name(ucfirst($this->modelInfo['name']))->where($pmap)->order('id desc')->find(); + $nmap = [ + ['category_id', '=', $detail['category_id']], + ['id', '>', $param['id']] + ]; + $next = Db::name(ucfirst($this->modelInfo['name']))->where($nmap)->order('id asc')->find(); + + $this->data = [ + 'model' => $this->modelInfo, + 'info' => $detail, + 'prev' => $prev, + 'next' => $next + ]; return $this->fetch(); } @@ -43,15 +119,21 @@ class Content extends Base { * @return [type] [description] */ public function search() { - return $this->fetch(); - } + $param = $this->request->param(); + $list = []; + + if (isset($param['keyword']) && $param['keyword'] != '') { + $map[] = ['title', 'LIKE', '%'.$param['keyword'].'%']; + } - /** - * @title 内容详情 - * @return [type] [description] - */ - public function detail() { + $this->data = [ + "list" => $list + ]; return $this->fetch(); } + protected function setModel(){ + $this->modelInfo = Model::where('name', $this->request->param('name'))->find()->append(['grid_list', 'attr_group'])->toArray(); + $this->model = Db::name($this->modelInfo['name']); + } } diff --git a/public/template/default/front/content_detail.html b/public/template/default/front/content_detail.html new file mode 100644 index 00000000..2f7a1e7a --- /dev/null +++ b/public/template/default/front/content_detail.html @@ -0,0 +1,37 @@ + + + + + + +SentCMS网站管理系统 + + + + + + +
+ 注册 + 登录 +
+
+
+ {$info['title']} +

{$info['create_time']|time_format}

+
+
+ + diff --git a/public/template/default/front/content_index.html b/public/template/default/front/content_index.html new file mode 100644 index 00000000..fbc2cf62 --- /dev/null +++ b/public/template/default/front/content_index.html @@ -0,0 +1,37 @@ + + + + + + +SentCMS网站管理系统 + + + + + + +
+ 注册 + 登录 +
+
+
+ {$model['title']}频道 +

{:print_r($model)}

+
+
+ + diff --git a/public/template/default/front/content_lists.html b/public/template/default/front/content_lists.html new file mode 100644 index 00000000..847f3de1 --- /dev/null +++ b/public/template/default/front/content_lists.html @@ -0,0 +1,40 @@ + + + + + + +SentCMS网站管理系统 + + + + + + +
+ 注册 + 登录 +
+
+
+ +
+
+ + diff --git a/public/template/default/front/content_search.html b/public/template/default/front/content_search.html new file mode 100644 index 00000000..feb10157 --- /dev/null +++ b/public/template/default/front/content_search.html @@ -0,0 +1,35 @@ + + + + + + +SentCMS网站管理系统 + + + + + + +
+ 注册 + 登录 +
+
+
+
+
+ + diff --git a/route/app.php b/route/app.php index 91ee2a60..fb60af5c 100755 --- a/route/app.php +++ b/route/app.php @@ -16,7 +16,7 @@ $model = Model::where('status', '>', 0)->field(['id', 'name'])->select()->toArra foreach ($model as $value) { Route::rule('/admin/' . $value['name'] . '/:function', 'admin.content/:function')->append(['name'=>$value['name'], 'model_id' => $value['id']]); Route::rule($value['name'] . '/index', 'front.content/index')->append(['name'=>$value['name'], 'model_id' => $value['id']]); - Route::rule($value['name'] . '/list/[:id]', 'front.content/lists')->append(['name'=>$value['name'], 'model_id' => $value['id']]); + Route::rule($value['name'] . '/list/:id', 'front.content/lists')->append(['name'=>$value['name'], 'model_id' => $value['id']]); Route::rule($value['name'] . '/detail-:id', 'front.content/detail')->append(['name'=>$value['name'], 'model_id' => $value['id']]); Route::rule('/user/' . $value['name'] . '/:function', 'user.content/:function')->append(['name'=>$value['name'], 'model_id' => $value['id']]); }