From abb2071c29a8a1dd8e5010fe2f1b9c21722aa989 Mon Sep 17 00:00:00 2001 From: zwesy Date: Fri, 4 Dec 2020 10:11:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=EF=BC=9A=E4=BA=A7=E5=93=81?= =?UTF-8?q?=E4=B8=AD=E5=BF=83=E8=B0=83=E6=95=B4=E4=B8=BA=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=A4=9A=E5=88=86=E7=B1=BB=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/Article.php | 22 ++++++++++++++++++++-- app/model/Article.php | 2 +- app/model/Category.php | 2 -- route/app.php | 1 + view/article/products.html | 16 +++++++++++++++- 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/app/controller/Article.php b/app/controller/Article.php index 257ec21..1c4a265 100644 --- a/app/controller/Article.php +++ b/app/controller/Article.php @@ -67,14 +67,17 @@ class Article extends Base } else { $topCategory = Category::getById($TopCId); } + $categoryChildren = Category::getChildrenByParentId($topCategory['id']); $this->data['topCategory'] = $topCategory; - $this->data['categoryChildren'] = Category::getChildrenByParentId($topCategory['id']); + $this->data['categoryChildren'] = $categoryChildren; switch($template) { + case 'products' : + $this->assignProducts($topCategory, $category, $categoryChildren); + break; case 'news' : $this->assignNews($topCategory, $category); break; default : - $this->data['items'] = MArticle::getListPageByCategory($category['id'], $category['number'] ? $category['number'] : 20); } } @@ -85,6 +88,21 @@ class Article extends Base } + // 产品中心 - 展示当前分类和所有子类产品 + private function assignProducts($topCategory, $category, $categoryChildren) + { + $keyword = input('param.keyword', ''); + $cateIds[] = $category['id']; + if($topCategory['id'] == $category['id']) { + $children = $categoryChildren; + } else { + $children = Category::getChildrenByParentId($category['id']); + } + foreach ($children as $child) { + $cateIds[] = $child['id']; + } + $this->data['items'] = MArticle::getListPageByCategories($cateIds, $category['number'] ? $category['number'] : 20, $keyword); + } // 新闻 private function assignNews($topCategory, $category) diff --git a/app/model/Article.php b/app/model/Article.php index bc36d01..18d443d 100644 --- a/app/model/Article.php +++ b/app/model/Article.php @@ -246,7 +246,7 @@ class Article extends Base 'query' => $param ]; if(empty($order)) { - $order = ['create_time'=>'desc']; + $order = ['sort'=>'desc']; } return self::where($where) ->order($order) diff --git a/app/model/Category.php b/app/model/Category.php index 62348c1..5483b2c 100644 --- a/app/model/Category.php +++ b/app/model/Category.php @@ -15,8 +15,6 @@ class Category extends Base 'honors_manage' => 26, // 荣誉资质管理 'history_manage' => 29, // 发展历程管理 'products' => 2, // 产品中心 - 'products' => 2, // 产品中心 - 'products' => 2, // 产品中心 'service' => 5, // 品质与服务 'service_children' => [ 'before' => 12, // 售前服务 diff --git a/route/app.php b/route/app.php index e7c70a8..7f25354 100644 --- a/route/app.php +++ b/route/app.php @@ -10,6 +10,7 @@ // +---------------------------------------------------------------------- use think\facade\Route; +Route::rule('products', 'article/index')->name('products'); Route::get('article/:id', "article/detail"); Route::get('articles/:category_id', "article/index"); Route::get('page/:category_id', "page/index"); diff --git a/view/article/products.html b/view/article/products.html index b839f4d..92acf52 100644 --- a/view/article/products.html +++ b/view/article/products.html @@ -1,7 +1,7 @@ {layout name="layout" /} -
+
{$category.title ?? ''} @@ -12,6 +12,20 @@
+
+
+ + + +
+
{if isset($items)}