vali 6 年之前
父节点
当前提交
fbfbb549ef
共有 1 个文件被更改,包括 20 次插入16 次删除
  1. 20 16
      vendor/GatewayWorker_windows/Applications/whisper/Events.php

+ 20 - 16
vendor/GatewayWorker_windows/Applications/whisper/Events.php

@@ -206,8 +206,8 @@ class Events
             Gateway::sendToCurrentClient('{"type":"pong"}');
             return;
         } else {
-            echo "onMessage: " . $message . "\r\n";
-            print_r([self::$global->kfList, self::$global->userList, self::$global->uidSimpleList, self::$global->userToKf]);
+            //echo "onMessage: " . $message . "\r\n";
+            // print_r([self::$global->kfList, self::$global->userList, self::$global->uidSimpleList, self::$global->userToKf, $_SESSION['remotip'] . '.' . $_SESSION['remotport']]);
         }
 
         $message = json_decode($message, true);
@@ -606,7 +606,7 @@ class Events
         self::servicetrutoother('IN', $toukfid, $fromkfuid, $new_id, $uid);
 
         //回转接人,转接成功
-        Gateway::sendToCurrentClient(json_encode(['message_type' => 'trunconnect', 'data' => ['status' => 1], 256]));
+        Gateway::sendToCurrentClient(json_encode(['message_type' => 'trunconnect', 'data' => ['status' => 1]], 256));
 
         return;
     }
@@ -744,7 +744,6 @@ class Events
         $onlinekf = self::$global->kfList;
         if (!isset($onlinekf[$group]) || count($onlinekf[$group]) <= 0) {
             Gateway::sendToClient($client_id, json_encode(['message_type' => 'notice', 'content' => '暂时没有客服上班,请稍后再咨询。'], 256));
-            sleep(1);
             Gateway::closeClient($client_id);
             return;
         }
@@ -809,7 +808,8 @@ class Events
     {
         $isKefuoff = isset($_SESSION['iskefu']) ? $_SESSION['iskefu'] : 0;
         $uid = isset($_SESSION['uid']) ? $_SESSION['uid'] : false;
-        //echo "下线:$uid  - $client_id - $isKefuoff \n";
+
+        //echo "下线:uid: $uid  - cid: $client_id - iskf: $isKefuoff \n";
 
         $adminList = self::$global->adminList ?? [];
         $key = array_search($client_id, $adminList);
@@ -839,8 +839,8 @@ class Events
         $simpliUsers = self::$global->uidSimpleList;
         $simpliUsersID_UID_Arr = [];
         if (!empty($simpliUsers)) {
-            foreach ($simpliUsers as $key => $val) {
-                $simpliUsersID_UID_Arr[$val['0']] = $key;
+            foreach ($simpliUsers as $cuid => $val) {
+                $simpliUsersID_UID_Arr[$val['0']] = $cuid;
             }
         }
 
@@ -849,22 +849,26 @@ class Events
             foreach ($user_info as $val) {
                 Gateway::sendToClient($val, json_encode(['type' => 'serviceoffline', 'msg' => '客户人员下线!'], 256));
                 if (isset($simpliUsersID_UID_Arr[$val])) {
-                    self::$db->query("update `ws_service_log` set `status` = '2',end_time=$now  where `user_id`= '$simpliUsersID_UID_Arr[$val]' and  kf_id='$uid' and  group_id=$group  and  `status`!=2 ");
-
                     // 修改会话时长
                     $serviceLog = self::$db->query("select `start_time`,`servicelog_id`,`intime` from `ws_service_log` where `user_id`= '$simpliUsersID_UID_Arr[$val]' and  kf_id='$uid' and  group_id=$group  and  `status`!=2");
-                    $servicelog_id = $serviceLog[0]['servicelog_id'];
-                    self::$db->query("update `ws_service_log` set `servicelog_close_type` = 4 where `servicelog_id`= '$servicelog_id'");
-                    $logCount = self::$db->query("select count(*) as `count` from `ws_chat_log` where `servicelog_id`= '$servicelog_id'");
-                    $alarmCount = $logCount[0]['count'];
-                    $cvtOvertime = time() - $serviceLog[0]['start_time'];
-                    $alarmLineTime = $serviceLog[0]['start_time'] - $serviceLog[0]['intime'];
-                    self::$db->query("update `ws_alarm` set `alarm_cvtOvertime` = '$cvtOvertime',`alarm_lineTime` = '$alarmLineTime',`alarm_count` = '$alarmCount'
+                    if ($serviceLog) {
+                        $servicelog_id = $serviceLog[0]['servicelog_id'];
+                        $logCount = self::$db->query("select count(*) as `count` from `ws_chat_log` where `servicelog_id`= '$servicelog_id'");
+                        $alarmCount = $logCount[0]['count'];
+                        $cvtOvertime = time() - $serviceLog[0]['start_time'];
+                        $alarmLineTime = $serviceLog[0]['start_time'] - $serviceLog[0]['intime'];
+                        self::$db->query("update `ws_alarm` set `alarm_cvtOvertime` = '$cvtOvertime',`alarm_lineTime` = '$alarmLineTime',`alarm_count` = '$alarmCount'
                                       where `servicelog_id`= '$servicelog_id'");
+                    }
                 }
                 Gateway::closeClient($val);
             }
         }
+        if ($uid) {
+            $uiiid = intval(substr($uid, 2));
+            self::$db->query("update `ws_service_log` set `status` = '2',end_time=$now,`servicelog_close_type` = 4   where  kf_id=$uiiid and  group_id=$group  and  `status`!=2 ");
+        }
+
         unset($kefuinfo_old_new[$group][$uid]);
 
         $kfid = intval(substr($uid, 2));