Commit 26c76d0b authored by hujun's avatar hujun

聊天相互登录设备

parent 43e4b9ec
...@@ -190,20 +190,20 @@ class Broker extends Basic ...@@ -190,20 +190,20 @@ class Broker extends Basic
$redis_->set("agent_city_" . $agents_data['id'], $site_city[0]['city']); $redis_->set("agent_city_" . $agents_data['id'], $site_city[0]['city']);
$redis_->set("agent_site_id_" . $agents_data['id'], $agents_data['site_id']); $redis_->set("agent_site_id_" . $agents_data['id'], $agents_data['site_id']);
/*处理多个手机登录聊天*/ // /*处理多个手机登录聊天*/
$m_chat_ext = new ChatUserExt(); // $m_chat_ext = new ChatUserExt();
$bind_where['is_forbidden'] = 0; // $bind_where['is_forbidden'] = 0;
$bind_where['user_id'] = $agents_data['id']; // $bind_where['user_id'] = $agents_data['id'];
$bind_where['type'] = 1; // $bind_where['type'] = 1;
$del_bind_id = $m_chat_ext->getChatUserExtByUserId($bind_where, 'a.id,a.push_id', 100); // $del_bind_id = $m_chat_ext->getChatUserExtByUserId($bind_where, 'a.id,a.push_id', 100);
if (count($del_bind_id) > 0) { // if (count($del_bind_id) > 0) {
foreach ($del_bind_id as $v) { // foreach ($del_bind_id as $v) {
if ($v['push_id'] != $params["push_id"]) { // if ($v['push_id'] != $params["push_id"]) {
$m_chat_ext->updateDate(['is_forbidden'=>1], ['id'=>$v['id']]); // $m_chat_ext->updateDate(['is_forbidden'=>1], ['id'=>$v['id']]);
} // }
} // }
} // }
/*处理多个手机登录聊天*/ // /*处理多个手机登录聊天*/
return $this->response(200, $data['msg'], $data['data']); return $this->response(200, $data['msg'], $data['data']);
} }
......
...@@ -86,7 +86,7 @@ class ChatService ...@@ -86,7 +86,7 @@ class ChatService
//todo 保存或更新push_id //todo 保存或更新push_id
//todo 1.判断设备id +id 的数据是否存在,存在并且push_id和提交的不同则修改,否者新增 //todo 1.判断设备id +id 的数据是否存在,存在并且push_id和提交的不同则修改,否者新增
if ($id > 0 && $device_id && $push_id) { if ($id > 0 && $device_id && $push_id) {
$this->savePushId($id, $device_id, $push_id); $this->savePushIdV2($id, $device_id, $push_id);
} }
return [ "code" => 200, "only_id" => $only_id ]; return [ "code" => 200, "only_id" => $only_id ];
} }
...@@ -139,6 +139,61 @@ class ChatService ...@@ -139,6 +139,61 @@ class ChatService
return true; return true;
} }
/**
* @param $chat_user_id
* @param $device_id
* @param $push_id
* @return bool
* @throws \think\Exception
* @throws \think\exception\DbException
*/
private function savePushIdV2($chat_user_id, $device_id, $push_id)
{
//todo 根据设备来判断使用设备用户,
$where['device_id'] = $device_id;
$where['push_id'] = $push_id;
$info = $this->chatUserExtModel->getChatUserExt($where, 'id,ext_id,device_id,push_id,is_forbidden');
$result = false;
if (count($info) > 0) {
$current_user_id = 0;
foreach ($info as $k=>$v) {
if ($v['is_forbidden'] == 0) {
if ($v['ext_id'] != $chat_user_id) {
$this->chatUserExtModel->addChatUserExt(['is_forbidden'=>1], $v['id']);
}
} else {
if ($v['ext_id'] == $chat_user_id) {
$this->chatUserExtModel->addChatUserExt(['is_forbidden'=>0], $v['id']);
$current_user_id = $chat_user_id;
}
}
}
if (empty($current_user_id)) {
//todo 当前用户没有使用过该设备,新增
$params["ext_id"] = $chat_user_id;
$params["device_id"] = $device_id;
$params["push_id"] = $push_id;
$params["is_forbidden"] = 0;
$result = $this->chatUserExtModel->addChatUserExt($params);
}
} else {
//todo 保存或更新push_id
$params["ext_id"] = $chat_user_id;
$params["device_id"] = $device_id;
$params["push_id"] = $push_id;
$params["is_forbidden"] = 0;
$result = $this->chatUserExtModel->addChatUserExt($params);
}
if (!$result) {
return false;
}
return true;
}
/** /**
* 生成唯一id * 生成唯一id
* @param $userId integer 用户id * @param $userId integer 用户id
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment