diff --git a/app/index/controller/TopicNas.php b/app/index/controller/TopicNas.php index 76ee2214..06a5d01e 100644 --- a/app/index/controller/TopicNas.php +++ b/app/index/controller/TopicNas.php @@ -246,19 +246,36 @@ 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']); }]) ->field([ 'id', + 'pid', 'name', 'icon' ]) ->language($this->lang_id) - ->parent($parent) +// ->parent($parent) + ->parentChild($parent_two) ->isShow(true) ->order(['sort' => 'asc', 'id' => 'desc']) ->select(); + dump($article_categorys);exit; + //查询三级分类 + $article_categorys_new = []; + if (!$article_categorys->isEmpty()) { + foreach ($article_categorys as $kk=>$vv) { + $article_categorys_two = []; + if ( $parent == $vv->pid ) { + + } + + } + } + View::assign('article_categorys', $article_categorys); return View::fetch('help_detail'); diff --git a/app/index/model/ArticleCategoryModel.php b/app/index/model/ArticleCategoryModel.php index 223ffcd4..b6e43ed0 100644 --- a/app/index/model/ArticleCategoryModel.php +++ b/app/index/model/ArticleCategoryModel.php @@ -46,6 +46,17 @@ class ArticleCategoryModel extends ArticleCategoryBaseModel $query->where('pid', '=', $parent); } + // 所属上级分类范围查询 + public function scopeParentChild($query, $parent) + { + if (is_array($parent)) { + $query->where('pid', 'IN', $parent); + return; + } + $query->where('pid', '=', $parent); + } + + // 所属子分类范围查询 public function scopeChild($query, $id, $merge_self = false) {