vali 6 年之前
父節點
當前提交
318ed44c1f
共有 1 個文件被更改,包括 116 次插入31 次删除
  1. 116 31
      vendor/GatewayWorker_windows/Applications/whisper/Events.php

+ 116 - 31
vendor/GatewayWorker_windows/Applications/whisper/Events.php

@@ -186,6 +186,7 @@ class Events
                     self::KFStatusCg($client_id, $message);
                     break;
                 case 'changeOtherhKeFu';
+                    self::changeOtherhKeFu($client_id, $smessage);
                     break;
                 // 弹出评价.
                 case 'getEvaluate';
@@ -198,7 +199,7 @@ class Events
     public static function chatMessage($message)
     {
         // 获取当前会话工单.
-        $data = json_decode(self::$redis->HGET('SERVICELOG',$message['conversationId']), true);
+        $data = json_decode(self::$redis->HGET('SERVICELOG', $message['conversationId']), true);
         $chat_message = [
             'message_type' => 'chatMessage',
             'data' => [
@@ -212,7 +213,7 @@ class Events
             $data['alarm_corresponding'] = time() - $data['start_time'];
         }
         // 发送消息.
-        if (substr($message['from_id'],0,2) === 'KF') {
+        if (substr($message['from_id'], 0, 2) === 'KF') {
             $data['userLastTime'] = time();
             Gateway::sendToClient($data['client_id'], json_encode($chat_message));
         } else {
@@ -279,15 +280,6 @@ class Events
     }
 
 
-    //客户工单内部组转接
-    public static function changeOtherhKeFu($client_id, $smessage)
-    {
-
-
-        return;
-    }
-
-
     public static function KFStatusCg($client_id, $message)
     {
         if (!isset($_SESSION['iskefu']) || $_SESSION['iskefu'] != 1) {
@@ -1081,7 +1073,7 @@ class Events
             if (!$data['userLastTime']) {
                 if ($data['start_time'] <= $unoperated) {
                     self::serverClose($k);
-                // 如果小于设定时间前一分钟则给出提示.
+                    // 如果小于设定时间前一分钟则给出提示.
                 } elseif ($data['start_time'] <= $setUnoperated) {
                     $chat_message = [
                         'message_type' => 'overtime',
@@ -1091,11 +1083,11 @@ class Events
                     ];
                     Gateway::sendToClient($data['client_id'], json_encode($chat_message, 256));
                 }
-            // 双方静默超时.
+                // 双方静默超时.
             } elseif ($data['userLastTime'] <= $overtime && $data['serverLastTime'] <= $overtime) {
                 self::serverClose($k);
-            // 如果小于设定时间前一分钟则给出提示.
-            }  elseif ($data['userLastTime'] <= $setOvertime && $data['serverLastTime'] <= $setOvertime) {
+                // 如果小于设定时间前一分钟则给出提示.
+            } elseif ($data['userLastTime'] <= $setOvertime && $data['serverLastTime'] <= $setOvertime) {
                 $chat_message = [
                     'message_type' => 'overtime',
                     'data' => [
@@ -1183,6 +1175,107 @@ class Events
         }
     }
 
+    //客户工单内部组转接
+    public static function changeOtherhKeFu($client_id, $smessage)
+    {
+        $message = $smessage['data'];
+
+        $groupid = isset($message['fromgroup']) ? intval($message['fromgroup']) : 0;
+        $groupidto = isset($message['togroup']) ? intval($message['togroup']) : 0;
+        $toukfid = isset($message['toukfuid']) ? $message['toukfuid'] : 0;
+        $fromkfuid = isset($message['fromkfuid']) ? $message['fromkfuid'] : 0;
+        $uid = isset($message['uid']) ? intval($message['uid']) : 0;
+        $word = isset($message['word']) ? $message['word'] : '';
+
+        if (empty($groupid) || empty($groupidto) || empty($toukfid) || empty($fromkfuid) || empty($uid) || ($toukfid == $fromkfuid)) {
+            self::DebugOut('changeOtherhKeFu exit1...');
+            return false;
+        }
+        if (!Gateway::isUidOnline($toukfid) || !Gateway::isUidOnline($uid)) {
+            self::DebugOut('changeOtherhKeFu exit2...');
+            return false;
+        }
+
+        $kf_info_from = json_decode(self::$redis->hget(self::KFINFOKEY, $fromkfuid), true);
+        $kf_info_to = json_decode(self::$redis->hget(self::KFINFOKEY, $toukfid), true);
+        $user_info = json_decode(self::$redis->hget(self::USERINFOKEY, $uid), true);
+        $serviceid = intval($user_info['serverid']);
+
+        if (empty($kf_info_from) || empty($kf_info_to) || empty($user_info) || empty($serviceid)) {
+            self::DebugOut('changeOtherhKeFu exit23...');
+            return false;
+        }
+
+        if ($kf_info_to['status'] != 1) {
+            self::DebugOut('changeOtherhKeFu exit4...');
+            return false;
+        }
+
+        /////////取消原有会话,开启新会话
+        $oldlog = self::$db->select('*')->from('ws_service_log')->where('servicelog_id=:servicelog_id ')->bindValues(['servicelog_id' => $serviceid])->orderByDESC(['servicelog_id'])->row();
+        if (!$oldlog) {
+            self::DebugOut('changeOtherhKeFu exit5...');
+            return false;
+        }
+        self::serverClose($serviceid);
+        unset($oldlog['servicelog_id']);
+
+        $oldlog = array_merge($oldlog, ['kf_id' => self::getkfid($toukfid), 'start_time' => time(), 'end_time' => 0, 'status' => 1, 'evaluate_id' => 0]);
+        $new_id = self::$db->insert('ws_service_log')->cols($oldlog)->query();
+        if (!$new_id) {
+            self::DebugOut('changeOtherhKeFu exit6...');
+            return false;
+        }
+
+        ///更新redis数据
+        $kf_info_from['user_info'] = self::ArrayDataopt($kf_info_from['user_info'], $user_info['client_id'], 0);
+        $kf_info_from['task'] = count($kf_info_from['user_info']);
+        self::$redis->hset(self::KFINFOKEY, $fromkfuid, json_encode($kf_info_from, 256));
+        $kf_info_to['user_info'] = self::ArrayDataopt($kf_info_to['user_info'], $user_info['client_id'], 1, $new_id);
+        $kf_info_to['task'] = count($kf_info_to['user_info']);
+        self::$redis->hset(self::KFINFOKEY, $toukfid, json_encode($kf_info_to, 256));
+        $user_info['kfuid'] = $toukfid;
+        $user_info['serverid'] = $new_id;
+        self::$redis->hset(self::USERINFOKEY, $uid, json_encode($user_info, 256));
+
+        unset($kf_info_to['user_info']);
+        ///通知消息发送--------------
+        // 通知会员发送信息绑定客服的id
+        $noticeUser = [
+            'message_type' => 'connect',
+            'data' => [
+                'kf_id' => $toukfid,
+                'conversationId' => $new_id,
+                'kf_name' => $kf_info_to['name'],
+                'serverInfo' => $kf_info_to,
+            ]
+        ];
+        Gateway::sendToClient($user_info['client_id'], json_encode($noticeUser, 256));
+        unset($noticeUser);
+
+        // 通知客服端绑定会员的信息
+        $userinfoarr = ['id' => $uid, 'name' => $oldlog['user_name'], 'avatar' => $oldlog['user_avatar'], 'website' => $oldlog['website'], 'browse' => $oldlog['browse'], 'system' => $oldlog['system'], 'ip' => $oldlog['user_ip'], 'group' => $oldlog['group_id'], 'client_id' => $oldlog['client_id']];
+        $noticeKf = [
+            'message_type' => 'connect',
+            'data' => [
+                'user_info' => $userinfoarr,
+                'conversationId' => $new_id,
+            ]
+        ];
+        Gateway::sendToClient($kf_info_to['client_id'], json_encode($noticeKf, 256));
+        unset($noticeKf);
+
+        self::servicetrutoother('OUT', $fromkfuid, $toukfid, $tmp_old_service_logid, $uid);
+        self::servicetrutoother('IN', $toukfid, $fromkfuid, $new_id, $uid);
+
+        //回转接人,转接成功
+        Gateway::sendToCurrentClient(json_encode(['message_type' => 'trunconnect', 'data' => ['status' => 1]], 256));
+
+        self::DebugOut('changekf 转换成功!');
+
+        return;
+    }
+
 
     //客服在线状态写组
     private static function writeLogKfStatus($kf, $status, $flag = 1)
@@ -1206,19 +1299,20 @@ class Events
     public static function resetServiceLog($kfid = 0)
     {
         $t = time() - 24 * 3600 * 7;
+        $now = time();
 
         if ($kfid) {
             if ((substr($kfid, 0, 2) == 'KF')) {
                 $kfid = intval(substr($kfid, 2));
             }
             $kfid = intval($kfid);
-            self::$db->query("update ws_service_log set status=2 where kf_id=$kfid and  start_time>=$t and  status!=2");
+            self::$db->query("update ws_service_log set status=2,end_time=$now where  start_time>=$t and  kf_id=$kfid and  status!=2");
             self::$redis->hdel(self::KFINFOKEY, 'KF' . $kfid);
         } else {
             self::$redis->del(self::KFINFOKEY);
             self::$redis->del(self::USERLIST);
             self::$redis->del(self::USERINFOKEY);
-            self::$db->query("update ws_service_log set status=2 where  start_time>=$t and  status!=2");
+            self::$db->query("update ws_service_log set status=2,end_time=$now where  start_time>=$t and  status!=2");
         }
 
     }
@@ -1284,6 +1378,11 @@ class Events
 
             self::writeLogKfStatus(0, 0, 0);
 
+            //每5分钟更新一次系统配置文件
+            Timer::add(5, function () {
+                self::userOnlineTask();
+            });
+
             //初始化.....
             self::upsystemconfig();
             //每5分钟更新一次系统配置文件
@@ -1299,21 +1398,7 @@ class Events
     //调试使用
     public static function mydebug($client_id, $message)
     {
-        $ret = self::$db->insert('ws_service_log')->cols(array(
-            'user_id' => 1,
-            'client_id' => 'acasdfasf',
-            'user_name' => 'test',
-            'user_avatar' => '',
-            'user_ip' => '',
-            'kf_id' => 1,
-            'start_time' => 1212,
-            'group_id' => 4,
-            'website' => '',
-            'system' => '',
-            'browse' => ''
-        ))->query();
 
-        print_r($ret);
     }
 
     public static function MySendMsg($clientId, $msg)