Commit c3de05b5 authored by hujun's avatar hujun Committed by zw

保留一个有效状态

parent 8e75ebba
......@@ -86,7 +86,7 @@ class ChatService
//todo 保存或更新push_id
//todo 1.判断设备id +id 的数据是否存在,存在并且push_id和提交的不同则修改,否者新增
if ($id > 0 && $device_id && $push_id) {
$this->savePushIdV2($id, $device_id, $push_id, $chatUser[0]['type']);
$this->savePushIdV2($id, $device_id, $push_id);
}
return [ "code" => 200, "only_id" => $only_id ];
}
......@@ -143,32 +143,30 @@ class ChatService
* @param $chat_user_id
* @param $device_id
* @param $push_id
* @param $type
* @return bool
* @throws Exception
* @throws \think\Exception
* @throws \think\exception\DbException
*/
private function savePushIdV2($chat_user_id, $device_id, $push_id, $type)
private function savePushIdV2($chat_user_id, $device_id, $push_id)
{
//todo 根据设备来判断使用设备用户,
$where['device_id'] = $device_id;
$where['type'] = $type;
$info = $this->chatUserExtModel->getChatUserExtByUserId($where, 'a.id,a.ext_id,a.device_id,a.push_id,a.is_forbidden', 100);
$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 && $push_id == $v['push_id']) {
$this->chatUserExtModel->updateDate(['is_forbidden'=>1], ['id'=>$v['id']]);
if ($v['ext_id'] != $chat_user_id) {
$this->chatUserExtModel->addChatUserExt(['is_forbidden'=>1], $v['id']);
} else {
$this->chatUserExtModel->updateDate(['update_time'=>date('Y-m-d H:i:s')], ['id'=>$v['id']]);
$current_user_id = $chat_user_id;
}
} else {
if ($v['ext_id'] == $chat_user_id && $push_id == $v['push_id']) {
$this->chatUserExtModel->updateDate(['is_forbidden'=>0], ['id'=>$v['id'], 'ext_id'=>$chat_user_id]);
if ($v['ext_id'] == $chat_user_id && $current_user_id != $chat_user_id) {
$this->chatUserExtModel->addChatUserExt(['is_forbidden'=>0], $v['id']);
$current_user_id = $chat_user_id;
}
}
......@@ -181,6 +179,15 @@ class ChatService
$params["push_id"] = $push_id;
$params["is_forbidden"] = 0;
$result = $this->chatUserExtModel->addChatUserExt($params);
} else {
$old_device_where['ext_id'] = $current_user_id;
$old_device_where['is_forbidden'] = 0;
$old_device_where['push_id'] = ['<>', $push_id];
$info = $this->chatUserExtModel->getChatUserExt($where, 'id');
foreach ($info as $k2=>$v2) {
$this->chatUserExtModel->addChatUserExt(['is_forbidden'=> 1], $v2['id']);
}
}
} else {
//todo 保存或更新push_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