vali 6 vuotta sitten
vanhempi
commit
5892637e39

+ 88 - 1
application/admin/controller/Report.php

@@ -4,6 +4,10 @@ namespace app\admin\controller;
 
 
 use  app\admin\model\Countmidtable;
+use app\admin\model\Users as Usersmodel;
+use app\admin\model\Groups as GroupsModel;
+use app\admin\model\Servicetimelog as ServicetimelogModel;
+use app\admin\model\Kfstatetimes as KfstatetimesModel;
 
 /**
  * 报表类
@@ -75,7 +79,7 @@ class Report extends Base
             ];
         }
 
-        $queueData =(new  Countmidtable())->getQueryDay($timeInterval['days_list']);
+        $queueData = (new  Countmidtable())->getQueryDay($timeInterval['days_list']);
 
 
         $this->assign([
@@ -97,6 +101,89 @@ class Report extends Base
     }//end index()
 
 
+    public function attendancereport()
+    {
+
+        $goups = (new GroupsModel)->where(['status' => 1])->select();
+
+        if (request()->isAjax()) {
+
+            $param = input('param.');
+            $limit = $param['pageSize'];
+            $offset = ($param['pageNumber'] - 1) * $limit;
+
+            $param = input('param.searchText');
+            if (empty($param)) {
+                $param = '0|0';
+            }
+            list($zone, $sgroup) = explode('|', $param);
+            if (empty($zone)) {
+                $zoneArray1 = [date("Y-m-d")];
+            } else {
+                $zonesarr = explode(',', $zone);
+                $dd = $this->Date_segmentation($zonesarr['0'], $zonesarr['1']);
+                $zoneArray1 = $dd['days_list'];
+            }
+            $zoneArray = array_map(function ($i) {
+                return "'$i'";
+            }, $zoneArray1);
+            $uidarr = (new Usersmodel())->getUidsBygid(intval($sgroup), 1, 1);
+
+            if (!$uidarr) {
+                return json(['rows' => [], 'total' => 0]);
+            }
+
+            $model1 = new ServicetimelogModel();
+            $model2 = new  KfstatetimesModel();
+            $ret1 = $model1->getDayData($zoneArray1, $uidarr['uids']);
+            $ret2 = $model2->getDayData($zoneArray1, $uidarr['uids']);
+            $retall = $this->reportDataFormat($ret1, $ret2, $uidarr['objs'], $zoneArray1, $limit, $offset);
+
+            return json($retall);
+        }
+
+        $this->assign('groups', $goups);
+        return $this->fetch();
+    }
+
+    function reportDataFormat($onoffdata, $timesdata, $uobjarr, $dataArray, $limit, $offset)
+    {
+        $allData = [];
+        $all_last = [];
+        foreach ($dataArray as $day) {
+            foreach ($uobjarr as $uid => $user) {
+                $kfuid = 'KF' . $uid;
+                if (isset($onoffdata[$day][$kfuid])) {
+                    $allData[$day][$kfuid] = ['of0' => $onoffdata[$day][$kfuid][0], 'of1' => $onoffdata[$day][$kfuid][1]];
+                } else {
+                    $allData[$day][$kfuid] = ['of0' => '', 'of1' => ''];
+                }
+
+                if (isset($timesdata[$day][$kfuid])) {
+                    $all_last[] = array_merge($timesdata[$day][$kfuid], $allData[$day][$kfuid], ['uname' => $uobjarr[$uid]->user_name,'account' => $uobjarr[$uid]->user_account,'day'=>$day]);
+                } else {
+                    $all_last[] = array_merge(['0' => 0, '1' => 0, '2' => 0, '3' => 0], $allData[$day][$kfuid], ['uname' => $uobjarr[$uid]->user_name, 'account' => $uobjarr[$uid]->user_account,'day'=>$day]);
+                }
+            }
+        }
+
+        $len = count($all_last);
+        $return = ['rows' => [], 'total' => $len];
+        if ($offset >= $len) {
+            return $return;
+        }
+        $begin = $offset;
+        $end = ($offset + $limit);
+        $end = ($end > $len) ? $len - 1 : $end;
+
+        for ($i = $begin; $i < $end; $i++) {
+            $return['rows'][] = $all_last[$i];
+        }
+
+        return $return;
+    }
+
+
     /**
      * 时间分割
      *

+ 70 - 0
application/admin/model/Kfstatetimes.php

@@ -0,0 +1,70 @@
+<?php
+
+namespace app\admin\model;
+
+use think\Model;
+
+/**
+ * 客服状态改变时长模型
+ */
+class Kfstatetimes extends Model
+{
+    public function getDayData($dataArray, $uidArray = [])
+    {
+        $ret = $this->where(['sday' => ['IN', $dataArray]]);
+        if ($uidArray) {
+            $ret = $ret->where(['kfuid' => ['IN', $uidArray]]);
+        }
+        $ret = $ret->order(['kfuid' => 'asc'])->select();
+        if (!$ret) {
+            return false;
+        }
+
+        $return = $this->getOneUserData($ret);
+
+        return $return;
+    }
+
+    private function getOneUserData($array)
+    {
+        $return = [];
+        foreach ($array as $val) {
+            $return[$val->sday][$val->kfuid][$val->kstatus] = $val->stime;
+
+        }
+
+        foreach ($return as $sday => $sval) {
+            foreach ($sval as $kfuid => $tval) {
+
+                if (!isset($tval['0'])) {
+                    $return[$sday][$kfuid]['0'] = 0;
+                }
+
+                if (!isset($tval['1'])) {
+                    $return[$sday][$kfuid]['1'] = 0;
+                }
+                if (!isset($tval['2'])) {
+                    $return[$sday][$kfuid]['2'] = 0;
+                }
+                if (!isset($tval['3'])) {
+                    $return[$sday][$kfuid]['3'] = 0;
+                }
+
+                $return[$sday][$kfuid]['all'] = $return[$sday][$kfuid]['1'] + $return[$sday][$kfuid]['2'] + $return[$sday][$kfuid]['3'];
+                if ($return[$sday][$kfuid]['all']) {
+                    $return[$sday][$kfuid]['s1p'] = floatPointDigit($return[$sday][$kfuid]['1'] / $return[$sday][$kfuid]['all']);
+                    $return[$sday][$kfuid]['s2p'] = floatPointDigit($return[$sday][$kfuid]['2'] / $return[$sday][$kfuid]['all']);
+                    $return[$sday][$kfuid]['s3p'] = floatPointDigit($return[$sday][$kfuid]['3'] / $return[$sday][$kfuid]['all']);
+                } else {
+                    $return[$sday][$kfuid]['s1p'] = 0;
+                    $return[$sday][$kfuid]['s2p'] = 0;
+                    $return[$sday][$kfuid]['s3p'] = 0;
+                }
+            }
+        }
+
+        return $return;
+    }
+
+
+}

