From 72f974c083efc2b30f1700d33cb8b495fe260cc6 Mon Sep 17 00:00:00 2001 From: ouzhiqiang <835402500@qq.com> Date: Thu, 18 Sep 2025 15:25:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/index/controller/TopicNas.php | 19 ++++++++++++++++++- app/index/model/ArticleCategoryModel.php | 11 +++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) 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) {