diff --git a/app/index/controller/TopicNas.php b/app/index/controller/TopicNas.php index c4315039..ad52c5fc 100644 --- a/app/index/controller/TopicNas.php +++ b/app/index/controller/TopicNas.php @@ -192,6 +192,8 @@ class TopicNas extends Common { // 获取文章分类及文章数据 $parent = ArticleCategoryModel::uniqueLabel('CATEGORY_681182e0a4529')->language($this->lang_id)->value('id'); + $parent_two = ArticleCategoryModel::parent($parent)->language($this->lang_id)->column('id');//二级分类id + array_push($parent_two,$parent); $article_categorys = ArticleCategoryModel::with(['article' => function($query) { $query->field(['id', 'title', 'category_id']) ->order(['sort' => 'asc', 'id' => 'desc']) @@ -199,15 +201,48 @@ class TopicNas extends Common }]) ->field([ 'id', + 'pid', 'name', 'icon' ]) ->language($this->lang_id) - ->parent($parent) +// ->parent($parent) + ->parentChild($parent_two) ->isShow(true) ->order(['sort' => 'asc', 'id' => 'desc']) ->select(); - View::assign('article_categorys', $article_categorys); + //查询三级分类 + $article_categorys_new = []; + $article_categorys_two = []; +// dump($article_categorys->toArray());exit; + if (!$article_categorys->isEmpty()) { + foreach ($article_categorys->toArray() as $kk=>$vv) { + if ( $parent == $vv['pid'] ) { + array_push($article_categorys_new,$vv); + } else { + $article_categorys_two[$vv['pid']][] = $vv; + } + } + if ( !empty($article_categorys_two) ) { + foreach ($article_categorys_new as &$vvv) { + $articles = $vvv['article']; + if ( isset($article_categorys_two[$vvv['id']]) ) { + foreach ($article_categorys_two[$vvv['id']] as $v) { + foreach ($v['article'] as $av) { + if ( count($articles) < 3 ) { + array_push($articles,$av); + } + } + } + } + $vvv['article'] = $articles; + } + } + } + + + View::assign('article_categorys', $article_categorys_new); +// View::assign('article_categorys', $article_categorys); $contacts = []; // 获取banner数据 diff --git a/app/index/view/pc/topic_nas/help.html b/app/index/view/pc/topic_nas/help.html index 7773f437..5c448443 100644 --- a/app/index/view/pc/topic_nas/help.html +++ b/app/index/view/pc/topic_nas/help.html @@ -32,7 +32,7 @@
{volist name="vo.article" id="va" key="index"} - +
{$va.title} @@ -41,7 +41,7 @@
{/volist} {if condition="count($vo.article) >= 3"} - + {:lang_i18n('查看更多')} > {/if}