vali 6 gadi atpakaļ
vecāks
revīzija
6eea7d28bf

+ 11 - 1
application/admin/controller/Kfonitoring.php

@@ -2,6 +2,7 @@
 
 namespace app\admin\controller;
 
+use app\admin\model\Kfonline;
 use app\common\tools;
 use app\common\KfjkLogic;
 use app\admin\model\Users as UserModel;
@@ -11,6 +12,7 @@ class Kfonitoring extends Base
 
     public function kfjiankong()
     {
+
         $kfgroup = tools::getKfGroup();
         $return = [] ;
 
@@ -21,7 +23,15 @@ class Kfonitoring extends Base
             $kdidsArray = $logic->getValiKF($groupid,$onlinestatus);
             $return = $logic->getAllData($kdidsArray);
 
-            return json($return);
+            if (empty($kdidsArray)){
+                $lastreturn['total'] = 0 ;  //总数据
+                $lastreturn['rows'] = [];
+            }else{
+                $lastreturn['total'] = count($return);  //总数据
+                $lastreturn['rows'] = $return;
+            }
+
+            return json($lastreturn);
         }
         $this->assign('kfgroup',$kfgroup);
         return $this->fetch('kfonitoring/kfjiankong');

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

@@ -0,0 +1,34 @@
+<?php
+
+namespace app\admin\model;
+
+use think\Model;
+
+/**
+ * 智能问答分组模型
+ */
+class Kfonline extends Model
+{
+    public function getOnlineAll($status = 0)
+    {
+        $return = [];
+        if ($status == 0) {
+            $rets = $this->all();
+        } else {
+            $rets = $this->where(['status' => $status])->select();
+        }
+
+        if ($rets) {
+            foreach ($rets as $ret) {
+                $return[$ret->uid] = trim($ret->uid,'KF');
+            }
+        }
+        return $return;
+    }
+
+    public function user()
+    {
+        $this->hasOne('Users', 'uid', 'id');
+    }
+
+}

+ 0 - 24
application/admin/model/Kfonlline.php

@@ -1,24 +0,0 @@
-<?php
-namespace app\admin\model;
-
-use think\Model;
-
-/**
- * 智能问答分组模型
- */
-class Kfonlline extends Model
-{
-    public function getOnlineAll(){
-        $return = [] ;
-        $ret =   $this->all();
-        if ($ret){
-            $return[$ret['uid']] = $ret['uid'];
-        }
-        return $return ;
-    }
-
-    public function  user(){
-        $this->hasOne('Users','uid','id');
-    }
-
-}

+ 4 - 4
application/admin/view/kfonitoring/kfjiankong.html

@@ -42,7 +42,7 @@
                         </select>
                     </div>
 
-                    <div class="form-group">
+                    <div class="form-group" style="display: none">
                         <lable>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</lable>
                         <select name="type3" id="type3" class="form-control">
                             <option value="0">所有会话</option>
@@ -63,10 +63,10 @@
                 <div class="example">
                     <table id="cusTable">
                         <thead>
-                        <th data-field="id">客服</th>
+                        <th data-field="uid">客服</th>
                         <th data-field="hhl">会话量</th>
                         <th data-field="jdl">接待量</th>
-                        <th data-field="pjhhsc">平均会话时长</th>
+                        <th data-field="pjhysc">平均会话时长</th>
                         <th data-field="cpl">参评率</th>
                         <th data-field="mydl">满意度率</th>
                         <th data-field="pjxysc">平均响应时长</th>
@@ -98,7 +98,7 @@
             url: "{:url('kfonitoring/kfjiankong')}", //获取数据的地址
             striped: true,  //表格显示条纹
             pagination: true, //启动分页
-            pageSize: 20,  //每页显示的记录数
+            pageSize: 50,  //每页显示的记录数
             pageNumber:1, //当前第几页
             pageList: [5, 10, 15, 20, 25],  //记录数可选列表
             sidePagination: "server", //表示服务端请求

+ 27 - 0
application/common.php

@@ -34,4 +34,31 @@ function removeDir($directory)
     }
 
     return true;
+}
+
+
+function Kfid($uid)
+{
+    return trim($uid, 'KF');
+}
+
+function kfUid($id)
+{
+    return 'KF' . $id;
+}
+
+//数组转为健的数组
+function kftoKey($uidArray, $type = 0)
+{
+    $return = [];
+    foreach ($uidArray as $val) {
+        if ($type == 0) {
+            $return[$val] = 0;
+        } elseif ($type==1) {
+            $return[$val] = [];
+        }else{
+            $return[$val] = $val;
+        }
+    }
+    return $return ;
 }

+ 98 - 39
application/common/KfjkLogic.php

@@ -8,7 +8,7 @@
 
 namespace App\common;
 
-use app\admin\model\Kfonlline;
+use app\admin\model\Kfonline;
 use app\admin\model\Users;
 use think\Db;
 
