fix: nas帮助中心搜索

This commit is contained in:
2025-06-11 11:38:25 +08:00
parent 4023d1f6d7
commit 613727fe44

View File

@@ -269,6 +269,25 @@ class TopicNas extends Common
{ {
$keywords = request()->post('keywords'); $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([ $articles = ArticleModel::field([
'id', 'id',
'title' 'title'
@@ -277,6 +296,7 @@ class TopicNas extends Common
'title' => $keywords??null 'title' => $keywords??null
]) ])
->language($this->lang_id) ->language($this->lang_id)
->where('category_id', 'IN', array_column($categorys, 'id'))
->select(); ->select();
return success('success', $articles->toArray()); return success('success', $articles->toArray());