peijunlei 2 weeks ago
parent
commit
0fb6099c80
  1. 58
      app/common.php
  2. 3
      app/service/ContentService.php
  3. 8
      public/themes/website/1/zh/demo/news.html
  4. 1178
      public/themes/website/1/zh/demo/single_index.html

58
app/common.php

@ -1637,3 +1637,61 @@ if (!function_exists('isHcListEmpty')) {
return false; 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 [];
}
}
}

3
app/service/ContentService.php

@ -471,6 +471,9 @@ class ContentService {
if($param['isTop'] != 2){ if($param['isTop'] != 2){
$where['is_top'] = 1; $where['is_top'] = 1;
} }
if($param['isTop'] == 2){
$where['is_top'] = 2;
}
// switch ($param['isTop']) { // switch ($param['isTop']) {
// case 1: // case 1:

8
public/themes/website/1/zh/demo/news.html

@ -91,7 +91,7 @@
</div> </div>
</div> </div>
{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} {/hcTaglib:contentPage2}
{php} {php}
$news_has_featured = false; $news_has_featured = false;
@ -110,8 +110,8 @@
{volist name="hc_featured" id="vo_content"} {volist name="hc_featured" id="vo_content"}
{php} {php}
$content = $vo_content['content'] ?? ''; // 富文本 $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'] ?? ''; $create_time_str = $vo_content['create_time'] ?? '';
{/php} {/php}
<div class="swiper-slide n-featured__slide" data-category="company"> <div class="swiper-slide n-featured__slide" data-category="company">
@ -169,7 +169,7 @@
<div class="n-grid"> <div class="n-grid">
{hcTaglib:contentPage2 cid="$current_cate_id" mainField="id,category_id,title,sub_title,thumbnail,content,description,create_time" subField="" name="hc_content" limit="6" item="content_sub22" sort="sort asc" isTop="2"}
{hcTaglib:contentPage2 cid="$current_cate_id" mainField="id,category_id,title,sub_title,thumbnail,content,description,create_time,is_top" subField="" name="hc_content" limit="6" item="content_sub22" sort="sort asc" isTop="2"}
{/hcTaglib:contentPage2} {/hcTaglib:contentPage2}
{volist name="hc_content" id="vo_content"} {volist name="hc_content" id="vo_content"}

1178
public/themes/website/1/zh/demo/single_index.html
File diff suppressed because it is too large
View File

Loading…
Cancel
Save