+ 58 - 0
application/admin/model/Servicetimelog.php

@@ -0,0 +1,58 @@
+<?php
+
+namespace app\admin\model;
+
+use think\Model;
+
+/**
+ * 客服上线下线日志模型
+ */
+class Servicetimelog extends Model
+{
+
+    //按日期用户查
+    //
+    public function getDayData($dataArray, $uidArray = [])
+    {
+        $ret = $this->where(['cdate' => ['IN', $dataArray]]);
+        if ($uidArray) {
+            $ret = $ret->where(['kfid' => ['IN', $uidArray]]);
+        }
+        $ret = $ret->order(['kfid' => 'asc', 'cdate' => 'asc', 'ctime' => 'asc'])->select();
+
+
+        if (!$ret) {
+            return false;
+        }
+
+        $return = $this->getOneUserData($ret);
+        return $return;
+    }
+
+    private function getOneUserData($array)
+    {
+
+        $return = [];
+        foreach ($array as $val) {
+            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) {
+                    $return[$val->cdate][$val->kfid]['1'] = $val->cdate . ' ' . $val->ctime;
+                }
+            }
+
+            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) {
+                    $return[$val->cdate][$val->kfid]['0'] = $val->cdate . ' ' . $val->ctime;
+                }
+            }
+        }
+
+        return $return;
+    }
+
+
+}

+ 31 - 6
application/admin/model/Users.php

@@ -1,4 +1,5 @@
 <?php
+
 namespace app\admin\model;
 
 use think\Model;
@@ -9,16 +10,40 @@ use think\Model;
  */
 class Users extends Model
 {
-    public function getByGroup($group=0){
-        if ($group){
-            return $this->where(['group_id'=>$group])->select();
-        }else{
+    public function getByGroup($group = 0)
+    {
+        if ($group) {
+            return $this->where(['group_id' => $group])->select();
+        } else {
             return $this->all();
         }
     }
 
-    public function  groupinfo(){
-        return  $this->belongsTo('Groups','group_id','id');
+    public function groupinfo()
+    {
+        return $this->belongsTo('Groups', 'group_id', 'id');
+    }
+
+    public function getUidsBygid($groupid = 0, $pre = 0, $returnobj = 0)
+    {
+        $ret = $this->getByGroup($groupid);
+
+        $return = [];
+        if ($ret) {
+            foreach ($ret as $val) {
+                $return['uids'][] = $pre ? 'KF' . $val->id : $val->id;
+                if ($returnobj) {
+                    $return['objs'][$val->id] = $val;
+                }
+            }
+            if (!$returnobj) {
+                return $return['uids'];
+            }
+            return $return;
+        } else {
+            return false;
+        }
+
     }
 
 }

+ 10 - 1
application/common.php

@@ -61,4 +61,13 @@ function kftoKey($uidArray, $type = 0)
         }
     }
     return $return ;
-}
+}
+
+
+//保留小数位数
+function  floatPointDigit($data,$long=2){
+    $long = intval($long) ;
+    $for1 = "%.".$long."f" ;
+    $for2 = "%.".($long+1)."f" ;
+    return  sprintf($for1,substr(sprintf($for2, $data), 0, -1));
+}

+ 3 - 4
vendor/GatewayWorker_windows/Applications/whisper/Events.php

@@ -1384,10 +1384,10 @@ class Events
         $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();
+        if ($sret) {
+            self::$db->update('ws_countmidtable')->cols(array('dcontent' => intval($sret['dcontent']) + 1))->where('id=' . $sret['id'])->query();
         } else {
-            $db->insert('ws_countmidtable')->cols(array(
+            self::$db->insert('ws_countmidtable')->cols(array(
                 'dtype' => $dtype,
                 'mdate' => $today,
                 'datatype' => 1,
@@ -1730,7 +1730,6 @@ 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']]);
                 self::serverClose($serviceLog[$found_key]['client_id'], $v['servicelog_id']);
                 // 如果对话为客服的最后一次对话且时间小于设定时间前一分钟则给出提示.
             } elseif ($v['time_line'] <= $setOvertime) {