System.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\Office;
  4. use think\cache\driver\Redis;
  5. /**
  6. * 管理系统系统设置类
  7. */
  8. class System extends Base
  9. {
  10. /**
  11. * 基础设置
  12. *
  13. * @access public
  14. */
  15. public function basics()
  16. {
  17. // 表单提交.
  18. if (request()->isPost()) {
  19. $param = input('post.');
  20. try {
  21. // 修改系统欢迎语.
  22. if (empty($param['advertisement_img']) === false) {
  23. $updateAstData['advertisement_img'] = $param['advertisement_img'];
  24. }
  25. if (empty($param['logo_img']) === false) {
  26. $updateinfo['logo'] = $param['logo_img'];
  27. }
  28. $updateAstData['advertisement_url'] = $param['advertisementUrl'];
  29. $updateAstData['advertisement_status'] = $param['status'];
  30. model('Advertisement')->updateAst($updateAstData);
  31. // 修改系统欢迎语.
  32. $updateSysData['word'] = $param['systemWord'];
  33. $updateSysWhere['id'] = 1;
  34. model('Reply')->updateReply($updateSysWhere, $updateSysData);
  35. // 修改客服欢迎语.
  36. $updateSevData['word'] = $param['serverWord'];
  37. $updateSevWhere['id'] = 2;
  38. model('Reply')->updateReply($updateSevWhere, $updateSevData);
  39. if(!empty($updateinfo)){
  40. db('settings')->where('id',1)->update($updateinfo);
  41. }
  42. return json(['code' => 1, 'data' => '', 'msg' => '设置成功']);
  43. } catch (\Exception $e) {
  44. return json(['code' => -2, 'data' => '', 'msg' => $e->getMessage()]);
  45. }//end try
  46. }//end if
  47. // 获取广告.
  48. $advertisement = model('Advertisement')->findAst();
  49. // 获取系统欢迎语.
  50. $replySystemWhere['id'] = 1;
  51. $replySystem = model('Reply')->findReply($replySystemWhere);
  52. // 获取客服欢迎语.
  53. $replyServerWhere['id'] = 2;
  54. $replyServer = model('Reply')->findReply($replyServerWhere);
  55. // 获取logo.
  56. $settings = db('settings')->find();
  57. $this->assign(
  58. [
  59. 'advertisement' => $advertisement,
  60. 'replySystem' => $replySystem,
  61. 'replyServer' => $replyServer,
  62. 'settings' => $settings,
  63. 'status' => config('kf_status'),
  64. ]
  65. );
  66. return $this->fetch();
  67. }//end basics()
  68. /**
  69. * 会话设置
  70. *
  71. * @access public
  72. */
  73. public function conversation()
  74. {
  75. // 表单提交.
  76. if (request()->isPost()) {
  77. $param = input('post.');
  78. try {
  79. // 修改会话超时.
  80. $updateOvertimeData['systemconfig_data'] = $param['overtime'];
  81. $updateOvertimeData['systemconfig_content'] = $param['overtimeInfo'];
  82. $updateOvertimeWhere['systemconfig_id'] = 1;
  83. model('Systemconfig')->updateSystemconfig($updateOvertimeWhere, $updateOvertimeData);
  84. // 修改访客静默.
  85. $upUptdData['systemconfig_data'] = $param['unoperated'];
  86. $upUptdData['systemconfig_content'] = $param['unoperatedInfo'];
  87. $upUptdWhere['systemconfig_id'] = 2;
  88. model('Systemconfig')->updateSystemconfig($upUptdWhere, $upUptdData);
  89. // 质检会话时长设置.
  90. $upAllTimeData['systemconfig_data'] = $param['verifyAllTime'];
  91. $upAllTimeWhere['systemconfig_id'] = 3;
  92. model('Systemconfig')->updateSystemconfig($upAllTimeWhere, $upAllTimeData);
  93. // 质检会话响应时长设置.
  94. $upReturnTimeData['systemconfig_data'] = $param['verifyReturnTime'];
  95. $upReturnTimeWhere['systemconfig_id'] = 4;
  96. model('Systemconfig')->updateSystemconfig($upReturnTimeWhere, $upReturnTimeData);
  97. // 满意度评价回合限制.
  98. $upRoundData['systemconfig_data'] = $param['round'];
  99. $upRoundWhere['systemconfig_id'] = 5;
  100. model('Systemconfig')->updateSystemconfig($upRoundWhere, $upRoundData);
  101. // 客服接待人数设置.
  102. $upKfConfigData['max_service'] = $param['max_service'];
  103. $upKfConfigData['kfConfig_maxWait'] = $param['kfConfig_maxWait'];
  104. db('kf_config')->where('id', 1)->update($upKfConfigData);
  105. return json(['code' => 1, 'data' => '', 'msg' => '设置成功']);
  106. } catch (\Exception $e) {
  107. return json(['code' => -2, 'data' => '', 'msg' => $e->getMessage()]);
  108. }//end try
  109. }//end if
  110. // 获取设置.
  111. $systemconfig = model('Systemconfig')->selectSystemconfig();
  112. $kfConfig = db('kf_config')->where('id', 1)->find();
  113. $this->assign(
  114. [
  115. 'systemconfig' => $systemconfig,
  116. 'kfConfig' => $kfConfig,
  117. 'status' => config('kf_status'),
  118. ]
  119. );
  120. return $this->fetch();
  121. }//end conversation()
  122. // 自动回复设置
  123. public function reply()
  124. {
  125. if(request()->isPost()){
  126. $param = input('post.');
  127. if(empty($param['word'])){
  128. return json(['code' => -1, 'data' => '', 'msg' => '回复内容不能为空']);
  129. }
  130. try{
  131. db('reply')->where('id', 1)->update($param);
  132. }catch(\Exception $e){
  133. return json(['code' => -2, 'data' => '', 'msg' => $e->getMessage()]);
  134. }
  135. return json(['code' => 1, 'data' => '', 'msg' => '设置成功']);
  136. }
  137. $info = db('reply')->where('id', 1)->find();
  138. $this->assign([
  139. 'info' => $info,
  140. 'status' => config('kf_status')
  141. ]);
  142. return $this->fetch();
  143. }
  144. // 历史会话记录
  145. public function wordsLog()
  146. {
  147. // $toExcel = input('param.toExcel', 0);
  148. if(request()->isAjax()){
  149. $param = input('param.');
  150. $limit = $param['pageSize'];
  151. $offset = ($param['pageNumber'] - 1) * $limit;
  152. // 默认显示最近7天
  153. $start = input('param.start');
  154. $end = input('param.end');
  155. $user_id = input('param.user_id');
  156. $group_id = input('param.group_id');
  157. $temp = db('service_log');
  158. $countTmp = db('service_log');
  159. if(strlen($param['searchText'])){
  160. $temp = $temp->whereLike('user_name', '%'.$param['searchText'].'%');
  161. $countTmp = $countTmp->whereLike('user_name', '%'.$param['searchText'].'%');
  162. }
  163. //日期
  164. if(!empty($start) && !empty($end) && $start <= $end){
  165. $temp = $temp->whereBetween('start_time', [strtotime($start), strtotime($end . ' 23:59:59')]);
  166. $countTmp = $countTmp->whereBetween('start_time', [strtotime($start), strtotime($end . ' 23:59:59')]);
  167. }
  168. //结束时间为空
  169. if(!empty($start) && empty($end)){
  170. $temp = $temp->where('start_time','>',strtotime($start));
  171. $countTmp = $countTmp->where('start_time','>',strtotime($start));
  172. }
  173. //开始时间为空
  174. if(empty($start) && !empty($end)){
  175. $temp = $temp->where('start_time','<',strtotime($end . ' 23:59:59'));
  176. $countTmp = $countTmp->where('start_time','<',strtotime($end . ' 23:59:59'));
  177. }
  178. //客服
  179. if($user_id != 0){
  180. $temp = $temp->where('kf_id', $user_id);
  181. $countTmp = $countTmp->where('kf_id', $user_id);
  182. }
  183. //客服组
  184. if($group_id != 0){
  185. $temp = $temp->where('group_id', $group_id);
  186. $countTmp = $countTmp->where('group_id', $group_id);
  187. }
  188. $result = $temp->limit($offset, $limit)->order('start_time', 'desc')->select();
  189. //所有客服
  190. $users = db('users')->select();
  191. //所有客服组
  192. $groups = db('groups')->select();
  193. //满意度
  194. $evaluate = db('evaluate')->select();
  195. //$alarm报警信息
  196. $alarm = db('alarm')->select();
  197. foreach($result as $key=>$vo){
  198. if($result[$key]['intime'] != 0){
  199. $result[$key]['intime'] = date('Y-m-d H:i:s', $vo['intime']);
  200. }else{
  201. $result[$key]['intime'] = '-';
  202. }
  203. if($result[$key]['start_time'] != 0){
  204. $result[$key]['start_time'] = date('Y-m-d H:i:s', $vo['start_time']);
  205. }else{
  206. $result[$key]['start_time'] = '-';
  207. }
  208. if($result[$key]['end_time'] != 0){
  209. $result[$key]['end_time'] = date('Y-m-d H:i:s', $vo['end_time']);
  210. }else{
  211. $result[$key]['end_time'] = '-';
  212. }
  213. //客服名称
  214. for($i=0;$i<count($users);$i++){
  215. if($result[$key]['kf_id'] == $users[$i]['id']){
  216. $result[$key]['kefu_name'] = $users[$i]['user_name'];
  217. }
  218. }
  219. //满意度
  220. for($j=0;$j<count($evaluate);$j++){
  221. if($result[$key]['evaluate_id'] == $evaluate[$j]['evaluate_id']){
  222. $result[$key]['evaluate_name'] = $evaluate[$j]['evaluate_name'];
  223. }
  224. }
  225. //客服所在组
  226. for($a=0;$a<count($groups);$a++){
  227. if($result[$key]['group_id'] == $groups[$a]['id']){
  228. $result[$key]['group_name'] = $groups[$a]['name'];
  229. }
  230. }
  231. //会话时长/响应时长
  232. for($b=0;$b<count($alarm);$b++){
  233. if($result[$key]['servicelog_id'] == $alarm[$b]['servicelog_id']){
  234. //会话时长
  235. $conversation_min = intval($alarm[$b]['alarm_cvtOvertime']/60);
  236. $conversation_s = $alarm[$b]['alarm_cvtOvertime']%60;
  237. $result[$key]['conversation'] = $conversation_min.'分'.$conversation_s.'秒';
  238. //响应时长
  239. $response_min = intval($alarm[$b]['alarm_corresponding']/60);
  240. $response_s = $alarm[$b]['alarm_corresponding']%60;
  241. $result[$key]['response'] = $response_min.'分'.$response_s.'秒';
  242. }
  243. }
  244. if($vo['servicelog_close_type'] == 0){
  245. $result[$key]['servicelog_close_type'] = '未知';
  246. }
  247. if($vo['servicelog_close_type'] == 1){
  248. $result[$key]['servicelog_close_type'] = '无效会话';
  249. }
  250. if($vo['servicelog_close_type'] == 2){
  251. $result[$key]['servicelog_close_type'] = '双方静默';
  252. }
  253. if($vo['servicelog_close_type'] == 3){
  254. $result[$key]['servicelog_close_type'] = '客服关闭';
  255. }
  256. if($vo['servicelog_close_type'] == 4){
  257. $result[$key]['servicelog_close_type'] = '客服掉线';
  258. }
  259. if($vo['servicelog_close_type'] == 5){
  260. $result[$key]['servicelog_close_type'] = '转出';
  261. }
  262. // 生成操作按钮
  263. if(0 != $vo['servicelog_id']){
  264. $result[$key]['operate'] = $this->makeBtn($vo['servicelog_id']);
  265. }
  266. }
  267. $return['total'] = $countTmp->count(); //总数据
  268. $return['rows'] = $result;
  269. // if (!$toExcel) {
  270. // return json($return);
  271. // } else {
  272. // $head = ['工单id', '访客进线时间', '接待客服', '所在组', '访客账号', '开始时间', '结束时间', '会话时长', '响应时长', '关闭原因', '满意度'];
  273. // $key = ['servicelog_id', 'intime', 'kefu_name', 'group_name', 'user_name', 'start_time', 'end_time', 'conversation', 'response', 'servicelog_close_type', 'evaluate_name'];
  274. // (new Office())->outdata('工作报表数据导出', $result, $head, $key);
  275. // return true;
  276. // }
  277. return json($return);
  278. }
  279. //所有客服
  280. $users = db('users')->select();
  281. $useroption = '';
  282. if(!empty($users)){
  283. $option = '<option value="0">全部客服</option>';
  284. for($i=0;$i<count($users);$i++){
  285. $option = $option.'<option value="'.$users[$i]['id'].'">'.$users[$i]['user_name'].'</option>';
  286. }
  287. $useroption = '<select class="selector_user" lay-verify="required" lay-filter="user_id">'.$option.'</select>';
  288. }
  289. //所有客服组
  290. $groups = db('groups')->select();
  291. $groupoption = '';
  292. if(!empty($groups)){
  293. $option = '<option value="0">全部客服组</option>';
  294. for($j=0;$j<count($groups);$j++){
  295. $option = $option.'<option value="'.$groups[$j]['id'].'">'.$groups[$j]['name'].'</option>';
  296. }
  297. $groupoption = '<select class="selector_group" lay-verify="required" lay-filter="group_id">'.$option.'</select>';
  298. }
  299. $this->assign([
  300. 'useroption' => $useroption,
  301. 'groupoption' => $groupoption
  302. ]);
  303. return $this->fetch('wordslog');
  304. }
  305. function matching($str, $a, $b)
  306. {
  307. $pattern = '/('.$a.')(.*)(?)('.$b.')/'; //正则规则匹配支付串中任何一个位置字符串
  308. //$pattern = '/(#\[)(.*)(?)(\]\/)/';
  309. preg_match_all($pattern,$str,$m);
  310. //preg_match_all($pattern, $str, $m); //返回一个匹配结果
  311. //print_r($m);die; //到时候在这里书写返回值就好了 .die;
  312. }
  313. // 历史会话记录详情
  314. public function detail($id, $type='')
  315. {
  316. $chat = db('chat_log')->where('servicelog_id',$id)->order('time_line')->select();
  317. $html = '';
  318. for($i=0;$i<count($chat);$i++){
  319. $content = json_decode($chat[$i]['content'], true);
  320. $chat[$i]['time_line'] = date('H:i',$chat[$i]['time_line']);
  321. if(!empty($content['text'])){
  322. $content['content'] = '&nbsp&nbsp'.$content['text'].'&nbsp&nbsp';
  323. }
  324. if(!empty($content['img'])){
  325. $content['content'] = '<img width="100%" src="'.$content['img'].'"/>';
  326. }
  327. if(!empty(strstr($chat[$i]['to_id'], 'KF'))){
  328. /*$preg1 = "/^#[*]$/";
  329. $preg= '/xue[\s\S]*?om/i';
  330. preg_match_all($preg1,"#[哈哈]/",$res);
  331. var_dump($res);*/
  332. $this->matching("#[哈哈]/","#\[","\]\/");
  333. //$this->getFacesIcon();
  334. $html = $html . '<div style="margin-top:15px;width:75%"><div>'.$chat[$i]['from_name'].'&nbsp&nbsp&nbsp'.$chat[$i]['time_line'].'</div>';
  335. $html = $html . '<div style="margin-top:5px;display:inline-block;*display:inline;*zoom:1;word-break:break-all;word-wrap:break-word" class="form-content">'.$content['content'].'</div></div>';
  336. }else{
  337. $html = $html . '<div style="margin-top:15px;width:75%;margin-left:25%;text-align:right;"><div>'.$chat[$i]['from_name'].'&nbsp&nbsp&nbsp'.$chat[$i]['time_line'].'</div>';
  338. $html = $html . '<div style="margin-top:5px;display:inline-block;*display:inline;*zoom:1;text-align:left;word-break:break-all;word-wrap:break-word" class="form-content">'.$content['content'].'</div></div>';
  339. }
  340. }
  341. $redis = new Redis;
  342. if ($type === 'onLine') {
  343. $servicelog = json_decode($redis->handler()->Hget('SERVICELOG', $id), true);
  344. } else {
  345. $servicelog = db('service_log')->where('servicelog_id',$id)->find();
  346. }
  347. //满意度
  348. $evaluate = db('evaluate')->where('evaluate_id',$servicelog['evaluate_id'])->find();
  349. $evaluate = '<img width="40px" style="margin-top:15px;" src="'.$evaluate['evaluate_url'].'"/>';
  350. //$alarm报警信息
  351. if ($type === 'onLine') {
  352. $alarm = json_decode($redis->handler()->Hget('SERVICELOG', $id), true);
  353. } else {
  354. $alarm = db('alarm')->where('servicelog_id',$id)->find();
  355. }
  356. //会话超时标准
  357. $verifyAllTime = db('systemconfig')->where('systemconfig_name','质检会话时长设置')->find();
  358. //会话响应时长标准
  359. $verifyReturnTime = db('systemconfig')->where('systemconfig_name','质检会话响应时长设置')->find();
  360. $span = '';
  361. if(!empty($alarm)){
  362. if($alarm['alarm_userSensitive'] != 0){
  363. $span = $span . '<span class="alarm_info">访客敏感词</span>';
  364. }
  365. if($alarm['alarm_serverSensitive'] != 0){
  366. $span = $span . '<span class="alarm_info">客服敏感词</span>';
  367. }
  368. if($alarm['alarm_corresponding'] > $verifyReturnTime['systemconfig_data']){
  369. $span = $span . '<span class="alarm_info">响应超时</span>';
  370. }
  371. if($alarm['alarm_cvtOvertime'] > $verifyAllTime['systemconfig_data']){
  372. $span = $span . '<span class="alarm_info">会话超时</span>';
  373. }
  374. if($alarm['alarm_respond'] == 1){
  375. $span = $span . '<span class="alarm_info">客服未回应</span>';
  376. }
  377. }
  378. //用户信息
  379. $account = db('accounts')->where('id',$servicelog['user_id'])->find();
  380. $label = db('accountslabel')->where('id', $account['label_id'])->find();
  381. $account['label'] = $label['name'];
  382. $this->assign([
  383. 'html' => $html,
  384. 'span' => $span,
  385. 'evaluate' => $evaluate,
  386. 'servicelog' => $servicelog,
  387. 'account' => $account
  388. ]);
  389. return $this->fetch();
  390. }
  391. // 生成按钮
  392. private function makeBtn($id)
  393. {
  394. $operate = '<a href="' . url('system/detail', ['id' => $id]) . '">';
  395. $operate .= '<button type="button" class="btn btn-primary btn-sm"><i class="fa fa-paste"></i> 详情</button></a> ';
  396. return $operate;
  397. }
  398. public function getFacesIcon($facesIcon) {
  399. $data = ["[微笑]", "[嘻嘻]", "[哈哈]", "[可爱]", "[可怜]", "[挖鼻]", "[吃惊]", "[害羞]", "[挤眼]", "[闭嘴]", "[鄙视]",
  400. "[爱你]", "[泪]", "[偷笑]", "[亲亲]", "[生病]", "[太开心]", "[白眼]", "[右哼哼]", "[左哼哼]", "[嘘]", "[衰]",
  401. "[委屈]", "[吐]", "[哈欠]", "[抱抱]", "[怒]", "[疑问]", "[馋嘴]", "[拜拜]", "[思考]", "[汗]", "[困]", "[睡]",
  402. "[钱]", "[失望]", "[酷]", "[色]", "[哼]", "[鼓掌]", "[晕]", "[悲伤]", "[抓狂]", "[黑线]", "[阴险]", "[怒骂]",
  403. "[互粉]", "[心]", "[伤心]", "[猪头]", "[熊猫]", "[兔子]", "[ok]", "[耶]", "[good]", "[NO]", "[赞]", "[来]",
  404. "[弱]", "[草泥马]", "[神马]", "[囧]", "[浮云]", "[给力]", "[围观]", "[威武]", "[奥特曼]", "[礼物]", "[钟]",
  405. "[话筒]", "[蜡烛]", "[蛋糕]"];
  406. $key = array_search($facesIcon, $data);
  407. return $key;
  408. }
  409. public function toexcel()
  410. {
  411. $param = input('param.');
  412. $limit = $param['pageSize'];
  413. $offset = ($param['pageNumber'] - 1) * $limit;
  414. $start = $param['start'];
  415. $end = $param['end'];
  416. $where = [];
  417. if($param['user_id'] != 0){
  418. $where['kf_id'] = $param['user_id'];
  419. }
  420. if($param['group_id'] != 0){
  421. $where['group_id'] = $param['group_id'];
  422. }
  423. if(!empty($param['username'])){
  424. $where['user_name'] = $param['username'];
  425. }
  426. $result = db('service_log')->whereBetween('start_time', [strtotime($start), strtotime($end . ' 23:59:59')])->where($where)->limit($offset, $limit)->order('start_time', 'desc')->select();
  427. //所有客服
  428. $users = db('users')->select();
  429. //所有客服组
  430. $groups = db('groups')->select();
  431. //满意度
  432. $evaluate = db('evaluate')->select();
  433. //$alarm报警信息
  434. $alarm = db('alarm')->select();
  435. foreach($result as $key=>$vo){
  436. if($result[$key]['intime'] != 0){
  437. $result[$key]['intime'] = date('Y-m-d H:i:s', $vo['intime']);
  438. }else{
  439. $result[$key]['intime'] = '-';
  440. }
  441. if($result[$key]['start_time'] != 0){
  442. $result[$key]['start_time'] = date('Y-m-d H:i:s', $vo['start_time']);
  443. }else{
  444. $result[$key]['start_time'] = '-';
  445. }
  446. if($result[$key]['end_time'] != 0){
  447. $result[$key]['end_time'] = date('Y-m-d H:i:s', $vo['end_time']);
  448. }else{
  449. $result[$key]['end_time'] = '-';
  450. }
  451. //客服昵称
  452. for($i=0;$i<count($users);$i++){
  453. if($result[$key]['kf_id'] == $users[$i]['id']){
  454. $result[$key]['kefu_name'] = $users[$i]['user_name'];
  455. }
  456. }
  457. //满意度
  458. $result[$key]['evaluate_name'] = '';
  459. for($j=0;$j<count($evaluate);$j++){
  460. if($result[$key]['evaluate_id'] == $evaluate[$j]['evaluate_id']){
  461. $result[$key]['evaluate_name'] = $evaluate[$j]['evaluate_name'];
  462. }
  463. }
  464. //客服所在组
  465. for($a=0;$a<count($groups);$a++){
  466. if($result[$key]['group_id'] == $groups[$a]['id']){
  467. $result[$key]['group_name'] = $groups[$a]['name'];
  468. }
  469. }
  470. //会话时长/响应时长
  471. $result[$key]['conversation'] = '';
  472. $result[$key]['response'] = '';
  473. for($b=0;$b<count($alarm);$b++){
  474. if($result[$key]['servicelog_id'] == $alarm[$b]['servicelog_id']){
  475. //会话时长
  476. $conversation_min = intval($alarm[$b]['alarm_cvtOvertime']/60);
  477. $conversation_s = $alarm[$b]['alarm_cvtOvertime']%60;
  478. $result[$key]['conversation'] = $conversation_min.'分'.$conversation_s.'秒';
  479. //响应时长
  480. $response_min = intval($alarm[$b]['alarm_corresponding']/60);
  481. $response_s = $alarm[$b]['alarm_corresponding']%60;
  482. $result[$key]['response'] = $response_min.'分'.$response_s.'秒';
  483. }
  484. }
  485. if($vo['servicelog_close_type'] == 0){
  486. $result[$key]['servicelog_close_type'] = '未知';
  487. }
  488. if($vo['servicelog_close_type'] == 1){
  489. $result[$key]['servicelog_close_type'] = '访客静默';
  490. }
  491. if($vo['servicelog_close_type'] == 2){
  492. $result[$key]['servicelog_close_type'] = '会话超时';
  493. }
  494. if($vo['servicelog_close_type'] == 3){
  495. $result[$key]['servicelog_close_type'] = '客服关闭';
  496. }
  497. if($vo['servicelog_close_type'] == 4){
  498. $result[$key]['servicelog_close_type'] = '客服掉线';
  499. }
  500. if($vo['servicelog_close_type'] == 5){
  501. $result[$key]['servicelog_close_type'] = '转接';
  502. }
  503. //工单聊天详情
  504. $chat_log = db('chat_log')->where('servicelog_id',$vo['servicelog_id'])->order('time_line', 'desc')->select();
  505. $result[$key]['detail'] = '';
  506. for($c=0;$c<count($chat_log);$c++){
  507. $content = json_decode($chat_log[$c]['content'], true);
  508. $chat_log[$c]['time_line'] = date('Y-m-d H:i:s',$chat_log[$c]['time_line']);
  509. $result[$key]['detail'] = $result[$key]['detail'].' '.$chat_log[$c]['time_line'].' '.$chat_log[$c]['from_name'];
  510. if(!empty($content['text'])){
  511. $content['content'] = $content['text'];
  512. }
  513. if(!empty($content['img'])){
  514. $content['content'] = '<img width="100%" src="'.$content['img'].'"/>';
  515. }
  516. $result[$key]['detail'] = $result[$key]['detail'].' '.$content['content'];
  517. }
  518. }
  519. $head = ['工单id', '访客进线时间', '接待客服', '所在组', '访客账号', '开始时间', '结束时间', '会话时长', '响应时长', '关闭原因', '满意度','来源ip','来源网站','来源系统','来源浏览器','聊天详情'];
  520. $key = ['servicelog_id', 'intime', 'kefu_name', 'group_name', 'user_name', 'start_time', 'end_time', 'conversation', 'response', 'servicelog_close_type', 'evaluate_name','user_ip','website','system','browse','detail'];
  521. (new Office())->outdata('工单数据导出', $result, $head, $key);
  522. return true;
  523. }
  524. }