diff --git a/app/index/controller/TopicNas.php b/app/index/controller/TopicNas.php index 5884aeed..c4315039 100644 --- a/app/index/controller/TopicNas.php +++ b/app/index/controller/TopicNas.php @@ -343,8 +343,18 @@ class TopicNas extends Common ->language($this->lang_id) ->where('category_id', 'IN', array_column($categorys, 'id')) ->select(); + //查询上级id + $parent_two = ArticleCategoryModel::parentColumn(array_column($categorys, 'id'))->language($this->lang_id)->column('pid','id');//二级分类id + $articles_data = $articles->toArray(); + foreach ($articles_data as &$v) { + $v['pid'] = 0; + if ( $parent_two[$v['category_id']] !== $parent ) { + $v['pid'] = $v['category_id']; + $v['category_id'] = $parent_two[$v['category_id']]; + } + } - return success('success', $articles->toArray()); + return success('success', $articles_data); } /** diff --git a/app/index/model/ArticleCategoryModel.php b/app/index/model/ArticleCategoryModel.php index b6e43ed0..64f48fd1 100644 --- a/app/index/model/ArticleCategoryModel.php +++ b/app/index/model/ArticleCategoryModel.php @@ -56,6 +56,16 @@ class ArticleCategoryModel extends ArticleCategoryBaseModel $query->where('pid', '=', $parent); } + // 所属上级分类查询 + public function scopeParentColumn($query, $parent) + { + if (is_array($parent)) { + $query->where('id', 'IN', $parent); + return; + } + $query->where('id', '=', $parent); + } + // 所属子分类范围查询 public function scopeChild($query, $id, $merge_self = false) diff --git a/app/index/view/mobile/topic_nas/help_detail.html b/app/index/view/mobile/topic_nas/help_detail.html index ea383098..5273a800 100644 --- a/app/index/view/mobile/topic_nas/help_detail.html +++ b/app/index/view/mobile/topic_nas/help_detail.html @@ -73,14 +73,14 @@
+ class="arrow {if condition='$ad.id == $Request.get.pid'}rotate{/if}">

