System.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. <?php
  2. namespace app\admin\controller;
  3. /**
  4. * 管理系统系统设置类
  5. */
  6. class System extends Base
  7. {
  8. /**
  9. * 基础设置
  10. *
  11. * @access public
  12. */
  13. public function basics()
  14. {
  15. // 表单提交.
  16. if (request()->isPost()) {
  17. $param = input('post.');
  18. try {
  19. // 修改系统欢迎语.
  20. if (empty($param['advertisement_img']) === false) {
  21. $updateAstData['advertisement_img'] = $param['advertisement_img'];
  22. }
  23. $updateAstData['advertisement_url'] = $param['advertisementUrl'];
  24. $updateAstData['advertisement_status'] = $param['status'];
  25. model('Advertisement')->updateAst($updateAstData);
  26. // 修改系统欢迎语.
  27. $updateSysData['word'] = $param['systemWord'];
  28. $updateSysWhere['id'] = 1;
  29. model('Reply')->updateReply($updateSysWhere, $updateSysData);
  30. // 修改客服欢迎语.
  31. $updateSevData['word'] = $param['serverWord'];
  32. $updateSevWhere['id'] = 2;
  33. model('Reply')->updateReply($updateSevWhere, $updateSevData);
  34. return json(['code' => 1, 'data' => '', 'msg' => '设置成功']);
  35. } catch (\Exception $e) {
  36. return json(['code' => -2, 'data' => '', 'msg' => $e->getMessage()]);
  37. }//end try
  38. }//end if
  39. // 获取广告.
  40. $advertisement = model('Advertisement')->findAst();
  41. // 获取系统欢迎语.
  42. $replySystemWhere['id'] = 1;
  43. $replySystem = model('Reply')->findReply($replySystemWhere);
  44. // 获取客服欢迎语.
  45. $replyServerWhere['id'] = 2;
  46. $replyServer = model('Reply')->findReply($replyServerWhere);
  47. $this->assign(
  48. [
  49. 'advertisement' => $advertisement,
  50. 'replySystem' => $replySystem,
  51. 'replyServer' => $replyServer,
  52. 'status' => config('kf_status'),
  53. ]
  54. );
  55. return $this->fetch();
  56. }//end basics()
  57. /**
  58. * 会话设置
  59. *
  60. * @access public
  61. */
  62. public function conversation()
  63. {
  64. // 表单提交.
  65. if (request()->isPost()) {
  66. $param = input('post.');
  67. try {
  68. // 修改会话超时.
  69. $updateOvertimeData['systemconfig_data'] = $param['overtime'];
  70. $updateOvertimeWhere['systemconfig_id'] = 1;
  71. model('Systemconfig')->updateSystemconfig($updateOvertimeWhere, $updateOvertimeData);
  72. // 修改访客静默.
  73. $upUptdData['systemconfig_data'] = $param['unoperated'];
  74. $upUptdWhere['systemconfig_id'] = 2;
  75. model('Systemconfig')->updateSystemconfig($upUptdWhere, $upUptdData);
  76. // 质检会话时长设置.
  77. $upAllTimeData['systemconfig_data'] = $param['verifyAllTime'];
  78. $upAllTimeWhere['systemconfig_id'] = 3;
  79. model('Systemconfig')->updateSystemconfig($upAllTimeWhere, $upAllTimeData);
  80. // 质检会话响应时长设置.
  81. $upReturnTimeData['systemconfig_data'] = $param['verifyReturnTime'];
  82. $upReturnTimeWhere['systemconfig_id'] = 4;
  83. model('Systemconfig')->updateSystemconfig($upReturnTimeWhere, $upReturnTimeData);
  84. // 满意度评价回合限制.
  85. $upRoundData['systemconfig_data'] = $param['round'];
  86. $upRoundWhere['systemconfig_id'] = 5;
  87. model('Systemconfig')->updateSystemconfig($upRoundWhere, $upRoundData);
  88. // 客服接待人数设置.
  89. $upKfConfigData['max_service'] = $param['max_service'];
  90. $upKfConfigData['kfConfig_maxWait'] = $param['kfConfig_maxWait'];
  91. db('kf_config')->where('id', 1)->update($upKfConfigData);
  92. return json(['code' => 1, 'data' => '', 'msg' => '设置成功']);
  93. } catch (\Exception $e) {
  94. return json(['code' => -2, 'data' => '', 'msg' => $e->getMessage()]);
  95. }//end try
  96. }//end if
  97. // 获取设置.
  98. $systemconfig = model('Systemconfig')->selectSystemconfig();
  99. $kfConfig = db('kf_config')->where('id', 1)->find();
  100. $this->assign(
  101. [
  102. 'systemconfig' => $systemconfig,
  103. 'kfConfig' => $kfConfig,
  104. 'status' => config('kf_status'),
  105. ]
  106. );
  107. return $this->fetch();
  108. }//end conversation()
  109. // 自动回复设置
  110. public function reply()
  111. {
  112. if(request()->isPost()){
  113. $param = input('post.');
  114. if(empty($param['word'])){
  115. return json(['code' => -1, 'data' => '', 'msg' => '回复内容不能为空']);
  116. }
  117. try{
  118. db('reply')->where('id', 1)->update($param);
  119. }catch(\Exception $e){
  120. return json(['code' => -2, 'data' => '', 'msg' => $e->getMessage()]);
  121. }
  122. return json(['code' => 1, 'data' => '', 'msg' => '设置成功']);
  123. }
  124. $info = db('reply')->where('id', 1)->find();
  125. $this->assign([
  126. 'info' => $info,
  127. 'status' => config('kf_status')
  128. ]);
  129. return $this->fetch();
  130. }
  131. // 历史会话记录
  132. public function wordsLog()
  133. {
  134. if(request()->isAjax()){
  135. $param = input('param.');
  136. $limit = $param['pageSize'];
  137. $offset = ($param['pageNumber'] - 1) * $limit;
  138. // 默认显示最近7天
  139. $start = input('param.start');
  140. $end = input('param.end');
  141. $user_id = input('param.user_id');
  142. $group_id = input('param.group_id');
  143. $temp = db('service_log');
  144. $countTmp = db('service_log');
  145. if(!empty($param['searchText'])){
  146. $temp = $temp->whereLike('user_name', '%'.$param['searchText'].'%');
  147. $countTmp = $countTmp->whereLike('user_name', '%'.$param['searchText'].'%');
  148. }
  149. //日期
  150. if(!empty($start) && !empty($end) && $start <= $end){
  151. $temp = $temp->whereBetween('start_time', [strtotime($start), strtotime($end . ' 23:59:59')]);
  152. $countTmp = $countTmp->whereBetween('start_time', [strtotime($start), strtotime($end . ' 23:59:59')]);
  153. }
  154. //结束时间为空
  155. if(!empty($start) && empty($end)){
  156. $temp = $temp->where('start_time','>',strtotime($start));
  157. $countTmp = $temp->where('start_time','>',strtotime($start));
  158. }
  159. //开始时间为空
  160. if(empty($start) && !empty($end)){
  161. $temp = $temp->where('start_time','<',strtotime($end . ' 23:59:59'));
  162. $countTmp = $temp->where('start_time','<',strtotime($end . ' 23:59:59'));
  163. }
  164. //开始时间/结束时间都为空(默认查七天)
  165. // if(empty($start) && empty($end)){
  166. // $temp = $temp->where('start_time','<',time())->where('start_time','>',time()-604800);
  167. // $countTmp = $temp->where('start_time','<',time())->where('start_time','>',time()-604800);
  168. // }
  169. //客服
  170. if($user_id != 0){
  171. $temp = $temp->where('kf_id', $user_id);
  172. $countTmp = $countTmp->where('kf_id', $user_id);
  173. }
  174. //客服组
  175. if($group_id != 0){
  176. $temp = $temp->where('group_id', $group_id);
  177. $countTmp = $temp->where('group_id', $group_id);
  178. }
  179. $result = $temp->limit($offset, $limit)->order('start_time', 'desc')->select();
  180. //所有客服
  181. $users = db('users')->select();
  182. //所有客服组
  183. $groups = db('groups')->select();
  184. //满意度
  185. $evaluate = db('evaluate')->select();
  186. //$alarm报警信息
  187. $alarm = db('alarm')->select();
  188. foreach($result as $key=>$vo){
  189. if($result[$key]['intime'] != 0){
  190. $result[$key]['intime'] = date('Y-m-d H:i:s', $vo['intime']);
  191. }else{
  192. $result[$key]['intime'] = '-';
  193. }
  194. if($result[$key]['start_time'] != 0){
  195. $result[$key]['start_time'] = date('Y-m-d H:i:s', $vo['start_time']);
  196. }else{
  197. $result[$key]['start_time'] = '-';
  198. }
  199. if($result[$key]['end_time'] != 0){
  200. $result[$key]['end_time'] = date('Y-m-d H:i:s', $vo['start_time']);
  201. }else{
  202. $result[$key]['end_time'] = '-';
  203. }
  204. //客服名称
  205. for($i=0;$i<count($users);$i++){
  206. if($result[$key]['kf_id'] == $users[$i]['id']){
  207. $result[$key]['kefu_name'] = $users[$i]['user_name'];
  208. }
  209. }
  210. //满意度
  211. for($j=0;$j<count($evaluate);$j++){
  212. if($result[$key]['evaluate_id'] == $evaluate[$j]['evaluate_id']){
  213. $result[$key]['evaluate_name'] = $evaluate[$j]['evaluate_name'];
  214. }
  215. }
  216. //客服所在组
  217. for($a=0;$a<count($groups);$a++){
  218. if($result[$key]['group_id'] == $groups[$a]['id']){
  219. $result[$key]['group_name'] = $groups[$a]['name'];
  220. }
  221. }
  222. //会话时长/响应时长
  223. for($b=0;$b<count($alarm);$b++){
  224. if($result[$key]['servicelog_id'] == $alarm[$b]['servicelog_id']){
  225. //会话时长
  226. $conversation_min = intval($alarm[$b]['alarm_cvtOvertime']/60);
  227. $conversation_s = $alarm[$b]['alarm_cvtOvertime']%60;
  228. $result[$key]['conversation'] = $conversation_min.':'.$conversation_s;
  229. //响应时长
  230. $response_min = intval($alarm[$b]['alarm_corresponding']/60);
  231. $response_s = $alarm[$b]['alarm_corresponding']%60;
  232. $result[$key]['response'] = $response_min.':'.$response_s;
  233. }
  234. }
  235. // 生成操作按钮
  236. if(0 != $vo['servicelog_id']){
  237. $result[$key]['operate'] = $this->makeBtn($vo['servicelog_id']);
  238. }
  239. }
  240. $return['total'] = $countTmp->count(); //总数据
  241. $return['rows'] = $result;
  242. return json($return);
  243. }
  244. //所有客服
  245. $users = db('users')->select();
  246. if(!empty($users)){
  247. $option = '<option value="0">全部客服</option>';
  248. for($i=0;$i<count($users);$i++){
  249. $option = $option.'<option value="'.$users[$i]['id'].'">'.$users[$i]['user_name'].'</option>';
  250. }
  251. $useroption = '<select lay-verify="required" lay-filter="user_id">'.$option.'</select>';
  252. }
  253. //所有客服组
  254. $groups = db('groups')->select();
  255. if(!empty($groups)){
  256. $option = '<option value="0">全部客服组</option>';
  257. for($j=0;$j<count($groups);$j++){
  258. $option = $option.'<option value="'.$groups[$j]['id'].'">'.$groups[$j]['name'].'</option>';
  259. }
  260. $groupoption = '<select lay-verify="required" lay-filter="group_id">'.$option.'</select>';
  261. }
  262. $this->assign([
  263. 'useroption' => $useroption,
  264. 'groupoption' => $groupoption
  265. ]);
  266. return $this->fetch('wordslog');
  267. }
  268. // 历史会话记录详情
  269. public function detail($id)
  270. {
  271. $chat = db('chat_log')->where('servicelog_id',$id)->order('time_line')->select();
  272. $html = '';
  273. for($i=0;$i<count($chat);$i++){
  274. $content = json_decode($chat[$i]['content'], true);
  275. $chat[$i]['time_line'] = date('H:i',$chat[$i]['time_line']);
  276. if(!empty(strstr($chat[$i]['to_id'], 'KF'))){
  277. $html = $html . '<div style="margin-top:15px;width: 30%;"><div>'.$chat[$i]['from_name'].'&nbsp&nbsp&nbsp'.$chat[$i]['time_line'].'</div>';
  278. $html = $html . '<p style="margin-top:5px;" class="form-content">'.$content['text'].'</p></div>';
  279. }else{
  280. $html = $html . '<div style="margin-top:15px;width: 30%;margin-left:70%;text-align:right;"><div>'.$chat[$i]['from_name'].'&nbsp&nbsp&nbsp'.$chat[$i]['time_line'].'</div>';
  281. $html = $html . '<p style="margin-top:5px;" class="form-content">'.$content['text'].'</p></div>';
  282. }
  283. }
  284. $servicelog = db('service_log')->where('servicelog_id',$id)->find();
  285. //满意度
  286. $evaluate = db('evaluate')->where('evaluate_id',$servicelog['evaluate_id'])->find();
  287. $evaluate = $evaluate['evaluate_name'];
  288. //$alarm报警信息
  289. $alarm = db('alarm')->where('servicelog_id',$id)->find();
  290. //会话超时标准
  291. $verifyAllTime = db('systemconfig')->where('systemconfig_name','质检会话时长设置')->find();
  292. //会话响应时长标准
  293. $verifyReturnTime = db('systemconfig')->where('systemconfig_name','质检会话响应时长设置')->find();
  294. $ul = '';
  295. if(!empty($alarm)){
  296. $ul = $ul . '<ul class="alarm"><li>触犯警报</li>';
  297. if($alarm['alarm_userSensitive'] != 0){
  298. $ul = $ul . '<li class="alarm_info">访客敏感词</li>';
  299. }
  300. if($alarm['alarm_serverSensitive'] != 0){
  301. $ul = $ul . '<li class="alarm_info">客服敏感词</li>';
  302. }
  303. if($alarm['alarm_corresponding'] > $verifyReturnTime['systemconfig_data']){
  304. $ul = $ul . '<li class="alarm_info">响应超时</li>';
  305. }
  306. if($alarm['alarm_cvtOvertime'] > $verifyAllTime['systemconfig_data']){
  307. $ul = $ul . '<li class="alarm_info">会话超时</li>';
  308. }
  309. $ul = $ul . '</ul>';
  310. }
  311. //用户信息
  312. $account = db('accounts')->where('id',$servicelog['user_id'])->find();
  313. $this->assign([
  314. 'html' => $html,
  315. 'ul' => $ul,
  316. 'evaluate' => $evaluate,
  317. 'servicelog' => $servicelog,
  318. 'account' => $account
  319. ]);
  320. return $this->fetch();
  321. }
  322. // 生成按钮
  323. private function makeBtn($id)
  324. {
  325. $operate = '<a href="' . url('system/detail', ['id' => $id]) . '">';
  326. $operate .= '<button type="button" class="btn btn-primary btn-sm"><i class="fa fa-paste"></i> 详情</button></a> ';
  327. return $operate;
  328. }
  329. }