diff --git a/app/index/controller/TopicNas.php b/app/index/controller/TopicNas.php index 0ba369eb..70e15097 100644 --- a/app/index/controller/TopicNas.php +++ b/app/index/controller/TopicNas.php @@ -269,6 +269,25 @@ class TopicNas extends Common { $keywords = request()->post('keywords'); // 根据关键词查询文章 + $parent = ArticleCategoryModel::uniqueLabel('CATEGORY_681182e0a4529') + ->language($this->lang_id) + ->value('id'); + + // 获取帮且中心分类子分类 + $table_name = (new ArticleCategoryModel)->getTable(); + $categorys = \think\facade\Db::query(preg_replace( + '/\s+/u', + ' ', + "WITH RECURSIVE article_tree_by AS ( + SELECT a.id, a.pid FROM $table_name a WHERE a.id = {$parent} + UNION ALL + SELECT k.id, k.pid FROM $table_name k INNER JOIN article_tree_by t ON t.id = k.pid + ) + SELECT id FROM article_tree_by WHERE id <> {$parent}" + )); + if (empty($categorys)) return success('success', []); + + // 获取文章数据 $articles = ArticleModel::field([ 'id', 'title' @@ -277,6 +296,7 @@ class TopicNas extends Common 'title' => $keywords??null ]) ->language($this->lang_id) + ->where('category_id', 'IN', array_column($categorys, 'id')) ->select(); return success('success', $articles->toArray());