|
@@ -3,11 +3,11 @@
|
|
|
namespace app\api\controller;
|
|
|
|
|
|
use app\common\controller\Api;
|
|
|
+use app\utils\RedisUtil;
|
|
|
use think\Request;
|
|
|
use getusersig\getusersig;
|
|
|
use tencentim\tencentim;
|
|
|
use think\Db;
|
|
|
-use Redis;
|
|
|
|
|
|
/**
|
|
|
* 腾讯im接口
|
|
@@ -485,10 +485,7 @@ exit;
|
|
|
if($groupInfo["ErrorCode"] == 0) $groupsites[] = $groupInfo["GroupInfo"][0];
|
|
|
|
|
|
// 踢出用户在线组
|
|
|
- $redis = new Redis();
|
|
|
- $redisconfig = config("redis");
|
|
|
- $redis->connect($redisconfig["host"], $redisconfig["port"]);
|
|
|
- $redis->HDel("online_".$v["GroupId"],$user_id);
|
|
|
+ RedisUtil::getInstance('online',$v["GroupId"])->HDel($user_id);
|
|
|
}
|
|
|
// 强制下麦
|
|
|
$this->downSite($user_id,$groupsites);
|
|
@@ -506,10 +503,7 @@ exit;
|
|
|
$userInfo = \app\common\model\User::field("avatar")->where(["id"=>$user_id])->find();
|
|
|
$userAvatar = isset($userInfo["avatar"])?$userInfo["avatar"]:"";
|
|
|
|
|
|
- $redis = new Redis();
|
|
|
- $redisconfig = config("redis");
|
|
|
- $redis->connect($redisconfig["host"], $redisconfig["port"]);
|
|
|
- $redisData = $redis->get("party_".$party_id);
|
|
|
+ $redisData = RedisUtil::getInstance('party',$party_id)->get();
|
|
|
if(!$redisData) {
|
|
|
return true;
|
|
|
}
|
|
@@ -519,8 +513,7 @@ exit;
|
|
|
$partyuser = isset($partyInfo["party_user"])?$partyInfo["party_user"]:"";
|
|
|
if(is_array($partyuser)) foreach($partyuser as $k => $v) if($v === $userAvatar) unset($partyInfo["party_user"][$k]);
|
|
|
|
|
|
- $redis->set("party_".$party_id,json_encode($partyInfo));
|
|
|
-
|
|
|
+ RedisUtil::getInstance('party',$party_id)->set(json_encode($partyInfo));
|
|
|
}
|
|
|
|
|
|
|
|
@@ -531,10 +524,7 @@ exit;
|
|
|
if (!$party_id || !$user_id) {
|
|
|
return false;
|
|
|
}
|
|
|
- $redis = new Redis();
|
|
|
- $redisconfig = config("redis");
|
|
|
- $redis->connect($redisconfig["host"], $redisconfig["port"]);
|
|
|
- $data=unserialize($redis->hGet("party_lineup",$party_id));
|
|
|
+ $data=unserialize(RedisUtil::getInstance('party_lineup')->hGet($party_id));
|
|
|
// 更改红点排麦数量
|
|
|
$num = 0;
|
|
|
$send = false;
|
|
@@ -545,7 +535,7 @@ exit;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- $redis->hSet("party_lineup",$party_id,serialize($data));
|
|
|
+ RedisUtil::getInstance('party_lineup')->hSet($party_id,serialize($data));
|
|
|
|
|
|
if($send) {
|
|
|
is_array($data) && $num = count($data);
|
|
@@ -665,15 +655,11 @@ exit;
|
|
|
//没有UserId
|
|
|
}elseif($input['EventType'] == 103){
|
|
|
//进入房间,主播role=20 观众role=21
|
|
|
- $redis = new Redis();
|
|
|
- $redisconfig = config("redis");
|
|
|
- $redis->connect($redisconfig["host"], $redisconfig["port"]);
|
|
|
-
|
|
|
$userId = $input['EventInfo']['UserId'];
|
|
|
- $redis->hSet("online_" . $roomId, $userId, $userId);
|
|
|
+ RedisUtil::getInstance('online',$roomId)->hSet($userId, $userId);
|
|
|
|
|
|
// 记录在线用户在房间情况
|
|
|
- $redis->hSet("livingUser",$userId,$roomId);
|
|
|
+ RedisUtil::getInstance('livingUser')->hSet($userId,$roomId);
|
|
|
|
|
|
// 更新房间在线状态
|
|
|
$partyInfo = $redis->get("party_" . $roomId);
|
|
@@ -700,34 +686,30 @@ exit;
|
|
|
|
|
|
}elseif($input['EventType'] == 104){
|
|
|
//退出房间,主播role=20 观众role=21
|
|
|
- $redis = new Redis();
|
|
|
- $redisconfig = config("redis");
|
|
|
- $redis->connect($redisconfig["host"], $redisconfig["port"]);
|
|
|
-
|
|
|
$userId = $input['EventInfo']['UserId'];
|
|
|
- $redis->HDel("online_" . $roomId, $userId);
|
|
|
+ RedisUtil::getInstance('online',$roomId)->HDel($userId);
|
|
|
|
|
|
// 扣除在线用户在房间情况
|
|
|
- $redis->hDel("livingUser",$userId);
|
|
|
+ RedisUtil::getInstance('livingUser')->hDel($userId);
|
|
|
|
|
|
// 更新房间在线状态
|
|
|
- $partyInfo = $redis->get("party_" . $roomId);
|
|
|
+ $partyInfo = RedisUtil::getInstance('party',$roomId)->get();
|
|
|
if ($partyInfo) {
|
|
|
$partyInfo = json_decode($partyInfo, true);
|
|
|
- $memCount = count($redis->hGetAll("online_" . $roomId));
|
|
|
+ $memCount = count(RedisUtil::getInstance('online',$roomId)->hGetAll());
|
|
|
if ($memCount <= 0) {
|
|
|
$partyInfo["is_online"] = 0;
|
|
|
- $redis->set("party_" . $roomId, json_encode($partyInfo));
|
|
|
+ RedisUtil::getInstance('party',$roomId)->set(json_encode($partyInfo));
|
|
|
\app\common\model\Party::update(["is_online" => 0], ["id" => $roomId]);
|
|
|
}
|
|
|
}
|
|
|
//
|
|
|
- $liveInfo = $redis->get("livebc_" . $roomId);
|
|
|
+ $liveInfo = RedisUtil::getInstance('livebc',$roomId)->get();
|
|
|
if ($liveInfo) {
|
|
|
$liveInfo = json_decode($liveInfo, true);
|
|
|
if($input['EventInfo']['Role'] == 20){
|
|
|
$liveInfo["is_online"] = 0;
|
|
|
- $redis->set("livebc_" . $roomId, json_encode($liveInfo));
|
|
|
+ RedisUtil::getInstance('livebc',$roomId)->set(json_encode($liveInfo));
|
|
|
\app\common\model\Party::update(["is_online" => 0], ["id" => $roomId]);
|
|
|
$rs_user = Db::name('user')->where('id',$userId)->update(['is_livebc'=>0]);
|
|
|
}
|
|
@@ -782,14 +764,11 @@ exit;
|
|
|
//\app\common\model\User::update(["is_live"=>0],["id"=>$info["To_Account"]]);
|
|
|
|
|
|
// 获取用户在派对直播间情况信息
|
|
|
- $redis = new Redis();
|
|
|
- $redisconfig = config("redis");
|
|
|
- $redis->connect($redisconfig["host"], $redisconfig["port"]);
|
|
|
- $livingUserPartyId = $redis->hGet("livingUser", $info["To_Account"]);
|
|
|
+ $livingUserPartyId = RedisUtil::getInstance('livingUser')->hGet($info["To_Account"]);
|
|
|
if ($livingUserPartyId) {
|
|
|
// 扣除在线用户在房间情况
|
|
|
- $redis->hDel("livingUser", $info["To_Account"]);
|
|
|
- $redis->HDel("online_" . $livingUserPartyId, $info["To_Account"]);
|
|
|
+ RedisUtil::getInstance('livingUser')->hDel( $info["To_Account"]);
|
|
|
+ RedisUtil::getInstance('online',$livingUserPartyId)->HDel($info["To_Account"]);
|
|
|
}
|
|
|
|
|
|
// 获取用户所在群信息
|
|
@@ -805,10 +784,7 @@ exit;
|
|
|
if($groupInfo["ErrorCode"] == 0) $groupsites[] = $groupInfo["GroupInfo"][0];
|
|
|
|
|
|
// 踢出用户在线组
|
|
|
- $redis = new Redis();
|
|
|
- $redisconfig = config("redis");
|
|
|
- $redis->connect($redisconfig["host"], $redisconfig["port"]);
|
|
|
- $redis->HDel("online_".$v["GroupId"],$info["To_Account"]);
|
|
|
+ RedisUtil::getInstance('online',$v["GroupId"])->HDel($info["To_Account"]);
|
|
|
|
|
|
// 更新麦位前四
|
|
|
$this->updatePosition($info["To_Account"],$v["GroupId"]);
|
|
@@ -817,24 +793,24 @@ exit;
|
|
|
$this->cancelLineup($info["To_Account"],$v["GroupId"]);
|
|
|
|
|
|
// 房间状态变更
|
|
|
- $partyInfo = $redis->get("party_".$v["GroupId"]);
|
|
|
+ $partyInfo = RedisUtil::getInstance('party',$v["GroupId"])->get();
|
|
|
if($partyInfo) {
|
|
|
$partyInfo = json_decode($partyInfo,true);
|
|
|
- $memCount = count($redis->hGetAll("online_".$v["GroupId"]));
|
|
|
+ $memCount = count(RedisUtil::getInstance('online',$v["GroupId"])->hGetAll());
|
|
|
if($memCount <= 0) {
|
|
|
$partyInfo["is_online"] = 0;
|
|
|
- $redis->set("party_".$v["GroupId"],json_encode($partyInfo));
|
|
|
+ RedisUtil::getInstance('party',$v["GroupId"])->set(json_encode($partyInfo));
|
|
|
\app\common\model\Party::update(["is_online"=>0],["id"=>$v["GroupId"]]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $liveInfo = $redis->get("live_".$v["GroupId"]);
|
|
|
+ $liveInfo = RedisUtil::getInstance('live',$v["GroupId"])->get();
|
|
|
if($liveInfo) {
|
|
|
$liveInfo = json_decode($liveInfo,true);
|
|
|
- $memCount = count($redis->hGetAll("online_".$v["GroupId"]));
|
|
|
+ $memCount = count(RedisUtil::getInstance('online',$v["GroupId"])->hGetAll());
|
|
|
if($memCount <= 0) {
|
|
|
$liveInfo["is_online"] = 0;
|
|
|
- $redis->set("live_".$v["GroupId"],json_encode($liveInfo));
|
|
|
+ RedisUtil::getInstance('live',$v["GroupId"])->set(json_encode($liveInfo));
|
|
|
\app\common\model\Party::update(["is_online"=>0],["id"=>$v["GroupId"]]);
|
|
|
}
|
|
|
}
|
|
@@ -847,12 +823,9 @@ exit;
|
|
|
}
|
|
|
break;
|
|
|
// case 'Group.CallbackAfterNewMemberJoin': // 新成员入群
|
|
|
-// $redis = new Redis();
|
|
|
-// $redisconfig = config("redis");
|
|
|
-// $redis->connect($redisconfig["host"], $redisconfig["port"]);
|
|
|
// $members = $input["NewMemberList"];
|
|
|
// if($members) foreach($members as $k => $v) {
|
|
|
-// $redis->hSet("online_".$input["GroupId"],$v["Member_Account"],$v["Member_Account"]);
|
|
|
+// RedisUtil::getInstance('online',$input["GroupId"])->hSet($v["Member_Account"],$v["Member_Account"]);
|
|
|
// // 更新房间在线状态
|
|
|
// $party_id = $input["GroupId"];
|
|
|
// $partyInfo = $redis->get("party_".$party_id);
|
|
@@ -872,33 +845,30 @@ exit;
|
|
|
// echo json_encode($res);
|
|
|
// break;
|
|
|
// case 'Group.CallbackAfterMemberExit': // 成员离开
|
|
|
-// $redis = new Redis();
|
|
|
-// $redisconfig = config("redis");
|
|
|
-// $redis->connect($redisconfig["host"], $redisconfig["port"]);
|
|
|
// $members = $input["ExitMemberList"];
|
|
|
// if($members) foreach($members as $k => $v) {
|
|
|
-// $redis->HDel("online_".$input["GroupId"],$v["Member_Account"]);
|
|
|
+// RedisUtil::getInstance('online',$input["GroupId"])->HDel($v["Member_Account"]);
|
|
|
// }
|
|
|
// // 更新房间在线状态
|
|
|
// $party_id = $input["GroupId"];
|
|
|
-// $partyInfo = $redis->get("party_".$party_id);
|
|
|
+// $partyInfo = RedisUtil::getInstance('party',$party_id)->get();
|
|
|
// if($partyInfo) {
|
|
|
// $partyInfo = json_decode($partyInfo,true);
|
|
|
-// $memCount = count($redis->hGetAll("online_".$party_id));
|
|
|
+// $memCount = count(RedisUtil::getInstance('online',$party_id)->hGetAll());
|
|
|
// if($memCount <= 0) {
|
|
|
// $partyInfo["is_online"] = 0;
|
|
|
-// $redis->set("party_".$party_id,json_encode($partyInfo));
|
|
|
+// RedisUtil::getInstance('party',$party_id)->set(json_encode($partyInfo));
|
|
|
// \app\common\model\Party::update(["is_online"=>0],["id"=>$party_id]);
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
-// $liveInfo = $redis->get("live_".$party_id);
|
|
|
+// $liveInfo = RedisUtil::getInstance('live',$party_id)->get();
|
|
|
// if($liveInfo) {
|
|
|
// $liveInfo = json_decode($liveInfo,true);
|
|
|
-// $memCount = count($redis->hGetAll("online_".$party_id));
|
|
|
+// $memCount = count(RedisUtil::getInstance('online',$party_id)->hGetAll());
|
|
|
// if($memCount <= 0) {
|
|
|
// $liveInfo["is_online"] = 0;
|
|
|
-// $redis->set("live_".$party_id,json_encode($liveInfo));
|
|
|
+// RedisUtil::getInstance('live',$party_id)->set(json_encode($liveInfo));
|
|
|
// \app\common\model\Party::update(["is_online"=>0],["id"=>$party_id]);
|
|
|
// }
|
|
|
// }
|