Files
midi-php/application/api/model/RoomPit.php

931 lines
45 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\api\model;
use app\common\controller\Push;
use think\Cache;
use think\Db;
use think\Model;
class RoomPit extends Model
{
protected $table = 'fa_vs_room_pit';
//创建房间麦位
public function create_room_pit($type,$room_id)
{
if($type == 2){ //K歌
$pitnumber = 22;
$ii = 11;
}else{
$pitnumber = 10;
$ii = 1;
}
for ($i = $ii; $i <= $pitnumber; $i++){
$data[] = [
'room_id' => $room_id,
'user_id' => 0,
'pit_number' => $i,
];
}
$reslut = $this->saveAll($data);
if(!$reslut){
return ['code' => 0, 'msg' => '创建失败', 'data' => null];
}
return ['code' => 1, 'msg' => '创建成功', 'data' => null];
}
//获取房间所有的空麦位剔除一部分
public function getRoomNullPitWithout($room_id, $not_in_pits) {
$where['room_id'] = $room_id;
$where['user_id'] = 0;
$where['is_mute'] = 0;
$where['is_lock'] = 0;
if ($not_in_pits) {
$where['pit_number'] = ['not in', $not_in_pits];
}
return db::name('vs_room_pit')->where($where)->order('pit_number asc')->value('pit_number');
}
//用户上麦
public function OnPit($user_id,$room_id,$pit_number)
{
$on = $this->where(['room_id' => $room_id, 'pit_number' => $pit_number])->update(['user_id' => $user_id]);
if(!$on){
return ['code' => 0, 'msg' => '上麦失败', 'data' => null];
}
// $nickname = model('User')->where(['id' => $user_id])->value('nickname');
$FromUserInfo = db::name('user')->where('id',$user_id)->field('id as user_id,nickname,avatar,sex')->find();
$FromUserInfo['icon'][0] = model('UserData')->user_wealth_icon($user_id);//财富图标
$FromUserInfo['icon'][1] = model('UserData')->user_charm_icon($user_id);//魅力图标
$FromUserInfo['dress'] = model('Decorate')->user_decorate_detail($user_id,1);
$FromUserInfo['charm'] = db::name('vs_room_user_charm')->where(['user_id' => $user_id,'room_id' => $room_id])->value('charm');
//推送告诉前端上了几号麦位
if($pit_number == 9){
$pit_text = '主持麦';
//查询房间是否隐藏
$is_hide = db::name('vs_room')->where(['id' => $room_id])->value('is_show_room');
if($is_hide == 2){
db::name('vs_room')->where(['id' => $room_id])->update(['is_show_room' => 1]);
}
}elseif ($pit_number == 10) {
$pit_text = '嘉宾麦';
}else{
$pit_text = $pit_number . '号麦';
}
$text['text'] = $FromUserInfo['nickname'].' 上了 ' . $pit_text;
$text['FromUserInfo'] = $FromUserInfo;
$text['pit_number'] = $pit_number;
//聊天室推送系统消息
model('Chat')->sendMsg(1003,$room_id,$text);
if($pit_number == 9){
//推送消息给设置此用户开播提醒的人
$remind_users = db::name('vs_user_live_remind')->where('remind_user_id' , $user_id)->select('user_id');
$remind_user = [];
foreach ($remind_users as $k=>$v){
$remind_user[$k] = 'u'.$v['user_id'];
if($k >= 499){ //批量发单聊消息 最大数500个
//结束整个循环
break;
}
}
$content = [
'type' => 1,
'roomID' => $room_id,
'content' => '您关注的用户' . $FromUserInfo['nickname'] . '正在直播,快去围观吧!',
];
model('Tencent')->batchsendmsg($remind_user,json_encode($content));
}
return ['code' => 1, 'msg' => '上麦成功', 'data' => null];
}
//用户下麦
public function DownPit($user_id,$room_id,$pit_number)
{
if(!$pit_number){
$pit_number = db::name('vs_room_pit')->where(['room_id' => $room_id, 'user_id' => $user_id])->value('pit_number');
if(!$pit_number){
return ['code' => 0, 'msg' => '该用户已不在'.$pit_number.'麦', 'data' => null];
}
}
$where['room_id'] = $room_id;
$where['pit_number'] = $pit_number;
$where['user_id'] = $user_id;
$accept_pit_info = db::name('vs_room_pit')->where($where)->find();
if(!$accept_pit_info){
return ['code' => 0, 'msg' => '该用户已不在'.$pit_number.'麦', 'data' => null];
}
//判断当前房间是否正在pk
$is_pk = db::name('vs_room_pk')->where(['room_id_a' => $room_id])->where(['status' => ['in',[2,3,4]]])->value('room_id_b') ?? 0;
if(!$is_pk){
$is_pk = db::name('vs_room_pk')->where(['room_id_b' => $room_id])->where(['status' => ['in',[2,3,4]]])->value('room_id_a') ?? 0;
}
if($is_pk > 0 && $pit_number == 9){
return ['code' => 0, 'msg' => '当前房间正在pk中', 'data' => null];
}
$step = db::name('vs_room')->where(['id' => $room_id, 'type_id' => 7])->value('step');
if($step && $step != 1 && $pit_number <= 9){
return ['code' => 0, 'msg' => '交友房 此阶段不可操作', 'data' => null];
}
$FromUserInfo = db::name('user')->where('id',$user_id)->field('id as user_id,nickname,avatar,sex')->find();
$FromUserInfo['icon'][0] = model('UserData')->user_wealth_icon($user_id);//财富图标
$FromUserInfo['icon'][1] = model('UserData')->user_charm_icon($user_id);//魅力图标
if($pit_number == 888){
$text['text'] = $FromUserInfo['nickname'].' 下了拍卖位 ';
$text['type'] = 2 ;
}else{
if($pit_number <= 0){
$pit_number = db::name('vs_room_pit')->where(['room_id' => $room_id, 'user_id' => $user_id])->value('pit_number');
}
$down = $this->where(['room_id' => $room_id, 'user_id' => $user_id])->update(['user_id' => 0]);
if(!$down){
return ['code' => 0, 'msg' => '下麦失败', 'data' => null];
}
if($pit_number == 9){
$pit_text = '主持麦';
}elseif ($pit_number == 10) {
$pit_text = '嘉宾麦';
}else{
$pit_text = $pit_number . '号麦';
}
$text['text'] = $FromUserInfo['nickname'].' 下了 ' . $pit_text;
}
//推送告诉前端下了几号麦位
$text['FromUserInfo'] = $FromUserInfo;
$text['pit_number'] = $pit_number;
if($pit_number == 888){
model('Chat')->sendMsg(1022,$room_id,$text);
}else{
model('Chat')->sendMsg(1004,$room_id,$text);
}
return ['code' => 1, 'msg' => '下麦成功', 'data' => null];
}
//申请上麦
public function apply_pit($user_id,$room_id,$pit_number = 0)
{
if($room_id <= 0){
return ['code' => 0, 'msg' => '请选择房间', 'data' => null];
}
//查询房间状态
$room_info = db::name('vs_room')->where(['id' => $room_id, 'apply_status' => 2])->field('id,room_status,room_up_pit_type,label_id,step')->find();
if(!$room_info){
return ['code' => 0, 'msg' => '房间不存在', 'data' => null];
}
if($room_info['room_status'] != 1){
return ['code' => 0, 'msg' => '房间违规或关闭', 'data' => null];
}
if($pit_number == 10){
return ['code' => 0, 'msg' => '请等待主持抱麦', 'data' => null];
}
//检查是否在坑位上
$pit_infos = db::name('vs_room_pit')->where(['room_id' => $room_id, 'user_id' => $user_id])->field('id,pit_number')->find();
if($pit_infos){
return ['code' => 0, 'msg' => '您已上麦', 'data' => null];
}
if($room_info['label_id'] == 5 && $room_info['step'] != 1 && $pit_number < 9){
return ['code' => 0, 'msg' => '交友房 此阶段不可操作', 'data' => null];
}
//自由麦
if($room_info['room_up_pit_type'] == 2){
if($pit_number > 0){
if($room_info['label_id'] == 5){//交友
if($pit_number == 7 || $pit_number == 8){
return ['code' => 0, 'msg' => '该麦位已锁定了', 'data' => null];
}
}
//查询当前麦位是否有人
$pit_info = db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => $pit_number])->field('id,user_id,is_lock')->find();
if($pit_info['user_id'] > 0){
return ['code' => 0, 'msg' => '该麦位有人', 'data' => null];
}
//当前麦位是否正常
if($pit_info['is_lock'] == 1){
return ['code' => 0, 'msg' => '该麦位被锁定', 'data' => null];
}
if($pit_number ==9){
//检查用户是否是房主或主持
$is_room_owner =db::name('vs_room')->where(['id' => $room_id, 'user_id' => $user_id])->field('id')->find();
$is_room_host = db::name('vs_room_host')->where(['room_id' => $room_id, 'user_id' => $user_id,'delete_time' => null])->field('id')->find();
if(!$is_room_owner && !$is_room_host){
return ['code' => 0, 'msg' => '您还不是房间主持人', 'data' => null];
}
}
}else{
if($room_info['label_id'] == 5){//交友
$pit_number = $this->getRoomNullPitWithout($room_id, [7,8,9,10]);
}else{
$pit_number = $this->getRoomNullPitWithout($room_id, [9, 10]);
}
if(!$pit_number){
return ['code' => 0, 'msg' => '当前房间没有空麦位', 'data' => null];
}
}
//换麦使用
if(isset($pit_infos) && $pit_infos['pit_number'] > 0){
//下麦
$dow = $this ->DownPit($user_id,$room_id,$pit_infos['pit_number']);
if($dow['code'] != 1){
return ['code' => 0, 'msg' => '操作失败', 'data' => null];
}
}
$ompit = $this->OnPit($user_id,$room_id,$pit_number);//用户上了这个房间的几号麦位
if($ompit['code'] != 1){
return ['code' => 0, 'msg' => '上麦失败', 'data' => null];
}
return ['code' => 1, 'msg' => '上麦成功', 'data' => null];
}else{
if($pit_number == 9){
//检查用户是否是房主或主持
$is_room_owner = db::name('vs_room')->where(['id' => $room_id, 'user_id' => $user_id])->field('id')->find();
$is_room_host = db::name('vs_room_host')->where(['room_id' => $room_id, 'user_id' => $user_id,'delete_time' => null])->field('id')->find();
//查看主持坑9坑
$host_pit = $this->where(['room_id' => $room_id, 'pit_number' => 9])->value('user_id');
if(($is_room_owner || $is_room_host) && $host_pit == 0){
//查询用户是否在麦位上
$is_on = $this->where(['room_id' => $room_id, 'user_id' => $user_id])->value('pit_number');
if($is_on){
//下麦
$dow = $this ->DownPit($user_id,$room_id,$is_on);
if($dow['code'] != 1){
return ['code' => 0, 'msg' => '操作失败', 'data' => null];
}
}
//直接上主持麦
$ont = $this->OnPit($user_id,$room_id,9);//用户上了这个房间的几号麦位
if($ont['code'] != 1){
return ['code' => 0, 'msg' => '上麦失败', 'data' => null];
}
//查找是否在申请列表里
$apply_pit = db::name('vs_room_pit_apply')->where(['room_id' => $room_id, 'user_id' => $user_id])->find();
if($apply_pit){
$this->clear_apply_pit_list($user_id, $room_id, $user_id);
// db::name('vs_room_pit_apply')->where(['room_id' => $room_id, 'user_id' => $user_id])->delete();
// $count = db::name('vs_room_pit_apply')->where(['room_id' => $room_id,'status' => 0])->count();
// //申请上麦推送消息
// $text = [
// 'text' => '申请上麦',
// 'count' => $count
// ];
// model('Chat')->sendMsg(1034,$room_id,$text);
}
return ['code' => 1, 'msg' => '上麦成功', 'data' => null];
}
}
//检查用户是否已经申请
$apply_pit_info = db::name('vs_room_pit_apply')->where(['room_id' => $room_id, 'user_id' => $user_id,'apply_type' =>1])->field('id')->find();
if($apply_pit_info){
return ['code' => 0, 'msg' => '请勿重复申请', 'data' => null];
}
if(isset($pit_infos) && $pit_infos['pit_number'] > 0){
return ['code' => 0, 'msg' => '用户已在麦上,请先下麦后再申请', 'data' => null];
}
//放入等待区
$data = [
'room_id' => $room_id,
'user_id' => $user_id,
'status' => 0,
'apply_type' => 1
];
$reslut = db::name('vs_room_pit_apply')->insert($data);
if(!$reslut){
return ['code' => 0, 'msg' => '申请失败', 'data' => null];
}
$count = db::name('vs_room_pit_apply')->where(['room_id' => $room_id,'status' => 0])->count();
//申请上麦推送消息
$text = [
'text' => '申请上麦',
'count' => $count
];
model('Chat')->sendMsg(1034,$room_id,$text);
return ['code' => 1, 'msg' => '申请成功,请等待房主审核', 'data' => null];
}
}
//申请上麦列表
public function apply_pit_list($userId,$room_id)
{
if(!$room_id){
return ['code' => 0, 'msg' => '请选择房间', 'data' => null];
}
$where = [
'a.room_id' => $room_id,
'a.status' => 0,
];
// $res = model('Room')->get_room_label($room_id);
// $room_label = $res['data']['label_id'];
// $room_type = $res['data']['type_id'];
// if($room_label == 1 && ($room_type == 1 || $room_type == 3 || $room_type == 4)){
// $where['a.apply_type'] = 1;
// }elseif ($room_label == 2 && ($room_type == 1 || $room_type == 3 || $room_type == 4)){
// $where['a.apply_type'] = 2;
// }
$list['regular'] = db::name('vs_room_pit_apply')->alias('a')->join('user b','a.user_id = b.id')
->where($where)->where('a.type',0)->field('a.user_id,a.rank_value,b.nickname,b.avatar')
->order('a.rank_value desc')->select();
$list['special'] = db::name('vs_room_pit_apply')->alias('a')->join('user b','a.user_id = b.id')
->where($where)->where('a.type',1)->field('a.user_id,a.rank_value,b.nickname,b.avatar')
->order('a.rank_value desc')->select();
$list['gift_info'] = db::name('vs_room_pit_apply_help_gift')->where('room_id',$room_id)->find();
if($list['gift_info']){
$list['gift_info']['gift_name'] = db::name('vs_gift')->where('gid',$list['gift_info']['gift_id'])->value('gift_name');
$list['gift_info']['base_image'] = db::name('vs_gift')->where('gid',$list['gift_info']['gift_id'])->value('base_image');
}
return ['code' => 1, 'msg' => '获取成功', 'data' => $list];
}
//上麦助力
public function help_apply_pit($user_id,$room_id,$apply_id)
{
if(!$room_id){
return ['code' => 0, 'msg' => '请选择房间', 'data' => null];
}
if(!$apply_id){
return ['code' => 0, 'msg' => '请选择助力用户', 'data' => null];
}
//查询当前房间设置的助力;礼物
$gift_info = db::name('vs_room_pit_apply_help_gift')->where(['room_id' => $room_id])->field('id,gift_id,gift_price')->find();
if(!$gift_info){
return ['code' => 0, 'msg' => '当前房间没有设置助力礼物', 'data' => null];
}
// $res = model('Room')->get_room_label($room_id);
// $room_label = $res['data']['label_id'];
// $room_type = $res['data']['type_id'];
// if($room_label == 1 && ($room_type == 1 || $room_type == 3 || $room_type == 4)){
// $apply_type = 1;
// }elseif ($room_label == 2 && ($room_type == 1 || $room_type == 3 || $room_type == 4)){
// $apply_type = 2;
// }
//助力
$data = [
'user_id' => $user_id,
'help_user_id' => $apply_id,
'room_id' => $room_id,
'rank_value' => $gift_info['gift_price'],
// 'apply_type' => $apply_type,
'createtime'=> time(),
];
//开启事务
db::startTrans();
$reslut = db::name('vs_room_pit_apply_help')->insert($data);
if(!$reslut){
db::rollback();
return ['code' => 0, 'msg' => '助力失败!', 'data' => null];
}
$apply_user = db::name('vs_room_pit_apply')->where(['room_id' => $room_id,'user_id'=>$apply_id,'status'=>0])->find();
if(!$apply_user){
db::rollback();
return ['code' => 0, 'msg' => '用户已上麦或退出', 'data' => null];
}
$apply_data = [
'type' => 1,
'updatetime'=> time(),
'rank_value'=>$apply_user['rank_value']+$gift_info['gift_price'],
];
$reslut = db::name('vs_room_pit_apply')->where(['id' => $apply_user['id']])->update($apply_data);
if(!$reslut){
db::rollback();
return ['code' => 0, 'msg' => '助力失败,', 'data' => null];
}
//当前房间主持人麦位是谁
$room_host_id = db::name('vs_room_pit')->where(['room_id' => $room_id,'pit_number' => 9])->value('user_id');
if($room_host_id == 0){
$room_host_id = db::name('vs_room')->where(['id' => $room_id])->value('user_id');
}
//走送礼流程(用户,在房间中,给谁(插队上麦给当前主持人),送了什么礼物,多少个)
$give_gift = model('GiveGift')->give_gift($user_id,$room_host_id,$gift_info['gift_id'],1,2,1,$room_id,9);
if($give_gift['code'] != 1){
db::rollback();
return ['code' => 0, 'msg' => $give_gift['msg'].'助力失败。', 'data' => null];
}
db::commit();
$data = $this -> apply_pit_list($user_id,$room_id);
return ['code' => 1, 'msg' => '助力成功', 'data' => $data['data']];
}
//同意上麦
public function agree_pit($user_id,$room_id,$apply_id)
{
if(!$room_id){
return ['code' => 0, 'msg' => '请选择房间', 'data' => null];
}
if(!$apply_id){
return ['code' => 0, 'msg' => '请选择申请用户', 'data' => null];
}
$res = model('Room')->get_room_label($room_id);
$room_label = $res['data']['label_id'];
$room_type = $res['data']['type_id'];
if($room_label == 1 && ($room_type == 1 || $room_type == 3 || $room_type == 4)){
$apply_type = 1;//聊天
}elseif ($room_label == 2 && ($room_type == 1 || $room_type == 3 || $room_type == 4)){
$apply_type = 2;//K歌
}elseif($room_type == 2){
$apply_type = 3;//拍卖
}elseif($room_type == 7){
$apply_type = 7;//交友
}else{
$apply_type = 1;//聊天
}
// if($apply_type == 1){
// //判断当前用户是否是房主或在主持麦位上的主持
// $is_room_owner = model('Room')->where(['id' => $room_id, 'user_id' => $user_id])->field('id')->find();
// $is_room_host = db::name('vs_room_pit')->where(['room_id' => $room_id, 'user_id' => $user_id,'pit_number' => 9])->field('id')->find();
// if(!$is_room_owner && !$is_room_host){
// return ['code' => 0, 'msg' => '您不是房主 或 不在主持位,没有权限操作', 'data' => null];
// }
// }else{
// $is_room_host = db::name('vs_room_pit')->where(['room_id' => $room_id, 'user_id' => $user_id,'pit_number' => 9])->field('id')->find();
// if(!$is_room_host){
// return ['code' => 0, 'msg' => '您不在主持位,没有权限操作', 'data' => null];
// }
// }
$to_user = explode(',',$apply_id);
if(count($to_user) >= 1){
if($apply_type == 1) {
$i = 0;
foreach ($to_user as &$value) {
//查询当前空麦位
$empty_pit = $this->getRoomNullPitWithout($room_id, [9, 10]);
if (!$empty_pit) {
//退出循环 并终止循环
break;
}
//查询是否已经上麦
$is_on_pit = db::name('vs_room_pit')->where(['room_id' => $room_id, 'user_id' => $value])->field('id')->find();
if ($is_on_pit) {
continue;
}
//删除他的申请上麦
$reslut = db::name('vs_room_pit_apply')->where(['user_id' => $value, 'room_id' => $room_id, 'status' => 0,'apply_type' => 1])->delete();
if (!$reslut) {
continue;
}
$on = $this->OnPit($value, $room_id, $empty_pit);//用户上了这个房间的几号麦位
if ($on['code'] != 1) {
continue;
}
$i++;
//1-禁麦位2-清空消息3-清空魅力值4-加入黑名单5-踢出房间6-关闭麦克风7-申请上麦8-同意上麦9-拒绝上麦10-点歌11-开启PK',
model('Room')->room_operation_record($user_id,$room_id,8,$value,$empty_pit);
}
$count = db::name('vs_room_pit_apply')->where(['room_id' => $room_id,'status' => 0])->count();
//申请上麦推送消息(数据重置)
$text = [
'text' => '申请上麦',
'count' => $count
];
model('Chat')->sendMsg(1034,$room_id,$text);
return ['code' => 1, 'msg' => $i . '位用户上麦成功', 'data' => null];
}elseif($apply_type == 2){
if(db::name('vs_room_pit_simulate')->where(['room_id' => $room_id])->count() >= 20){
return ['code' => 0, 'msg' => '暂无空麦位', 'data' => null];
}
foreach ($to_user as &$value) {
if(db::name('vs_room_pit_simulate')->where(['room_id' => $room_id])->count() >= 20){
//结束循环
break;
}
//删除他的申请上麦
$reslut = db::name('vs_room_pit_apply')->where(['user_id' => $value, 'room_id' => $room_id, 'status' => 0,'apply_type' => 2])->delete();
if (!$reslut) {
continue;
}
$ompit = db::name('vs_room_pit_simulate')->insert(
[
'room_id' => $room_id,
'user_id' => $value,
'status' => 1,//1-K歌模式虚假上麦
]
);//用户上了这个房间的麦位
if (!$ompit) {
continue;
}
//聊天室推送系统消息
$FromUserInfo = db::name('user')->where('id',$value)->field('id as user_id,nickname,avatar,sex')->find();
$FromUserInfo['icon'][0] = model('UserData')->user_wealth_icon($value);//财富图标
$FromUserInfo['icon'][1] = model('UserData')->user_charm_icon($value);//魅力图标
$FromUserInfo['dress'] = model('Decorate')->user_decorate_detail($value,1);
$text['text'] = $FromUserInfo['nickname'].' 上麦了 ';
$text['FromUserInfo'] = $FromUserInfo;
$text['pit_number'] = 9999;
model('Chat')->sendMsg(1003,$room_id,$text);
//1-禁麦位2-清空消息3-清空魅力值4-加入黑名单5-踢出房间6-关闭麦克风7-申请上麦8-同意上麦9-拒绝上麦10-点歌11-开启PK',
model('Room')->room_operation_record($user_id,$room_id,8,$value);
}
$count = db::name('vs_room_pit_apply')->where(['room_id' => $room_id,'status' => 0])->count();
//申请上麦推送消息
$text = [
'text' => '申请上麦',
'count' => $count
];
model('Chat')->sendMsg(1034,$room_id,$text);
return ['code' => 1, 'msg' => '上麦成功', 'data' => null];
}elseif($apply_type == 3){
if(count($to_user) >= 2){
return ['code' => 0, 'msg' => '拍卖模式下只能一个人上麦', 'data' => null];
}
//拍卖房当前到哪一步了
$step = db::name('vs_room_auction')->where(['room_id' => $room_id])->order('auction_id desc')->value('status');
if($step == 2){
return ['code' => 0, 'msg' => '拍卖已经开始', 'data' => null];
}
//拍卖位上有人吗
$paimai_user = Cache::get('auction_user_'.$room_id);
if($paimai_user){
//有人就让他下麦
return ['code' => 0, 'msg' => '拍卖位上已有人,请先抱对方下麦', 'data' => null];
}
$i = 0;
foreach ($to_user as &$value) {
$i++;
//删除他的申请上麦
$reslut = db::name('vs_room_pit_apply')->where(['user_id' => $value, 'room_id' => $room_id, 'status' => 0])->delete();
if (!$reslut) {
continue;
}
//聊天室推送系统消息
$FromUserInfo = db::name('user')->where('id',$value)->field('id as user_id,nickname,avatar,sex')->find();
$FromUserInfo['icon'][0] = model('UserData')->user_wealth_icon($value);//财富图标
$FromUserInfo['icon'][1] = model('UserData')->user_charm_icon($value);//魅力图标
$FromUserInfo['dress'] = model('Decorate')->user_decorate_detail($value,1);
$text['text'] = $FromUserInfo['nickname'].' 上了拍卖位 ';
$text['FromUserInfo'] = $FromUserInfo;
$text['pit_number'] = 888;
$text['type'] = 1 ;
model('Chat')->sendMsg(1022,$room_id,$text);
Cache::set('auction_user_'.$room_id,$value);
//1-禁麦位2-清空消息3-清空魅力值4-加入黑名单5-踢出房间6-关闭麦克风7-申请上麦8-同意上麦9-拒绝上麦10-点歌11-开启PK',
model('Room')->room_operation_record($user_id,$room_id,8,$value);
if($i >= 1){
break;
}
}
$count = db::name('vs_room_pit_apply')->where(['room_id' => $room_id,'status' => 0])->count();
//申请上麦推送消息
$text = [
'text' => '申请上麦',
'count' => $count
];
model('Chat')->sendMsg(1034,$room_id,$text);
return ['code' => 1, 'msg' => '上麦成功', 'data' => null];
}elseif($apply_type == 7) {
$i = 0;
foreach ($to_user as &$value) {
//查询当前空麦位
$empty_pit = $this->getRoomNullPitWithout($room_id, [7,8,9,10]);
if (!$empty_pit) {
//退出循环 并终止循环
break;
}
//查询是否已经上麦
$is_on_pit = db::name('vs_room_pit')->where(['room_id' => $room_id, 'user_id' => $value])->field('id')->find();
if ($is_on_pit) {
continue;
}
//删除他的申请上麦
$reslut = db::name('vs_room_pit_apply')->where(['user_id' => $value, 'room_id' => $room_id, 'status' => 0,'apply_type' => 1])->delete();
if (!$reslut) {
continue;
}
$on = $this->OnPit($value, $room_id, $empty_pit);//用户上了这个房间的几号麦位
if ($on['code'] != 1) {
continue;
}
$i++;
//1-禁麦位2-清空消息3-清空魅力值4-加入黑名单5-踢出房间6-关闭麦克风7-申请上麦8-同意上麦9-拒绝上麦10-点歌11-开启PK',
model('Room')->room_operation_record($user_id,$room_id,8,$value,$empty_pit);
}
$count = db::name('vs_room_pit_apply')->where(['room_id' => $room_id,'status' => 0])->count();
//申请上麦推送消息(数据重置)
$text = [
'text' => '申请上麦',
'count' => $count
];
model('Chat')->sendMsg(1034,$room_id,$text);
return ['code' => 1, 'msg' => $i . '位用户上麦成功', 'data' => null];
}
}
return ['code' => 0, 'msg' => '请选择申请上麦的用户', 'data' => null];
}
//清空上麦申请
public function clear_apply_pit_list($userId,$room_id,$apply_id = 0)
{
if(!$room_id){
return ['code' => 0, 'msg' => '请选择房间', 'data' => null];
}
//判断当前用户是否是房主或主持
$is_room_owner = model('Room')->where(['id' => $room_id, 'user_id' => $userId])->field('id')->find();
$is_room_host = db::name('vs_room_pit')->where(['room_id' => $room_id, 'user_id' => $userId,'pit_number' => 9])->field('id')->find();
if(!$is_room_owner && !$is_room_host){
return ['code' => 0, 'msg' => '您不是房主 或 不在主持麦,没有权限操作', 'data' => null];
}
// $res = model('Room')->get_room_label($room_id);
// $room_label = $res['data']['label_id'];
// $room_type = $res['data']['type_id'];
// if($room_label == 1 && ($room_type == 1 || $room_type == 3 || $room_type == 4)){
// $apply_type = 1;
// }elseif ($room_label == 2 && ($room_type == 1 || $room_type == 3 || $room_type == 4)){
// $apply_type = 2;
// }else{
// $apply_type = 1;
// }
if($apply_id){
$to_user = explode(',',$apply_id);
if(count($to_user) >= 1){
foreach ($to_user as &$value){
$where['user_id'] = $value;
$where['room_id'] = $room_id;
$where['status'] = 0;
// $where['apply_type'] = $apply_type;
db::name('vs_room_pit_apply')->where($where)->delete();
//1-禁麦位2-清空消息3-清空魅力值4-加入黑名单5-踢出房间6-关闭麦克风7-申请上麦8-同意上麦9-拒绝上麦10-点歌11-开启PK',
model('Room')->room_operation_record($userId,$room_id,9,$value);
}
}
}else{
$where['room_id'] = $room_id;
$where['status'] = 0;
// $where['apply_type'] = $apply_type;
db::name('vs_room_pit_apply')->where($where)->delete();
}
$count = db::name('vs_room_pit_apply')->where(['room_id' => $room_id,'status' => 0])->count();
//申请上麦推送消息
$text = [
'text' => '申请上麦',
'count' => $count
];
model('Chat')->sendMsg(1034,$room_id,$text);
return ['code' => 1, 'msg' => '操作成功', 'data' => null];
}
//设置插麦礼物
public function set_room_pit_apply_help_gift($user_id,$room_id,$gift_id,$gift_price)
{
if(!$room_id){
return ['code' => 0, 'msg' => '请选择房间', 'data' => null];
}
if(!$gift_id){
return ['code' => 0, 'msg' => '请选择礼物', 'data' => null];
}
if(!$gift_price){
$gift_price = db::name('vs_gift')->where(['gid' => $gift_id])->value('gift_price');
}
//判断当前用户是否是房主或在主持麦位上的主持
$is_room_owner = model('Room')->where(['id' => $room_id, 'user_id' => $user_id])->field('id')->find();
$is_room_host = db::name('vs_room_pit')->where(['room_id' => $room_id, 'user_id' => $user_id,'pit_number' => 9])->field('id')->find();
if(!$is_room_owner && !$is_room_host){
return ['code' => 0, 'msg' => '您不是房主 或 不在主持位,没有权限操作', 'data' => null];
}
$room_pit_apply_help_gift = db::name('vs_room_pit_apply_help_gift')->where(['room_id' => $room_id])->find();
if($room_pit_apply_help_gift) {
$data = [
'user_id' => $user_id,
'gift_id' => $gift_id,
'gift_price' => $gift_price,
'updatetime' => time(),
];
$reslut = db::name('vs_room_pit_apply_help_gift')->where(['room_id' => $room_id])->update($data);
if(!$reslut){
return ['code' => 0, 'msg' => '操作失败', 'data' => null];
}
}else{
$data = [
'user_id' => $user_id,
'room_id' => $room_id,
'gift_id' => $gift_id,
'gift_price' => $gift_price,
'createtime' => time(),
];
$reslut = db::name('vs_room_pit_apply_help_gift')->insert($data);
if(!$reslut){
return ['code' => 0, 'msg' => '操作失败', 'data' => null];
}
}
return ['code' => 1, 'msg' => '操作成功', 'data' => null];
}
//修改房间上麦模式
public function change_room_up_pit_type($user_id,$room_id)
{
if(!$room_id){
return ['code' => 0, 'msg' => '请选择房间', 'data' => null];
}
//判断当前用户是否有权限
$owner = db::name('vs_room')->where(['id' => $room_id, 'user_id' => $user_id])->field('id')->find();
$host = db::name('vs_room_host')->where(['room_id' => $room_id, 'user_id' => $user_id,'delete_time' => null])->find();
if(!$owner && !$host){
return ['code' => 0, 'msg' => '没有权限操作', 'data' => null];
}
$pit_type = db::name('vs_room')->where(['id' => $room_id])->value('room_up_pit_type');
if($pit_type == 1){
//房间模式
$room_type = db::name('vs_room')->where(['id' => $room_id])->value('type_id');
if($room_type == 2){
return ['code' => 0, 'msg' => '房间模式下,不允许切换麦位模式', 'data' => null];
}
$type = 2;
}else{
$type = 1;
}
$reslut = db::name('vs_room')->where(['id' => $room_id])->update(['room_up_pit_type' => $type]);
if(!$reslut){
return ['code' => 0, 'msg' => '操作失败', 'data' => null];
}
if($pit_type == 1){
//申请上麦的全部下麦
model('RoomPit')->clear_apply_pit_list($user_id, $room_id);
}
//推送消息给前端
$text['room_up_pit_type'] = $type;
model('Chat')->sendMsg(1014,$room_id,$text);
return ['code' => 1, 'msg' => '操作成功', 'data' => null];
}
//抱麦
//1-抱麦 2-踢下去
public function host_user_pit($user_id,$room_id,$pit_number,$accept_user_id,$type)
{
if(!$room_id){
return ['code' => 0, 'msg' => '请选择房间', 'data' => null];
}
if(!$accept_user_id){
return ['code' => 0, 'msg' => '请选择用户', 'data' => null];
}
if($type == 1){//抱麦
$on_9_pit = db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => 9])->value('user_id');
if($on_9_pit <= 0){
return ['code' => 0, 'msg' => '您暂未上主持麦位,请先上麦', 'data' => null];
}
if(!$pit_number){
$room_type = db::name('vs_room')->where(['id' => $room_id])->value('type_id');
if($room_type == 2){
if(Cache::get('auction_user_'.$room_id)){
return ['code' => 0, 'msg' => '拍卖位上已有人,请先抱对方下麦', 'data' => null];
}else{
$FromUserInfo = db::name('user')->where('id',$accept_user_id)->field('id as user_id,nickname,avatar,sex')->find();
$FromUserInfo['icon'][0] = model('api/UserData')->user_wealth_icon($accept_user_id);//财富图标
$FromUserInfo['icon'][1] = model('api/UserData')->user_charm_icon($accept_user_id);//魅力图标
$FromUserInfo['dress'] = model('api/Decorate')->user_decorate_detail($accept_user_id,1);
$FromUserInfo['charm'] = db::name('vs_room_user_charm')->where(['room_id' => $room_id, 'user_id' => $accept_user_id])->value('charm');
//推送告诉前端上了几号麦位
$text['text'] = $FromUserInfo['nickname'].' 上了拍卖位 ';
$text['FromUserInfo'] = $FromUserInfo;
$text['pit_number'] = $pit_number;
$text['type'] = 1 ;
//聊天室推送系统消息
model('api/Chat')->sendMsg(1022,$room_id,$text);
Cache::set('auction_user_'.$room_id,$accept_user_id);
return ['code' => 1, 'msg' => '操作成功', 'data' => null];
}
}
//查询当前空麦位
$empty_pit = $this->getRoomNullPitWithout($room_id, [9, 10]);
if(!$empty_pit){
return ['code' => 0, 'msg' => '没有空麦位', 'data' => null];
}else{
$pit_number = $empty_pit;
}
}else{
if($pit_number == 888){
$FromUserInfo = db::name('user')->where('id',$accept_user_id)->field('id as user_id,nickname,avatar,sex')->find();
$FromUserInfo['icon'][0] = model('api/UserData')->user_wealth_icon($accept_user_id);//财富图标
$FromUserInfo['icon'][1] = model('api/UserData')->user_charm_icon($accept_user_id);//魅力图标
$FromUserInfo['dress'] = model('api/Decorate')->user_decorate_detail($accept_user_id,1);
$FromUserInfo['charm'] = db::name('vs_room_user_charm')->where(['room_id' => $room_id, 'user_id' => $accept_user_id])->value('charm');
//推送告诉前端上了几号麦位
$text['text'] = $FromUserInfo['nickname'].' 上了拍卖位 ';
$text['FromUserInfo'] = $FromUserInfo;
$text['pit_number'] = $pit_number;
$text['type'] = 1 ;
//聊天室推送系统消息
model('api/Chat')->sendMsg(1022,$room_id,$text);
Cache::set('auction_user_'.$room_id,$accept_user_id);
return ['code' => 1, 'msg' => '操作成功', 'data' => null];
}
//判断当前麦位是否为空
$where['room_id'] = $room_id;
$where['pit_number'] = $pit_number;
$pit_user_id = db::name('vs_room_pit')->where($where)->value('user_id');
if($pit_user_id > 0){
return ['code' => 0, 'msg' => '麦位上有人', 'data' => null];
}
}
$where['room_id'] = $room_id;
$where['pit_number'] = $pit_number;
$where['is_lock'] = 0;
$pit_info = db::name('vs_room_pit')->where($where)->find();
if(!$pit_info){
return ['code' => 0, 'msg' => '麦位不存在或已锁麦', 'data' => null];
}
$where['user_id'] = $accept_user_id;
unset($where['pit_number']);
$accept_pit_info = db::name('vs_room_pit')->where($where)->find();
if($accept_pit_info){
return ['code' => 0, 'msg' => '该用户已上麦', 'data' => null];
}
$onpit = $this ->OnPit($accept_user_id,$room_id,$pit_number);
if($onpit['code'] != 1){
return ['code' => 0, 'msg' => '操作失败', 'data' => null];
}
//删除申请上麦
model('RoomPit')->clear_apply_pit_list($user_id, $room_id, $accept_user_id);
}else{//2-踢下去
//判断权限
if($pit_number != 888){
if(!model('QuanXian')->quan_xian($user_id, $accept_user_id, $room_id)){
return ['code' => 0, 'msg' => '您没有权限操作', 'data' => null];
}
}
if(!$pit_number || $pit_number == 888){
$roomInfo = db::name('vs_room')->where('id',$room_id)->field('label_id,type_id')->find();
if($roomInfo['type_id'] == 2){//拍卖
//查询当前是否处于拍卖中
$auctioning = db::name('vs_room_auction')
->where(['room_id' => $room_id, 'status' => 2, 'user_id' => $accept_user_id])->find();
if($auctioning){
return ['code' => 0, 'msg' => '该用户正在拍卖中', 'data' => null];
}
//查询当前用户是否正在拍卖中
if($pit_number == 888 && Cache::get('auction_user_'.$room_id) != $accept_user_id){
return ['code' => 0, 'msg' => '拍卖用户不是当前操作用户', 'data' => null];
}
//清除缓存
Cache::rm('auction_user_'.$room_id);
$FromUserInfo = db::name('user')->where('id',$accept_user_id)->field('id as user_id,nickname,avatar,sex')->find();
$FromUserInfo['icon'][0] = model('UserData')->user_wealth_icon($accept_user_id);//财富图标
$FromUserInfo['icon'][1] = model('UserData')->user_charm_icon($accept_user_id);//魅力图标
//推送告诉前端下了几号麦位
$text['text'] = $FromUserInfo['nickname'].' 下了拍卖位 ';
$text['FromUserInfo'] = $FromUserInfo;
$text['pit_number'] = $pit_number;
$text['type'] = 2 ;
model('api/Chat')->sendMsg(1022,$room_id,$text);
}
if($roomInfo['label_id'] == 2 && ($roomInfo['type_id'] == 1 || $roomInfo['type_id'] == 4 || $roomInfo['type_id'] == 3)){
$res = model('RoomSong')->down_kpit($accept_user_id, $room_id);
if($res['code'] != 1){
return ['code' => 0, 'msg' => $res['msg'], 'data' => null];
}
}
}else{
$step = db::name('vs_room')->where(['id' => $room_id, 'type_id' => 7])->value('step');
if($step && $step != 1){
return ['code' => 0, 'msg' => '交友房 此阶段不可操作', 'data' => null];
}
$where['room_id'] = $room_id;
$where['pit_number'] = $pit_number;
$where['user_id'] = $accept_user_id;
$accept_pit_info = db::name('vs_room_pit')->where($where)->find();
if(!$accept_pit_info){
return ['code' => 0, 'msg' => '该用户已不在'.$pit_number.'麦', 'data' => null];
}
$dow = $this ->DownPit($accept_user_id,$room_id,$pit_number);
if($dow['code'] != 1){
return ['code' => 0, 'msg' => '操作失败', 'data' => null];
}
}
}
return ['code' => 1, 'msg' => '操作成功', 'data' => null];
}
}