|
|
@@ -331,11 +331,11 @@ class Events
|
|
|
case 'evaluate':
|
|
|
self::evaluate($client_id, $message);
|
|
|
break;
|
|
|
- // 关闭会话.
|
|
|
- case 'closeUser':
|
|
|
+ // 客服关闭会话.
|
|
|
+ case 'kfCloseUser':
|
|
|
$client = Gateway::getClientIdByUid($message['data']['to_id']);
|
|
|
if(!empty($client)){
|
|
|
- self::onClose($client['0']);
|
|
|
+ self::serverClose($client['0']);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
@@ -350,8 +350,50 @@ class Events
|
|
|
*/
|
|
|
public static function onClose($client_id)
|
|
|
{
|
|
|
- print_r([$client_id,self::$global->uidSimpleList,self::$global->userList]);
|
|
|
+ $uidSimpleList = self::$global->uidSimpleList;
|
|
|
+ $userId = '';
|
|
|
+ foreach ($uidSimpleList as $k => $v) {
|
|
|
+ if ($v[0] == $client_id) {
|
|
|
+ $userId = $k;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $kfId = '';
|
|
|
+ if ($userId) {
|
|
|
+ $userToKf = self::$global->userToKf;
|
|
|
+ $kfId = $userToKf[$userId][1];
|
|
|
+ }
|
|
|
+ if ($kfId) {
|
|
|
+ $client = Gateway::getClientIdByUid($kfId);
|
|
|
+ // 返回.
|
|
|
+ $chat_message = [
|
|
|
+ 'message_type' => 'userClose',
|
|
|
+ 'data' => [
|
|
|
+ 'content' => '用户连接已断开',
|
|
|
+ 'time' => date('H:i'),
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ Gateway::sendToClient($client['0'], json_encode($chat_message));
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 客服结束会话
|
|
|
+ * @param int $client_id 连接id
|
|
|
+ *
|
|
|
+ * tips: 当服务端主动退出的时候,会出现 exit status 9.原因是:服务端主动断开之后,连接的客户端会走这个方法,而短时间内进程
|
|
|
+ * 需要处理这多的逻辑,又有cas操作,导致进程退出会超时,然后会被内核杀死,从而报出错误 9.实际对真正的业务没有任何的影响。
|
|
|
+ */
|
|
|
+ public static function serverClose($client_id)
|
|
|
+ {
|
|
|
+ // 返回.
|
|
|
+ $chat_message = [
|
|
|
+ 'message_type' => 'closeBysever',
|
|
|
+ 'data' => [
|
|
|
+ 'content' => '客服停止了该会话',
|
|
|
+ 'time' => date('H:i'),
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ Gateway::sendToClient($client_id, json_encode($chat_message));
|
|
|
$isServiceUserOut = false;
|
|
|
// 将会员服务信息,从客服的服务列表中移除
|
|
|
$old = $kfList = self::$global->kfList;
|
|
|
@@ -361,7 +403,7 @@ class Events
|
|
|
|
|
|
$isServiceUserOut = true;
|
|
|
|
|
|
- // 根据client id 去更新这个会员离线的一些信息
|
|
|
+ // 根据client id 去更新会话工单一些信息
|
|
|
self::$db->query("update `ws_service_log` set `end_time` = " . time() . " , `status` = '2' where `client_id`= '" . $client_id . "'");
|
|
|
|
|
|
// 从会员的内存表中检索出该会员的信息,并更新内存
|
|
|
@@ -380,7 +422,7 @@ class Events
|
|
|
while(!self::$global->cas('uidSimpleList', $oldSimple, $simpleList)){};
|
|
|
unset($oldSimple, $simpleList);
|
|
|
|
|
|
- //$outUser = self::$db->query("select `user_id`,`group_id` from `ws_service_log` where `client_id`= '" . $client_id . "'");
|
|
|
+ $outUser = self::$db->query("select `user_id`,`group_id` from `ws_service_log` where `client_id`= '" . $client_id . "'");
|
|
|
// 通知 客服删除退出的用户
|
|
|
if(!empty($outUser)){
|
|
|
$del_message = [
|
|
|
@@ -587,7 +629,12 @@ class Events
|
|
|
|
|
|
while(!self::$global->cas('kfList', self::$global->kfList, $res['data']['4'])){}; // 更新客服数据
|
|
|
while(!self::$global->cas('userList', self::$global->userList, $res['data']['5'])){}; // 更新会员数据
|
|
|
-
|
|
|
+ $userToKf = self::$global->userToKf;
|
|
|
+ $userToKf[$res['data']['3']['id']] = [
|
|
|
+ $res['data']['3']['id'],
|
|
|
+ $res['data']['0']
|
|
|
+ ];
|
|
|
+ self::$global->userToKf = $userToKf;
|
|
|
// 通知会员发送信息绑定客服的id
|
|
|
$noticeUser = [
|
|
|
'message_type' => 'connect',
|
|
|
@@ -857,7 +904,7 @@ class Events
|
|
|
*/
|
|
|
private static function evaluate($client_id, $message)
|
|
|
{
|
|
|
- // 查询问题.
|
|
|
+ // 修改数据库.
|
|
|
$evaluate_id = $message['data']['evaluate_id'];
|
|
|
$result = self::$db->query("UPDATE `ws_service_log` SET `evaluate_id` = '" . $evaluate_id . "' WHERE `client_id`='" . $client_id . "'");
|
|
|
if ($result) {
|