更新:新闻详情和产品详情调整

virtual
zwesy 2020-12-04 15:55:52 +08:00
parent e086098616
commit 7a9495b180
8 changed files with 86 additions and 25 deletions

View File

@ -37,13 +37,6 @@ class Article extends Base
} }
MArticle::updateById($id, ['views' => $article['views'] + 1]); MArticle::updateById($id, ['views' => $article['views'] + 1]);
$category = Category::getById($article['category_id']); $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']; $keywords = $article['seo_keywords'] ? $article['seo_keywords'] : $this->system['seo_keywords'];
$description = $article['seo_description'] ? $article['seo_description'] : $this->system['seo_description']; $description = $article['seo_description'] ? $article['seo_description'] : $this->system['seo_description'];
$this->setSeo($article['title'], $keywords, $description); $this->setSeo($article['title'], $keywords, $description);
@ -51,9 +44,7 @@ class Article extends Base
$this->data['article'] = $article; $this->data['article'] = $article;
$this->data['category'] = $category; $this->data['category'] = $category;
$this->data['categoryId'] = $category['id']; $this->data['categoryId'] = $category['id'];
$this->data['topCategory'] = $topCategory; $this->templateDetailAssign($article, $category);
$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'] ?? ''); return $this->view($category['template_detail'] ?? '');
} }
@ -86,6 +77,22 @@ class Article extends Base
// 详情数据绑定 // 详情数据绑定
private function templateDetailAssign($article, $category) 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;
}
} }

View File

@ -36,13 +36,13 @@ class Article extends Base
/** /**
* 根据文章ID和栏目ID获取下一篇文章 * 根据文章ID和栏目ID获取下一篇文章
* @param int $id 当前文章ID * @param int $id 当前文章ID
* @param int $categoryId 当前文章栏目ID * @param array $categoryIds 当前文章栏目IDs
* @param bool $orderSort 是否以“sort”字段排序 * @param bool $orderSort 是否以“sort”字段排序
* @param int $currentSort 当前文章的排序号 * @param int $currentSort 当前文章的排序号
* @param bool $sortDesc 是否以sort字段倒叙排列 * @param bool $sortDesc 是否以sort字段倒叙排列
* @return array * @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 = []; $whereMap = [];
if($orderSort && $currentSort > 0) { if($orderSort && $currentSort > 0) {
@ -58,7 +58,7 @@ class Article extends Base
$order = ['id'=> 'asc']; $order = ['id'=> 'asc'];
} }
return self::where($whereMap) return self::where($whereMap)
->where('category_id', $categoryId) ->whereIn('category_id', $categoryIds)
->where('status', 1) ->where('status', 1)
->order($order) ->order($order)
->findOrEmpty() ->findOrEmpty()
@ -68,13 +68,13 @@ class Article extends Base
/** /**
* 根据文章ID和栏目ID获取上一篇文章 * 根据文章ID和栏目ID获取上一篇文章
* @param int $id 当前文章ID * @param int $id 当前文章ID
* @param int $categoryId 当前文章栏目ID * @param array $categoryIds 当前文章栏目IDs
* @param bool $orderSort 是否以“sort”字段排序 * @param bool $orderSort 是否以“sort”字段排序
* @param int $currentSort 当前文章的排序号 * @param int $currentSort 当前文章的排序号
* @param bool $sortDesc 是否以sort字段倒叙排列 * @param bool $sortDesc 是否以sort字段倒叙排列
* @return array * @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 = []; $whereMap = [];
if($orderSort && $currentSort > 0) { if($orderSort && $currentSort > 0) {
@ -90,7 +90,7 @@ class Article extends Base
$order = ['id'=> 'desc']; $order = ['id'=> 'desc'];
} }
return self::where($whereMap) return self::where($whereMap)
->where('category_id',$categoryId) ->whereIn('category_id', $categoryIds)
->where('status', 1) ->where('status', 1)
->order($order) ->order($order)
->findOrEmpty() ->findOrEmpty()

View File

@ -49,6 +49,7 @@ input,select,textarea{outline:medium none; resize: none;}
/*nav*/ /*nav*/
/**/ /**/
.nav {width: 75%;}
.nav ul li{ float: left; position: relative; margin-left: 1.25rem; transition: all .6s;} .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{ 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;} .nav ul li span a::before{ content: ''; width: 0; height: 4px; position: absolute; left: 0; bottom: 0; background: #F9BE3E; transition: all .6s; opacity: 0;}

View File

@ -107,3 +107,7 @@ $(function() {
}); });
layui.use(['layer', 'form', 'element'], function(){
var layer = layui.layer,form = layui.form,element = layui.element;
});

