feat: add community post categories and channels

This commit is contained in:
hajimi
2026-08-02 17:39:52 +08:00
parent 95f03af60e
commit b0b278d11f
18 changed files with 1132 additions and 12 deletions
@@ -3,6 +3,7 @@
namespace app\api\lists\community;
use app\api\lists\BaseApiDataLists;
use app\common\model\community\CommunityCategory;
use app\common\model\community\CommunityPost;
use app\common\model\community\CommunityFollow;
use app\common\model\community\CommunityTag;
@@ -61,6 +62,11 @@ class CommunityPostLists extends BaseApiDataLists
$where[] = ['id', '=', 0];
}
}
foreach (['is_recommend', 'is_hot', 'is_topic', 'category_id'] as $field) {
if (isset($this->params[$field]) && $this->params[$field] !== '') {
$where[] = [$field, '=', (int) $this->params[$field]];
}
}
return $where;
}
@@ -88,7 +94,7 @@ class CommunityPostLists extends BaseApiDataLists
public function lists(): array
{
$list = $this->buildQuery()
->field('id,origin_id,user_id,content,images,ext,post_type,match_id,is_paid,price_points,paid_count,view_count,like_count,comment_count,share_count,is_top,is_hot,is_recommend,create_time')
->field('id,origin_id,user_id,content,images,ext,post_type,category_id,match_id,is_paid,price_points,paid_count,view_count,like_count,comment_count,share_count,is_top,is_hot,is_recommend,is_topic,create_time')
->orderRaw('is_top DESC, is_hot DESC, create_time DESC')
->limit($this->limitOffset, $this->limitLength)
->select()
@@ -107,6 +113,11 @@ class CommunityPostLists extends BaseApiDataLists
}
}
$categoryIds = array_values(array_filter(array_unique(array_column($list, 'category_id'))));
$categoryNames = $categoryIds
? CommunityCategory::whereIn('id', $categoryIds)->column('name', 'id')
: [];
// 批量查询帖子标签 → post_id => [tag_name, ...]
$tagMap = [];
if ($postIds) {
@@ -166,6 +177,7 @@ class CommunityPostLists extends BaseApiDataLists
$item['user'] = $userMap[$item['user_id']] ?? null;
$item['tags'] = $tagMap[$item['id']] ?? [];
$item['category_name'] = $categoryNames[$item['category_id']] ?? '';
$item['source_url'] = $ext['url'] ?? '';
$item['is_liked'] = false;
if ($this->userId) {