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)}