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() // 自动回复设置 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 customerService() { if(request()->isPost()){ $param = input('post.'); db('kf_config')->where('id', 1)->update($param); return json(['code' => 1, 'data' => '', 'msg' => '设置成功']); } $this->assign([ 'config' => db('kf_config')->where('id', 1)->find(), 'status' => config('kf_status') ]); return $this->fetch(); } // 历史会话记录 public function wordsLog() { 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(!empty($param['searchText'])){ $user = db('users')->where('user_name', $param['searchText'])->find(); $temp = $temp->where('kf_id', $user['id']); $countTmp = $countTmp->where('kf_id', $user['id']); } //日期 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(); //满意度 $evaluate = db('evaluate')->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['start_time']); }else{ $result[$key]['end_time'] = '-'; } //客服名称 for($i=0;$imakeBtn($vo['servicelog_id']); } } $return['total'] = $countTmp->count(); //总数据 $return['rows'] = $result; return json($return); } //所有客服 $users = db('users')->select(); if(!empty($users)){ $option = ''; for($i=0;$i'.$users[$i]['user_name'].''; } $useroption = ''; } //所有客服组 $groups = db('groups')->select(); if(!empty($groups)){ $option = ''; for($j=0;$j'.$groups[$j]['name'].''; } $groupoption = ''; } $this->assign([ 'useroption' => $useroption, 'groupoption' => $groupoption ]); return $this->fetch(); } // 历史会话记录详情 public function detail($id) { $chat = db('chat_log')->where('servicelog_id',$id)->order('time_line')->select(); $html = ''; for($i=0;$i
'.$chat[$i]['from_name'].'   '.$chat[$i]['time_line'].'
'; $html = $html . '

'.$chat[$i]['content'].'

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

'.$chat[$i]['content'].'

'; } } $servicelog = db('service_log')->where('servicelog_id',$id)->find(); $evaluate = db('evaluate')->where('evaluate_id',$servicelog['evaluate_id'])->find(); $evaluate = $evaluate['evaluate_name']; $this->assign([ 'html' => $html, 'evaluate' => $evaluate ]); return $this->fetch(); } // 生成按钮 private function makeBtn($id) { $operate = ''; $operate .= ' '; return $operate; } }