ChatController.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Http\Controllers\Admin;
  12. use App\Services\ChatMessageService;
  13. /**
  14. * 聊天管理-控制器
  15. * Class ChatController
  16. * @package App\Http\Controllers
  17. */
  18. class ChatController extends Backend
  19. {
  20. /**
  21. * 构造函数
  22. * @author laravel开发员
  23. * @since 2020/11/11
  24. * ChatController constructor.
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. $this->service = new ChatMessageService();
  30. }
  31. /**
  32. * 获取聊天消息历史
  33. * @return array
  34. */
  35. public function index()
  36. {
  37. $pageSize = request()->post('limit', 30);
  38. $params = request()->all();
  39. $list = $this->service->getDataList($params, $pageSize);
  40. $message = array(
  41. "msg" => '操作成功',
  42. "code" => 0,
  43. "data" => isset($list['list'])? $list['list']:[],
  44. "count" => isset($list['total'])? $list['total']:0,
  45. );
  46. return $message;
  47. }
  48. /**
  49. * 获取最新的聊天窗口列表
  50. * @return array
  51. */
  52. public function newlist()
  53. {
  54. $pageSize = request()->post('limit', 30);
  55. $params = request()->all();
  56. $type = isset($params['type'])? $params['type'] : 2;
  57. if($type == 2){
  58. $list = $this->service->getDataList($params, $pageSize);
  59. }else{
  60. $list = $this->service->getWaitList($params, $pageSize);
  61. }
  62. $userId = $this->userInfo['user_type']==2? $this->userInfo['user_id'] : 1;
  63. $counts = $this->service->getNewCount($userId);
  64. $message = array(
  65. "msg" => '操作成功',
  66. "code" => 0,
  67. "data" => isset($list['list'])? $list['list']:[],
  68. "counts" => $counts,
  69. );
  70. return $message;
  71. }
  72. }