房间用户列表

This commit is contained in:
2025-12-09 19:34:01 +08:00
parent dd8ec0d7df
commit 6edee924c7

View File

@@ -1800,9 +1800,8 @@ class Room extends Model
//房间在线列表
//房间在线列表
public function room_online_list($room_id, $page = 1, $limit = 5)
{
public function room_online_list($room_id, $page = 1, $limit = 5)
{
if (!$room_id) {
return ['code' => 0, 'msg' => '参数错误'];
}
@@ -1850,26 +1849,53 @@ public function room_online_list($room_id, $page = 1, $limit = 5)
// 计算麦下用户需要的数量
$onPitCount = count($lists['on_pit']);
$needOffPitCount = $limit - $onPitCount;
// 获取麦下用户(非隐身用户)
if ($needOffPitCount > 0) {
// 计算偏移量
$offset = ($page - 1) * $limit;
// 麦下用户分页逻辑:
// 1. 第一页显示部分麦下用户使得总数量为limit如果有足够的麦下用户
// 2. 后续页:只显示麦下用户,按照正常的分页逻辑
if ($page == 1) {
// 第一页需要补充到limit数量
$actualOffset = 0;
} else {
// 其他页需要考虑麦上用户占用的位置
// 麦上用户只在第一页显示,所以其他页的偏移量需要减去第一页麦上用户的数量
$actualOffset = ($page - 1) * $limit - $onPitCount;
// 第一页需要的麦下用户数量 = limit - 麦上用户数量
$needOffPitCount = $limit - $onPitCount;
if ($needOffPitCount > 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]) // 非隐身且未上麦
->limit(0, $needOffPitCount)
->select();
if(!empty($offPitUser)){
foreach ($offPitUser as &$v) {
$v['icon'][0] = model('UserData')->user_wealth_icon($v['user_id']);//财富图标
$v['icon'][1] = model('UserData')->user_charm_icon($v['user_id']);//魅力图标
//判断是否是歌手 如果是 返回等级图标
$isSinnger = db::name('vs_singer')->where(['user_id' => $v['user_id'], 'status' => 1])->value('level');
if ($isSinnger) {
$v['icon'][2] = db::name('vs_singer_level')->where(['level' => $isSinnger, 'deletetime' => 0])->value('image');//等级图标
}
//用户的角色
$role = $this->get_user_role($v['user_id'], $room_id);
$v['role'] = $role['role'];
$v['pit_number'] = $role['pit_number'];
}
unset($v); // 释放引用
$lists['off_pit'] = $offPitUser;
}
}
} else {
// 第二页及以后:只显示麦下用户
// 偏移量计算:(页码-1)*每页数量 - 麦上用户数量
// 因为第一页包含了麦上用户,所以从第二页开始需要调整偏移量
$offset = ($page - 1) * $limit - $onPitCount;
$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]) // 非隐身且未上麦
->limit($actualOffset, $needOffPitCount)
->limit($offset, $limit)
->select();
if(!empty($offPitUser)){
@@ -1913,8 +1939,7 @@ public function room_online_list($room_id, $page = 1, $limit = 5)
}
return ['code' => 1, 'msg' => '成功', 'data' => $lists];
}
}