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/app/service/ContentService.php b/app/service/ContentService.php index d449dd4..2277bc6 100644 --- a/app/service/ContentService.php +++ b/app/service/ContentService.php @@ -471,6 +471,9 @@ class ContentService { if($param['isTop'] != 2){ $where['is_top'] = 1; } + if($param['isTop'] == 2){ + $where['is_top'] = 2; + } // switch ($param['isTop']) { // case 1: diff --git a/public/themes/website/1/zh/demo/news.html b/public/themes/website/1/zh/demo/news.html index e7fed29..a7d4a47 100644 --- a/public/themes/website/1/zh/demo/news.html +++ b/public/themes/website/1/zh/demo/news.html @@ -91,7 +91,7 @@ - {hcTaglib:contentPage2 cid="$current_cate_id" mainField="id,category_id,title,sub_title,thumbnail,content,description,create_time" subField="" name="hc_featured" limit="100" item="content_sub22" sort="sort asc" isTop="1"} + {hcTaglib:contentPage2 cid="$current_cate_id" mainField="id,category_id,title,sub_title,thumbnail,content,description,create_time,is_top" subField="" name="hc_featured" limit="100" item="content_sub22" sort="sort asc" isTop="1"} {/hcTaglib:contentPage2} {php} $news_has_featured = false; @@ -110,8 +110,8 @@ {volist name="hc_featured" id="vo_content"} {php} $content = $vo_content['content'] ?? ''; // 富文本 - $description = $vo_content['description'] ?? ''; - $title = $vo_content['description'] ?? ''; + $description = $vo_content['description'] ?? ''; // 描述 + $title = $vo_content['title'] ?? ''; // 标题 $create_time_str = $vo_content['create_time'] ?? ''; {/php}