System.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. public function reply()
  59. {
  60. if(request()->isPost()){
  61. $param = input('post.');
  62. if(empty($param['word'])){
  63. return json(['code' => -1, 'data' => '', 'msg' => '回复内容不能为空']);
  64. }
  65. try{
  66. db('reply')->where('id', 1)->update($param);
  67. }catch(\Exception $e){
  68. return json(['code' => -2, 'data' => '', 'msg' => $e->getMessage()]);
  69. }
  70. return json(['code' => 1, 'data' => '', 'msg' => '设置成功']);
  71. }
  72. $info = db('reply')->where('id', 1)->find();
  73. $this->assign([
  74. 'info' => $info,
  75. 'status' => config('kf_status')
  76. ]);
  77. return $this->fetch();
  78. }
  79. // 客服设置
  80. public function customerService()
  81. {
  82. if(request()->isPost()){
  83. $param = input('post.');
  84. db('kf_config')->where('id', 1)->update($param);
  85. return json(['code' => 1, 'data' => '', 'msg' => '设置成功']);
  86. }
  87. $this->assign([
  88. 'config' => db('kf_config')->where('id', 1)->find(),
  89. 'status' => config('kf_status')
  90. ]);
  91. return $this->fetch();
  92. }
  93. // 历史会话记录
  94. public function wordsLog()
  95. {
  96. if(request()->isAjax()){
  97. $param = input('param.');
  98. $limit = $param['pageSize'];
  99. $offset = ($param['pageNumber'] - 1) * $limit;
  100. // 默认显示最近7天
  101. $start = input('param.start');
  102. $end = input('param.end');
  103. $user_id = input('param.user_id');
  104. $group_id = input('param.group_id');
  105. $temp = db('service_log');
  106. $countTmp = db('service_log');
  107. if(!empty($param['searchText'])){
  108. $user = db('users')->where('user_name', $param['searchText'])->find();
  109. $temp = $temp->where('kf_id', $user['id']);
  110. $countTmp = $countTmp->where('kf_id', $user['id']);
  111. }
  112. //日期
  113. if(!empty($start) && !empty($end) && $start <= $end){
  114. $temp = $temp->whereBetween('start_time', [strtotime($start), strtotime($end . ' 23:59:59')]);
  115. $countTmp = $countTmp->whereBetween('start_time', [strtotime($start), strtotime($end . ' 23:59:59')]);
  116. }
  117. //结束时间为空
  118. if(!empty($start) && empty($end)){
  119. $temp = $temp->where('start_time','>',strtotime($start));
  120. $countTmp = $temp->where('start_time','>',strtotime($start));
  121. }
  122. //开始时间为空
  123. if(empty($start) && !empty($end)){
  124. $temp = $temp->where('start_time','<',strtotime($end . ' 23:59:59'));
  125. $countTmp = $temp->where('start_time','<',strtotime($end . ' 23:59:59'));
  126. }
  127. //开始时间/结束时间都为空(默认查七天)
  128. if(empty($start) && empty($end)){
  129. $temp = $temp->where('start_time','<',time())->where('start_time','>',time()-604800);
  130. $countTmp = $temp->where('start_time','<',time())->where('start_time','>',time()-604800);
  131. }
  132. //客服
  133. if($user_id != 0){
  134. $temp = $temp->where('kf_id', $user_id);
  135. $countTmp = $countTmp->where('kf_id', $user_id);
  136. }
  137. //客服组
  138. if($group_id != 0){
  139. $temp = $temp->where('group_id', $group_id);
  140. $countTmp = $temp->where('group_id', $group_id);
  141. }
  142. $result = $temp->limit($offset, $limit)->order('start_time', 'desc')->select();
  143. //所有客服
  144. $users = db('users')->select();
  145. //满意度
  146. $evaluate = db('evaluate')->select();
  147. foreach($result as $key=>$vo){
  148. if($result[$key]['intime'] != 0){
  149. $result[$key]['intime'] = date('Y-m-d H:i:s', $vo['intime']);
  150. }else{
  151. $result[$key]['intime'] = '-';
  152. }
  153. if($result[$key]['start_time'] != 0){
  154. $result[$key]['start_time'] = date('Y-m-d H:i:s', $vo['start_time']);
  155. }else{
  156. $result[$key]['start_time'] = '-';
  157. }
  158. if($result[$key]['end_time'] != 0){
  159. $result[$key]['end_time'] = date('Y-m-d H:i:s', $vo['start_time']);
  160. }else{
  161. $result[$key]['end_time'] = '-';
  162. }
  163. //客服名称
  164. for($i=0;$i<count($users);$i++){
  165. if($result[$key]['kf_id'] == $users[$i]['id']){
  166. $result[$key]['kefu_name'] = $users[$i]['user_name'];
  167. }
  168. }
  169. //满意度
  170. for($j=0;$j<count($evaluate);$j++){
  171. if($result[$key]['evaluate_id'] == $evaluate[$j]['evaluate_id']){
  172. $result[$key]['evaluate_name'] = $evaluate[$j]['evaluate_name'];
  173. }
  174. }
  175. // 生成操作按钮
  176. if(0 != $vo['servicelog_id']){
  177. $result[$key]['operate'] = $this->makeBtn($vo['servicelog_id']);
  178. }
  179. }
  180. $return['total'] = $countTmp->count(); //总数据
  181. $return['rows'] = $result;
  182. return json($return);
  183. }
  184. //所有客服
  185. $users = db('users')->select();
  186. if(!empty($users)){
  187. $option = '<option value="0">全部客服</option>';
  188. for($i=0;$i<count($users);$i++){
  189. $option = $option.'<option value="'.$users[$i]['id'].'">'.$users[$i]['user_name'].'</option>';
  190. }
  191. $useroption = '<select name="user_id" id="user_id" class="form-control">'.$option.'</select>';
  192. }
  193. //所有客服组
  194. $groups = db('groups')->select();
  195. if(!empty($groups)){
  196. $option = '<option value="0">全部客服组</option>';
  197. for($j=0;$j<count($groups);$j++){
  198. $option = $option.'<option value="'.$groups[$j]['id'].'">'.$groups[$j]['name'].'</option>';
  199. }
  200. $groupoption = '<select name="group_id" id="group_id" class="form-control">'.$option.'</select>';
  201. }
  202. $this->assign([
  203. 'useroption' => $useroption,
  204. 'groupoption' => $groupoption
  205. ]);
  206. return $this->fetch();
  207. }
  208. // 历史会话记录详情
  209. public function detail($id)
  210. {
  211. $chat = db('chat_log')->where('servicelog_id',$id)->order('time_line')->select();
  212. $html = '';
  213. for($i=0;$i<count($chat);$i++){
  214. $chat[$i]['time_line'] = date('H:i',$chat[$i]['time_line']);
  215. if(!empty(strstr($chat[$i]['to_id'], 'KF'))){
  216. $html = $html . '<div style="margin-top:15px;width: 30%;"><div>'.$chat[$i]['from_name'].'&nbsp&nbsp&nbsp'.$chat[$i]['time_line'].'</div>';
  217. $html = $html . '<p style="margin-top:5px;" class="form-content">'.$chat[$i]['content'].'</p></div>';
  218. }else{
  219. $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>';
  220. $html = $html . '<p style="margin-top:5px;" class="form-content">'.$chat[$i]['content'].'</p></div>';
  221. }
  222. }
  223. $servicelog = db('service_log')->where('servicelog_id',$id)->find();
  224. //满意度
  225. $evaluate = db('evaluate')->where('evaluate_id',$servicelog['evaluate_id'])->find();
  226. $evaluate = $evaluate['evaluate_name'];
  227. //用户信息
  228. $account = db('accounts')->where('id',$servicelog['user_id'])->find();
  229. $this->assign([
  230. 'html' => $html,
  231. 'evaluate' => $evaluate,
  232. 'servicelog' => $servicelog,
  233. 'account' => $account
  234. ]);
  235. return $this->fetch();
  236. }
  237. // 生成按钮
  238. private function makeBtn($id)
  239. {
  240. $operate = '<a href="' . url('system/detail', ['id' => $id]) . '">';
  241. $operate .= '<button type="button" class="btn btn-primary btn-sm"><i class="fa fa-paste"></i> 详情</button></a> ';
  242. return $operate;
  243. }
  244. }