feat: show author follower count on post cards

This commit is contained in:
hajimi
2026-08-02 19:59:58 +08:00
parent 883b3143d5
commit 115a859dd3
2 changed files with 35 additions and 2 deletions
@@ -107,11 +107,26 @@ class CommunityPostLists extends BaseApiDataLists
// 批量查询用户 → id 为 key
$userMap = [];
$fansCountMap = [];
if ($userIds) {
$users = User::field('id,sn,nickname,avatar,sex')->whereIn('id', $userIds)->select()->toArray();
foreach ($users as $u) {
$userMap[$u['id']] = $u;
}
$fansCounts = CommunityFollow::whereIn('follow_user_id', $userIds)
->field('follow_user_id, COUNT(*) AS fans_count')
->group('follow_user_id')
->select()
->toArray();
foreach ($fansCounts as $fansCount) {
$fansCountMap[(int) $fansCount['follow_user_id']] = (int) $fansCount['fans_count'];
}
foreach ($userMap as $userId => &$user) {
$user['fans_count'] = $fansCountMap[(int) $userId] ?? 0;
}
unset($user);
}
$categoryIds = array_values(array_filter(array_unique(array_column($list, 'category_id'))));