System.php 25 KB

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