isPost()) { $param = input('post.'); try { // 修改系统欢迎语. if (empty($param['advertisement_img']) === false) { $updateAstData['advertisement_img'] = $param['advertisement_img']; } $updateAstData['advertisement_url'] = $param['advertisementUrl']; $updateAstData['advertisement_status'] = $param['status']; model('Advertisement')->updateAst($updateAstData); // 修改系统欢迎语. $updateSysData['word'] = $param['systemWord']; $updateSysWhere['id'] = 1; model('Reply')->updateReply($updateSysWhere, $updateSysData); // 修改客服欢迎语. $updateSevData['word'] = $param['serverWord']; $updateSevWhere['id'] = 2; model('Reply')->updateReply($updateSevWhere, $updateSevData); return json(['code' => 1, 'data' => '', 'msg' => '设置成功']); } catch (\Exception $e) { return json(['code' => -2, 'data' => '', 'msg' => $e->getMessage()]); }//end try }//end if // 获取广告. $advertisement = model('Advertisement')->findAst(); // 获取系统欢迎语. $replySystemWhere['id'] = 1; $replySystem = model('Reply')->findReply($replySystemWhere); // 获取客服欢迎语. $replyServerWhere['id'] = 2; $replyServer = model('Reply')->findReply($replyServerWhere); $this->assign( [ 'advertisement' => $advertisement, 'replySystem' => $replySystem, 'replyServer' => $replyServer, 'status' => config('kf_status'), ] ); return $this->fetch(); }//end basics() /** * 会话设置 * * @access public */ public function conversation() { // 表单提交. if (request()->isPost()) { $param = input('post.'); try { // 修改会话超时. $updateOvertimeData['systemconfig_data'] = $param['overtime']; $updateOvertimeWhere['systemconfig_id'] = 1; model('Systemconfig')->updateSystemconfig($updateOvertimeWhere, $updateOvertimeData); // 修改访客静默. $upUptdData['systemconfig_data'] = $param['unoperated']; $upUptdWhere['systemconfig_id'] = 2; model('Systemconfig')->updateSystemconfig($upUptdWhere, $upUptdData); // 质检会话时长设置. $upAllTimeData['systemconfig_data'] = $param['verifyAllTime']; $upAllTimeWhere['systemconfig_id'] = 3; model('Systemconfig')->updateSystemconfig($upAllTimeWhere, $upAllTimeData); // 质检会话响应时长设置. $upReturnTimeData['systemconfig_data'] = $param['verifyReturnTime']; $upReturnTimeWhere['systemconfig_id'] = 4; model('Systemconfig')->updateSystemconfig($upReturnTimeWhere, $upReturnTimeData); // 满意度评价回合限制. $upRoundData['systemconfig_data'] = $param['round']; $upRoundWhere['systemconfig_id'] = 5; model('Systemconfig')->updateSystemconfig($upRoundWhere, $upRoundData); // 客服接待人数设置. $upKfConfigData['max_service'] = $param['max_service']; $upKfConfigData['kfConfig_maxWait'] = $param['kfConfig_maxWait']; db('kf_config')->where('id', 1)->update($upKfConfigData); return json(['code' => 1, 'data' => '', 'msg' => '设置成功']); } catch (\Exception $e) { return json(['code' => -2, 'data' => '', 'msg' => $e->getMessage()]); }//end try }//end if // 获取设置. $systemconfig = model('Systemconfig')->selectSystemconfig(); $kfConfig = db('kf_config')->where('id', 1)->find(); $this->assign( [ 'systemconfig' => $systemconfig, 'kfConfig' => $kfConfig, 'status' => config('kf_status'), ] ); return $this->fetch(); }//end conversation() // 自动回复设置 public function reply() { if(request()->isPost()){ $param = input('post.'); if(empty($param['word'])){ return json(['code' => -1, 'data' => '', 'msg' => '回复内容不能为空']); } try{ db('reply')->where('id', 1)->update($param); }catch(\Exception $e){ return json(['code' => -2, 'data' => '', 'msg' => $e->getMessage()]); } return json(['code' => 1, 'data' => '', 'msg' => '设置成功']); } $info = db('reply')->where('id', 1)->find(); $this->assign([ 'info' => $info, 'status' => config('kf_status') ]); return $this->fetch(); } // 历史会话记录 public function wordsLog() { $toExcel = input('param.toExcel', 0); if(request()->isAjax()){ $param = input('param.'); $limit = $param['pageSize']; $offset = ($param['pageNumber'] - 1) * $limit; // 默认显示最近7天 $start = input('param.start'); $end = input('param.end'); $user_id = input('param.user_id'); $group_id = input('param.group_id'); $temp = db('service_log'); $countTmp = db('service_log'); if(strlen($param['searchText'])){ $temp = $temp->whereLike('user_name', '%'.$param['searchText'].'%'); $countTmp = $countTmp->whereLike('user_name', '%'.$param['searchText'].'%'); } //日期 if(!empty($start) && !empty($end) && $start <= $end){ $temp = $temp->whereBetween('start_time', [strtotime($start), strtotime($end . ' 23:59:59')]); $countTmp = $countTmp->whereBetween('start_time', [strtotime($start), strtotime($end . ' 23:59:59')]); } //结束时间为空 if(!empty($start) && empty($end)){ $temp = $temp->where('start_time','>',strtotime($start)); $countTmp = $temp->where('start_time','>',strtotime($start)); } //开始时间为空 if(empty($start) && !empty($end)){ $temp = $temp->where('start_time','<',strtotime($end . ' 23:59:59')); $countTmp = $temp->where('start_time','<',strtotime($end . ' 23:59:59')); } //开始时间/结束时间都为空(默认查七天) // if(empty($start) && empty($end)){ // $temp = $temp->where('start_time','<',time())->where('start_time','>',time()-604800); // $countTmp = $temp->where('start_time','<',time())->where('start_time','>',time()-604800); // } //客服 if($user_id != 0){ $temp = $temp->where('kf_id', $user_id); $countTmp = $countTmp->where('kf_id', $user_id); } //客服组 if($group_id != 0){ $temp = $temp->where('group_id', $group_id); $countTmp = $temp->where('group_id', $group_id); } $result = $temp->limit($offset, $limit)->order('start_time', 'desc')->select(); //所有客服 $users = db('users')->select(); //所有客服组 $groups = db('groups')->select(); //满意度 $evaluate = db('evaluate')->select(); //$alarm报警信息 $alarm = db('alarm')->select(); foreach($result as $key=>$vo){ if($result[$key]['intime'] != 0){ $result[$key]['intime'] = date('Y-m-d H:i:s', $vo['intime']); }else{ $result[$key]['intime'] = '-'; } if($result[$key]['start_time'] != 0){ $result[$key]['start_time'] = date('Y-m-d H:i:s', $vo['start_time']); }else{ $result[$key]['start_time'] = '-'; } if($result[$key]['end_time'] != 0){ $result[$key]['end_time'] = date('Y-m-d H:i:s', $vo['end_time']); }else{ $result[$key]['end_time'] = '-'; } //客服名称 for($i=0;$imakeBtn($vo['servicelog_id']); } } $return['total'] = $countTmp->count(); //总数据 $return['rows'] = $result; if (!$toExcel) { return json($return); } else { $head = ['工单id', '访客进线时间', '接待客服', '所在组', '访客账号', '开始时间', '结束时间', '会话时长', '响应时长', '关闭原因', '满意度']; $key = ['servicelog_id', 'intime', 'kefu_name', 'group_name', 'user_name', 'start_time', 'end_time', 'conversation', 'response', 'servicelog_close_type', 'evaluate_name']; (new Office())->outdata('工作报表数据导出', $result, $head, $key); return true; } return json($return); } //所有客服 $users = db('users')->select(); $useroption = ''; if(!empty($users)){ $option = ''; for($i=0;$i'.$users[$i]['user_name'].''; } $useroption = ''; } //所有客服组 $groups = db('groups')->select(); $groupoption = ''; if(!empty($groups)){ $option = ''; for($j=0;$j'.$groups[$j]['name'].''; } $groupoption = ''; } $this->assign([ 'useroption' => $useroption, 'groupoption' => $groupoption ]); return $this->fetch('wordslog'); } function matching($str, $a, $b) { $pattern = '/('.$a.')(.*)(?)('.$b.')/'; //正则规则匹配支付串中任何一个位置字符串 //$pattern = '/(#\[)(.*)(?)(\]\/)/'; preg_match_all($pattern,$str,$m); //preg_match_all($pattern, $str, $m); //返回一个匹配结果 //print_r($m);die; //到时候在这里书写返回值就好了 .die; } // 历史会话记录详情 public function detail($id) { $chat = db('chat_log')->where('servicelog_id',$id)->order('time_line')->select(); $html = ''; for($i=0;$i'; } if(!empty(strstr($chat[$i]['to_id'], 'KF'))){ /*$preg1 = "/^#[*]$/"; $preg= '/xue[\s\S]*?om/i'; preg_match_all($preg1,"#[哈哈]/",$res); var_dump($res);*/ $this->matching("#[哈哈]/","#\[","\]\/"); //$this->getFacesIcon(); $html = $html . '
'.$chat[$i]['from_name'].'   '.$chat[$i]['time_line'].'
'; $html = $html . '

'.$content['content'].'

'; }else{ $html = $html . '
'.$chat[$i]['from_name'].'   '.$chat[$i]['time_line'].'
'; $html = $html . '

'.$content['content'].'

'; } } $servicelog = db('service_log')->where('servicelog_id',$id)->find(); //满意度 $evaluate = db('evaluate')->where('evaluate_id',$servicelog['evaluate_id'])->find(); $evaluate = ''; //$alarm报警信息 $alarm = db('alarm')->where('servicelog_id',$id)->find(); //会话超时标准 $verifyAllTime = db('systemconfig')->where('systemconfig_name','质检会话时长设置')->find(); //会话响应时长标准 $verifyReturnTime = db('systemconfig')->where('systemconfig_name','质检会话响应时长设置')->find(); $span = ''; if(!empty($alarm)){ if($alarm['alarm_userSensitive'] != 0){ $span = $span . '访客敏感词'; } if($alarm['alarm_serverSensitive'] != 0){ $span = $span . '客服敏感词'; } if($alarm['alarm_corresponding'] > $verifyReturnTime['systemconfig_data']){ $span = $span . '响应超时'; } if($alarm['alarm_cvtOvertime'] > $verifyAllTime['systemconfig_data']){ $span = $span . '会话超时'; } if($alarm['alarm_respond'] == 1){ $span = $span . '客服未回应'; } } //用户信息 $account = db('accounts')->where('id',$servicelog['user_id'])->find(); $label = db('accountslabel')->where('id', $account['label_id'])->find(); $account['label'] = $label['name']; $this->assign([ 'html' => $html, 'span' => $span, 'evaluate' => $evaluate, 'servicelog' => $servicelog, 'account' => $account ]); return $this->fetch(); } // 生成按钮 private function makeBtn($id) { $operate = ''; $operate .= ' '; return $operate; } public function getFacesIcon($facesIcon) { $data = ["[微笑]", "[嘻嘻]", "[哈哈]", "[可爱]", "[可怜]", "[挖鼻]", "[吃惊]", "[害羞]", "[挤眼]", "[闭嘴]", "[鄙视]", "[爱你]", "[泪]", "[偷笑]", "[亲亲]", "[生病]", "[太开心]", "[白眼]", "[右哼哼]", "[左哼哼]", "[嘘]", "[衰]", "[委屈]", "[吐]", "[哈欠]", "[抱抱]", "[怒]", "[疑问]", "[馋嘴]", "[拜拜]", "[思考]", "[汗]", "[困]", "[睡]", "[钱]", "[失望]", "[酷]", "[色]", "[哼]", "[鼓掌]", "[晕]", "[悲伤]", "[抓狂]", "[黑线]", "[阴险]", "[怒骂]", "[互粉]", "[心]", "[伤心]", "[猪头]", "[熊猫]", "[兔子]", "[ok]", "[耶]", "[good]", "[NO]", "[赞]", "[来]", "[弱]", "[草泥马]", "[神马]", "[囧]", "[浮云]", "[给力]", "[围观]", "[威武]", "[奥特曼]", "[礼物]", "[钟]", "[话筒]", "[蜡烛]", "[蛋糕]"]; $key = array_search($facesIcon, $data); return $key; } public function toexcel() { $result = db('service_log')->order('start_time', 'desc')->select(); //所有客服 $users = db('users')->select(); //所有客服组 $groups = db('groups')->select(); //满意度 $evaluate = db('evaluate')->select(); //$alarm报警信息 $alarm = db('alarm')->select(); foreach($result as $key=>$vo){ if($result[$key]['intime'] != 0){ $result[$key]['intime'] = date('Y-m-d H:i:s', $vo['intime']); }else{ $result[$key]['intime'] = '-'; } if($result[$key]['start_time'] != 0){ $result[$key]['start_time'] = date('Y-m-d H:i:s', $vo['start_time']); }else{ $result[$key]['start_time'] = '-'; } if($result[$key]['end_time'] != 0){ $result[$key]['end_time'] = date('Y-m-d H:i:s', $vo['end_time']); }else{ $result[$key]['end_time'] = '-'; } //客服名称 for($i=0;$iwhere('servicelog_id',$vo['servicelog_id'])->order('time_line', 'desc')->select(); $result[$key]['detail'] = ''; for($c=0;$c'; } $result[$key]['detail'] = $result[$key]['detail'].' '.$content['content']; } } $head = ['工单id', '访客进线时间', '接待客服', '所在组', '访客账号', '开始时间', '结束时间', '会话时长', '响应时长', '关闭原因', '满意度','聊天详情']; $key = ['servicelog_id', 'intime', 'kefu_name', 'group_name', 'user_name', 'start_time', 'end_time', 'conversation', 'response', 'servicelog_close_type', 'evaluate_name','detail']; (new Office())->outdata('工单数据导出', $result, $head, $key); return true; } }