房间用户列表

This commit is contained in:
2025-12-09 19:46:23 +08:00
parent 41c90c615b
commit 2726aa852d

View File

@@ -1847,14 +1847,10 @@ class Room extends Model
}
}
// 计算麦用户需要的数量
// 计算麦用户数量
$onPitCount = count($lists['on_pit']);
// 获取麦下用户(非隐身用户)
// 麦下用户分页逻辑:
// 1. 第一页显示部分麦下用户使得总数量为limit如果有足够的麦下用户
// 2. 后续页:只显示麦下用户,按照正常的分页逻辑
if ($page == 1) {
// 第一页:需要的麦下用户数量 = limit - 麦上用户数量
$needOffPitCount = $limit - $onPitCount;
@@ -1887,11 +1883,26 @@ class Room extends Model
}
} else {
// 第二页及以后:只显示麦下用户
// 偏移量计算:(页码-1)*每页数量 - 麦上用户数量
// 因为第一页包含了麦上用户,所以从第二页开始需要调整偏移量
$offset = ($page - 1) * $limit - $onPitCount;
// 添加这行代码确保偏移量不会为负数
$offset = max(0, $offset);
// 偏移量计算:对于第二页及以后,我们需要考虑第一页已经展示的麦下用户数量
// 第一页展示的麦下用户数量是 min(limit - onPitCount, totalOffPitCount)
// 所以从第二页开始的偏移量应该是 (page-2) * limit + (limit - onPitCount)
// 先查询所有符合条件的麦下用户总数
$totalOffPitCount = db::name('vs_room_visitor')->alias('a')
->join('user b', 'a.user_id = b.id')
->where(['a.room_id' => $room_id,'b.hide_status' => 0,'a.is_onpit' => 1])
->count();
// 计算偏移量
if ($page == 2) {
// 第二页的偏移量就是第一页展示的麦下用户数量
$offset = min($limit - $onPitCount, $totalOffPitCount);
} else {
// 第三页及以后需要考虑前面所有页已经展示的麦下用户
// 前面已经展示的麦下用户 = 第一页展示的 + (page-2) * limit
$firstPageOffPitCount = min($limit - $onPitCount, $totalOffPitCount);
$offset = $firstPageOffPitCount + ($page - 2) * $limit;
}
$offPitUser = db::name('vs_room_visitor')->alias('a')
->join('user b', 'a.user_id = b.id')