Jonlin 6 years ago
parent
commit
a432ac3993

+ 62 - 55
application/admin/controller/Report.php

@@ -1,6 +1,10 @@
 <?php
+
 namespace app\admin\controller;
 
+
+use  app\admin\model\Countmidtable;
+
 /**
  * 报表类
  */
@@ -16,10 +20,11 @@ class Report extends Base
      */
     public function index()
     {
-        $param  = input('param.');
+        $param = input('param.');
         $startTime = isset($param['start']) ? $param['start'] : date('Y-m-d', strtotime("-6 day"));
         $endTime = isset($param['end']) ? $param['end'] : date('Y-m-d');
-        $timeInterval = $this->Date_segmentation($startTime,$endTime);
+        $timeInterval = $this->Date_segmentation($startTime, $endTime);
+        $queueData = [];
         $chatData = [];
         $serviceData = [];
         $xData = [];
@@ -32,7 +37,7 @@ class Report extends Base
             $dayBegin = strtotime($value);
             $dayEnd = strtotime($value) + 24 * 60 * 60;
             $chatLogCountWhere['start_time'] = ['between', [$dayBegin, $dayEnd]];
-            $join   = [
+            $join = [
                 'alarm b' => 'a.servicelog_id = b.servicelog_id',
             ];
             $field = ['alarm_count', 'evaluate_id', 'system'];
@@ -69,10 +74,15 @@ class Report extends Base
                 'name' => $k,
             ];
         }