@@ -28,78 +28,137 @@ use think\Db;
 class KfjkLogic
 {
 
-    public function getAllData($uidarray)
+    public function getAllData($kfuidarray)
     {
-        if (empty($uidarray)) {
+        if (empty($kfuidarray)) {
             return false;
         }
-
-        $todayall = $this->getTodayServiceData($uidarray);
-        if (!$todayall){
-            return false ;
+        $todayall = $this->getTodayServiceData($kfuidarray);
+        if (!$todayall) {
+            return false;
         }
+        $kfuidarray_index = kftoKey($kfuidarray, 1);
 
 
+        $uids = $kfuidarray ;
+        $hyl = $this->hyl($kfuidarray, $todayall);
+        $jdl = $this->jdl($kfuidarray, $todayall);
+        $pjhysc = $this->pjhusc($kfuidarray, $todayall);
+        $cpl = $this->cpl($kfuidarray, $todayall);
 
+        foreach ($kfuidarray_index as $uid => $val) {
+            $kfuidarray_index[$uid]['uid'] = $uids[$uid];
+            $kfuidarray_index[$uid]['hhl'] = $hyl[$uid];
+            $kfuidarray_index[$uid]['jdl'] = $jdl[$uid];
+            $kfuidarray_index[$uid]['pjhysc'] = $pjhysc[$uid];
+            $kfuidarray_index[$uid]['cpl'] = $cpl[$uid];
+        }
 
+        $last = [] ;
+        foreach ( $kfuidarray_index as $val){
+            $last[] = $val;
+        }
 
-
+        return $last;
     }
 
 
+    //按条件获取用户数组 组ID, 在线状态  0为全部
     public function getValiKF($groupid, $onlinestatus)
     {
-        $groupusers = [];
-        $kfgroup = (new Users)->getByGroup($groupid);
-
-        if (!$kfgroup) {
-            return [];
+        $groupusers = (new Users)->getByGroup($groupid);
+        $groupuserArray = [];
+        if ($groupusers) {
+            foreach ($groupusers as $val) {
+                $groupuserArray[$val['id']] = $val['id'];
+            }
         }
+        $statusArr = (new Kfonline())->getOnlineAll($onlinestatus);
+        $return = array_intersect($groupuserArray, $statusArr);
+        return $return;
+    }
 
-        foreach ($kfgroup as $val) {
-            $groupusers[] = $val['id'];
-        }
 
-        if ($onlinestatus) {
-            $m = (new Kfonlline())->getOnlineAll();
-            if (!$m) {
-                return [];
-            }
+    //会话量 统计
+    public function hyl($uidArray, $alllogs)
+    {
+        $rets = kftoKey($uidArray);
 
-            $statuukfs = [];
-            foreach ($m as $sval) {
-                if (($sval['status']) == $onlinestatus) {
-                    $statuukfs[] = $sval['uid'];
+        foreach ($rets as $uid) {
+            foreach ($alllogs as $log) {
+                if ($uid == $log['kf_id']) {
+                    $rets[$uid]++;
                 }
             }
-
-            if (!$statuukfs) {
-                return [];
-            }
-            return $statuukfs;
         }
-        return $groupusers;
+        return $rets;
     }
 
-    public function hyl($kfuid)
-    {
 
+    //接待量 统计
+    public function jdl($uidArray, $alllogs)
+    {
+        $rets = kftoKey($uidArray);
+        foreach ($rets as $uid) {
+            foreach ($alllogs as $log) {
+                if ($uid == $log['kf_id']) {
+                    $rets[$uid]++;
+                }
+            }
+        }
+        return $rets;
     }
 
-    public function jdl($kfuid)
+    //平均会话时长 统计
+    public function pjhusc($uidArray, $alllogs)
     {
 
-    }
+        $rets = kftoKey($uidArray, 1);
 
-    public function pjhusc($kfuid)
-    {
+        foreach ($rets as $uid) {
+            foreach ($alllogs as $log) {
+                if ($uid == $log['kf_id'] && $log['status'] == 2) {
+                    $rets[$uid]['count']++;
+                    $rets[$uid]['times'] += ($log['end_time'] - $log['start_time']);
+                }
+            }
+        }
 
+        $return = [];
+        foreach ($rets as $uid => $val) {
+            if (isset($rets[$uid]['count'])) {
+                $return[$uid] = $return[$uid]['times'] / $return[$uid]['count'];
+            } else {
+                $return[$uid] = 0;
+            }
+        }
 
+        return $return;
     }
 
-    public function cpl($kfuid)
+
+    //参评率
+    public function cpl($uidArray, $alllogs)
     {
+        $rets = kftoKey($uidArray, 1);
+        foreach ($rets as $uid) {
+            foreach ($alllogs as $log) {
+                if ($uid == $log['kf_id']) {
+                    $rets[$uid]['count']++;
+                    $rets[$uid]['pl'] += ($log['evaluate_id'] > 0 ? 1 : 0);
+                }
+            }
+        }
 
+        $return = [];
+        foreach ($rets as $uid => $val) {
+            if (isset($rets[$uid]['count'])) {
+                $return[$uid] = $return[$uid]['pl'] / $return[$uid]['cocountunt'];
+            } else {
+                $return[$uid] = 0;
+            }
+        }
+        return $return;
     }
 
     public function mydl($kfuid)
@@ -122,7 +181,7 @@ class KfjkLogic
         $today_begin = strtotime(date("Y-m-d"));
         $today_end = $today_begin + 86400;
 
-        $filds = "group_id,kf_id,user_id,status,start_time,intime,end_time,evaluate_id" ;
+        $filds = "group_id,kf_id,user_id,status,start_time,intime,end_time,evaluate_id";
         if ($kfuidArray) {
             $ret = Db::name('service_log')->field($filds)->where(['start_time' => ['>=', $today_begin], 'kf_id' => ['IN', $kfuidArray]])->where(['start_time' => ['<', $today_end]])->select();
         } else {