System.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * User: nickbai
  4. * Date: 2017/10/31 12:47
  5. * Email: 1902822973@qq.com
  6. */
  7. namespace app\admin\controller;
  8. class System extends Base
  9. {
  10. // 自动回复设置
  11. public function reply()
  12. {
  13. if(request()->isPost()){
  14. $param = input('post.');
  15. if(empty($param['word'])){
  16. return json(['code' => -1, 'data' => '', 'msg' => '回复内容不能为空']);
  17. }
  18. try{
  19. db('reply')->where('id', 1)->update($param);
  20. }catch(\Exception $e){
  21. return json(['code' => -2, 'data' => '', 'msg' => $e->getMessage()]);
  22. }
  23. return json(['code' => 1, 'data' => '', 'msg' => '设置成功']);
  24. }
  25. $info = db('reply')->where('id', 1)->find();
  26. $this->assign([
  27. 'info' => $info,
  28. 'status' => config('kf_status')
  29. ]);
  30. return $this->fetch();
  31. }
  32. // 客服设置
  33. public function customerService()
  34. {
  35. if(request()->isPost()){
  36. $param = input('post.');
  37. db('kf_config')->where('id', 1)->update($param);
  38. return json(['code' => 1, 'data' => '', 'msg' => '设置成功']);
  39. }
  40. $this->assign([
  41. 'config' => db('kf_config')->where('id', 1)->find(),
  42. 'status' => config('kf_status')
  43. ]);
  44. return $this->fetch();
  45. }
  46. // 历史会话记录
  47. public function wordsLog()
  48. {
  49. if(request()->isAjax()){
  50. $param = input('param.');
  51. $limit = $param['pageSize'];
  52. $offset = ($param['pageNumber'] - 1) * $limit;
  53. // 默认显示最近7天
  54. $start = input('param.start');
  55. $end = input('param.end');
  56. $temp = db('chat_log');
  57. $countTmp = db('chat_log');
  58. if(!empty($param['searchText'])){
  59. $temp = $temp->where('from_name', $param['searchText'])->whereOr('to_name', $param['searchText']);
  60. $countTmp = $countTmp->where('from_name', $param['searchText'])->whereOr('to_name', $param['searchText']);
  61. }
  62. if(!empty($start) && !empty($end) && $start <= $end){
  63. $temp = $temp->whereBetween('time_line', [strtotime($start), strtotime($end . ' 23:59:59')]);
  64. $countTmp = $countTmp->whereBetween('time_line', [strtotime($start), strtotime($end . ' 23:59:59')]);
  65. }
  66. $result = $temp->limit($offset, $limit)->order('id', 'desc')->select();
  67. foreach($result as $key=>$vo){
  68. $result[$key]['time_line'] = date('Y-m-d H:i:s', $vo['time_line']);
  69. }
  70. $return['total'] = $countTmp->count(); //总数据
  71. $return['rows'] = $result;
  72. return json($return);
  73. }
  74. return $this->fetch();
  75. }
  76. }