Ver Fonte

'修改会话超时设置'

Ethan há 6 anos atrás
pai
commit
f4df154405

+ 9 - 9
application/admin/view/index/index.html

@@ -103,7 +103,7 @@
                 <h5>当前会话</h5>
             </div>
             <div class="ibox-title" id="current2" style="width: 100px; cursor:pointer; background: #eee" onclick="current(2)">
-                <h5>在线客服</h5>
+                <h5>登陆客服</h5>
             </div>
             <div class="ibox-title" style="width: calc(100% - 200px); background: #eee;">
             </div>
@@ -182,13 +182,13 @@
                         </div>
                     </div>
                     <div class="form-group" style="margin-left: 40px">
-                        <label>报警状态:</label>
+                        <label>登陆状态:</label>
                         <div class="input-group col-sm-4 layui-form" style="width: 120px;">
                             <select lay-verify="required" lay-filter="alarm"  name="type2" id="type2">
                                 <option value="">所有状态</option>
                                 <option value="1">在线状态</option>
-                                <option value="2">休息状态</option>
-                                <option value="3">隐身状态</option>
+                                <option value="3">休息状态</option>
+                                <option value="2">隐身状态</option>
                             </select>
                         </div>
                     </div>
@@ -218,11 +218,11 @@
                         <thead>
                         <th data-field="uidname">客服</th>
                         <th data-field="hhl">当前会话量</th>
-                        <th data-field="jdl">接待量</th>
-                        <th data-field="pjhysc">平均会话时长</th>
-                        <th data-field="cpl">参评率</th>
-                        <th data-field="mydl">满意度</th>
-                        <th data-field="pjxysc">平均响应时长</th>
+                        <th data-field="jdl">今日接待量</th>
+                        <th data-field="pjhysc">今日平均会话时长</th>
+                        <th data-field="cpl">今日参评率</th>
+                        <th data-field="mydl">今日满意度</th>
+                        <th data-field="pjxysc">今日平均响应时长</th>
                         <th data-field="jrxxsc">今日休息时长</th>
                         <th data-field="fxx">发消息</th>
                         </thead>

+ 2 - 2
application/service/controller/Login.php

@@ -32,10 +32,10 @@ class Login extends Controller
             return json(['code' => -3, 'data' => '', 'msg' => '此账号已禁用']);
         }
 
-        $has = db('kfonline')->where('uid','KF'.$user['id'])->select();
+        /*$has = db('kfonline')->where('uid','KF'.$user['id'])->select();
         if(!empty($has)){
             return json(['code' => -4, 'data' => '', 'msg' => '此账号已登录']);
-        }
+        }*/
 
         if(md5($password . config('salt')) != $user['user_pwd']){
             return json(['code' => -2, 'data' => '', 'msg' => '密码错误']);

+ 97 - 24
vendor/GatewayWorker_windows/Applications/whisper/Events.php

@@ -106,7 +106,7 @@ class Events
             });
 
             // 检查对话时效给出.
