diff --git a/application/api/controller/SingerSong.php b/application/api/controller/SingerSong.php index 58fcf79..4d6a9da 100644 --- a/application/api/controller/SingerSong.php +++ b/application/api/controller/SingerSong.php @@ -161,4 +161,17 @@ class SingerSong extends BaseCom } + //切歌 + public function singerSongCut() + { + $id = input('id', 0);//点歌列表的ID + if (!$id) { + return V(0, '请选择要切的歌曲列表ID'); + } + + $reslut = model('SingerSong')->singerSongCut($this->uid, $id); + return V($reslut['code'], $reslut['msg'], $reslut['data']); + } + + } \ No newline at end of file diff --git a/application/api/model/SingerSong.php b/application/api/model/SingerSong.php index 0b560f4..130a9c8 100644 --- a/application/api/model/SingerSong.php +++ b/application/api/model/SingerSong.php @@ -274,4 +274,49 @@ class SingerSong extends Model } return true; } + + + /* + * 切歌 + * @param room_id 房间id + * @param user_id 用户id + * @param song_id 歌曲id + */ + public function singerSongCut($user_id,$song_id) + { + $sonng_log = db::name('vs_song_log')->where(['id' => $song_id])->find(); + $singer_user_id = db::name('vs_singer_song')->where(['id' => $sonng_log['singer_song_id']])->value('user_id'); + //判断用户是否是房主 + $room_info = db::name('vs_room')->where('id', $sonng_log['room_id'])->field('user_id')->find(); + //判断用户是否是主持 + $room_user_info = db::name('vs_room_host')->where(['room_id' => $sonng_log['room_id'], 'user_id' => $user_id,'delete_time' => null])->find(); + if ($room_info['user_id'] != $user_id && !$room_user_info && $singer_user_id != $user_id) { + return ['code' => 0, 'msg' => '您没有权限切歌','data' => null]; + } + if ($sonng_log) { + if ($sonng_log['status'] == 1) { + $up = db::name('vs_song_log')->where(['id' => $song_id])->update(['status' => 2]); + if ($up) { + $id = db::name('vs_song_log')->where(['room_id' => $sonng_log['room_id'],'status' => 0])->order('sort desc')->value('id'); + if($id){ + db::name('vs_song_log')->where(['id' => $id])->update(['status' => 1]); + //给前端推送 + $text = [ + 'text' => '切歌', + 'id' => $id, + ]; + //聊天室推送系统消息 + model('Chat')->sendMsg(1072,$sonng_log['room_id'],$text); + }else{ + return ['code' => 0, 'msg' => '暂无歌曲,请点歌吧','data' => null]; + } + }else{ + return ['code' => 0, 'msg' => '切歌失败','data' => null]; + } + } + }else{ + return ['code' => 0, 'msg' => '网络错误','data' => null]; + } + return ['code' => 1, 'msg' => '切歌成功','data' => null]; + } } \ No newline at end of file