SupplierChat.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 SupplierChat extends Controller
  10. {
  11. protected $user;
  12. protected $supplierUser;
  13. /**
  14. * 构造方法
  15. */
  16. public function initialize()
  17. {
  18. $this->user = $this->getUser();
  19. $this->supplierUser = $this->getSupplierUser($this->user);
  20. }
  21. //我的聊天列表
  22. public function index()
  23. {
  24. $Chat = new ChatModel;
  25. $list = $Chat->mySupplierList($this->supplierUser['supplier_user_id']);
  26. return $this->renderSuccess('', compact('list'));
  27. }
  28. //添加消息
  29. public function add()
  30. {
  31. $Chat = new ChatModel;
  32. if ($Chat->add($this->postData(), $this->user)) {
  33. return $this->renderSuccess('发送成功');
  34. } else {
  35. return $this->renderError($Chat->getError() ?: '发送失败');
  36. }
  37. }
  38. //获取聊天信息
  39. public function message($user_id)
  40. {
  41. $Chat = new ChatModel;
  42. $user['user_id'] = $user_id;
  43. $data = $this->postData();
  44. $data['supplier_user_id'] = $this->supplierUser['supplier_user_id'];
  45. $list = $Chat->getMessage($data, $user);
  46. return $this->renderSuccess('', compact('list'));
  47. }
  48. //获取消息条数
  49. public function messageCount()
  50. {
  51. $Chat = new ChatModel;
  52. $num = $Chat->mCount($this->user);
  53. return $this->renderSuccess('', compact('num'));
  54. }
  55. //获取聊天用户信息
  56. public function getInfo()
  57. {
  58. $Chat = new ChatModel;
  59. $data = $this->postData();
  60. $data['shop_supplier_id'] = $this->supplierUser['shop_supplier_id'];
  61. $data['supplier_user_id'] = $this->supplierUser['supplier_user_id'];
  62. $info = $Chat->getInfo($data);
  63. return $this->renderSuccess('', compact('info'));
  64. }
  65. //绑定uid
  66. public function bindClient()
  67. {
  68. $param = $this->postData();
  69. Gateway::bindUid($param['client_id'], 'supplier_' .$this->supplierUser['supplier_user_id']);
  70. $data['Online'] = Gateway::isUidOnline($param['user_id']) ? 'on' : 'off';
  71. return $this->renderSuccess('绑定成功', compact('data'));
  72. }
  73. }