System.php 25 KB

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