System.php 25 KB

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