Server.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace app\admin\controller;
  3. class Server extends Base
  4. {
  5. public function index()
  6. {
  7. // 客服信息
  8. $userInfo = db('users')->where('id', cookie('l_user_id'))->find();
  9. $this->assign([
  10. 'uinfo' => $userInfo,
  11. 'word' => db('words')->select(),
  12. 'groups' => db('groups')->where('status', 1)->select(),
  13. 'status' => db('kf_config')->where('id', 1)->find()
  14. ]);
  15. return $this->fetch();
  16. }
  17. // 获取服务用户列表
  18. // 此方法是为了防止客服工作期间错误的刷新工作台,导致服务人员消失的问题
  19. public function getUserList()
  20. {
  21. if(request()->isAjax()){
  22. // 此处只查询过去 三个小时 内的未服务完的用户
  23. $userList = db('service_log')->field('user_id id,user_name name,user_avatar avatar,user_ip ip')
  24. ->where('kf_id', cookie('l_user_id'))
  25. ->where('start_time', '>', time() - 3600 * 3)->where('end_time', 0)->select();
  26. return json(['code' => 1, 'data' => $userList, 'msg' => 'ok']);
  27. }
  28. }
  29. // 获取聊天记录
  30. public function getChatLog()
  31. {
  32. if(request()->isAjax()){
  33. $param = input('param.');
  34. $limit = 10; // 一次显示10 条聊天记录
  35. $offset = ($param['page'] - 1) * $limit;
  36. $logs = db('chat_log')->where(function($query) use($param){
  37. $query->where('from_id', $param['uid'])->where('to_id', 'KF' . cookie('l_user_id'));
  38. })->whereOr(function($query) use($param){
  39. $query->where('from_id', 'KF' . cookie('l_user_id'))->where('to_id', $param['uid']);
  40. })->limit($offset, $limit)->order('id', 'desc')->select();
  41. $total = db('chat_log')->where(function($query) use($param){
  42. $query->where('from_id', $param['uid'])->where('to_id', 'KF' . cookie('l_user_id'));
  43. })->whereOr(function($query) use($param){
  44. $query->where('from_id', 'KF' . cookie('l_user_id'))->where('to_id', $param['uid']);
  45. })->count();
  46. foreach($logs as $key=>$vo){
  47. $logs[$key]['type'] = 'user';
  48. $logs[$key]['time_line'] = date('Y-m-d H:i:s', $vo['time_line']);
  49. if($vo['from_id'] == 'KF' . cookie('l_user_id')){
  50. $logs[$key]['type'] = 'mine';
  51. }
  52. }
  53. return json(['code' => 1, 'data' => $logs, 'msg' => intval($param['page']), 'total' => ceil($total / $limit)]);
  54. }
  55. }
  56. // ip 定位
  57. public function getCity()
  58. {
  59. $ip = input('param.ip');
  60. $ip2region = new \Ip2Region();
  61. $info = $ip2region->btreeSearch($ip);
  62. $city = explode('|', $info['region']);
  63. if(0 != $info['city_id']){
  64. return json(['code' => 1, 'data' => $city['2'] . $city['3'] . $city['4'], 'msg' => 'ok']);
  65. }else{
  66. return json(['code' => 1, 'data' => $city['0'], 'msg' => 'ok']);
  67. }
  68. }
  69. }