View File

@ -1,2 +1,36 @@
{layout name="layout" /} {layout name="layout" /}
新闻详情 <div class="page-banner w-100" style="background-image: url({:getImgSrc($topCategory, '__IMG__/page_ban4.jpg')});">
<div class="info">
<div class="w-1200">
<strong>{$category.title ?? ''}</strong>
<p>{:nl2br($category.description ?? '')}</p>
</div>
</div>
</div>
<!-- -->
<div class="all-center-box">
<div class="news-info w-100">
<div class="w-1200">
<div class="top-box w-100">
<span>{$article.title}</span>
<p>{$article.create_time|date="Y/m/d"}</p>
</div>
<div class="cen-box w-100">
{:nl2br($article.content)}
</div>
<div class="lower-box w-100">
<p>
{if isset($prev) && count($prev) >0}
<a href="{:url('article/detail', ['id' => $prev.id])}">上一篇</a>
{/if}
{if (isset($prev) && count($prev) >0) && (isset($next) && count($next) >0)}&emsp;/&emsp;{/if}
{if isset($next) && count($next) >0}
<a href="{:url('article/detail', ['id' => $next.id])}">下一篇</a>
{/if}
</p>
<a href="javascript:history.back(-1);" class="btns">返回</a>
</div>
</div>
</div>
</div>

View File

@ -24,11 +24,11 @@
<div class="lower-box w-100"> <div class="lower-box w-100">
<p> <p>
{if isset($prev) && count($prev) >0} {if isset($prev) && count($prev) >0}
<a href="{:url('article/detail', ['id' => $prev.id])}">上一篇</a> <a href="{:url('article/detail', ['id' => $prev.id, 'source'=>$currentCateId])}">上一篇</a>
{/if} {/if}
{if (isset($prev) && count($prev) >0) && (isset($next) && count($next) >0)}&emsp;/&emsp;{/if} {if (isset($prev) && count($prev) >0) && (isset($next) && count($next) >0)}&emsp;/&emsp;{/if}
{if isset($next) && count($next) >0} {if isset($next) && count($next) >0}
<a href="{:url('article/detail', ['id' => $next.id])}">下一篇</a> <a href="{:url('article/detail', ['id' => $next.id, 'source'=>$currentCateId])}">下一篇</a>
{/if} {/if}
</p> </p>
<a href="javascript:history.back(-1);" class="btns">返回</a> <a href="javascript:history.back(-1);" class="btns">返回</a>

View File

@ -25,18 +25,17 @@
<input name="keyword" class="layui-input" placeholder="关键词查询..." value="{$keyword ?? ''}"/> <input name="keyword" class="layui-input" placeholder="关键词查询..." value="{$keyword ?? ''}"/>
<button type="submit" class="layui-btn layui-btn-normal">查询</button> <button type="submit" class="layui-btn layui-btn-normal">查询</button>
</form> </form>
<script type="text/javascript">
layui.use(['layer', 'form', 'element'], function(){
var layer = layui.layer,form = layui.form,element = layui.element;
});
</script>
</div> </div>
<div class="w-1200"> <div class="w-1200">
{if isset($items)} {if isset($items)}
<div class="center-block w-100"> <div class="center-block w-100">
<ul> <ul>
{foreach $items as $item} {foreach $items as $item}
<li><a href="{:url('article/detail', ['id' => $item.id])}"><span><img src="{:getImgSrc($item, '__IMG__/default_bg.jpg')}" ></span><p>{$item.title}</p></a></li> <li>
<a href="{:url('article/detail', ['id' => $item.id, 'source'=>$categoryId])}">
<span><img src="{:getImgSrc($item, '__IMG__/default_bg.jpg')}" ></span><p>{$item.title}</p>
</a>
</li>
{/foreach} {/foreach}
</ul> </ul>
</div> </div>

0
view/page/contact.html Normal file
View File