vali 6 years ago
parent
commit
a309eed87d
1 changed files with 29 additions and 22 deletions
  1. 29 22
      vendor/GatewayWorker_windows/Applications/whisper/Events.php

+ 29 - 22
vendor/GatewayWorker_windows/Applications/whisper/Events.php

@@ -41,9 +41,10 @@ class Events
     public static function onWorkerStart($worker)
     public static function onWorkerStart($worker)
     {
     {
         if (empty(self::$db)) {
         if (empty(self::$db)) {
-            self::$db = new \Workerman\MySQL\Connection('192.168.2.186', '3306', 'root', '', 'customer_service');
+            self::$db = new \Workerman\MySQL\Connection('192.168.2.200', '3306', 'vali', '1234', 'customer_service');
         }
         }
 
 
+
         if (empty(self::$global)) {
         if (empty(self::$global)) {
             self::$global = new \GlobalData\Client('127.0.0.1:2207');
             self::$global = new \GlobalData\Client('127.0.0.1:2207');
             // 客服列表
             // 客服列表
@@ -91,6 +92,9 @@ class Events
                 self::writeLog(2);
                 self::writeLog(2);
             });
             });
 
 
+        }
+        if (1 == $worker->id) {
+
             //每1分钟发一次本组排队数
             //每1分钟发一次本组排队数
             Timer::add(60 * 1, function () {
             Timer::add(60 * 1, function () {
                 self::lineup();
                 self::lineup();
@@ -102,20 +106,24 @@ class Events
             Timer::add(60 * 10, function () {
             Timer::add(60 * 10, function () {
                 self::upsystemconfig();
                 self::upsystemconfig();
             });
             });
+        }
+
+        if (2 == $worker->id) {
 
 
             // 检查对话时效给出.
             // 检查对话时效给出.
             Timer::add(6, function () {
             Timer::add(6, function () {
                 self::overTime();
                 self::overTime();
             });
             });
+        }
 
 
+        if (3 == $worker->id) {
             // 实时监控.
             // 实时监控.
             Timer::add(60, function () {
             Timer::add(60, function () {
                 $adminList = self::$global->adminList ?? [];
                 $adminList = self::$global->adminList ?? [];
                 self::systemMonitoring($adminList);
                 self::systemMonitoring($adminList);
             });
             });
-
-
         }
         }
+
     }
     }
 
 
     /**
     /**
@@ -179,7 +187,7 @@ class Events
         }
         }
         unset($sayHello);
         unset($sayHello);
         // 检测是否开启广告
         // 检测是否开启广告
-        $advertisement = self::$db->query('select `*` from `ws_advertisement` where `advertisement_status` = 1');
+        $advertisement = self::$db->query('select * from `ws_advertisement` where `advertisement_status` = 1');
         if (!empty($advertisement)) {
         if (!empty($advertisement)) {
             $chat_message = [
             $chat_message = [
                 'message_type' => 'advertisement',
                 'message_type' => 'advertisement',
@@ -202,8 +210,8 @@ class Events
             //Gateway::sendToCurrentClient('{"type":"pong"}');
             //Gateway::sendToCurrentClient('{"type":"pong"}');
             return;
             return;
         } else {
         } 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]);
         }
         }
 
 
         $message = json_decode($message, true);
         $message = json_decode($message, true);
@@ -221,7 +229,6 @@ class Events
                     break;
                     break;
                 // 顾客初始化
                 // 顾客初始化
                 case 'userInit';
                 case 'userInit';
-                print_r([self::$global->kfList,$message['data']]);
                     $data = $message['data'];
                     $data = $message['data'];
                     self::userInitEnt($client_id, $data);
                     self::userInitEnt($client_id, $data);
                     break;
                     break;
@@ -439,18 +446,18 @@ class Events
         $kfs = self::$global->kfList;
         $kfs = self::$global->kfList;
         $groupnamemap = self::$global->groupmap;
         $groupnamemap = self::$global->groupmap;
 
 
-        if (!$kfs  ||  empty($nowkfid)) {
+        if (!$kfs || empty($nowkfid)) {
             return $return;
             return $return;
         }
         }
 
 
         $ret = [];
         $ret = [];
 
 
         foreach ($kfs as $gruop => $users) {
         foreach ($kfs as $gruop => $users) {
-               foreach ($users as $uid=>$uinfo){
-                   if ($uid != $nowkfid){
-                       $ret[] = ['groupid'=>$gruop,'groupname'=>$groupnamemap[$gruop],'kfuid'=>$uid,'kfname'=>$uinfo['name'],'kfjobname'=>$uinfo['job_name']];
-                   }
-               }
+            foreach ($users as $uid => $uinfo) {
+                if ($uid != $nowkfid) {
+                    $ret[] = ['groupid' => $gruop, 'groupname' => $groupnamemap[$gruop], 'kfuid' => $uid, 'kfname' => $uinfo['name'], 'kfjobname' => $uinfo['job_name']];
+                }
+            }
         }
         }
         $return['data'] = $ret;
         $return['data'] = $ret;
         return $return;
         return $return;
@@ -674,10 +681,10 @@ class Events
         if (empty($uid) || empty($token)) {
         if (empty($uid) || empty($token)) {
             return false;
             return false;
         }
         }
-        $expire_time_vali = time() - 60 * 60 * 24 * 3;
-
+        $expire_time_vali = time() - 60 * 60 * 24;
         $kfid = intval(substr($uid, 2));
         $kfid = intval(substr($uid, 2));
-        $ret = self::$db->select('*')->from('ws_users')->where('id= :id and  token=:token and  expire_time>=:expire_time')->bindValues(array('id' => $kfid, 'token' => $token, 'expire_time' => $expire_time_vali))->row();
+        $ret = self::$db->select('*')->from('ws_users')->where('id=:id and  token=:token and  expire_time>=:expire_time')->bindValues(array('id' => $kfid, 'token' => $token, 'expire_time' => $expire_time_vali))->row();
+
         if ($ret) {
         if ($ret) {
             self::$db->update('ws_users')->cols(array('online_status' => 1, 'online_connectid' => $client))->where('id=' . $kfid)->query();
             self::$db->update('ws_users')->cols(array('online_status' => 1, 'online_connectid' => $client))->where('id=' . $kfid)->query();
             return $ret;
             return $ret;
@@ -772,9 +779,9 @@ class Events
         //echo "下线:$uid  - $client_id - $isKefuoff \n";
         //echo "下线:$uid  - $client_id - $isKefuoff \n";
 
 
         $adminList = self::$global->adminList ?? [];
         $adminList = self::$global->adminList ?? [];
-        $key = array_search($client_id ,$adminList);
+        $key = array_search($client_id, $adminList);
         if (strlen($key)) {
         if (strlen($key)) {
-            array_splice($adminList,$key,1);
+            array_splice($adminList, $key, 1);
             self::$global->adminList = $adminList;
             self::$global->adminList = $adminList;
         }
         }
         if (empty($uid)) {
         if (empty($uid)) {
@@ -1617,8 +1624,8 @@ class Events
 
 
         $group = self::$db->query("SELECT *  FROM `ws_groups`");
         $group = self::$db->query("SELECT *  FROM `ws_groups`");
         $arr = [];
         $arr = [];
-        if ($group){
-            foreach ($group as $val){
+        if ($group) {
+            foreach ($group as $val) {
                 $arr[$val['id']] = $val['name'];
                 $arr[$val['id']] = $val['name'];
             }
             }
             self::$global->groupmap = $arr;
             self::$global->groupmap = $arr;
@@ -1689,7 +1696,7 @@ class Events
             // 如果对话为客服的最后一次对话且时间小于设定时间则结束工单.
             // 如果对话为客服的最后一次对话且时间小于设定时间则结束工单.
             if ($v['time_line'] <= $overtime) {
             if ($v['time_line'] <= $overtime) {
                 $found_key = array_search($v['servicelog_id'], array_column($serviceLog, 'servicelog_id'));
                 $found_key = array_search($v['servicelog_id'], array_column($serviceLog, 'servicelog_id'));
-                print_r([1,$serviceLog[$found_key]['client_id']]);
+                print_r([1, $serviceLog[$found_key]['client_id']]);
                 self::serverClose($serviceLog[$found_key]['client_id'], $v['servicelog_id']);
                 self::serverClose($serviceLog[$found_key]['client_id'], $v['servicelog_id']);
                 // 如果对话为客服的最后一次对话且时间小于设定时间前一分钟则给出提示.
                 // 如果对话为客服的最后一次对话且时间小于设定时间前一分钟则给出提示.
             } elseif ($v['time_line'] <= $setOvertime) {
             } elseif ($v['time_line'] <= $setOvertime) {
@@ -1735,7 +1742,7 @@ class Events
         $serverSensitive = 0; // 客服敏感词报警次数.
         $serverSensitive = 0; // 客服敏感词报警次数.
         $csdNumber = 0; // 响应超时次数.
         $csdNumber = 0; // 响应超时次数.
         $csdTime = []; // 响应超时时间.
         $csdTime = []; // 响应超时时间.
-        foreach ($serviceLog  as $k => $v) {
+        foreach ($serviceLog as $k => $v) {
             // 工单报警总次数.
             // 工单报警总次数.
             $allCount = 0;
             $allCount = 0;
             // 差评次数.
             // 差评次数.