From 4a254d9f2883e221cee42cb743ec86291ede6d89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=8E=E6=B8=85?= <18691022700@163.com> Date: Sat, 3 Jan 2026 12:55:04 +0800 Subject: [PATCH] =?UTF-8?q?k=E6=AD=8C=E6=88=BF=20=20=E6=9C=89=E5=B7=B2?= =?UTF-8?q?=E7=82=B9=E6=AD=8C=E6=9B=B2=20=20=E4=BD=86=E6=98=AF=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E6=AD=A3=E5=9C=A8=E6=BC=94=E5=94=B1=E7=9A=84=E6=AD=8C?= =?UTF-8?q?=20=20=E7=BD=AE=E9=A1=B6=E8=A7=A3=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/model/RoomSong.php | 73 ++++++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 8 deletions(-) diff --git a/application/api/model/RoomSong.php b/application/api/model/RoomSong.php index ff9c936d..67053ddf 100644 --- a/application/api/model/RoomSong.php +++ b/application/api/model/RoomSong.php @@ -175,7 +175,7 @@ class RoomSong extends Model public function song($room_id,$user_id,$song_code,$song_name,$singer,$poster,$duration){ $action = 0;//初始值,1-申请点歌,2-切歌,3-下一首歌曲变化,4-拒绝申请点歌 //查询当前房间中的场次状态 - $times_status = db::name('vs_room_song')->where('room_id',$room_id)->field('times,times_status')->order('did desc')->find(); + $times_status = db::name('vs_room_song')->where('room_id',$room_id)->field('times,times_status')->order('sort desc')->find(); if(!empty($times_status)){//已经有歌曲 if($times_status['times_status'] == 2){//这一场次结束了 $data['sort'] = 10000;//排序,新场次第一首歌 @@ -261,13 +261,16 @@ class RoomSong extends Model //把这个信息存储到redis Cache::set("api:room:song:nextInfo:" . $room_id, $did); } - $text = [ - 'action' => $action, - 'total' => $total, - 'songInfo' => $nowInfo, - 'nextInfo' => $nextInfo - ]; - model('Chat')->sendMsg(1013,$room_id,$text); + if($action){ + $text = [ + 'action' => $action, + 'total' => $total, + 'songInfo' => $nowInfo, + 'nextInfo' => $nextInfo + ]; + model('Chat')->sendMsg(1013,$room_id,$text); + } + //1-禁麦位,2-清空消息,3-清空魅力值,4-加入黑名单,5-踢出房间,6-关闭麦克风,7-申请上麦,8-同意上麦,9-拒绝上麦,10-点歌,11-开启PK', model('Room')->room_operation_record($user_id,$room_id,10,0,0,$did); return ['code'=>1,'msg'=>'申请成功','data'=>null]; @@ -328,6 +331,7 @@ class RoomSong extends Model if($sort_up[0]['did'] == $room_song_id){ return ['code'=>0,'msg'=>'已经是第一首歌了','data'=>null]; } + if($type == 1){ //上移 foreach ($sort_up as $k=>$v){ if($v['did'] == $room_song_id){ @@ -347,8 +351,61 @@ class RoomSong extends Model if(!$res){ return ['code'=>0,'msg'=>'操作失败','data'=>null]; } + $data = db::name('vs_room_song')->where(['room_id' => $sort['room_id'],'status' => 1,'times' =>$sort['times'],'times_status' => 1]) ->order('sort desc')->select(); + + //查询当前是否有正在演唱的歌曲 + $now_room_song = db::name('vs_room_song') ->where('room_id',$sort['room_id']) + ->where('times',$sort['times']) + ->where('status',2) + ->find(); + if(empty($now_room_song)){ + $total = db::name('vs_room_song') + ->where(['room_id' => $sort['room_id'],'status' => 1,'times_status' => 1]) + ->count(); + $nowInfo = [ + 'did' => $data[0]['did'], + 'song_code' => $data[0]['song_code'], + 'song_name' => $data[0]['song_name'], + 'singer' => $data[0]['singer'], + 'poster' => $data[0]['poster'], + 'duration' => $data[0]['duration'], + 'user_id' => $data[0]['user_id'], + 'dress' => model('Decorate')->user_decorate_detail($data[0]['user_id'], 1), + 'nickname' => db::name('user')->where('id',$data[0]['user_id'])->value('nickname'), + 'avatar' => db::name('user')->where('id',$data[0]['user_id'])->value('avatar'), + 'charm' => db::name('vs_room_user_charm')->where(['user_id' => $data[0]['user_id'],'room_id' => $sort['room_id']])->value('charm'), + ]; + if(isset($data[1]['did'])){ + $nextInfo = [ + 'did' => $data[1]['did'], + 'song_code' => $data[1]['song_code'], + 'song_name' => $data[1]['song_name'], + 'singer' => $data[1]['singer'], + 'poster' => $data[1]['poster'], + 'duration' => $data[1]['duration'], + 'user_id' => $data[1]['user_id'], + 'dress' => model('Decorate')->user_decorate_detail($data[1]['user_id'], 1), + 'nickname' => db::name('user')->where('id',$data[1]['user_id'])->value('nickname'), + 'avatar' => db::name('user')->where('id',$data[1]['user_id'])->value('avatar'), + 'charm' => db::name('vs_room_user_charm')->where(['user_id' =>$data[1]['user_id'],'room_id' => $sort['room_id']])->value('charm'), + ]; + }else{ + $nextInfo = null; + } + + $text = [ + 'action' => 2, + 'total' => $total, + 'songInfo' => $nowInfo, + 'nextInfo' => $nextInfo + ]; + model('Chat')->sendMsg(1013,$sort['room_id'],$text); + Cache::set("api:room:song:nextInfo:" . $sort['room_id'],$data[0]['did']); + return ['code'=>1,'msg'=>'操作成功','data'=>$data]; + } + $did = Cache::get("api:room:song:nextInfo:" . $sort['room_id']); //歌曲移动后,下一首播放歌曲信息 发生改变 推送给前端 if($data[0]['did'] != $did){