feat: show author follower count on post cards
This commit is contained in:
@@ -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'))));
|
||||
|
||||
Reference in New Issue
Block a user