find();
// 表单提交.
if (request()->isPost()) {
$param = input('post.');
try {
// 修改系统欢迎语.
if (empty($param['advertisement_img']) === false) {
$updateAstData['advertisement_img'] = $param['advertisement_img'];
}
if (empty($param['logo_img']) === false) {
$updateinfo['logo'] = $param['logo_img'];
}
$updateinfo['enterprise_name'] = $param['enterprise_name'];
$updateinfo['visitor_url'] = $param['visitor_url'];
$updateinfo['customer_url'] = $param['customer_url'];
$updateinfo['backend_url'] = $param['backend_url'];
$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);
if (!empty($updateinfo)) {
db('settings')->where('id', 1)->update($updateinfo);
$err = $this->updateJsTmpl($updateinfo);
if ($err == -20003) {
return json(['code' => -2, 'data' => '', 'msg' => 'JS调用模板路径不可以写']);
}
}
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);
// 获取logo.
$this->assign(
[
'advertisement' => $advertisement,
//'replySystem' => $replySystem,
'replyServer' => $replyServer,
'settings' => $settings,
'socket' => config('socket'),
'status' => config('kf_status'),
]
);
return $this->fetch();
}//end basics()
public function updateJsTmpl($settings)
{
$src = ROOT_PATH . 'public/entranceJs/jstmpl.js';
$tar = ROOT_PATH . 'public/entranceJs/FloatingButton.js';
if (is_writable($tar) && is_readable($src)) {
$content = file_get_contents($src);
$content = str_replace('{VISITOR_DOMAIN}', $settings['visitor_url'], $content);
$content = str_replace('{CUSTOMER_DOMAIN}', $settings['customer_url'], $content);
$content = str_replace('{ADMIN_DOMAIN}', $settings['backend_url'], $content);
file_put_contents($tar, $content);
} else {
return -20003;
}
}
/**
* 系统欢迎语
*
* @access public
*/
public function welcoming()
{
if (request()->isAjax()) {
$replySystemWhere['type'] = 1;
$result = model('Reply')->selectReply($replySystemWhere);
foreach ($result as $key => $vo) {
// 生成操作按钮
$result[$key]['operate'] = $this->makeBotton($vo['id']);
$result[$key]['word'] = htmlspecialchars_decode($vo['word']);
}
$return['rows'] = $result;
return json($return);
}
$this->assign([
'socket' => config('socket'),
]);
return $this->fetch();
}//end welcoming()
/**
* 修改系统欢迎语
*
* @access public
*/
public function editWelcome()
{
if (request()->isAjax()) {
$param = input('post.');
$where['id'] = $param['id'];
$data['sort'] = $param['sort'];
$data['word'] = htmlspecialchars($param['word']);
try {
model('Reply')->updateReply($where, $data);
} catch (\Exception $e) {
return json(['code' => -2, 'data' => '', 'msg' => $e->getMessage()]);
}
return json(['code' => 1, 'data' => '', 'msg' => '编辑成功']);
}
$id = input('param.id');
$replySystemWhere['id'] = $id;
$replySystem = model('Reply')->findReply($replySystemWhere);
$this->assign([
'replySystem' => $replySystem,
'socket' => config('socket'),
]);
return $this->fetch('editwelcome');
}//end editWelcome()
/**
* 新增系统欢迎语
*
* @access public
*/
public function delWelcome()
{
if (request()->isAjax()) {
$id = input('param.id');
$where['id'] = $id;
try {
model('Reply')->delReply($where);
} catch (\Exception $e) {
return json(['code' => -1, 'data' => '', 'msg' => $e->getMessage()]);
}
return json(['code' => 1, 'data' => '', 'msg' => '删除成功']);
}
}
/**
* 新增系统欢迎语
*
* @access public
*/
public function addWelcome()
{
if (request()->isAjax()) {
$param = input('post.');
$data['sort'] = $param['sort'];
$data['word'] = htmlspecialchars($param['word']);
$data['status'] = 1;
$data['type'] = 1;
try {
model('Reply')->addReply($data);
} catch (\Exception $e) {
return json(['code' => -2, 'data' => '', 'msg' => $e->getMessage()]);
}
return json(['code' => 1, 'data' => '', 'msg' => '新增成功']);
}
$this->assign([
'socket' => config('socket'),
]);
return $this->fetch('addwelcome');
}//end addWelcome()
/**
* 会话设置
*
* @access public
*/
public function conversation()
{
// 表单提交.
if (request()->isPost()) {
$param = input('post.');
try {
// 修改会话超时.
$updateOvertimeData['systemconfig_data'] = $param['overtime'];
$updateOvertimeData['systemconfig_content'] = $param['overtimeInfo'];
$updateOvertimeWhere['systemconfig_id'] = 1;
model('Systemconfig')->updateSystemconfig($updateOvertimeWhere, $updateOvertimeData);
// 修改访客静默.
$upUptdData['systemconfig_data'] = $param['unoperated'];
$upUptdData['systemconfig_content'] = $param['unoperatedInfo'];
$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);
// 客服接待人数设置.
$upMSWhere['systemconfig_enName'] = 'KFMaxServices';
$upMSData['systemconfig_data'] = $param['max_service'];
model('Systemconfig')->updateSystemconfig($upMSWhere, $upMSData);
// 最大排队人数设置.
$upMWWhere['systemconfig_enName'] = 'maxWait';
$upMWData['systemconfig_data'] = $param['kfConfig_maxWait'];
model('Systemconfig')->updateSystemconfig($upMWWhere, $upMWData);
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();
$this->assign(
[
'systemconfig' => $systemconfig,
'status' => config('kf_status'),
'socket' => config('socket'),
]
);
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,
'socket' => config('socket'),
'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 = $countTmp->where('start_time', '>', strtotime($start));
}
//开始时间为空
if (empty($start) && !empty($end)) {
$temp = $temp->where('start_time', '<', strtotime($end . ' 23:59:59'));
$countTmp = $countTmp->where('start_time', '<', strtotime($end . ' 23:59:59'));
}
//客服
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 = $countTmp->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']);
$date = explode(' ', $result[$key]['intime']);
$year = explode('-', $result[$key]['intime']);
if ($date[0] == date('Y-m-d', time())) {
$result[$key]['intime'] = '' . $date[1] . '';
} else if ($date[0] == date('Y-m-d', strtotime("-1 day"))) {
$result[$key]['intime'] = '' . '昨天 ' . $date[1] . '';
} else {
if ($year[0] == date('Y', time())) {
$result[$key]['intime'] = '' . date('m-d H:i:s', strtotime($result[$key]['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']);
$date = explode(' ', $result[$key]['start_time']);
$year = explode('-', $result[$key]['start_time']);
if ($date[0] == date('Y-m-d', time())) {
$result[$key]['start_time'] = '' . $date[1] . '';
} else if ($date[0] == date('Y-m-d', strtotime("-1 day"))) {
$result[$key]['start_time'] = '' . '昨天 ' . $date[1] . '';
} else {
if ($year[0] == date('Y', time())) {
$result[$key]['start_time'] = '' . date('m-d H:i:s', strtotime($result[$key]['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']);
$date = explode(' ', $result[$key]['end_time']);
$year = explode('-', $result[$key]['end_time']);
if ($date[0] == date('Y-m-d', time())) {
$result[$key]['end_time'] = '' . $date[1] . '';
} else if ($date[0] == date('Y-m-d', strtotime("-1 day"))) {
$result[$key]['end_time'] = '' . '昨天 ' . $date[1] . '';
} else {
if ($year[0] == date('Y', time())) {
$result[$key]['end_time'] = '' . date('m-d H:i:s', strtotime($result[$key]['end_time'])) . '';
}
}
} else {
$result[$key]['end_time'] = '-';
}
//客服名称
for ($i = 0; $i < count($users); $i++) {
if ($result[$key]['kf_id'] == $users[$i]['id']) {
$result[$key]['kefu_name'] = $users[$i]['user_name'];
}
}
//满意度
for ($j = 0; $j < count($evaluate); $j++) {
if ($result[$key]['evaluate_id'] == $evaluate[$j]['evaluate_id']) {
$result[$key]['evaluate_name'] = $evaluate[$j]['evaluate_name'];
}
}
//客服所在组
for ($a = 0; $a < count($groups); $a++) {
if ($result[$key]['group_id'] == $groups[$a]['id']) {
$result[$key]['group_name'] = $groups[$a]['name'];
}
}
//会话时长/响应时长
for ($b = 0; $b < count($alarm); $b++) {
if ($result[$key]['servicelog_id'] == $alarm[$b]['servicelog_id']) {
//会话时长
$conversation_min = intval($alarm[$b]['alarm_cvtOvertime'] / 60);
$conversation_s = $alarm[$b]['alarm_cvtOvertime'] % 60;
$result[$key]['conversation'] = $conversation_min . '分' . $conversation_s . '秒';
//响应时长
$response_min = intval($alarm[$b]['alarm_corresponding'] / 60);
$response_s = $alarm[$b]['alarm_corresponding'] % 60;
$result[$key]['response'] = $response_min . '分' . $response_s . '秒';
}
}
if ($vo['servicelog_close_type'] == 0) {
$result[$key]['servicelog_close_type'] = '未知';
}
if ($vo['servicelog_close_type'] == 1) {
$result[$key]['servicelog_close_type'] = '无效会话';
}
if ($vo['servicelog_close_type'] == 2) {
$result[$key]['servicelog_close_type'] = '双方静默';
}
if ($vo['servicelog_close_type'] == 3) {
$result[$key]['servicelog_close_type'] = '客服关闭';
}
if ($vo['servicelog_close_type'] == 4) {
$result[$key]['servicelog_close_type'] = '客服掉线';
}
if ($vo['servicelog_close_type'] == 5) {
$result[$key]['servicelog_close_type'] = '转出';
}
if ($vo['servicelog_close_type'] == 6) {
$result[$key]['servicelog_close_type'] = '用户关闭';
}
// 生成操作按钮
if (0 != $vo['servicelog_id']) {
$result[$key]['operate'] = $this->makeBtn($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 < count($users); $i++) {
$option = $option . '';
}
$useroption = '';
}
//所有客服组
$groups = db('groups')->select();
$groupoption = '';
if (!empty($groups)) {
$option = '';
for ($j = 0; $j < count($groups); $j++) {
$option = $option . '';
}
$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,$type='')
{
$chat = db('chat_log')->where('servicelog_id', $id)->order('time_line')->select();
$html = '';
for ($i = 0; $i < count($chat); $i++) {
$content = json_decode($chat[$i]['content'], true);
$chat[$i]['time_line'] = date('H:i', $chat[$i]['time_line']);
if (!empty($content['text'])) {
$content['content'] = '  ' . $content['text'] . '  ';
}
if (!empty($content['img'])) {
$content['content'] = '';
}
if ((strpos($chat[$i]['to_id'], 'KF')) !== false) {
/*$preg1 = "/^#[*]$/";
$preg= '/xue[\s\S]*?om/i';
preg_match_all($preg1,"#[哈哈]/",$res);
var_dump($res);*/
$this->matching("#[哈哈]/", "#\[", "\]\/");
//$this->getFacesIcon();
$html = $html . '