error('错误页面'); } $category = Category::getById($categoryId); if(empty($category)){ return $this->error('错误页面'); } $description = $category['description'] ? $category['description'] : $this->system['seo_description']; $this->setSeo($category['title'], $this->system['seo_keywords'], $description); $this->data['category'] = $category; $this->data['categoryId'] = $categoryId; $this->templateAssign($category); return $this->view($category['template_list'] ?? ''); } //详情 public function detail($id=0) { if($id <= 0){ return $this->error('错误页面'); } $article = MArticle::getById($id); if(empty($article)){ return $this->error('无此文章'); } MArticle::updateById($id, ['views' => $article['views'] + 1]); $category = Category::getById($article['category_id']); $TopCId = Category::firstGradeById($category['id']); if($TopCId == $category['id']) { $topCategory = $category; } else { $topCategory = Category::getById($TopCId); } $keywords = $article['seo_keywords'] ? $article['seo_keywords'] : $this->system['seo_keywords']; $description = $article['seo_description'] ? $article['seo_description'] : $this->system['seo_description']; $this->setSeo($article['title'], $keywords, $description); $this->data['article'] = $article; $this->data['category'] = $category; $this->data['categoryId'] = $category['id']; $this->data['topCategory'] = $topCategory; $this->data['prev'] = MArticle::getPrevArticleByIdAndCategoryId($id, $article['category_id'], true, $article['sort'], true); $this->data['next'] = MArticle::getNextArticleByIdAndCategoryId($id, $article['category_id'], true, $article['sort'], true); return $this->view($category['template_detail'] ?? ''); } // 列表数据绑定 private function templateAssign($category) { $template = strtolower($category['template_list'] ?? ''); $TopCId = Category::firstGradeById($category['id']); if($TopCId == $category['id']) { $topCategory = $category; } else { $topCategory = Category::getById($TopCId); } $categoryChildren = Category::getChildrenByParentId($topCategory['id']); $this->data['topCategory'] = $topCategory; $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); } } // 详情数据绑定 private function templateDetailAssign($article, $category) { } // 产品中心 - 展示当前分类和所有子类产品 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) { } }