System.php 25 KB

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