From 9fbc544a85830d93fe65cf64b756f0886d399088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=8E=E6=B8=85?= <18691022700@163.com> Date: Tue, 9 Dec 2025 19:55:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=BF=E9=97=B4=E7=94=A8=E6=88=B7=E5=88=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/model/Room.php | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/application/api/model/Room.php b/application/api/model/Room.php index 731b9471..122e0796 100644 --- a/application/api/model/Room.php +++ b/application/api/model/Room.php @@ -1883,28 +1883,10 @@ class Room extends Model } } else { // 第二页及以后:只显示麦下用户 - // 偏移量计算:对于第二页及以后,我们需要考虑第一页已经展示的麦下用户数量 - // 第一页展示的麦下用户数量是 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; - } - - // 修复:确保偏移量不会为负数 + // 计算偏移量:总偏移量 = (页码-1) * 每页数量 - 麦上用户数量 + // 因为第一页包含了麦上用户,所以从第二页开始只需要麦下用户 + $offset = ($page - 1) * $limit - $onPitCount; + // 确保偏移量不会为负数 $offset = max(0, $offset); $offPitUser = db::name('vs_room_visitor')->alias('a')