System.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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. $user = db('users')->where('user_name', '%'.$param['searchText'].'%')->select();
  147. $temp = $temp->where('kf_id', $user['id']);
  148. $countTmp = $countTmp->where('kf_id', $user['id']);
  149. }
  150. //日期
  151. if(!empty($start) && !empty($end) && $start <= $end){
  152. $temp = $temp->whereBetween('start_time', [strtotime($start), strtotime($end . ' 23:59:59')]);
  153. $countTmp = $countTmp->whereBetween('start_time', [strtotime($start), strtotime($end . ' 23:59:59')]);
  154. }
  155. //结束时间为空
  156. if(!empty($start) && empty($end)){
  157. $temp = $temp->where('start_time','>',strtotime($start));
  158. $countTmp = $temp->where('start_time','>',strtotime($start));
  159. }
  160. //开始时间为空
  161. if(empty($start) && !empty($end)){
  162. $temp = $temp->where('start_time','<',strtotime($end . ' 23:59:59'));
  163. $countTmp = $temp->where('start_time','<',strtotime($end . ' 23:59:59'));
  164. }
  165. //开始时间/结束时间都为空(默认查七天)
  166. // if(empty($start) && empty($end)){
  167. // $temp = $temp->where('start_time','<',time())->where('start_time','>',time()-604800);
  168. // $countTmp = $temp->where('start_time','<',time())->where('start_time','>',time()-604800);
  169. // }
  170. //客服
  171. if($user_id != 0){
  172. $temp = $temp->where('kf_id', $user_id);
  173. $countTmp = $countTmp->where('kf_id', $user_id);
  174. }
  175. //客服组
  176. if($group_id != 0){
  177. $temp = $temp->where('group_id', $group_id);
  178. $countTmp = $temp->where('group_id', $group_id);
  179. }
  180. $result = $temp->limit($offset, $limit)->order('start_time', 'desc')->select();
  181. //所有客服
  182. $users = db('users')->select();
  183. //满意度
  184. $evaluate = db('evaluate')->select();
  185. foreach($result as $key=>$vo){
  186. if($result[$key]['intime'] != 0){
  187. $result[$key]['intime'] = date('Y-m-d H:i:s', $vo['intime']);
  188. }else{
  189. $result[$key]['intime'] = '-';
  190. }
  191. if($result[$key]['start_time'] != 0){
  192. $result[$key]['start_time'] = date('Y-m-d H:i:s', $vo['start_time']);
  193. }else{
  194. $result[$key]['start_time'] = '-';
  195. }
  196. if($result[$key]['end_time'] != 0){
  197. $result[$key]['end_time'] = date('Y-m-d H:i:s', $vo['start_time']);
  198. }else{
  199. $result[$key]['end_time'] = '-';
  200. }
  201. //客服名称
  202. for($i=0;$i<count($users);$i++){
  203. if($result[$key]['kf_id'] == $users[$i]['id']){
  204. $result[$key]['kefu_name'] = $users[$i]['user_name'];
  205. }
  206. }
  207. //满意度
  208. for($j=0;$j<count($evaluate);$j++){
  209. if($result[$key]['evaluate_id'] == $evaluate[$j]['evaluate_id']){
  210. $result[$key]['evaluate_name'] = $evaluate[$j]['evaluate_name'];
  211. }
  212. }
  213. // 生成操作按钮
  214. if(0 != $vo['servicelog_id']){
  215. $result[$key]['operate'] = $this->makeBtn($vo['servicelog_id']);
  216. }
  217. }
  218. $return['total'] = $countTmp->count(); //总数据
  219. $return['rows'] = $result;
  220. return json($return);
  221. }
  222. //所有客服
  223. $users = db('users')->select();
  224. if(!empty($users)){
  225. $option = '<option value="0">全部客服</option>';
  226. for($i=0;$i<count($users);$i++){
  227. $option = $option.'<option value="'.$users[$i]['id'].'">'.$users[$i]['user_name'].'</option>';
  228. }
  229. $useroption = '<select lay-verify="required" lay-filter="user_id">'.$option.'</select>';
  230. }
  231. //所有客服组
  232. $groups = db('groups')->select();
  233. if(!empty($groups)){
  234. $option = '<option value="0">全部客服组</option>';
  235. for($j=0;$j<count($groups);$j++){
  236. $option = $option.'<option value="'.$groups[$j]['id'].'">'.$groups[$j]['name'].'</option>';
  237. }
  238. $groupoption = '<select lay-verify="required" lay-filter="group_id">'.$option.'</select>';
  239. }
  240. $this->assign([
  241. 'useroption' => $useroption,
  242. 'groupoption' => $groupoption
  243. ]);
  244. return $this->fetch('wordslog');
  245. }
  246. // 历史会话记录详情
  247. public function detail($id)
  248. {
  249. $chat = db('chat_log')->where('servicelog_id',$id)->order('time_line')->select();
  250. $html = '';
  251. for($i=0;$i<count($chat);$i++){
  252. $chat[$i]['time_line'] = date('H:i',$chat[$i]['time_line']);
  253. if(!empty(strstr($chat[$i]['to_id'], 'KF'))){
  254. $html = $html . '<div style="margin-top:15px;width: 30%;"><div>'.$chat[$i]['from_name'].'&nbsp&nbsp&nbsp'.$chat[$i]['time_line'].'</div>';
  255. $html = $html . '<p style="margin-top:5px;" class="form-content">'.$chat[$i]['content'].'</p></div>';
  256. }else{
  257. $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>';
  258. $html = $html . '<p style="margin-top:5px;" class="form-content">'.$chat[$i]['content'].'</p></div>';
  259. }
  260. }
  261. $servicelog = db('service_log')->where('servicelog_id',$id)->find();
  262. //满意度
  263. $evaluate = db('evaluate')->where('evaluate_id',$servicelog['evaluate_id'])->find();
  264. $evaluate = $evaluate['evaluate_name'];
  265. //$alarm报警信息
  266. $alarm = db('alarm')->where('servicelog_id',$id)->find();
  267. $ul = '';
  268. if(!empty($alarm)){
  269. $ul = $ul . '<ul class="alarm"><li>触犯警报</li>';
  270. if($alarm['alarm_userSensitive'] != 0){
  271. $ul = $ul . '<li class="alarm_info">访客敏感词</li>';
  272. }
  273. if($alarm['alarm_serverSensitive'] != 0){
  274. $ul = $ul . '<li class="alarm_info">客服敏感词</li>';
  275. }
  276. if($alarm['alarm_corresponding'] != 0){
  277. $ul = $ul . '<li class="alarm_info">相应超时</li>';
  278. }
  279. if($alarm['alarm_cvtOvertime'] != 0){
  280. $ul = $ul . '<li class="alarm_info">会话超时</li>';
  281. }
  282. $ul = $ul . '</ul>';
  283. }
  284. //用户信息
  285. $account = db('accounts')->where('id',$servicelog['user_id'])->find();
  286. $this->assign([
  287. 'html' => $html,
  288. 'ul' => $ul,
  289. 'evaluate' => $evaluate,
  290. 'servicelog' => $servicelog,
  291. 'account' => $account
  292. ]);
  293. return $this->fetch();
  294. }
  295. // 生成按钮
  296. private function makeBtn($id)
  297. {
  298. $operate = '<a href="' . url('system/detail', ['id' => $id]) . '">';
  299. $operate .= '<button type="button" class="btn btn-primary btn-sm"><i class="fa fa-paste"></i> 详情</button></a> ';
  300. return $operate;
  301. }
  302. }