+
+        $queueData =(new  Countmidtable())->getQueryDay($timeInterval['days_list']);
+
+
         $this->assign([
             'xData' => json_encode($xData),
             'chatData' => json_encode($chatData),
             'serviceData' => json_encode($serviceData),
+            'queueData' => json_encode($queueData),
             'systemCount' => json_encode($systemCount),
             'evaluate' => json_encode([
                 'evaluateGood' => $evaluateGood,
@@ -96,85 +106,80 @@ class Report extends Base
     function Date_segmentation($start_date, $end_date)
     {
         //如果为空,则从今天的0点为开始时间
-        if(!empty($start_date))
-            $start_date=date('Y-m-d H:i:s',strtotime($start_date));
+        if (!empty($start_date))
+            $start_date = date('Y-m-d H:i:s', strtotime($start_date));
         else {
-            $start_date=date('Y-m-d 00:00:00',time());
+            $start_date = date('Y-m-d 00:00:00', time());
         }
 
         //如果为空,则以明天的0点为结束时间(不存在24:00:00,只会有00:00:00)
-        if(!empty($end_date))
-            $end_date=date('Y-m-d H:i:s',strtotime($end_date));
+        if (!empty($end_date))
+            $end_date = date('Y-m-d H:i:s', strtotime($end_date));
         else
-            $end_date=date('Y-m-d 00:00:00',strtotime('+1 day'));
+            $end_date = date('Y-m-d 00:00:00', strtotime('+1 day'));
 
         //between 查询 要求必须是从低到高
-        if($start_date>$end_date)
-        {
-            $ttt=$start_date;
-            $start_date=$end_date;
-            $end_date=$ttt;
-        }elseif($start_date==$end_date){
-            echo '时间输入错误';die;
+        if ($start_date > $end_date) {
+            $ttt = $start_date;
+            $start_date = $end_date;
+            $end_date = $ttt;
+        } elseif ($start_date == $end_date) {
+            echo '时间输入错误';
+            die;
         }
 
-        $time_s=strtotime($start_date);
-        $time_e=strtotime($end_date);
-        $seconds_in_a_day=86400;
+        $time_s = strtotime($start_date);
+        $time_e = strtotime($end_date);
+        $seconds_in_a_day = 86400;
 
         //生成中间时间点数组(时间戳格式、日期时间格式、日期序列)
-        $days_inline_array=array();
-        $times_inline_array=array();
+        $days_inline_array = array();
+        $times_inline_array = array();
 
         //日期序列
-        $days_list=array();
+        $days_list = array();
         //判断开始和结束时间是不是在同一天
-        $days_inline_array[0]=$start_date;  //初始化第一个时间点
-        $times_inline_array[0]=$time_s;     //初始化第一个时间点
-        $days_list[]=date('Y-m-d',$time_s);//初始化第一天
-        if(
-            date('Y-m-d',$time_s)
-            ==date('Y-m-d',$time_e)
-        ){
-            $days_inline_array[1]=$end_date;
-            $times_inline_array[1]=$time_e;
-        }
-        else
-        {
+        $days_inline_array[0] = $start_date;  //初始化第一个时间点
+        $times_inline_array[0] = $time_s;     //初始化第一个时间点
+        $days_list[] = date('Y-m-d', $time_s);//初始化第一天
+        if (date('Y-m-d', $time_s) == date('Y-m-d', $time_e)) {
+            $days_inline_array[1] = $end_date;
+            $times_inline_array[1] = $time_e;
+        } else {
             /**
              * A.取开始时间的第二天凌晨0点
              * B.用结束时间减去A
              * C.用B除86400取商,取余
              * D.用A按C的商循环+86400,取得分割时间点,如果C没有余数,则最后一个时间点 与 循环最后一个时间点一致
              */
-            $A_temp=date('Y-m-d 00:00:00',$time_s+$seconds_in_a_day);
-            $A=strtotime($A_temp);
-            $B=$time_e-$A;
-            $C_quotient=floor($B/$seconds_in_a_day);    //商舍去法取整
-            $C_remainder=fmod($B,$seconds_in_a_day);               //余数
-            $days_inline_array[1]=$A_temp;
-            $times_inline_array[1]=$A;
-            $days_list[]=date('Y-m-d',$A);              //第二天
-            for($increase_time=$A,$c_count_t=1;$c_count_t<=$C_quotient;$c_count_t++)
-            {
-                $increase_time+=$seconds_in_a_day;
-                $days_inline_array[]=date('Y-m-d H:i:s',$increase_time);
-                $times_inline_array[]=$increase_time;
-                $days_list[]=date('Y-m-d',$increase_time);
+            $A_temp = date('Y-m-d 00:00:00', $time_s + $seconds_in_a_day);
+            $A = strtotime($A_temp);
+            $B = $time_e - $A;
+            $C_quotient = floor($B / $seconds_in_a_day);    //商舍去法取整
+            $C_remainder = fmod($B, $seconds_in_a_day);               //余数
+            $days_inline_array[1] = $A_temp;
+            $times_inline_array[1] = $A;
+            $days_list[] = date('Y-m-d', $A);              //第二天
+            for ($increase_time = $A, $c_count_t = 1; $c_count_t <= $C_quotient; $c_count_t++) {
+                $increase_time += $seconds_in_a_day;
+                $days_inline_array[] = date('Y-m-d H:i:s', $increase_time);
+                $times_inline_array[] = $increase_time;
+                $days_list[] = date('Y-m-d', $increase_time);
             }
-            $days_inline_array[]=$end_date;
-            $times_inline_array[]=$time_e;
+            $days_inline_array[] = $end_date;
+            $times_inline_array[] = $time_e;
         }
 
         return array(
-            'start_date'=>$start_date,
-            'end_date'=>$end_date,
-            'days_list'=>$days_list,
-            'days_inline'=>$days_inline_array,
-            'times_inline'=>$times_inline_array
+            'start_date' => $start_date,
+            'end_date' => $end_date,
+            'days_list' => $days_list,
+            'days_inline' => $days_inline_array,
+            'times_inline' => $times_inline_array
         );
     }
 
+<<<<<<< HEAD
     // 工作报表
     public function workreport()
     {
@@ -279,5 +284,7 @@ class Report extends Base
 
         return $this->fetch();
     }
+=======
+>>>>>>> 725c05a5865a7a7fa45b0171f80d65c46633c315
 
 }//end class

+ 34 - 0
application/admin/model/Countmidtable.php

@@ -0,0 +1,34 @@
+<?php
+
+namespace app\admin\model;
+
+use think\Model;
+
+/**
+ * 分组模型
+ */
+class Countmidtable extends Model
+{
+    public function getQueryDay($dayarray, $key = 0)
+    {
+        // $dayarray => ['2019-07-07','2019-07-08'....];
+
+        $ret = $this->where(['dtype' => 'user.queue.day.length', 'mdate' => ['IN', $dayarray]])->select();
+        $tmpData = [];
+        if (count($ret) > 0) {
+            foreach ($ret as $val) {
+                $tmpData[$val['mdate']] = intval($val['dcontent']);
+            }
+        }
+        $return = [];
+        foreach ($dayarray as $sval) {
+            if ($key) {
+                $return[$sval] = isset($tmpData[$sval]) ? $tmpData[$sval] : 0;
+            } else {
+                $return[] = isset($tmpData[$sval]) ? $tmpData[$sval] : 0;
+            }
+        }
+        return $return;
+    }
+
+}

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

@@ -67,6 +67,7 @@
     var xData = {$xData};
     var chatData = {$chatData};
     var serviceData = {$serviceData};
+    var queueData = {$queueData};
     var evaluate = {$evaluate};
     var systemCount = {$systemCount};
     // 基于准备好的dom,初始化echarts实例
@@ -91,7 +92,7 @@
             top: 'top',
             icon: 'rect',
             //selectedMode: false, //取消图例上的点击事件
-            data: ['会话量', '消息量'],
+            data: ['会话量', '消息量','排队量'],
         },
         grid: {
             left: '30',
@@ -164,6 +165,13 @@
                 barWidth: 24,// 柱形的宽度
                 barGap: 0,
                 data: chatData
+            },
+            {
+                name: '排队量',
+                type: 'bar',
+                barWidth: 24,// 柱形的宽度
+                barGap: 0,
+                data: queueData
             }
         ]
     };

+ 64 - 23
vendor/GatewayWorker_windows/Applications/whisper/Events.php

@@ -41,9 +41,10 @@ class Events
     public static function onWorkerStart($worker)
     {
         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)) {
             self::$global = new \GlobalData\Client('127.0.0.1:2207');
             // 客服列表
@@ -80,6 +81,7 @@ class Events
 
         // 定时统计数据
         if (0 === $worker->id) {
+
             self::writeLogKfStatus(0, 0, 0);
 
             // 1分钟统计一次实时数据
@@ -113,9 +115,8 @@ class Events
                 $adminList = self::$global->adminList ?? [];
                 self::systemMonitoring($adminList);
             });
-
-
         }
+
     }
 
     /**
@@ -179,7 +180,7 @@ class Events
         }
         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)) {
             $chat_message = [
                 'message_type' => 'advertisement',
@@ -202,8 +203,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]);
         }
 
         $message = json_decode($message, true);
@@ -221,7 +222,6 @@ class Events
                     break;
                 // 顾客初始化
                 case 'userInit';
-                print_r([self::$global->kfList,$message['data']]);
                     $data = $message['data'];
                     self::userInitEnt($client_id, $data);
                     break;
@@ -254,12 +254,15 @@ class Events
                             'servicelog_id' => $message['data']['conversationId'],
                             'time_line' => time()
                         ];
-
                         self::$db->insert('ws_chat_log')->cols($serviceLog)->query();
+
+                        /*
                         if ($message['data']['sensitiveNumber']) {
 
                         }
                         self::$db->query("update `ws_alarm` set `alarm_corresponding` = '$corresponding',alarm_respond=2 where `servicelog_id`= '$servicelog_id'");
+                        */
+
                         unset($serviceLog);
                     }
                     if (isset($message['data']['isFirst']) && $message['data']['isFirst']) {
@@ -439,18 +442,18 @@ class Events
         $kfs = self::$global->kfList;
         $groupnamemap = self::$global->groupmap;
 
-        if (!$kfs  ||  empty($nowkfid)) {
+        if (!$kfs || empty($nowkfid)) {
             return $return;
         }
 
         $ret = [];
 
         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 $return;
@@ -566,6 +569,10 @@ class Events
         ];
         Gateway::sendToClient($tokfidclientid, json_encode($noticeKf, 256));
         unset($noticeKf);
+
+        self::servicetrutoother('OUT', $fromkfuid, $toukfid, $oldlog['servicelog_id'], $uid);
+        self::servicetrutoother('IN', $toukfid, $fromkfuid, $new_id, $uid);
+
         //回转接人,转接成功
         Gateway::sendToCurrentClient(json_encode(['message_type' => 'trunconnect', 'data' => ['status' => 1], 256]));
 
@@ -674,10 +681,10 @@ class Events
         if (empty($uid) || empty($token)) {
             return false;
         }
-        $expire_time_vali = time() - 60 * 60 * 24 * 3;
-
+        $expire_time_vali = time() - 60 * 60 * 24;
         $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) {
             self::$db->update('ws_users')->cols(array('online_status' => 1, 'online_connectid' => $client))->where('id=' . $kfid)->query();
             return $ret;
@@ -772,9 +779,9 @@ class Events
         //echo "下线:$uid  - $client_id - $isKefuoff \n";
 
         $adminList = self::$global->adminList ?? [];
-        $key = array_search($client_id ,$adminList);
+        $key = array_search($client_id, $adminList);
         if (strlen($key)) {
-            array_splice($adminList,$key,1);
+            array_splice($adminList, $key, 1);
             self::$global->adminList = $adminList;
         }
         if (empty($uid)) {
@@ -1331,6 +1338,9 @@ class Events
 
                 case -1:
                     $waitMsg = '暂时没有客服上班,请稍后再咨询。';
+                    Gateway::sendToClient($client_id, json_encode(['message_type' => "noservice", 'data' => ['content' => $waitMsg]], 256));
+                    Gateway::closeClient($client_id);
+                    return;
                     break;
                 case -2:
                     break;
@@ -1362,8 +1372,39 @@ class Events
                 }
             }
             Gateway::sendToGroup('group_' . $group, json_encode(['message_type' => 'kfqueuelength', 'leng' => $waitcount], 256));
