System.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\Office;
  4. /**
  5. * 管理系统系统设置类
  6. */
  7. class System extends Base
  8. {
  9. /**
  10. * 基础设置
  11. *
  12. * @access public
  13. */
  14. public function basics()
  15. {
  16. // 表单提交.
  17. if (request()->isPost()) {
  18. $param = input('post.');
  19. try {
  20. // 修改系统欢迎语.
  21. if (empty($param['advertisement_img']) === false) {
  22. $updateAstData['advertisement_img'] = $param['advertisement_img'];
  23. }
  24. if (empty($param['logo_img']) === false) {
  25. $updateinfo['logo'] = $param['logo_img'];
  26. }
  27. $updateAstData['advertisement_url'] = $param['advertisementUrl'];
  28. $updateAstData['advertisement_status'] = $param['status'];
  29. model('Advertisement')->updateAst($updateAstData);
  30. // 修改系统欢迎语.
  31. $updateSysData['word'] = $param['systemWord'];
  32. $updateSysWhere['id'] = 1;
  33. model('Reply')->updateReply($updateSysWhere, $updateSysData);
  34. // 修改客服欢迎语.
  35. $updateSevData['word'] = $param['serverWord'];
  36. $updateSevWhere['id'] = 2;
  37. model('Reply')->updateReply($updateSevWhere, $updateSevData);
  38. if(!empty($updateinfo)){
  39. db('settings')->where('id',1)->update($updateinfo);
  40. }
  41. return json(['code' => 1, 'data' => '', 'msg' => '设置成功']);
  42. } catch (\Exception $e) {
  43. return json(['code' => -2, 'data' => '', 'msg' => $e->getMessage()]);
  44. }//end try
  45. }//end if
  46. // 获取广告.
  47. $advertisement = model('Advertisement')->findAst();
  48. // 获取系统欢迎语.
  49. $replySystemWhere['id'] = 1;
  50. $replySystem = model('Reply')->findReply($replySystemWhere);
  51. // 获取客服欢迎语.
  52. $replyServerWhere['id'] = 2;
  53. $replyServer = model('Reply')->findReply($replyServerWhere);
  54. // 获取logo.
  55. $settings = db('settings')->find();
  56. $this->assign(
  57. [
  58. 'advertisement' => $advertisement,
  59. 'replySystem' => $replySystem,
  60. 'replyServer' => $replyServer,
  61. 'settings' => $settings,
  62. 'status' => config('kf_status'),
  63. ]
  64. );
  65. return $this->fetch();
  66. }//end basics()
  67. /**
  68. * 会话设置
  69. *
  70. * @access public
  71. */
  72. public function conversation()
  73. {
  74. // 表单提交.
  75. if (request()->isPost()) {
  76. $param = input('post.');
  77. try {
  78. // 修改会话超时.
  79. $updateOvertimeData['systemconfig_data'] = $param['overtime'];
  80. $updateOvertimeWhere['systemconfig_id'] = 1;
  81. model('Systemconfig')->updateSystemconfig($updateOvertimeWhere, $updateOvertimeData);
  82. // 修改访客静默.
  83. $upUptdData['systemconfig_data'] = $param['unoperated'];
  84. $upUptdWhere['systemconfig_id'] = 2;
  85. model('Systemconfig')->updateSystemconfig($upUptdWhere, $upUptdData);
  86. // 质检会话时长设置.
  87. $upAllTimeData['systemconfig_data'] = $param['verifyAllTime'];
  88. $upAllTimeWhere['systemconfig_id'] = 3;
  89. model('Systemconfig')->updateSystemconfig($upAllTimeWhere, $upAllTimeData);
  90. // 质检会话响应时长设置.
  91. $upReturnTimeData['systemconfig_data'] = $param['verifyReturnTime'];
  92. $upReturnTimeWhere['systemconfig_id'] = 4;
  93. model('Systemconfig')->updateSystemconfig($upReturnTimeWhere, $upReturnTimeData);
  94. // 满意度评价回合限制.
  95. $upRoundData['systemconfig_data'] = $param['round'];
  96. $upRoundWhere['systemconfig_id'] = 5;
  97. model('Systemconfig')->updateSystemconfig($upRoundWhere, $upRoundData);
  98. // 客服接待人数设置.
  99. $upKfConfigData['max_service'] = $param['max_service'];
  100. $upKfConfigData['kfConfig_maxWait'] = $param['kfConfig_maxWait'];
  101. db('kf_config')->where('id', 1)->update($upKfConfigData);
  102. return json(['code' => 1, 'data' => '', 'msg' => '设置成功']);
  103. } catch (\Exception $e) {
  104. return json(['code' => -2, 'data' => '', 'msg' => $e->getMessage()]);
  105. }//end try
  106. }//end if
  107. // 获取设置.
  108. $systemconfig = model('Systemconfig')->selectSystemconfig();
  109. $kfConfig = db('kf_config')->where('id', 1)->find();
  110. $this->assign(
  111. [
  112. 'systemconfig' => $systemconfig,
  113. 'kfConfig' => $kfConfig,
  114. 'status' => config('kf_status'),
  115. ]
  116. );
  117. return $this->fetch();
  118. }//end conversation()
  119. // 自动回复设置
  120. public function reply()
  121. {
  122. if(request()->isPost()){
  123. $param = input('post.');
  124. if(empty($param['word'])){
  125. return json(['code' => -1, 'data' => '', 'msg' => '回复内容不能为空']);
  126. }
  127. try{
  128. db('reply')->where('id', 1)->update($param);
  129. }catch(\Exception $e){
  130. return json(['code' => -2, 'data' => '', 'msg' => $e->getMessage()]);
  131. }
  132. return json(['code' => 1, 'data' => '', 'msg' => '设置成功']);
  133. }
  134. $info = db('reply')->where('id', 1)->find();
  135. $this->assign([
  136. 'info' => $info,
  137. 'status' => config('kf_status')
  138. ]);
  139. return $this->fetch();
  140. }
  141. // 历史会话记录
  142. public function wordsLog()
  143. {
  144. $toExcel = input('param.toExcel', 0);
  145. if(request()->isAjax()){
  146. $param = input('param.');
  147. $limit = $param['pageSize'];
  148. $offset = ($param['pageNumber'] - 1) * $limit;
  149. // 默认显示最近7天
  150. $start = input('param.start');
  151. $end = input('param.end');
  152. $user_id = input('param.user_id');
  153. $group_id = input('param.group_id');
  154. $temp = db('service_log');
  155. $countTmp = db('service_log');
  156. if(strlen($param['searchText'])){
  157. $temp = $temp->whereLike('user_name', '%'.$param['searchText'].'%');
  158. $countTmp = $countTmp->whereLike('user_name', '%'.$param['searchText'].'%');
  159. }
  160. //日期
  161. if(!empty($start) && !empty($end) && $start <= $end){
  162. $temp = $temp->whereBetween('start_time', [strtotime($start), strtotime($end . ' 23:59:59')]);
  163. $countTmp = $countTmp->whereBetween('start_time', [strtotime($start), strtotime($end . ' 23:59:59')]);
  164. }
  165. //结束时间为空
  166. if(!empty($start) && empty($end)){
  167. $temp = $temp->where('start_time','>',strtotime($start));
  168. $countTmp = $temp->where('start_time','>',strtotime($start));
  169. }
  170. //开始时间为空
  171. if(empty($start) && !empty($end)){
  172. $temp = $temp->where('start_time','<',strtotime($end . ' 23:59:59'));
  173. $countTmp = $temp->where('start_time','<',strtotime($end . ' 23:59:59'));
  174. }
  175. //开始时间/结束时间都为空(默认查七天)
  176. // if(empty($start) && empty($end)){
  177. // $temp = $temp->where('start_time','<',time())->where('start_time','>',time()-604800);
  178. // $countTmp = $temp->where('start_time','<',time())->where('start_time','>',time()-604800);
  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 = $temp->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 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 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)
  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'] = $content['text'];
  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. $servicelog = db('service_log')->where('servicelog_id',$id)->find();
  344. //满意度
  345. $evaluate = db('evaluate')->where('evaluate_id',$servicelog['evaluate_id'])->find();
  346. $evaluate = '<img width="40px" style="margin-top:15px;" src="'.$evaluate['evaluate_url'].'"/>';
  347. //$alarm报警信息
  348. $alarm = db('alarm')->where('servicelog_id',$id)->find();
  349. //会话超时标准
  350. $verifyAllTime = db('systemconfig')->where('systemconfig_name','质检会话时长设置')->find();
  351. //会话响应时长标准
  352. $verifyReturnTime = db('systemconfig')->where('systemconfig_name','质检会话响应时长设置')->find();
  353. $span = '';
  354. if(!empty($alarm)){
  355. if($alarm['alarm_userSensitive'] != 0){
  356. $span = $span . '<span class="alarm_info">访客敏感词</span>';
  357. }
  358. if($alarm['alarm_serverSensitive'] != 0){
  359. $span = $span . '<span class="alarm_info">客服敏感词</span>';
  360. }
  361. if($alarm['alarm_corresponding'] > $verifyReturnTime['systemconfig_data']){
  362. $span = $span . '<span class="alarm_info">响应超时</span>';
  363. }
  364. if($alarm['alarm_cvtOvertime'] > $verifyAllTime['systemconfig_data']){
  365. $span = $span . '<span class="alarm_info">会话超时</span>';
  366. }
  367. if($alarm['alarm_respond'] == 1){
  368. $span = $span . '<span class="alarm_info">客服未回应</span>';
  369. }
  370. }
  371. //用户信息
  372. $account = db('accounts')->where('id',$servicelog['user_id'])->find();
  373. $label = db('accountslabel')->where('id', $account['label_id'])->find();
  374. $account['label'] = $label['name'];
  375. $this->assign([
  376. 'html' => $html,
  377. 'span' => $span,
  378. 'evaluate' => $evaluate,
  379. 'servicelog' => $servicelog,
  380. 'account' => $account
  381. ]);
  382. return $this->fetch();
  383. }
  384. // 生成按钮
  385. private function makeBtn($id)
  386. {
  387. $operate = '<a href="' . url('system/detail', ['id' => $id]) . '">';
  388. $operate .= '<button type="button" class="btn btn-primary btn-sm"><i class="fa fa-paste"></i> 详情</button></a> ';
  389. return $operate;
  390. }
  391. public function getFacesIcon($facesIcon) {
  392. $data = ["[微笑]", "[嘻嘻]", "[哈哈]", "[可爱]", "[可怜]", "[挖鼻]", "[吃惊]", "[害羞]", "[挤眼]", "[闭嘴]", "[鄙视]",
  393. "[爱你]", "[泪]", "[偷笑]", "[亲亲]", "[生病]", "[太开心]", "[白眼]", "[右哼哼]", "[左哼哼]", "[嘘]", "[衰]",
  394. "[委屈]", "[吐]", "[哈欠]", "[抱抱]", "[怒]", "[疑问]", "[馋嘴]", "[拜拜]", "[思考]", "[汗]", "[困]", "[睡]",
  395. "[钱]", "[失望]", "[酷]", "[色]", "[哼]", "[鼓掌]", "[晕]", "[悲伤]", "[抓狂]", "[黑线]", "[阴险]", "[怒骂]",
  396. "[互粉]", "[心]", "[伤心]", "[猪头]", "[熊猫]", "[兔子]", "[ok]", "[耶]", "[good]", "[NO]", "[赞]", "[来]",
  397. "[弱]", "[草泥马]", "[神马]", "[囧]", "[浮云]", "[给力]", "[围观]", "[威武]", "[奥特曼]", "[礼物]", "[钟]",
  398. "[话筒]", "[蜡烛]", "[蛋糕]"];
  399. $key = array_search($facesIcon, $data);
  400. return $key;
  401. }
  402. public function toexcel()
  403. {
  404. $param = input('param.');
  405. $start = $param['start'];
  406. $end = $param['end'];
  407. $where = [];
  408. if(!empty($param['user_id'])){
  409. $where['user_id'] = $param['user_id'];
  410. }
  411. if(!empty($param['group_id'])){
  412. $where['group_id'] = $param['group_id'];
  413. }
  414. if(!empty($param['username'])){
  415. $where['user_name'] = $param['username'];
  416. }
  417. $result = db('service_log')->whereBetween('start_time', [strtotime($start), strtotime($end . ' 23:59:59')])->where($where)->order('start_time', 'desc')->select();
  418. //所有客服
  419. $users = db('users')->select();
  420. //所有客服组
  421. $groups = db('groups')->select();
  422. //满意度
  423. $evaluate = db('evaluate')->select();
  424. //$alarm报警信息
  425. $alarm = db('alarm')->select();
  426. foreach($result as $key=>$vo){
  427. if($result[$key]['intime'] != 0){
  428. $result[$key]['intime'] = date('Y-m-d H:i:s', $vo['intime']);
  429. }else{
  430. $result[$key]['intime'] = '-';
  431. }
  432. if($result[$key]['start_time'] != 0){
  433. $result[$key]['start_time'] = date('Y-m-d H:i:s', $vo['start_time']);
  434. }else{
  435. $result[$key]['start_time'] = '-';
  436. }
  437. if($result[$key]['end_time'] != 0){
  438. $result[$key]['end_time'] = date('Y-m-d H:i:s', $vo['end_time']);
  439. }else{
  440. $result[$key]['end_time'] = '-';
  441. }
  442. //客服名称
  443. for($i=0;$i<count($users);$i++){
  444. if($result[$key]['kf_id'] == $users[$i]['id']){
  445. $result[$key]['kefu_name'] = $users[$i]['user_name'];
  446. }
  447. }
  448. //满意度
  449. $result[$key]['evaluate_name'] = '';
  450. for($j=0;$j<count($evaluate);$j++){
  451. if($result[$key]['evaluate_id'] == $evaluate[$j]['evaluate_id']){
  452. $result[$key]['evaluate_name'] = $evaluate[$j]['evaluate_name'];
  453. }
  454. }
  455. //客服所在组
  456. for($a=0;$a<count($groups);$a++){
  457. if($result[$key]['group_id'] == $groups[$a]['id']){
  458. $result[$key]['group_name'] = $groups[$a]['name'];
  459. }
  460. }
  461. //会话时长/响应时长
  462. $result[$key]['conversation'] = '';
  463. $result[$key]['response'] = '';
  464. for($b=0;$b<count($alarm);$b++){
  465. if($result[$key]['servicelog_id'] == $alarm[$b]['servicelog_id']){
  466. //会话时长
  467. $conversation_min = intval($alarm[$b]['alarm_cvtOvertime']/60);
  468. $conversation_s = $alarm[$b]['alarm_cvtOvertime']%60;
  469. $result[$key]['conversation'] = $conversation_min.'分'.$conversation_s.'秒';
  470. //响应时长
  471. $response_min = intval($alarm[$b]['alarm_corresponding']/60);
  472. $response_s = $alarm[$b]['alarm_corresponding']%60;
  473. $result[$key]['response'] = $response_min.'分'.$response_s.'秒';
  474. }
  475. }
  476. if($vo['servicelog_close_type'] == 0){
  477. $result[$key]['servicelog_close_type'] = '未知';
  478. }
  479. if($vo['servicelog_close_type'] == 1){
  480. $result[$key]['servicelog_close_type'] = '访客静默';
  481. }
  482. if($vo['servicelog_close_type'] == 2){
  483. $result[$key]['servicelog_close_type'] = '会话超时';
  484. }
  485. if($vo['servicelog_close_type'] == 3){
  486. $result[$key]['servicelog_close_type'] = '客服关闭';
  487. }
  488. if($vo['servicelog_close_type'] == 4){
  489. $result[$key]['servicelog_close_type'] = '客服掉线';
  490. }
  491. if($vo['servicelog_close_type'] == 5){
  492. $result[$key]['servicelog_close_type'] = '转接';
  493. }
  494. //工单聊天详情
  495. $chat_log = db('chat_log')->where('servicelog_id',$vo['servicelog_id'])->order('time_line', 'desc')->select();
  496. $result[$key]['detail'] = '';
  497. for($c=0;$c<count($chat_log);$c++){
  498. $content = json_decode($chat_log[$c]['content'], true);
  499. $chat_log[$c]['time_line'] = date('Y-m-d H:i:s',$chat_log[$c]['time_line']);
  500. $result[$key]['detail'] = $result[$key]['detail'].' '.$chat_log[$c]['time_line'].' '.$chat_log[$c]['from_name'];
  501. if(!empty($content['text'])){
  502. $content['content'] = $content['text'];
  503. }
  504. if(!empty($content['img'])){
  505. $content['content'] = '<img width="100%" src="'.$content['img'].'"/>';
  506. }
  507. $result[$key]['detail'] = $result[$key]['detail'].' '.$content['content'];
  508. }
  509. }
  510. $head = ['工单id', '访客进线时间', '接待客服', '所在组', '访客账号', '开始时间', '结束时间', '会话时长', '响应时长', '关闭原因', '满意度','来源ip','来源网站','来源系统','来源浏览器','聊天详情'];
  511. $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'];
  512. (new Office())->outdata('工单数据导出', $result, $head, $key);
  513. return true;
  514. }
  515. }