浏览代码

Merge branch 'master' of http://git.bocai108.com:10180/Ethan/Customer-Service

Jonlin 6 年之前
父节点
当前提交
96372efdad

+ 2 - 2
application/admin/model/Servicetimelog.php

@@ -37,7 +37,7 @@ class Servicetimelog extends Model
             if (!isset($return[$val->cdate][$val->kfid]['1'])) {
                 $return[$val->cdate][$val->kfid]['1'] = $val->cdate . ' ' . $val->ctime;
             } else {
-                if ($return[$val->cdate][$val->kfid]['1'] < $val->cdate . ' ' . $val->ctime) {
+                if ($return[$val->cdate][$val->kfid]['1'] > $val->cdate . ' ' . $val->ctime) {
                     $return[$val->cdate][$val->kfid]['1'] = $val->cdate . ' ' . $val->ctime;
                 }
             }
@@ -45,7 +45,7 @@ class Servicetimelog extends Model
             if (!isset($return[$val->cdate][$val->kfid]['0'])) {
                 $return[$val->cdate][$val->kfid]['0'] = $val->cdate . ' ' . $val->ctime;
             } else {
-                if ($return[$val->cdate][$val->kfid]['0'] > $val->cdate . ' ' . $val->ctime) {
+                if ($return[$val->cdate][$val->kfid]['0'] < $val->cdate . ' ' . $val->ctime) {
                     $return[$val->cdate][$val->kfid]['0'] = $val->cdate . ' ' . $val->ctime;
                 }
             }

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

@@ -41,6 +41,7 @@ class Events
     public static function onWorkerStart($worker)
     {
         if (empty(self::$db)) {
+            //self::$db = new \Workerman\MySQL\Connection('192.168.2.168', '3306', 'vali', '123456', 'customer_service');
             self::$db = new \Workerman\MySQL\Connection('192.168.2.200', '3306', 'vali', '1234', 'customer_service');
         }
 
@@ -201,14 +202,13 @@ class Events
      */
     public static function onMessage($client_id, $message)
     {
-        /*if ($message == '{"type":"ping"}') {
+        if ($message == '{"type":"ping"}') {
             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]);
-        }*/
-
+            // print_r([self::$global->kfList, self::$global->userList, self::$global->uidSimpleList, self::$global->userToKf, $_SESSION['remotip'] . '.' . $_SESSION['remotport']]);
+        }
         $message = json_decode($message, true);
         if (isset($message['type'])) {
             switch ($message['type']) {
@@ -557,10 +557,11 @@ class Events
         }
         self::$db->update('ws_service_log')->cols(['status' => 2, 'end_time' => time()])->where('servicelog_id=' . $oldlog['servicelog_id'])->query();
         $tmp_old_service_logid = $oldlog['servicelog_id'];
+        $oldservicelog_id = $oldlog['servicelog_id'];
         unset($oldlog['servicelog_id']);
 
         // 修改会话时长
-        $servicelog_id = $oldlog['servicelog_id'];
+        $servicelog_id = $oldservicelog_id;
         $serviceLog = self::$db->query("select `start_time`,`intime` from `ws_service_log` 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'];
@@ -604,7 +605,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;
     }
@@ -742,7 +743,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;
         }
@@ -807,7 +807,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);
@@ -837,8 +838,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;
             }
         }
 
@@ -847,22 +848,28 @@ 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'");
+                        if ($logCount) {
+                            $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));
@@ -1501,7 +1508,10 @@ class Events
     //客服工单转单
     private static function servicetrutoother($type, $owen, $otherkfid, $serverid, $clientuid)
     {
-        $db->insert('ws_serviceturn_log')->cols(array(
+        $owen = intval(substr($owen, 2));
+        $otherkfid = intval(substr($otherkfid, 2));
+
+        self::$db->insert('ws_serviceturn_log')->cols(array(
             'stype' => $type,
             'uid' => $owen,
             'tuid' => $otherkfid,
@@ -1926,6 +1936,9 @@ class Events
             }
             $serviceLog[$k]['allCount'] = $allCount;
         }
+
+        print_r([$serviceLog, $csdTime, $verifyReturnTime]);
+
         // 查询对话时效设置.
         foreach ($adminList as $v) {
             $chat_message = [

+ 2 - 2
vendor/GatewayWorker_windows/Applications/whisper/start_gateway.php

@@ -36,8 +36,8 @@ $gateway->startPort = 2900;
 $gateway->registerAddress = '127.0.0.1:1238';
 
 // 心跳间隔
-$gateway->pingInterval = 10;
-$gateway->pingNotResponseLimit = 2;
+//$gateway->pingInterval = 10;
+//$gateway->pingNotResponseLimit = 2;
 // 心跳数据
 //$gateway->pingData = '{"message_type":"ping"}';