From 9cd31d2bc980adcd235920e0739a4fcf19df9e69 Mon Sep 17 00:00:00 2001 From: loucongjun <905507426@qq.com> Date: Fri, 4 Sep 2026 10:34:24 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common.php | 58 + public/themes/website/1/zh/demo/single_index.html | 1178 ++++++++------------- 2 files changed, 504 insertions(+), 732 deletions(-) diff --git a/app/common.php b/app/common.php index 62e7bb3..6f965b1 100644 --- a/app/common.php +++ b/app/common.php @@ -1637,3 +1637,61 @@ if (!function_exists('isHcListEmpty')) { return false; } } + +/** + * 获取指定栏目下所有子栏目及其内容 + * @param int $parentId 父栏目ID + * @param int $sellerId 商户ID + * @param int $limit 每个子栏目返回的内容条数 + * @param string $sort 排序方式 + * @return array + */ +if (!function_exists('getChildCategoriesContent')) { + function getChildCategoriesContent(int $parentId, int $sellerId, int $limit = 6, string $sort = 'publish_time desc'): array + { + if (empty($parentId)) { + return []; + } + try { + $categoryModel = new \app\model\Category(); + + // 1. 查询所有子栏目 + $childCates = $categoryModel->where('parent_id', $parentId) + ->where('seller_id', $sellerId) + ->order('sort asc') + ->select() + ->toArray(); + + if (empty($childCates)) { + return []; + } + + // 2. 获取所有子栏目ID + $childCateIds = array_column($childCates, 'id'); + + // 3. 查询这些子栏目下的文章 + $contents = \app\model\SubContent::where('category_id', 'in', $childCateIds) + ->where('seller_id', $sellerId) + ->where('is_del', 1) + ->field('id,main_id,title,category_id,description,thumbnail,publish_time') + ->order($sort) + ->limit($limit) + ->select() + ->toArray(); + + // 4. 批量查询附件URL + $thumbIds = array_unique(array_filter(array_column($contents, 'thumbnail'))); + if (!empty($thumbIds)) { + $attachments = \app\model\Attachment::whereIn('id', $thumbIds)->column('url', 'id'); + foreach ($contents as &$content) { + $content['thumbnail_url'] = $attachments[$content['thumbnail']] ?? ''; + } + unset($content); + } + + return $contents; + } catch (\Exception $e) { + return []; + } + } +} diff --git a/public/themes/website/1/zh/demo/single_index.html b/public/themes/website/1/zh/demo/single_index.html index 4b3f806..be323d5 100644 --- a/public/themes/website/1/zh/demo/single_index.html +++ b/public/themes/website/1/zh/demo/single_index.html @@ -3,9 +3,9 @@
-