System.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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. return json(['code' => 1, 'data' => '', 'msg' => '设置成功']);
  89. } catch (\Exception $e) {
  90. return json(['code' => -2, 'data' => '', 'msg' => $e->getMessage()]);
  91. }//end try
  92. }//end if
  93. // 获取设置.
  94. $systemconfig = model('Systemconfig')->selectSystemconfig();
  95. $this->assign(
  96. [
  97. 'systemconfig' => $systemconfig,
  98. 'status' => config('kf_status'),
  99. ]
  100. );
  101. return $this->fetch();
  102. }//end conversation()
  103. // 自动回复设置
  104. public function reply()
  105. {
  106. if(request()->isPost()){
  107. $param = input('post.');
  108. if(empty($param['word'])){
  109. return json(['code' => -1, 'data' => '', 'msg' => '回复内容不能为空']);
  110. }
  111. try{
  112. db('reply')->where('id', 1)->update($param);
  113. }catch(\Exception $e){
  114. return json(['code' => -2, 'data' => '', 'msg' => $e->getMessage()]);
  115. }
  116. return json(['code' => 1, 'data' => '', 'msg' => '设置成功']);
  117. }
  118. $info = db('reply')->where('id', 1)->find();
  119. $this->assign([
  120. 'info' => $info,
  121. 'status' => config('kf_status')
  122. ]);
  123. return $this->fetch();
  124. }
  125. // 历史会话记录
  126. public function wordsLog()
  127. {
  128. if(request()->isAjax()){
  129. $param = input('param.');
  130. $limit = $param['pageSize'];
  131. $offset = ($param['pageNumber'] - 1) * $limit;
  132. // 默认显示最近7天
  133. $start = input('param.start');
  134. $end = input('param.end');
  135. $user_id = input('param.user_id');
  136. $group_id = input('param.group_id');
  137. $temp = db('service_log');
  138. $countTmp = db('service_log');
  139. if(!empty($param['searchText'])){
  140. $user = db('users')->where('user_name', $param['searchText'])->find();
  141. $temp = $temp->where('kf_id', $user['id']);
  142. $countTmp = $countTmp->where('kf_id', $user['id']);
  143. }
  144. //日期
  145. if(!empty($start) && !empty($end) && $start <= $end){
  146. $temp = $temp->whereBetween('start_time', [strtotime($start), strtotime($end . ' 23:59:59')]);
  147. $countTmp = $countTmp->whereBetween('start_time', [strtotime($start), strtotime($end . ' 23:59:59')]);
  148. }
  149. //结束时间为空
  150. if(!empty($start) && empty($end)){
  151. $temp = $temp->where('start_time','>',strtotime($start));
  152. $countTmp = $temp->where('start_time','>',strtotime($start));
  153. }
  154. //开始时间为空
  155. if(empty($start) && !empty($end)){
  156. $temp = $temp->where('start_time','<',strtotime($end . ' 23:59:59'));
  157. $countTmp = $temp->where('start_time','<',strtotime($end . ' 23:59:59'));
  158. }
  159. //开始时间/结束时间都为空(默认查七天)
  160. if(empty($start) && empty($end)){
  161. $temp = $temp->where('start_time','<',time())->where('start_time','>',time()-604800);
  162. $countTmp = $temp->where('start_time','<',time())->where('start_time','>',time()-604800);
  163. }
  164. //客服
  165. if($user_id != 0){
  166. $temp = $temp->where('kf_id', $user_id);
  167. $countTmp = $countTmp->where('kf_id', $user_id);
  168. }
  169. //客服组
  170. if($group_id != 0){
  171. $temp = $temp->where('group_id', $group_id);
  172. $countTmp = $temp->where('group_id', $group_id);
  173. }
  174. $result = $temp->limit($offset, $limit)->order('start_time', 'desc')->select();
  175. //所有客服
  176. $users = db('users')->select();
  177. //满意度
  178. $evaluate = db('evaluate')->select();
  179. foreach($result as $key=>$vo){
  180. if($result[$key]['intime'] != 0){
  181. $result[$key]['intime'] = date('Y-m-d H:i:s', $vo['intime']);
  182. }else{
  183. $result[$key]['intime'] = '-';
  184. }
  185. if($result[$key]['start_time'] != 0){
  186. $result[$key]['start_time'] = date('Y-m-d H:i:s', $vo['start_time']);
  187. }else{
  188. $result[$key]['start_time'] = '-';
  189. }
  190. if($result[$key]['end_time'] != 0){
  191. $result[$key]['end_time'] = date('Y-m-d H:i:s', $vo['start_time']);
  192. }else{
  193. $result[$key]['end_time'] = '-';
  194. }
  195. //客服名称
  196. for($i=0;$i<count($users);$i++){
  197. if($result[$key]['kf_id'] == $users[$i]['id']){
  198. $result[$key]['kefu_name'] = $users[$i]['user_name'];
  199. }
  200. }
  201. //满意度
  202. for($j=0;$j<count($evaluate);$j++){
  203. if($result[$key]['evaluate_id'] == $evaluate[$j]['evaluate_id']){
  204. $result[$key]['evaluate_name'] = $evaluate[$j]['evaluate_name'];
  205. }
  206. }
  207. // 生成操作按钮
  208. if(0 != $vo['servicelog_id']){
  209. $result[$key]['operate'] = $this->makeBtn($vo['servicelog_id']);
  210. }
  211. }
  212. $return['total'] = $countTmp->count(); //总数据
  213. $return['rows'] = $result;
  214. return json($return);
  215. }
  216. //所有客服
  217. $users = db('users')->select();
  218. if(!empty($users)){
  219. $option = '<option value="0">全部客服</option>';
  220. for($i=0;$i<count($users);$i++){
  221. $option = $option.'<option value="'.$users[$i]['id'].'">'.$users[$i]['user_name'].'</option>';
  222. }
  223. $useroption = '<select name="user_id" id="user_id" class="form-control">'.$option.'</select>';
  224. }
  225. //所有客服组
  226. $groups = db('groups')->select();
  227. if(!empty($groups)){
  228. $option = '<option value="0">全部客服组</option>';
  229. for($j=0;$j<count($groups);$j++){
  230. $option = $option.'<option value="'.$groups[$j]['id'].'">'.$groups[$j]['name'].'</option>';
  231. }
  232. $groupoption = '<select name="group_id" id="group_id" class="form-control">'.$option.'</select>';
  233. }
  234. $this->assign([
  235. 'useroption' => $useroption,
  236. 'groupoption' => $groupoption
  237. ]);
  238. return $this->fetch('wordslog');
  239. }
  240. // 历史会话记录详情
  241. public function detail($id)
  242. {
  243. $chat = db('chat_log')->where('servicelog_id',$id)->order('time_line')->select();
  244. $html = '';
  245. for($i=0;$i<count($chat);$i++){
  246. $chat[$i]['time_line'] = date('H:i',$chat[$i]['time_line']);
  247. if(!empty(strstr($chat[$i]['to_id'], 'KF'))){
  248. $html = $html . '<div style="margin-top:15px;width: 30%;"><div>'.$chat[$i]['from_name'].'&nbsp&nbsp&nbsp'.$chat[$i]['time_line'].'</div>';
  249. $html = $html . '<p style="margin-top:5px;" class="form-content">'.$chat[$i]['content'].'</p></div>';
  250. }else{
  251. $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>';
  252. $html = $html . '<p style="margin-top:5px;" class="form-content">'.$chat[$i]['content'].'</p></div>';
  253. }
  254. }
  255. $servicelog = db('service_log')->where('servicelog_id',$id)->find();
  256. //满意度
  257. $evaluate = db('evaluate')->where('evaluate_id',$servicelog['evaluate_id'])->find();
  258. $evaluate = $evaluate['evaluate_name'];
  259. //$alarm报警信息
  260. $alarm = db('alarm')->where('servicelog_id',$id)->find();
  261. $ul = '';
  262. if(!empty($alarm)){
  263. $ul = $ul . '<ul class="alarm"><li>触犯警报</li>';
  264. if($alarm['alarm_userSensitive'] != 0){
  265. $ul = $ul . '<li class="alarm_info">访客敏感词</li>';
  266. }
  267. if($alarm['alarm_serverSensitive'] != 0){
  268. $ul = $ul . '<li class="alarm_info">客服敏感词</li>';
  269. }
  270. if($alarm['alarm_corresponding'] != 0){
  271. $ul = $ul . '<li class="alarm_info">相应超时</li>';
  272. }
  273. if($alarm['alarm_cvtOvertime'] != 0){
  274. $ul = $ul . '<li class="alarm_info">会话超时</li>';
  275. }
  276. $ul = $ul . '</ul>';
  277. }
  278. //用户信息
  279. $account = db('accounts')->where('id',$servicelog['user_id'])->find();
  280. $this->assign([
  281. 'html' => $html,
  282. 'ul' => $ul,
  283. 'evaluate' => $evaluate,
  284. 'servicelog' => $servicelog,
  285. 'account' => $account
  286. ]);
  287. return $this->fetch();
  288. }
  289. // 生成按钮
  290. private function makeBtn($id)
  291. {
  292. $operate = '<a href="' . url('system/detail', ['id' => $id]) . '">';
  293. $operate .= '<button type="button" class="btn btn-primary btn-sm"><i class="fa fa-paste"></i> 详情</button></a> ';
  294. return $operate;
  295. }
  296. }