重连后房间处理

This commit is contained in:
2025-09-28 19:32:13 +08:00
parent 61a9478bf3
commit 46b7afda8a

View File

@@ -2530,22 +2530,31 @@ class Room extends Model
}
//查询用户在几个房间
$room = db::name('vs_room_visitor')->where('user_id', $user_id)->select();
$room_list = [];
foreach ($room as $v){
$room_list[] = $v['room_id'];
}
$count = count($room_list);
if($count <= 1 && $room_id == $room_list[0]){
if($room){
$room_list = [];
foreach ($room as $v){
$room_list[] = $v['room_id'];
}
$count = count($room_list);
if($count == 1 && $room_id == $room_list[0]){
$room_info = db::name('vs_room_visitor')->where(['id' => $room[0]['id']])->update(['room_id' => $room_id, 'user_id' => $user_id, 'updatetime' => time(),'remarks' =>'断线后重连']);
if(!$room_info){
return ['code' => 0, 'msg' => '更新加入房间失败', 'data' => null];
}
}elseif ($count > 1)
{
//退出除过最后一个房间
for ($i = 0; $i < $count - 1; $i++){
db::name('vs_room_visitor')->where('user_id', $user_id)->where('room_id', $room_list[$i])->delete();
}
}
}else{
$room_info = db::name('vs_room_visitor')->insert(['room_id' => $room_id, 'user_id' => $user_id, 'createtime' => time(),'remarks' =>'断线后重连']);
if(!$room_info){
return ['code' => 0, 'msg' => '加入房间失败', 'data' => null];
}
}else{
//退出除过最后一个房间
for ($i = 0; $i < $count - 1; $i++){
db::name('vs_room_visitor')->where('user_id', $user_id)->where('room_id', $room_list[$i])->delete();
}
}
return ['code' => 1, 'msg' => '操作成功', 'data' => null];
}