getTodayServiceData($kfuidarray); if (!$todayall) { return false; } $kfuidarray_index = kftoKey($kfuidarray, 1); $uids = $kfuidarray; $uidsname = $this->uidName($kfuidarray); $hyl = $this->hyl($kfuidarray, $todayall); $jdl = $this->jdl($kfuidarray, $todayall); $pjhysc = $this->pjhusc($kfuidarray, $todayall); $cpl = $this->cpl($kfuidarray, $todayall); $mydl = $this->mydl($kfuidarray, $todayall); $pjxysc = $this->pjxysc($kfuidarray, $todayall); $jrxxsc = $this->jrxxsc($kfuidarray, $todayall); $kfip = $this->getKfinlineip(); foreach ($kfuidarray_index as $uid => $val) { $kfuidarray_index[$uid]['ip'] = $kfip['KF' . $uid]; $kfuidarray_index[$uid]['uid'] = $uids[$uid]; $kfuidarray_index[$uid]['uidname'] = $uidsname[$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]; $kfuidarray_index[$uid]['mydl'] = $mydl[$uid]; $kfuidarray_index[$uid]['pjxysc'] = $pjxysc[$uid]; $kfuidarray_index[$uid]['jrxxsc'] = $jrxxsc[$uid]; $kfuidarray_index[$uid]['fxx'] = $this->makeBtn($uid); } $last = []; foreach ($kfuidarray_index as $val) { $last[] = $val; } return $last; } // 生成按钮 private function makeBtn($id) { $operate = ' '; return $operate; } //按条件获取用户数组 组ID, 在线状态 0为全部 public function getValiKF($groupid, $onlinestatus) { $groupusers = (new Users)->getByGroup($groupid); $groupuserArray = []; if ($groupusers) { foreach ($groupusers as $val) { $groupuserArray[$val['id']] = $val['id']; } } $statusArr = (new KfonlineModel())->getOnlineAll($onlinestatus); $return = array_intersect($groupuserArray, $statusArr); return $return; } public function uidName($uidArray) { $users = (new Users)->where(['id' => ['IN', $uidArray]])->select(); $return = kftoKey($uidArray); foreach ($return as $uid => $ttttt) { foreach ($users as $nowuser) { if ($uid == $nowuser['id']) { $return[$uid] = $nowuser['user_name']; } } } return $return; } //会话量 统计 public function hyl($uidArray, $alllogs) { $rets = kftoKey($uidArray); foreach ($rets as $uid => $aaaa) { foreach ($alllogs as $log) { if ($uid == $log['kf_id'] && ($log['status'] == 1 || $log['status'] == 3)) { $rets[$uid]++; } } } return $rets; } //接待量 统计 public function jdl($uidArray, $alllogs) { $rets = kftoKey($uidArray); foreach ($rets as $uid => $aaa) { foreach ($alllogs as $log) { if ($uid == $log['kf_id']) { $rets[$uid]++; } } } return $rets; } //平均会话时长 统计 public function pjhusc($uidArray, $alllogs) { $rets = kftoKey($uidArray, 1); foreach ($rets as $uid => $aaa) { foreach ($alllogs as $log) { if ($uid == $log['kf_id']) { (!isset($rets[$uid]['count'])) ? ($rets[$uid]['count'] = 1) : $rets[$uid]['count']++; (!isset($rets[$uid]['times'])) ? ($rets[$uid]['times'] = 0) : ($rets[$uid]['times'] += (($log['end_time'] ? $log['end_time'] : $log['start_time']) - $log['start_time'])); } } } $return = []; foreach ($rets as $uid => $val) { if (isset($rets[$uid]['count'])) { $return[$uid] = intval($rets[$uid]['times'] / $rets[$uid]['count']); } else { $return[$uid] = 0; } } return $return; } //参评率 public function cpl($uidArray, $alllogs) { $rets = kftoKey($uidArray, 1); foreach ($rets as $uid => $aaa) { foreach ($alllogs as $log) { if ($uid == $log['kf_id']) { !(isset($rets[$uid]['count'])) ? 1 : $rets[$uid]['count']++; isset($rets[$uid]['pl']) ? ($rets[$uid]['pl'] = ($log['evaluate_id'] > 0 ? 1 : 0)) : 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($uidArray, $alllogs) { $rets = kftoKey($uidArray, 1); foreach ($rets as $uid => $aaa) { foreach ($alllogs as $log) { if ($uid == $log['kf_id'] && $log['evaluate_id'] > 0) { (!isset($rets[$uid]['count'])) ? ($rets[$uid]['count'] = 1) : $rets[$uid]['count']++; (!isset($rets[$uid]['times'])) ? (($log['evaluate_id'] == 1) ? 1 : 0) : (($log['evaluate_id'] == 1) ? $rets[$uid]['times']++ : ''); } } } $return = []; foreach ($rets as $uid => $val) { if (isset($rets[$uid]['count']) && isset($rets[$uid]['times'])) { $return[$uid] = $rets[$uid]['times'] / $rets[$uid]['count']; } else { $return[$uid] = 0; } } return $return; } //平均响应时长 public function pjxysc($uidArray, $alllogs) { $rets = kftoKey($uidArray); if (empty($alllogs)) { return $rets; } $serids = []; foreach ($alllogs as $val) { $serids[] = $val['servicelog_id']; } $times = Db::name('alarm')->field('alarm_corresponding,servicelog_id')->where(['alarm_respond' => 2, 'servicelog_id' => ['IN', $serids]])->select(); if ($times) { foreach ($alllogs as $key => $val) { foreach ($times as $sval) { if ($val['servicelog_id'] == $sval['servicelog_id']) { $alllogs[$key]['corresponding'] = $sval['alarm_corresponding']; } } } } $rets = kftoKey($uidArray, 1); foreach ($rets as $uid => $aaa) { foreach ($alllogs as $log) { if ($uid == $log['kf_id'] && isset($log['corresponding'])) { (!isset($rets[$uid]['count'])) ? ($rets[$uid]['count'] = 1) : $rets[$uid]['count']++; (!isset($rets[$uid]['times'])) ? ($rets[$uid]['times'] = intval($log['corresponding'])) : ($rets[$uid]['times'] += intval($log['corresponding'])); } } } $return = []; foreach ($rets as $uid => $val) { if (isset($rets[$uid]['count']) && isset($rets[$uid]['times'])) { $return[$uid] = intval($rets[$uid]['times'] / $rets[$uid]['count']); } else { $return[$uid] = 0; } } return $return; } //今日休息时长统计 public function jrxxsc($uidArray, $alllogs) { $kfuidarray = array_map(function ($i) { return 'KF' . $i; }, $uidArray); $return = kftoKey($uidArray); $rets = kftoKey($uidArray, 1); $today = date("Y-m-d"); $ret = Db::name('kfstatetimes')->field('kfuid,stime')->where(['sday' => $today, 'kfuid' => ['IN', $kfuidarray], 'kstatus' => 3])->select(); if (!$ret) { return $return; } foreach ($return as $uid => $ttttt) { foreach ($ret as $val) { $ruid = trim($val['kfuid'], 'KF'); if ($uid == $ruid) { $return[$uid] = $val['stime']; } } } return $return; } public function getTodayServiceData($kfuidArray = []) { $today_begin = strtotime(date("Y-m-d")); $today_end = $today_begin + 86400; $filds = "servicelog_id,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 { $ret = Db::name('service_log')->field($filds)->where(['start_time' => ['>=', $today_begin]])->where(['start_time' => ['<', $today_end]])->select(); } return $ret; } //获取在线客服ip地址 public function getKfinlineip() { $ret = Db::name('kfonline')->select(); $return = []; if ($ret) { foreach ($ret as $item) { //'KF22'=>'192.168.1.1'; $return[$item['uid']] = $item['ip']; } } return $return; } }