diff --git a/app/controller/Article.php b/app/controller/Article.php index da8d27e..ed3e1f6 100644 --- a/app/controller/Article.php +++ b/app/controller/Article.php @@ -37,13 +37,6 @@ class Article extends Base } 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); @@ -51,9 +44,7 @@ class Article extends Base $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); + $this->templateDetailAssign($article, $category); return $this->view($category['template_detail'] ?? ''); } @@ -86,6 +77,22 @@ class Article extends Base // 详情数据绑定 private function templateDetailAssign($article, $category) { + $template = strtolower($category['template_detail'] ?? ''); + $TopCId = Category::firstGradeById($category['id']); + if($TopCId == $category['id']) { + $topCategory = $category; + } else { + $topCategory = Category::getById($TopCId); + } + $this->data['topCategory'] = $topCategory; + switch ($template) { + case 'product': + $this->assignDetailForProduct($article, $topCategory); + break; + default : + $this->data['prev'] = MArticle::getPrevArticleByIdAndCategories($article['id'], [$article['category_id']], true, $article['sort'], true); + $this->data['next'] = MArticle::getNextArticleByIdAndCategories($article['id'], [$article['category_id']], true, $article['sort'], true); + } } @@ -128,5 +135,21 @@ class Article extends Base } } + // 产品详情 + private function assignDetailForProduct($article, $topCategory) + { + $cateIds[] = $article['category_id']; + $currentCateId = input('param.source', 0); + if($currentCateId == $topCategory['id']) { + $categoryList = Category::getChildrenByParentId($topCategory['id']); + foreach ($categoryList as $cate) { + $cateIds[] = $cate['id']; + } + } + $this->data['prev'] = MArticle::getPrevArticleByIdAndCategories($article['id'], $cateIds, true, $article['sort'], true); + $this->data['next'] = MArticle::getNextArticleByIdAndCategories($article['id'], $cateIds, true, $article['sort'], true); + $this->data['currentCateId'] = $currentCateId; + } + } \ No newline at end of file diff --git a/app/model/Article.php b/app/model/Article.php index babc195..dd03fef 100644 --- a/app/model/Article.php +++ b/app/model/Article.php @@ -36,13 +36,13 @@ class Article extends Base /** * 根据文章ID和栏目ID获取下一篇文章 * @param int $id 当前文章ID - * @param int $categoryId 当前文章栏目ID + * @param array $categoryIds 当前文章栏目IDs * @param bool $orderSort 是否以“sort”字段排序 * @param int $currentSort 当前文章的排序号 * @param bool $sortDesc 是否以sort字段倒叙排列 * @return array */ - public static function getNextArticleByIdAndCategoryId($id, $categoryId, $orderSort = false, $currentSort = 0, $sortDesc = false) + public static function getNextArticleByIdAndCategories($id, $categoryIds, $orderSort = false, $currentSort = 0, $sortDesc = false) { $whereMap = []; if($orderSort && $currentSort > 0) { @@ -58,7 +58,7 @@ class Article extends Base $order = ['id'=> 'asc']; } return self::where($whereMap) - ->where('category_id', $categoryId) + ->whereIn('category_id', $categoryIds) ->where('status', 1) ->order($order) ->findOrEmpty() @@ -68,13 +68,13 @@ class Article extends Base /** * 根据文章ID和栏目ID获取上一篇文章 * @param int $id 当前文章ID - * @param int $categoryId 当前文章栏目ID + * @param array $categoryIds 当前文章栏目IDs * @param bool $orderSort 是否以“sort”字段排序 * @param int $currentSort 当前文章的排序号 * @param bool $sortDesc 是否以sort字段倒叙排列 * @return array */ - public static function getPrevArticleByIdAndCategoryId($id, $categoryId, $orderSort = false, $currentSort = 0, $sortDesc = false) + public static function getPrevArticleByIdAndCategories($id, $categoryIds, $orderSort = false, $currentSort = 0, $sortDesc = false) { $whereMap = []; if($orderSort && $currentSort > 0) { @@ -90,7 +90,7 @@ class Article extends Base $order = ['id'=> 'desc']; } return self::where($whereMap) - ->where('category_id',$categoryId) + ->whereIn('category_id', $categoryIds) ->where('status', 1) ->order($order) ->findOrEmpty() diff --git a/public/static/css/style.css b/public/static/css/style.css index 3581eb9..967f965 100644 --- a/public/static/css/style.css +++ b/public/static/css/style.css @@ -49,6 +49,7 @@ input,select,textarea{outline:medium none; resize: none;} /*nav*/ /**/ +.nav {width: 75%;} .nav ul li{ float: left; position: relative; margin-left: 1.25rem; transition: all .6s;} .nav ul li span a{ float: left; font-size: 1.125rem; line-height: 5.9375rem; padding: 0 16px; position: relative; text-decoration: none; color: #fff;} .nav ul li span a::before{ content: ''; width: 0; height: 4px; position: absolute; left: 0; bottom: 0; background: #F9BE3E; transition: all .6s; opacity: 0;} diff --git a/public/static/js/script.js b/public/static/js/script.js index 88c16af..0b4786d 100644 --- a/public/static/js/script.js +++ b/public/static/js/script.js @@ -107,3 +107,7 @@ $(function() { }); + +layui.use(['layer', 'form', 'element'], function(){ + var layer = layui.layer,form = layui.form,element = layui.element; +}); \ No newline at end of file diff --git a/view/article/news_detail.html b/view/article/news_detail.html index a49a9eb..9f34760 100644 --- a/view/article/news_detail.html +++ b/view/article/news_detail.html @@ -1,2 +1,36 @@ {layout name="layout" /} -新闻详情 \ No newline at end of file +
+
+
+ {$category.title ?? ''} +

{:nl2br($category.description ?? '')}

+
+
+
+ + +
+
+
+
+ {$article.title} +

{$article.create_time|date="Y/m/d"}

+
+
+ {:nl2br($article.content)} +
+
+

+ {if isset($prev) && count($prev) >0} + 上一篇 + {/if} + {if (isset($prev) && count($prev) >0) && (isset($next) && count($next) >0)} / {/if} + {if isset($next) && count($next) >0} + 下一篇 + {/if} +

+ 返回 +
+
+
+
\ No newline at end of file diff --git a/view/article/product.html b/view/article/product.html index 15f397c..25fb5da 100644 --- a/view/article/product.html +++ b/view/article/product.html @@ -24,11 +24,11 @@

{if isset($prev) && count($prev) >0} - 上一篇 + 上一篇 {/if} {if (isset($prev) && count($prev) >0) && (isset($next) && count($next) >0)} / {/if} {if isset($next) && count($next) >0} - 下一篇 + 下一篇 {/if}

返回 diff --git a/view/article/products.html b/view/article/products.html index d2740c6..912aa1d 100644 --- a/view/article/products.html +++ b/view/article/products.html @@ -25,18 +25,17 @@ -
{if isset($items)}
diff --git a/view/page/contact.html b/view/page/contact.html new file mode 100644 index 0000000..e69de29