Chat.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\api\controller\plus\chat;
  3. use app\api\model\plus\chat\Chat as ChatModel;
  4. use app\api\controller\Controller;
  5. use \GatewayWorker\Lib\Gateway;
  6. /**
  7. * 客服消息
  8. */
  9. class Chat extends Controller
  10. {
  11. protected $user;
  12. /**
  13. * 构造方法
  14. */
  15. public function initialize()
  16. {
  17. $this->user = $this->getUser();
  18. }
  19. //我的聊天列表
  20. public function index()
  21. {
  22. $Chat = new ChatModel;
  23. $list = $Chat->myList($this->user);
  24. return $this->renderSuccess('', compact('list'));
  25. }
  26. //添加消息
  27. public function add()
  28. {
  29. $Chat = new ChatModel;
  30. if ($Chat->add($this->postData(), $this->user)) {
  31. return $this->renderSuccess('发送成功');
  32. } else {
  33. return $this->renderError($Chat->getError() ?: '发送失败');
  34. }
  35. }
  36. //获取聊天信息
  37. public function message()
  38. {
  39. $Chat = new ChatModel;
  40. $list = $Chat->getMessage($this->postData(), $this->user);
  41. return $this->renderSuccess('', compact('list'));
  42. }
  43. //获取聊天用户信息
  44. public function getInfo()
  45. {
  46. $Chat = new ChatModel;
  47. $info = $Chat->getInfo($this->postData());
  48. return $this->renderSuccess('', compact('info'));
  49. }
  50. //绑定uid
  51. public function bindClient()
  52. {
  53. $param = $this->postData();
  54. Gateway::bindUid($param['client_id'], $this->user['user_id']);
  55. $data['Online'] = Gateway::isUidOnline('supplier_' . $param['supplier_user_id']) ? 'on' : 'off';
  56. return $this->renderSuccess('绑定成功', compact('data'));
  57. }
  58. }