1118 lines
42 KiB
PHP
1118 lines
42 KiB
PHP
<?php
|
|
|
|
namespace app\api\model;
|
|
|
|
|
|
use think\Db;
|
|
use think\Model;
|
|
use think\facade\Env;
|
|
|
|
class XqRoom extends Model
|
|
{
|
|
|
|
//准备阶段
|
|
public function prepare_stage($uid,$rid){
|
|
$room_info = db::name('room')->where(['rid'=>$rid])->find();
|
|
if(empty($room_info)){
|
|
return ['code' => 201, 'msg' => '房间不存在!', 'data' => null];
|
|
}
|
|
|
|
if(!in_array($room_info['cate_id'],[36,37])){
|
|
return ['code' => 201, 'msg' => '该房间不是相亲房!', 'data' => null];
|
|
}
|
|
|
|
if($uid != $room_info['room_host_uid']){
|
|
return ['code' => 201, 'msg' => '仅限主持麦操作', 'data' => null];
|
|
}
|
|
|
|
//是否已有未结束阶段
|
|
$map = [];
|
|
$map[] = ['rid', '=', $rid];
|
|
$map[] = ['is_delete', '=', 1];
|
|
$room_xq1 = db::name('room_xq1')->where($map)->find();
|
|
|
|
if(!empty($room_xq1)){
|
|
return ['code' => 201, 'msg' => '本场相亲活动尚未结束!', 'data' => null];
|
|
}
|
|
|
|
|
|
if($room_info['cate_id']==36){
|
|
$type = 1; //男神
|
|
}else{
|
|
$type = 2; //女神
|
|
}
|
|
|
|
try {
|
|
Db::startTrans();
|
|
$room_micro_data = db::name('room_micro')->where('rid', $rid)->order('micro_id asc')->column('uid');
|
|
$jia_micro_num = 0;
|
|
$micro_uid_data = '';
|
|
$xq_uid = 0;
|
|
$invite_uid = 0;
|
|
foreach($room_micro_data as $a => $b){
|
|
if(in_array($a, [0,1,2,3,4,5]) && $b > 0){
|
|
$jia_micro_num += 1;
|
|
$micro_uid_data .= $b.',';
|
|
}elseif($a == 6 && $b > 0){
|
|
$xq_uid = $b;
|
|
}elseif($a == 7 && $b > 0){
|
|
$invite_uid = $b;
|
|
}
|
|
}
|
|
|
|
if(empty($xq_uid)){
|
|
return ['code' => 201, 'msg' => '相亲麦无人无法开启', 'data' => null];
|
|
}
|
|
|
|
if($jia_micro_num < 1){
|
|
return ['code' => 201, 'msg' => '嘉宾麦无人无法开启', 'data' => null];
|
|
}
|
|
$xq_talent_time = get_uncache_system_config('xq_talent_time');
|
|
|
|
$now_time = time();
|
|
$insert = [];
|
|
$insert['stage'] = 2;
|
|
$insert['rid'] = $rid;
|
|
$insert['xq_uid'] = $xq_uid;
|
|
$insert['jiabin_uids'] = trim($micro_uid_data,",");
|
|
$insert['invite_uid'] = $invite_uid;
|
|
$insert['type'] = $type;
|
|
$insert['host_uid'] = $room_info['room_host_uid'];
|
|
$insert['start_time'] = $now_time;
|
|
$insert['add_time'] = $now_time;
|
|
$insert['update_time'] = $now_time;
|
|
|
|
$insert['end_time'] = ($now_time + $xq_talent_time);
|
|
|
|
|
|
|
|
|
|
$reslut = db::name('room_xq1')->insert($insert);
|
|
if(!$reslut){
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
|
}
|
|
|
|
Db::commit();
|
|
model('api/room')->push_room_micro_data($rid);
|
|
return ['code' => 200, 'msg' => '准备成功', 'data' => null];
|
|
} catch (\Exception $e) {
|
|
// 回滚事务
|
|
dump($e);
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
public function choose_love_stage($uid,$rid){
|
|
$room_info = db::name('room')->where(['rid'=>$rid])->find();
|
|
if(empty($room_info)){
|
|
return ['code' => 201, 'msg' => '房间不存在!', 'data' => null];
|
|
}
|
|
|
|
if(!in_array($room_info['cate_id'],[36,37])){
|
|
return ['code' => 201, 'msg' => '该房间不是相亲房!', 'data' => null];
|
|
}
|
|
|
|
|
|
//是否已有未结束阶段
|
|
$map = [];
|
|
$map[] = ['rid', '=', $rid];
|
|
$map[] = ['is_delete', '=', 1];
|
|
$room_xq1 = db::name('room_xq1')->where($map)->find();
|
|
if(empty($room_xq1)){
|
|
return ['code' => 201, 'msg' => '暂无相亲活动!', 'data' => null];
|
|
}
|
|
|
|
if(($uid != $room_info['room_host_uid']) && ($uid != $room_info['room_owner_uid']) && ($uid != $room_xq1['xq_uid'])){
|
|
return ['code' => 201, 'msg' => '暂无权限!', 'data' => null];
|
|
}
|
|
|
|
|
|
|
|
if($room_xq1['stage'] != 2){
|
|
return ['code' => 201, 'msg' => '当前不是才艺展示阶段!', 'data' => null];
|
|
}
|
|
|
|
$reslut = db::name('room_xq1')->where('id',$room_xq1['id'])->update(['stage'=>3,'update_time'=>time()]);
|
|
model('api/room')->push_room_micro_data($rid);
|
|
return ['code' => 200, 'msg' => '操作成功', 'data' => null];
|
|
}
|
|
|
|
|
|
|
|
//关闭相亲活动
|
|
public function close_xq_activity($uid,$rid,$is_push=true){
|
|
$now_time = time();
|
|
$room_info = db::name('room')->where(['rid'=>$rid])->find();
|
|
if(empty($room_info)){
|
|
return ['code' => 201, 'msg' => '房间不存在!', 'data' => null];
|
|
}
|
|
|
|
//是否已有未结束阶段
|
|
$map = [];
|
|
$map[] = ['rid', '=', $rid];
|
|
$map[] = ['is_delete', '=', 1];
|
|
$room_xq1 = db::name('room_xq1')->where($map)->find();
|
|
if(empty($room_xq1)){
|
|
return ['code' => 201, 'msg' => '没有相亲活动!', 'data' => null];
|
|
}
|
|
|
|
//主持和房主有权限
|
|
if($uid != $room_info['room_host_uid'] && $uid != $room_info['room_owner_uid']){
|
|
return ['code' => 201, 'msg' => '仅限主持麦操作', 'data' => null];
|
|
}
|
|
|
|
$room_micro_data = db::name('room_micro')->where('rid', $rid)->order('micro_id asc')->column('uid');
|
|
$jia_micro_num = 0;
|
|
$xq_uid = 0;
|
|
$invite_uid = 0;
|
|
|
|
$micro_uid_data = $room_xq1['jiabin_uids'];
|
|
$jiabin_uids_data_arr = explode(",",$room_xq1['jiabin_uids']);
|
|
|
|
|
|
foreach($room_micro_data as $a => $b){
|
|
if(in_array($a, [0,1,2,3,4,5]) && $b > 0){
|
|
$jia_micro_num += 1;
|
|
if(!in_array($b,$jiabin_uids_data_arr)){
|
|
$micro_uid_data .= $b.',';
|
|
}
|
|
}elseif($a == 6 && $b > 0){
|
|
$xq_uid = $b;
|
|
}elseif($a == 7 && $b > 0){
|
|
$invite_uid = $b;
|
|
}
|
|
}
|
|
|
|
try {
|
|
Db::startTrans();
|
|
db::name('room_micro')->where([['micro_id','in',[1,2,3,4,5,6,7]],['rid','=',$rid]])->update([
|
|
// 'uid' => 0,
|
|
'light_type' => 0,
|
|
'is_spotlight' =>2,
|
|
'trac_line' =>2
|
|
]);
|
|
db::name('room_xq1')->where(['id'=>$room_xq1['id']])->update([
|
|
'stage' => 4,
|
|
'is_delete' => 2,
|
|
'delete_time' => $now_time,
|
|
'update_time' => time(),
|
|
'invite_uid' => $invite_uid,
|
|
'xq_uid' => $xq_uid,
|
|
'host_uid' => $room_info['room_host_uid'],
|
|
'jiabin_uids'=>trim($micro_uid_data, ',')
|
|
]);
|
|
Db::commit();
|
|
if($is_push){
|
|
model('api/room')->push_room_micro_data($rid);
|
|
}
|
|
return ['code' => 200, 'msg' => '关闭成功!', 'data' => null];
|
|
}catch (\Exception $e) {
|
|
// 回滚事务
|
|
dump($e);
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//用户亮灯
|
|
public function user_room_light_send_gift($uid,$rid,$num=1,$light_type=1){
|
|
if($light_type==2){
|
|
if(!preg_match("/^[1-9][0-9]*$/" ,$num) || $num <= 0){
|
|
return ['code' => 201, 'msg' => '礼物数量必须大于等于1!', 'data' => null];
|
|
}
|
|
|
|
$send_user = db::name('user')->where('uid', $uid)->find();
|
|
|
|
//礼物价值
|
|
$config = get_uncache_system_config();
|
|
$xq_burst_gid =$config['xq_burst_gid'];
|
|
|
|
$gift_info = db::name('gift')->where(['gid'=>$xq_burst_gid,'is_delete'=>1])->find();
|
|
$pay_price = $gift_info['gift_price'] * $num;
|
|
if($send_user['integral'] < $pay_price){
|
|
return ['code' => 201, 'msg' => '账户余额不足!', 'data' => null];
|
|
}
|
|
}
|
|
//房间详情
|
|
$room_info = db::name('room')->where(['rid'=>$rid])->find();
|
|
if(empty($room_info)){
|
|
return ['code' => 201, 'msg' => '房间不存在!', 'data' => null];
|
|
}
|
|
|
|
if(!in_array($room_info['cate_id'],[36,37])){
|
|
return ['code' => 201, 'msg' => '该房间不是相亲房!', 'data' => null];
|
|
}
|
|
|
|
$room_xq1_activity = db::name('room_xq1')->where(['rid'=>$rid,'is_delete'=>1])->order(['id'=>'desc'])->find();
|
|
if(empty($room_xq1_activity)){
|
|
return ['code' => 201, 'msg' => '当前房间没有相亲活动!', 'data' => null];
|
|
}
|
|
|
|
|
|
$close_light_uids = $room_xq1_activity['close_light_uids'];
|
|
if(!empty($close_light_uids)){
|
|
$close_light_uids = explode(",",$close_light_uids);
|
|
if(in_array($uid,$close_light_uids)){
|
|
return ['code' => 201, 'msg' => '您已经被灭过灯了!', 'data' => null];
|
|
}
|
|
}
|
|
|
|
//相亲房活动阶段
|
|
if($room_xq1_activity['stage'] != 3){
|
|
return ['code' => 201, 'msg' => '当前不处于心动选择阶段!', 'data' => null];
|
|
}
|
|
|
|
$jb_room_micro_info = db::name('room_micro')->where([['micro_id','in',[1,2,3,4,5,6]],['rid','=',$rid],['uid','=',$uid]])->find();
|
|
if(empty($jb_room_micro_info)){
|
|
return ['code' => 201, 'msg' => '您不在嘉宾麦!', 'data' => null];
|
|
}
|
|
|
|
//爆灯
|
|
if($jb_room_micro_info['light_type'] ==2){
|
|
if($light_type ==1){
|
|
return ['code' => 201, 'msg' => '不可将爆灯转为普通灯!', 'data' => null];
|
|
}
|
|
}
|
|
|
|
$xq_room_micro_info = db::name('room_micro')->where([['micro_id','=',7],['rid','=',$rid],['uid','<>',0]])->find();
|
|
if(empty($jb_room_micro_info)){
|
|
return ['code' => 201, 'msg' => '相亲麦暂无人员!', 'data' => null];
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
Db::startTrans();
|
|
//爆灯
|
|
if($light_type==2){
|
|
$receive_uid = $xq_room_micro_info['uid'];
|
|
$reslut = model('gift')->send_gift($uid, $receive_uid, $rid, $xq_burst_gid, $num, 1, 0);
|
|
if($reslut['code'] != 200){
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
|
}
|
|
db::name('room_micro')->where([['micro_id','in',[1,2,3,4,5,6]],['rid','=',$rid],['uid','=',$uid]])->update(['light_type'=>2]);
|
|
|
|
//普通灯
|
|
}elseif($light_type==1){
|
|
// 普通仅仅亮灯
|
|
db::name('room_micro')->where([['micro_id','in',[1,2,3,4,5,6]],['rid','=',$rid],['uid','=',$uid]])->update(['light_type'=>1]);
|
|
}
|
|
|
|
Db::commit();
|
|
model('api/room')->push_room_micro_data($rid);
|
|
return ['code' => 200, 'msg' => '操作成功', 'data' => null];
|
|
} catch (\Exception $e) {
|
|
// 回滚事务
|
|
dump($e);
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 用户uid 房间rid 麦位 micro_id
|
|
public function ju_guang_light($uid,$rid,$micro_id,$status=1){
|
|
if(!in_array($status,[1,2])){
|
|
return ['code' => 201, 'msg' => '请选择开启/关闭!', 'data' => null];
|
|
}
|
|
|
|
$micro_id = $micro_id + 1;
|
|
if(!in_array($micro_id,[1,2,3,4,5,6])){
|
|
return ['code' => 201, 'msg' => '亮灯麦位不在嘉宾麦!', 'data' => null];
|
|
}
|
|
|
|
$room_info = db::name('room')->where(['rid'=>$rid])->find();
|
|
if(empty($room_info)){
|
|
return ['code' => 201, 'msg' => '房间不存在!', 'data' => null];
|
|
}
|
|
|
|
if(!in_array($room_info['cate_id'],[36,37])){
|
|
return ['code' => 201, 'msg' => '该房间不是相亲房!', 'data' => null];
|
|
}
|
|
|
|
if($uid != $room_info['room_host_uid']){
|
|
return ['code' => 201, 'msg' => '仅限主持麦操作', 'data' => null];
|
|
}
|
|
|
|
|
|
$room_xq1_activity = db::name('room_xq1')->where(['rid'=>$rid,'is_delete'=>1])->order(['id'=>'desc'])->find();
|
|
if(empty($room_xq1_activity)){
|
|
return ['code' => 201, 'msg' => '当前房间没有相亲活动!', 'data' => null];
|
|
}
|
|
|
|
//相亲房活动阶段
|
|
if($room_xq1_activity['stage'] != 3){
|
|
return ['code' => 200, 'msg' => '当前不处于心动选择阶段!', 'data' => null];
|
|
}
|
|
|
|
|
|
|
|
$room_micro_data = db::name('room_micro')->where(['rid'=>$rid,'micro_id'=>$micro_id])->where('uid','<>',0)->find();
|
|
if(empty($room_micro_data)){
|
|
return ['code' => 201, 'msg' => '麦位暂无人员!', 'data' => null];
|
|
}
|
|
|
|
if($status == 1){
|
|
if($room_micro_data['is_spotlight'] == 1){
|
|
return ['code' => 201, 'msg' => '该麦位已经聚光!', 'data' => null];
|
|
}
|
|
}elseif($status==2){
|
|
if($room_micro_data['is_spotlight'] == 2){
|
|
return ['code' => 201, 'msg' => '该麦位已取消聚光!', 'data' => null];
|
|
}
|
|
}else{
|
|
return ['code' => 201, 'msg' => '操作类型非法!', 'data' => null];
|
|
}
|
|
|
|
|
|
try {
|
|
Db::startTrans();
|
|
//亮聚光灯
|
|
db::name('room_micro')->where(['rid'=>$rid,'micro_id'=>$micro_id])->update(['is_spotlight'=>$status]);
|
|
//其它麦位灭聚光灯
|
|
db::name('room_micro')->where([['rid','=',$rid],['micro_id','in',[1,2,3,4,5,6]],['micro_id','<>',$micro_id]])->update(['is_spotlight'=>2]);
|
|
Db::commit();
|
|
model('api/room')->push_room_micro_data($rid);
|
|
return ['code' => 200, 'msg' => '操作成功!', 'data' => null];
|
|
} catch (\Exception $e) {
|
|
// 回滚事务
|
|
dump($e);
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
|
}
|
|
}
|
|
|
|
|
|
//关闭相亲灯
|
|
public function close_xq_light($uid,$rid){
|
|
$user_room_micro = db::name('room_micro')->where(['rid'=>$rid,'uid'=>$uid])->where('micro_id','in',[1,2,3,4,5,6])->find();
|
|
if(empty($user_room_micro)){
|
|
return ['code' => 201, 'msg' => '您不在嘉宾麦!', 'data' => null];
|
|
}
|
|
|
|
$room_info = db::name('room')->where(['rid'=>$rid])->find();
|
|
if(empty($room_info)){
|
|
return ['code' => 201, 'msg' => '房间不存在!', 'data' => null];
|
|
}
|
|
|
|
if(!in_array($room_info['cate_id'],[36,37])){
|
|
return ['code' => 201, 'msg' => '该房间不是相亲房!', 'data' => null];
|
|
}
|
|
|
|
|
|
if(empty($user_room_micro)){
|
|
return ['code' => 201, 'msg' => '你不在嘉宾麦!', 'data' => null];
|
|
}
|
|
if($user_room_micro['light_type'] == 0){
|
|
return ['code' => 201, 'msg' => '您没有亮灯!', 'data' => null];
|
|
}
|
|
|
|
if($user_room_micro['light_type'] == 2){
|
|
return ['code' => 201, 'msg' => '爆灯不可以被灭!', 'data' => null];
|
|
}
|
|
db::name('room_micro')->where(['id'=>$user_room_micro['id']])->update(['light_type'=>0]);
|
|
model('api/room')->push_room_micro_data($rid);
|
|
return ['code' => 200, 'msg' => '操作成功!', 'data' => null];
|
|
}
|
|
|
|
|
|
|
|
//相亲位关闭灯光
|
|
public function xq_reverse_send_gift($uid,$close_uid,$rid,$gid=0,$num=1,$type=1){
|
|
$config = get_uncache_system_config();
|
|
// if($gid==$config['xq_close_gift_gid']){ //灭爆灯礼物gid
|
|
// $type = 1;
|
|
// }elseif($gid==$config['xq_normal_close_gift_gid']){ //灭普通灯礼物gid
|
|
// $type = 1;
|
|
// }elseif($gid==$config['qian_xian_gift_gid']){
|
|
// $type = 2;
|
|
// }elseif($gid==$config['qian_xian_gift_gid_2']){
|
|
// $type = 2;
|
|
// }else{
|
|
// return ['code' => 201, 'msg' => '礼物类型非法!', 'data' => null];
|
|
// }
|
|
|
|
if($gid==$config['xq_close_gift_gid']){ //灭爆灯礼物gid
|
|
$type = 1;
|
|
}elseif($gid==$config['qian_xian_gift_gid']){
|
|
$type = 2;
|
|
}else{
|
|
return ['code' => 201, 'msg' => '礼物类型非法!', 'data' => null];
|
|
}
|
|
|
|
if(!preg_match("/^[1-9][0-9]*$/" ,$num) || $num <= 0){
|
|
return ['code' => 201, 'msg' => '礼物数量必须大于等于1!', 'data' => null];
|
|
}
|
|
|
|
if($num !=1){
|
|
return ['code' => 201, 'msg' => '礼物数量必须为1!', 'data' => null];
|
|
}
|
|
|
|
|
|
$room_xq1_activity = db::name('room_xq1')->where(['rid'=>$rid,'is_delete'=>1])->find();
|
|
if(empty($room_xq1_activity)){
|
|
return ['code' => 201, 'msg' => '当前房间没有相亲活动!', 'data' => null];
|
|
}
|
|
|
|
|
|
//相亲房活动阶段
|
|
if($room_xq1_activity['stage'] != 3){
|
|
return ['code' => 201, 'msg' => '当前不处于心动选择阶段!', 'data' => null];
|
|
}
|
|
|
|
|
|
$xq_room_micro = db::name('room_micro')->where(['rid'=>$rid,'micro_id'=>7,'uid'=>$uid])->find();
|
|
|
|
if(empty($xq_room_micro)){
|
|
return ['code' => 201, 'msg' => '您不在相亲麦!', 'data' => null];
|
|
}
|
|
|
|
|
|
//查询对方爆灯类型
|
|
|
|
$micro_close_userinfo = db::name('room_micro')->where(['rid'=>$rid,'uid'=>$close_uid])->where('micro_id','in',[1,2,3,4,5,6])->find();
|
|
|
|
|
|
if(empty($micro_close_userinfo)){
|
|
return ['code' => 201, 'msg' => '对方不在嘉宾麦!', 'data' => null];
|
|
}
|
|
|
|
|
|
|
|
//对方没有亮灯
|
|
if(!in_array($micro_close_userinfo['light_type'],[1,2])){
|
|
return ['code' => 201, 'msg' => '对方没有亮灯!', 'data' => null];
|
|
}
|
|
|
|
|
|
//如果对方是爆灯
|
|
// if($micro_close_userinfo['light_type'] == 2){
|
|
// $config = get_uncache_system_config();
|
|
// if($config['xq_close_gift_gid'] != $gid){
|
|
// return ['code' => 201, 'msg' => '请赠送特定礼物!', 'data' => null];
|
|
// }
|
|
// }
|
|
|
|
|
|
// $config = get_uncache_system_config();
|
|
// if($type==1){
|
|
// if($config['xq_close_gift_gid'] != $gid){
|
|
// return ['code' => 201, 'msg' => '请赠送特定礼物!', 'data' => null];
|
|
// }
|
|
// }elseif($type==2){
|
|
// if($config['qian_xian_gift_gid'] != $gid){
|
|
// return ['code' => 201, 'msg' => '请赠送特牵线礼物!', 'data' => null];
|
|
// }
|
|
// }else{
|
|
// return ['code' => 201, 'msg' => '操作类型非法!', 'data' => null];
|
|
// }
|
|
|
|
$send_user = db::name('user')->where('uid', $uid)->find();
|
|
|
|
//礼物价值
|
|
$gift_info = db::name('gift')->where(['gid'=>$gid,'is_delete'=>1])->find();
|
|
$pay_price = $gift_info['gift_price'] * $num;
|
|
if($send_user['integral'] < $pay_price){
|
|
return ['code' => 201, 'msg' => '账户余额不足!', 'data' => null];
|
|
}
|
|
|
|
|
|
try {
|
|
$time = time();
|
|
Db::startTrans();
|
|
|
|
if($type==1){
|
|
//关闭灯光 不聚光
|
|
db::name('room_micro')
|
|
->where(['rid'=>$rid,'uid'=>$close_uid])
|
|
->where('micro_id','in',[1,2,3,4,5,6])
|
|
->update(['light_type'=>3,'update_time'=>$time]);
|
|
//赠送指定礼物
|
|
$reslut = model('gift')->send_gift($uid, $close_uid, $rid, $gid, $num, 1, 0);
|
|
if($reslut['code'] != 200){
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
|
}
|
|
//被关闭过的人员uid
|
|
$close_light_uids = trim($room_xq1_activity['close_light_uids'],",").",".$close_uid;
|
|
db::name('room_xq1')->where(['id'=>$room_xq1_activity['id']])->update(['close_light_uids'=>$close_light_uids,'update_time'=>time()]);
|
|
}elseif($type==2){
|
|
//关闭灯光 不聚光
|
|
db::name('room_micro')
|
|
->where(['rid'=>$rid,'uid'=>$close_uid])
|
|
->where('micro_id','in',[1,2,3,4,5,6])
|
|
->update(['trac_line'=>1,'update_time'=>$time]);
|
|
//赠送指定礼物
|
|
$reslut = model('gift')->send_gift($uid, $close_uid, $rid, $gid, $num, 1, 0);
|
|
if($reslut['code'] != 200){
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
|
}
|
|
|
|
//被关闭过的人员uid
|
|
$qian_xian_uids = trim($room_xq1_activity['qian_xian_uids'],",").",".$close_uid;
|
|
db::name('room_xq1')->where(['id'=>$room_xq1_activity['id']])->update(['qian_xian_uids'=>$qian_xian_uids,'update_time'=>time()]);
|
|
|
|
}
|
|
|
|
Db::commit();
|
|
return ['code' => 200, 'msg' => '操作成功!', 'data' => null];
|
|
} catch (\Exception $e) {
|
|
// 回滚事务
|
|
dump($e);
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//相亲指定礼物
|
|
public function xq_appoint_gift($type=1){
|
|
$config = get_uncache_system_config();
|
|
|
|
|
|
$gid1 = $config['xq_burst_gid']; //爆灯礼物gid
|
|
|
|
$gid2 = $config['xq_close_gift_gid'];
|
|
// $gid2_1 = $config['xq_normal_close_gift_gid']; //灭普通灯
|
|
|
|
$gid3 = $config['qian_xian_gift_gid']; //牵线礼物1
|
|
// $gid4 = $config['qian_xian_gift_gid_2']; //牵线礼物2
|
|
|
|
|
|
|
|
$gift_info1 = db::name('gift')->where(['gid'=>$gid1,'is_delete'=>1,'is_show'=>1])->field('gid,gift_name,gift_price,base_image,tag_name')->find();
|
|
if(!empty($gift_info1)){
|
|
$gift_info1['base_image'] = localpath_to_netpath($gift_info1['base_image']);
|
|
}
|
|
|
|
|
|
$gift_info2 = db::name('gift')->where(['gid'=>$gid2,'is_delete'=>1,'is_show'=>1])->field('gid,gift_name,gift_price,base_image,tag_name')->find();
|
|
if(!empty($gift_info2)){
|
|
$gift_info2['base_image'] = localpath_to_netpath($gift_info2['base_image']);
|
|
}
|
|
|
|
|
|
// $gift_info2_1 = db::name('gift')->where(['gid'=>$gid2_1,'is_delete'=>1,'is_show'=>1])->field('gid,gift_name,gift_price,base_image,tag_name')->find();
|
|
|
|
|
|
$gift_info3 = db::name('gift')->where(['gid'=>$gid3,'is_delete'=>1,'is_show'=>1])->field('gid,gift_name,gift_price,base_image,tag_name')->find();
|
|
if(!empty($gift_info3)){
|
|
$gift_info3['base_image'] = localpath_to_netpath($gift_info3['base_image']);
|
|
}
|
|
|
|
// $gift_info4 = db::name('gift')->where(['gid'=>$gid4,'is_delete'=>1,'is_show'=>1])->field('gid,gift_name,gift_price,base_image,tag_name')->find();
|
|
|
|
|
|
if($type==1){
|
|
$data = [
|
|
$gift_info1,
|
|
];
|
|
}elseif($type==2){
|
|
$data = [
|
|
$gift_info2,
|
|
// $gift_info2_1,
|
|
$gift_info3,
|
|
// $gift_info4
|
|
];
|
|
}else{
|
|
$data = [];
|
|
}
|
|
|
|
return ['code' => 200, 'msg' => '操作成功!', 'data' => $data];
|
|
}
|
|
|
|
|
|
//亮明身份
|
|
public function show_xq_sf($uid,$rid){
|
|
$room_info = db::name('room')->where(['rid'=>$rid])->find();
|
|
if(empty($room_info)){
|
|
return ['code' => 201, 'msg' => '房间不存在!', 'data' => null];
|
|
}
|
|
|
|
if(!in_array($room_info['cate_id'],[36,37])){
|
|
return ['code' => 201, 'msg' => '该房间不是相亲房!', 'data' => null];
|
|
}
|
|
|
|
$room_xq1_activity = db::name('room_xq1')->where(['rid'=>$rid,'is_delete'=>1])->find();
|
|
if(empty($room_xq1_activity)){
|
|
return ['code' => 201, 'msg' => '当前房间没有相亲活动!', 'data' => null];
|
|
}
|
|
|
|
$xq_room_micro_info = db::name('room_micro')->where([['micro_id','=',7],['rid','=',$rid],['uid','=',$uid]])->find();
|
|
if(empty($xq_room_micro_info) && ($uid != $room_info['room_host_uid'])){
|
|
return ['code' => 201, 'msg' => '您不是本场活动的相亲人员!', 'data' => null];
|
|
}
|
|
|
|
if($room_xq1_activity['xq_uid_sm'] == 1){
|
|
return ['code' => 201, 'msg' => '您已经亮明过身份了!', 'data' => null];
|
|
}
|
|
db::name('room_xq1')->where(['rid'=>$rid,'is_delete'=>1])->update(['xq_uid_sm'=>1,'update_time'=>time()]);
|
|
model('api/room')->push_room_micro_data($rid);
|
|
return ['code' => 200, 'msg' => '操作成功', 'data' => null];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//修改房间
|
|
public function modify_room_info($uid, $rid, $cate_id)
|
|
{
|
|
if(!in_array($cate_id,[36,37])){
|
|
return ['code' => 201, 'msg' => '房间类型非法!', 'data' => null];
|
|
}
|
|
|
|
$map = [];
|
|
$map[] = ['rid', '=', $rid];
|
|
$room_info = db::name('room')->where($map)->find();
|
|
if (empty($room_info)) {
|
|
return ['code' => 201, 'msg' => '房间信息不存在', 'data' => null];
|
|
}
|
|
$room_admin_uid_arr = db::name('room_admin')->where('rid', $rid)->where('is_delete', 1)->column('uid');
|
|
$room_host_uid_arr = db::name('room_host')->where('rid', $rid)->where('is_delete', 1)->column('uid');
|
|
if ($uid != $room_info['room_owner_uid'] && !in_array($uid, $room_admin_uid_arr) && !in_array($uid, $room_host_uid_arr)) {
|
|
return ['code' => 201, 'msg' => '无权限操作', 'data' => null];
|
|
}
|
|
|
|
$data = [];
|
|
|
|
if($room_info['cate_id'] != $cate_id && $cate_id > 0){
|
|
if(in_array($room_info['cate_id'],[36,37])){
|
|
$map = [];
|
|
$map[] = ['rid', '=', $rid];
|
|
$map[] = ['is_delete', '=', 1];
|
|
$room_dating_log = db::name('room_xq1')->where($map)->find();
|
|
if($room_dating_log){
|
|
return ['code' => 201, 'msg' => '当前玩法进行中,无法切换', 'data' => null];
|
|
}
|
|
}
|
|
$data['cate_id'] = $cate_id;
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
Db::startTrans();
|
|
$reslut = model('admin/room')->save($data, ['rid' => $rid]);
|
|
// if (!$reslut) {
|
|
// Db::rollback();
|
|
// return ['code' => 201, 'msg' => '编辑失败', 'data' => null];
|
|
// }
|
|
|
|
if($cate_id != $room_info['cate_id']){
|
|
//清理该房间所有麦位魅力值
|
|
$map = [];
|
|
$map[] = ['rid', '=', $rid];
|
|
$map[] = ['charm_value', '>', 0];
|
|
$list = db::name('room_user_cc')->where($map)->select();
|
|
if(!empty($list)){
|
|
foreach ($list as $k => $v){
|
|
$reslut = db::name('room_user_micro_charm_log')->where('cid', $v['cid'])->update(['change_value' => 0, 'update_time' => time()]);
|
|
if(!$reslut){
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => '编辑失败', 'data' => ''];
|
|
}
|
|
}
|
|
$reslut = db::name('room_user_cc')->where($map)->update(['charm_value' => 0, 'update_time' => time()]);
|
|
if(!$reslut){
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => '编辑失败', 'data' => ''];
|
|
}
|
|
}
|
|
db::name('room_micro')->where([['micro_id','in',[1,2,3,4,5,6,7]],['rid','=',$rid]])->update([
|
|
'uid' => 0,
|
|
'light_type' => 0,
|
|
'is_spotlight' =>2,
|
|
'trac_line' =>2
|
|
]);
|
|
|
|
// db::name('room_xq1')->where(['id'=>$room_xq1['id']])->update([
|
|
// 'stage' => 4,
|
|
// 'is_delete' => 2,
|
|
// 'update_time' => time(),
|
|
// ]);
|
|
|
|
|
|
}
|
|
|
|
Db::commit();
|
|
|
|
if($cate_id != $room_info['cate_id']){
|
|
$push_room_data = [];
|
|
$push_room_data['rid'] = $rid;
|
|
$push_room_data['type'] = 1;
|
|
|
|
$push_data = [];
|
|
$push_data['code'] = 369;
|
|
$push_data['msg'] = "房间类型变更推送";
|
|
$push_data['data'] = $push_room_data;
|
|
$reslut = model('api/WebSocketPush')->send_to_group($rid, $push_data);
|
|
}
|
|
|
|
return ['code' => 200, 'msg' => '编辑成功', 'data' => null];
|
|
} catch (\Exception $e) {
|
|
// 回滚事务
|
|
Db::rollback();
|
|
|
|
return ['code' => 201, 'msg' => '编辑失败', 'data' => null];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//生成私密小屋
|
|
public function xq_pd($uid,$receive_uid,$rid){
|
|
|
|
try {
|
|
Db::startTrans();
|
|
$config = get_uncache_system_config();
|
|
$now_time = time();
|
|
|
|
//主持和房主有权限
|
|
// if($uid != $room_info['room_host_uid'] && $uid != $room_info['room_owner_uid']){
|
|
// return ['code' => 201, 'msg' => '仅限主持麦操作', 'data' => null];
|
|
// }
|
|
$room_info = db::name('room')->where(['rid'=>$rid])->find();
|
|
if(empty($room_info)){
|
|
return ['code' => 201, 'msg' => '房间不存在!', 'data' => null];
|
|
}
|
|
|
|
if($uid != $room_info['room_host_uid']){
|
|
return ['code' => 201, 'msg' => '仅限主持麦操作!', 'data' => null];
|
|
}
|
|
|
|
|
|
$room_xq1_activity = db::name('room_xq1')->where(['rid'=>$rid,'is_delete'=>1])->find();
|
|
if(empty($room_xq1_activity)){
|
|
return ['code' => 201, 'msg' => '当前房间没有相亲活动!', 'data' => null];
|
|
}
|
|
|
|
//相亲房活动阶段
|
|
if($room_xq1_activity['stage'] != 3){
|
|
return ['code' => 201, 'msg' => '当前不处于心动选择阶段!', 'data' => null];
|
|
}
|
|
|
|
|
|
$xq_room_micro = db::name('room_micro')->where(['rid'=>$rid,'micro_id'=>7])->where('uid','<>',0)->find();
|
|
if(empty($xq_room_micro)){
|
|
return ['code' => 201, 'msg' => '相亲麦暂无人员!', 'data' => null];
|
|
}
|
|
|
|
|
|
$user_id = $xq_room_micro['uid']; //相亲麦人员
|
|
|
|
//嘉宾麦是否亮灯
|
|
$jia_bin_microinfo = db::name('room_micro')->where(['rid'=>$rid,'uid'=>$receive_uid])->where("micro_id",'in',[1,2,3,4,5,6])->find();
|
|
if(empty($jia_bin_microinfo)){
|
|
return ['code' => 201, 'msg' => '牵手人员不在嘉宾麦!', 'data' => null];
|
|
}
|
|
|
|
if(!in_array($jia_bin_microinfo['light_type'],[1,2])){
|
|
return ['code' => 201, 'msg' => '牵手人员未亮灯!', 'data' => null];
|
|
}
|
|
|
|
|
|
$prid = 0;
|
|
//是否有空闲的私密小屋
|
|
$map = [];
|
|
$map[] = ['is_use', '=', 2];
|
|
$room_privacy = db::name('room_privacy')->where($map)->find();
|
|
if(!empty($room_privacy)){
|
|
$update = [];
|
|
$update['rid'] = $rid;
|
|
$update['uid_data'] = $user_id.','.$receive_uid;
|
|
$update['is_use'] = 1;
|
|
$update['update_time'] = $now_time;
|
|
$update['end_time'] = $now_time + $config['privacy_room_time'];
|
|
$reslut = db::name('room_privacy')->where('prid', $room_privacy['prid'])->update($update);
|
|
if(!$reslut){
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => '操作失败3', 'data' => null];
|
|
}
|
|
$prid = $room_privacy['prid'];
|
|
}else{
|
|
$reslut = $this->create_privacy_room();
|
|
if($reslut['code'] != 200){
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
|
}
|
|
$prid = $reslut['data'];
|
|
|
|
$update = [];
|
|
$update['rid'] = $rid;
|
|
$update['uid_data'] = $user_id.','.$receive_uid;
|
|
$update['is_use'] = 1;
|
|
$update['update_time'] = $now_time;
|
|
$update['end_time'] = $now_time + $config['privacy_room_time'];
|
|
$reslut = db::name('room_privacy')->where('prid', $prid)->update($update);
|
|
if(!$reslut){
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => '操作失败1', 'data' => null];
|
|
}
|
|
}
|
|
if(empty($prid)){
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => '操作失败2', 'data' => null];
|
|
}
|
|
|
|
//关闭活动
|
|
$result = $this->pd_close_xq_activity($user_id,$receive_uid,$rid,false);
|
|
if($result['code'] != 200){
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => '操作失败12', 'data' => null];
|
|
}
|
|
|
|
|
|
|
|
Db::commit();
|
|
model('api/room')->push_room_micro_data($rid);
|
|
if(!empty($user_id)){
|
|
$push_send_user_data = [];
|
|
$push_send_user_data['rid'] = $rid;
|
|
$push_send_user_data['prid'] = $prid;
|
|
$push_send_user_data['agora_token'] = model('api/Agora')->agora_token_info($user_id, $prid);
|
|
$push_send_user_data['agora_app_id'] = $config['agora_app_id'];
|
|
|
|
$push_data = [];
|
|
$push_data['code'] = 351;
|
|
$push_data['msg'] = "推送进入私密小屋";
|
|
$push_data['data'] = $push_send_user_data;
|
|
model('api/WebSocketPush')->send_to_one($user_id, $push_data);
|
|
}
|
|
|
|
if(!empty($receive_uid)){
|
|
$push_send_receive_data = [];
|
|
$push_send_receive_data['rid'] = $rid;
|
|
$push_send_receive_data['prid'] = $prid;
|
|
$push_send_receive_data['agora_token'] = model('api/Agora')->agora_token_info($receive_uid, $prid);
|
|
$push_send_receive_data['agora_app_id'] = $config['agora_app_id'];
|
|
|
|
$push_data = [];
|
|
$push_data['code'] = 351;
|
|
$push_data['msg'] = "推送进入私密小屋";
|
|
$push_data['data'] = $push_send_receive_data;
|
|
model('api/WebSocketPush')->send_to_one($receive_uid, $push_data);
|
|
}
|
|
|
|
//房间推送code码
|
|
|
|
$push_data = [];
|
|
$push_data['code'] = 350;
|
|
$push_data['msg'] = "推送进入私密小屋";
|
|
$push_data['data'] = [];
|
|
|
|
model('api/WebSocketPush')->send_to_group($rid, $push_data);
|
|
|
|
|
|
return ['code' => 200, 'msg' => '操作成功!', 'data' => null];
|
|
} catch (\Exception $e) {
|
|
// 回滚事务
|
|
dump($e);
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//配对 关闭活动
|
|
public function pd_close_xq_activity($user_id,$receive_uid,$rid,$is_push=true){
|
|
$now_time = time();
|
|
$room_info = db::name('room')->where(['rid'=>$rid])->find();
|
|
if(empty($room_info)){
|
|
return ['code' => 201, 'msg' => '房间不存在!', 'data' => null];
|
|
}
|
|
|
|
//是否已有未结束阶段
|
|
$map = [];
|
|
$map[] = ['rid', '=', $rid];
|
|
$map[] = ['is_delete', '=', 1];
|
|
$room_xq1 = db::name('room_xq1')->where($map)->find();
|
|
if(empty($room_xq1)){
|
|
return ['code' => 201, 'msg' => '没有相亲活动!', 'data' => null];
|
|
}
|
|
|
|
//主持和房主有权限
|
|
// if($uid != $room_info['room_host_uid'] && $uid != $room_info['room_owner_uid']){
|
|
// return ['code' => 201, 'msg' => '仅限主持麦操作', 'data' => null];
|
|
// }
|
|
|
|
$room_micro_data = db::name('room_micro')->where('rid', $rid)->order('micro_id asc')->column('uid');
|
|
$jia_micro_num = 0;
|
|
$xq_uid = 0;
|
|
$invite_uid = 0;
|
|
|
|
$micro_uid_data = $room_xq1['jiabin_uids'];
|
|
$jiabin_uids_data_arr = explode(",",$room_xq1['jiabin_uids']);
|
|
|
|
|
|
foreach($room_micro_data as $a => $b){
|
|
if(in_array($a, [0,1,2,3,4,5]) && $b > 0){
|
|
$jia_micro_num += 1;
|
|
if(!in_array($b,$jiabin_uids_data_arr)){
|
|
$micro_uid_data .= $b.',';
|
|
}
|
|
}elseif($a == 6 && $b > 0){
|
|
$xq_uid = $b;
|
|
}elseif($a == 7 && $b > 0){
|
|
$invite_uid = $b;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
Db::startTrans();
|
|
//掉麦
|
|
db::name('room_micro')->where([["uid",'in',[$user_id,$receive_uid]],['micro_id','in',[1,2,3,4,5,6,7]],['rid','=',$rid]])->update([
|
|
'uid' => 0,
|
|
'light_type' => 0,
|
|
'is_spotlight' =>2,
|
|
'trac_line' =>2
|
|
]);
|
|
|
|
//除了私密小屋的人 掉麦
|
|
db::name('room_micro')->where([["uid",'not in',[$user_id,$receive_uid]],['micro_id','in',[1,2,3,4,5,6,7]],['rid','=',$rid]])->update([
|
|
'light_type' => 0,
|
|
'is_spotlight' =>2,
|
|
'trac_line' =>2
|
|
]);
|
|
|
|
db::name('room_xq1')->where(['id'=>$room_xq1['id']])->update([
|
|
'stage' => 4,
|
|
'is_delete' => 2,
|
|
'delete_time' => $now_time,
|
|
'update_time' => time(),
|
|
'invite_uid' => $invite_uid,
|
|
'xq_uid' => $xq_uid,
|
|
'host_uid' => $room_info['room_host_uid'],
|
|
'jiabin_uids'=>trim($micro_uid_data, ',')
|
|
]);
|
|
Db::commit();
|
|
if($is_push){
|
|
model('api/room')->push_room_micro_data($rid);
|
|
}
|
|
return ['code' => 200, 'msg' => '关闭成功!', 'data' => null];
|
|
}catch (\Exception $e) {
|
|
// 回滚事务
|
|
dump($e);
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//生成私密小屋
|
|
public function create_privacy_room(){
|
|
$config = get_uncache_system_config();
|
|
|
|
Db::startTrans();
|
|
try {
|
|
$prid = $this->get_available_prid();
|
|
|
|
$insert = [];
|
|
$insert['prid'] = $prid;
|
|
$insert['add_time'] = time();
|
|
$reslut = db::name('room_privacy')->insert($insert);
|
|
if(!$reslut){
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => '操作失败9', 'data' => null];
|
|
}
|
|
|
|
//创建腾讯IM群组
|
|
$reslut = model('Tencent')->create_group($prid);
|
|
|
|
if($reslut['code'] != 200){
|
|
Db::rollback();
|
|
return['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
|
}
|
|
|
|
Db::commit();
|
|
|
|
return ['code' => 200, 'msg' => '操作成功', 'data' => $prid];
|
|
} catch (\Exception $e) {
|
|
// 回滚事务
|
|
dump($e);
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//过滤私密房间ID
|
|
private function get_available_prid($prid = 0)
|
|
{
|
|
if (empty($prid)) {
|
|
$prid = db::name('room_privacy')->order('prid desc')->value('prid');
|
|
if(empty($prid)){
|
|
$prid = 1000001;
|
|
}
|
|
}
|
|
$prid = $prid + 1;
|
|
$user_info = db::name('room_privacy')->field('prid')->where('prid', $prid)->find();
|
|
if (!empty($user_info)) {
|
|
$this->get_available_prid($user_info['prid']);
|
|
} else {
|
|
return $prid;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|