更新:新闻详情和产品详情调整
parent
e086098616
commit
7a9495b180
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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()
|
||||
|
|
|
@ -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;}
|
||||
|
|
|
@ -107,3 +107,7 @@ $(function() {
|
|||
|
||||
|
||||
});
|
||||
|
||||
layui.use(['layer', 'form', 'element'], function(){
|
||||
var layer = layui.layer,form = layui.form,element = layui.element;
|
||||
});
|
|
@ -1,2 +1,36 @@
|
|||
{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)} / {/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>
|
|
@ -24,11 +24,11 @@
|
|||
<div class="lower-box w-100">
|
||||
<p>
|
||||
{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 (isset($prev) && count($prev) >0) && (isset($next) && count($next) >0)} / {/if}
|
||||
{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}
|
||||
</p>
|
||||
<a href="javascript:history.back(-1);" class="btns">返回</a>
|
||||
|
|
|
@ -25,18 +25,17 @@
|
|||
<input name="keyword" class="layui-input" placeholder="关键词查询..." value="{$keyword ?? ''}"/>
|
||||
<button type="submit" class="layui-btn layui-btn-normal">查询</button>
|
||||
</form>
|
||||
<script type="text/javascript">
|
||||
layui.use(['layer', 'form', 'element'], function(){
|
||||
var layer = layui.layer,form = layui.form,element = layui.element;
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
<div class="w-1200">
|
||||
{if isset($items)}
|
||||
<div class="center-block w-100">
|
||||
<ul>
|
||||
{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}
|
||||
</ul>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue