System.php 24 KB

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