房间用户列表
This commit is contained in:
@@ -1799,6 +1799,7 @@ class Room extends Model
|
||||
}
|
||||
|
||||
|
||||
//房间在线列表
|
||||
//房间在线列表
|
||||
public function room_online_list($room_id, $page = 1, $limit = 5)
|
||||
{
|
||||
@@ -1808,7 +1809,6 @@ class Room extends Model
|
||||
|
||||
$lists['on_pit'] = [];
|
||||
$lists['off_pit'] = [];
|
||||
$count = 0;
|
||||
|
||||
// 修改count计算逻辑:在麦上的用户即使隐身也要计算在内
|
||||
$lists['count'] = db::name('vs_room_visitor')->alias('a')
|
||||
@@ -1822,6 +1822,7 @@ class Room extends Model
|
||||
})
|
||||
->count();
|
||||
|
||||
// 第一页特殊处理,显示麦上用户
|
||||
if ($page == 1) {
|
||||
$onPitUser = db::name('vs_room_visitor')->alias('a')
|
||||
->join('user b', 'a.user_id = b.id')
|
||||
@@ -1847,17 +1848,28 @@ class Room extends Model
|
||||
}
|
||||
}
|
||||
|
||||
// 计算还需要多少个未上麦的用户来填满页面
|
||||
$pg = $limit - count($lists['on_pit']);
|
||||
// 计算麦下用户需要的数量
|
||||
$onPitCount = count($lists['on_pit']);
|
||||
$needOffPitCount = $limit - $onPitCount;
|
||||
|
||||
// 获取麦下用户(非隐身用户)
|
||||
if ($needOffPitCount > 0) {
|
||||
// 计算偏移量
|
||||
$offset = ($page - 1) * $limit;
|
||||
if ($page == 1) {
|
||||
// 第一页只需要补充到limit数量
|
||||
$actualOffset = 0;
|
||||
} else {
|
||||
// 其他页需要考虑麦上用户占用的位置
|
||||
// 麦上用户只在第一页显示,所以其他页的偏移量需要减去第一页麦上用户的数量
|
||||
$actualOffset = ($page - 1) * $limit - $onPitCount;
|
||||
}
|
||||
|
||||
// 正确处理分页逻辑,确保第二页及以后的数据完整性
|
||||
if($pg > 0){
|
||||
// 获取未上麦的用户(非隐身用户)
|
||||
$offPitUser = db::name('vs_room_visitor')->alias('a')
|
||||
->join('user b', 'a.user_id = b.id')
|
||||
->field('a.user_id,b.nickname,b.avatar,b.hide_status,a.is_onpit')
|
||||
->where(['a.room_id' => $room_id,'b.hide_status' => 0,'a.is_onpit' => 1]) // 非隐身且未上麦
|
||||
->page($page, $pg)
|
||||
->limit($actualOffset, $needOffPitCount)
|
||||
->select();
|
||||
|
||||
if(!empty($offPitUser)){
|
||||
@@ -1905,6 +1917,7 @@ class Room extends Model
|
||||
|
||||
|
||||
|
||||
|
||||
//用户在房间内的角色
|
||||
public function get_user_role($user_id, $room_id)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user