-            Timer::add(60, function () {
+            Timer::add(6, function () {
                 self::overTime();
             });
 
@@ -392,12 +392,16 @@ class Events
                 // 客服关闭会话.
                 case 'kfCloseUser':
                     $userId = $message['data']['to_id'];
+                    $kfId = $message['data']['kf_id'];
+                    $groupId = $message['data']['group_id'];
                     $client = Gateway::getClientIdByUid($userId);
+                    $servicelog_id = $message['data']['conversationId'];
+                    self::$db->query("update `ws_service_log` set `servicelog_close_type` = 3 where `servicelog_id`= '$servicelog_id'");
                     if (!empty($client)) {
                         $clientId = $client['0'];
-                        $servicelog_id = $message['data']['conversationId'];
-                        self::$db->query("update `ws_service_log` set `servicelog_close_type` = 3 where `servicelog_id`= '$servicelog_id'");
-                        self::serverClose($clientId, $servicelog_id);
+                        self::serverClose($clientId, $servicelog_id, $userId, $kfId, $groupId);
+                    } else {
+                        self::closeUser($servicelog_id, $userId, $kfId, $groupId);
                     }
                     break;
                 // 客服更改状态.
@@ -964,6 +968,26 @@ class Events
     }
 
 
+    /**
+     * 客服结束会话
+     *
+     * tips: 未有$client_id的关闭
+     */
+    public static function closeUser($servicelog_id, $userId, $kf_id, $groupId)
+    {
+        $userToKf = $userToKfNew = self::$global->userToKf;
+        $kfList = $userToKfNew = self::$global->kfList;
+        $del_message = [
+            'message_type' => 'delUser',
+            'data' => [
+                'id' => $userId
+            ]
+        ];
+        Gateway::sendToClient($kfList[$groupId]['KF'.$kf_id]['client_id'], json_encode($del_message, 256));
+        unset($del_message);
+    }
+
+
     /**
      * 客服结束会话
      * @param int $client_id 连接id
@@ -971,7 +995,7 @@ class Events
      * tips: 当服务端主动退出的时候,会出现 exit status 9.原因是:服务端主动断开之后,连接的客户端会走这个方法,而短时间内进程
      * 需要处理这多的逻辑,又有cas操作,导致进程退出会超时,然后会被内核杀死,从而报出错误 9.实际对真正的业务没有任何的影响。
      */
-    public static function serverClose($client_id, $servicelog_id)
+    public static function serverClose($client_id, $servicelog_id, $userId, $kf_id, $groupId)
     {
         // 返回.
         $chat_message = [
@@ -988,6 +1012,24 @@ class Events
         //echo "客户退出:". $sql ."\n";
         self::$db->query($sql);
         $isServiceUserOut = false;
+        $noticeIs = 0;
+
+        $userToKf = $userToKfNew = self::$global->userToKf;
+        $kfList = $userToKfNew = self::$global->kfList;
+        $del_message = [
+            'message_type' => 'delUser',
+            'data' => [
+                'id' => $userId
+            ]
+        ];
+        Gateway::sendToClient($kfList[$groupId]['KF'.$kf_id]['client_id'], json_encode($del_message, 256));
+        unset($del_message);
+        // 删除关联.
+        if (isset($userToKfNew[$userId])) {
+            unset($userToKfNew[$userId]);
+            do {
+            } while (!self::$global->cas('userToKf', $userToKf, $userToKfNew));
+        }
 
         // 修改会话时长
         $serviceLog = self::$db->query("select `start_time`,`intime` from `ws_service_log` where `servicelog_id`= '$servicelog_id'");
@@ -1029,14 +1071,6 @@ class Events
                     $outUser = self::$db->query("select `user_id`,`group_id` from `ws_service_log` where `client_id`= '" . $client_id . "'");
                     // 通知 客服删除退出的用户
                     if (!empty($outUser)) {
-                        $del_message = [
-                            'message_type' => 'delUser',
-                            'data' => [
-                                'id' => $outUser['0']['user_id']
-                            ]
-                        ];
-                        Gateway::sendToClient($vo['client_id'], json_encode($del_message, 256));
-                        unset($del_message);
 
                         // 尝试分配新会员进入服务
                         self::userOfflineTask($outUser['0']['group_id']);
@@ -1228,8 +1262,32 @@ class Events
                     }
                     break;
                 case -2:
+                    $waitMsg = '暂时没有客服上班,请稍后再咨询。';
+                    // 逐一通知
+                    foreach (self::$global->userList as $vo) {
+
+                        $waitMessage = [
+                            'message_type' => 'wait',
+                            'data' => [
+                                'content' => $waitMsg,
+                            ]
+                        ];
+                        Gateway::sendToClient($vo['client_id'], json_encode($waitMessage, 256));
+                    }
                     break;
                 case -3:
+                    $waitMsg = '暂时没有客服上班,请稍后再咨询。';
+                    // 逐一通知
+                    foreach (self::$global->userList as $vo) {
+
+                        $waitMessage = [
+                            'message_type' => 'wait',
+                            'data' => [
+                                'content' => $waitMsg,
+                            ]
+                        ];
+                        Gateway::sendToClient($vo['client_id'], json_encode($waitMessage, 256));
+                    }
                     break;
                 case -4:
                     // 逐一通知
@@ -1370,7 +1428,7 @@ class Events
 
                 case -1:
                     $waitMsg = '暂时没有客服上班,请稍后再咨询。';
-                    Gateway::sendToClient($client_id, json_encode(['message_type' => "notice", 'data' => ['content' => $waitMsg]], 256));
+                    Gateway::sendToClient($client_id, json_encode(['message_type' => "notice", 'content' => $waitMsg], 256));
                     Gateway::closeClient($client_id);
                     return;
                     break;
@@ -1718,7 +1776,7 @@ class Events
             }
         }
         // 查询未断开的工单.
-        $serviceLog = self::$db->query("SELECT `servicelog_id`,`client_id`,`start_time` FROM `ws_service_log` WHERE `status`='1' OR `status`='3'");
+        $serviceLog = self::$db->query("SELECT `servicelog_id`,`client_id`,`start_time`,`user_id`,`kf_id`,`group_id` FROM `ws_service_log` WHERE `status`='1' OR `status`='3'");
         $whereOr = '1=0';
         foreach ($serviceLog as $k => $v) {
             if ($k == 0) {
@@ -1739,14 +1797,30 @@ class Events
         $setUnoperated = strtotime('-' . (self::$global->unoperated['systemconfig_data'] - 60) . ' second');
         $unoperated = strtotime('-' . (self::$global->unoperated['systemconfig_data']) . ' second');
         $noResponse = strtotime('-' . (self::$global->noResponse['systemconfig_data']) . ' second');
-        // 访客静默超时.
         foreach ($serviceLog as $k => $v) {
+            // 会话超时关闭.
+            if ($v['start_time'] <= $overtime) {
+                $servicelog_id = $v['servicelog_id'];
+                self::$db->query("update `ws_service_log` set `servicelog_close_type` = 2 where `servicelog_id`= '$servicelog_id'");
+                self::serverClose($v['client_id'], $servicelog_id, $v['user_id'], $v['kf_id'], $v['group_id']);
+                // 如果小于设定时间前一分钟则给出提示.
+            } elseif ($v['start_time'] <= $setOvertime) {
+                $chat_message = [
+                    'message_type' => 'overtime',
+                    'data' => [
+                        'content' => self::$global->overtime['systemconfig_content'],
+                    ]
+                ];
+                Gateway::sendToClient($v['client_id'], json_encode($chat_message, 256));
+            }
+
+            // 访客静默超时.
+            // 如果没有说一句话.
             if (!strlen(array_search($v['servicelog_id'], array_column($chatLog, 'servicelog_id')))) {
-                // 如果小于设定时间则关闭会话.
                 if ($v['start_time'] <= $unoperated) {
                     $servicelog_id = $v['servicelog_id'];
                     self::$db->query("update `ws_service_log` set `servicelog_close_type` = 1 where `servicelog_id`= '$servicelog_id'");
-                    self::serverClose($v['client_id'], $servicelog_id);
+                    self::serverClose($v['client_id'], $servicelog_id, $v['user_id'], $v['kf_id'], $v['group_id']);
                     // 如果小于设定时间前一分钟则给出提示.
                 } elseif ($v['start_time'] <= $setUnoperated) {
                     $chat_message = [
@@ -1759,17 +1833,16 @@ class Events
                 }
             }
         }
-        // 循环检测会话时效,会话超时关闭.
+        // 访客静默超时.如果说了话
         foreach ($chatLog as $k => $v) {
-            $toWho = substr($v['to_id'], 0, 2);
             // 如果对话为客服的最后一次对话且时间小于设定时间则结束工单.
-            if ($v['time_line'] <= $overtime) {
+            if ($v['time_line'] <= $unoperated) {
                 $found_key = array_search($v['servicelog_id'], array_column($serviceLog, 'servicelog_id'));
                 $servicelog_id = $v['servicelog_id'];
-                self::$db->query("update `ws_service_log` set `servicelog_close_type` = 2 where `servicelog_id`= '$servicelog_id'");
-                self::serverClose($serviceLog[$found_key]['client_id'], $servicelog_id);
+                self::$db->query("update `ws_service_log` set `servicelog_close_type` = 1 where `servicelog_id`= '$servicelog_id'");
+                self::serverClose($serviceLog[$found_key]['client_id'], $servicelog_id, $serviceLog[$found_key]['user_id'], $serviceLog[$found_key]['kf_id'], $serviceLog[$found_key]['group_id']);
                 // 如果对话为客服的最后一次对话且时间小于设定时间前一分钟则给出提示.
-            } elseif ($v['time_line'] <= $setOvertime) {
+            } elseif ($v['time_line'] <= $setUnoperated) {
                 $chat_message = [
                     'message_type' => 'overtime',
                     'data' => [