+            self::todayqueuelength();
+        }
+
+    }
+
+    //今天排序累加
+    private static function todayqueuelength()
+    {
+        $dtype = 'user.queue.day.length';
+        $today = date("Y-m-d");
+
+        $sret = self::$db->select('*')->from('ws_countmidtable')->where('dtype=:dtype and  mdate=:mdate')->bindValues(array('dtype' => $dtype, 'mdate' => $today))->row();
+        if ($ret) {
+            $db->update('ws_countmidtable')->cols(array('dcontent' => intval($sret['dcontent']) + 1))->where('id=' . $sret['id'])->query();
+        } else {
+            $db->insert('ws_countmidtable')->cols(array(
+                'dtype' => $dtype,
+                'mdate' => $today,
+                'datatype' => 1,
+                'dcontent' => 1))->query();
         }
+    }
 
+    //客服工单转单
+    private static function servicetrutoother($type, $owen, $otherkfid, $serverid, $clientuid)
+    {
+        $db->insert('ws_serviceturn_log')->cols(array(
+            'stype' => $type,
+            'uid' => $owen,
+            'tuid' => $otherkfid,
+            'serverid' => $serverid,
+            'guestuid' => $clientuid
+        ))->query();
     }
 
 
@@ -1617,8 +1658,8 @@ class Events
 
         $group = self::$db->query("SELECT *  FROM `ws_groups`");
         $arr = [];
-        if ($group){
-            foreach ($group as $val){
+        if ($group) {
+            foreach ($group as $val) {
                 $arr[$val['id']] = $val['name'];
             }
             self::$global->groupmap = $arr;
@@ -1689,7 +1730,7 @@ class Events
             // 如果对话为客服的最后一次对话且时间小于设定时间则结束工单.
             if ($v['time_line'] <= $overtime) {
                 $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']);
                 // 如果对话为客服的最后一次对话且时间小于设定时间前一分钟则给出提示.
             } elseif ($v['time_line'] <= $setOvertime) {
@@ -1735,7 +1776,7 @@ class Events
         $serverSensitive = 0; // 客服敏感词报警次数.
         $csdNumber = 0; // 响应超时次数.
         $csdTime = []; // 响应超时时间.
-        foreach ($serviceLog  as $k => $v) {
+        foreach ($serviceLog as $k => $v) {
             // 工单报警总次数.
             $allCount = 0;
             // 差评次数.