| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- namespace client\controllers;
- use biz\MQ\services\ChatService;
- use common\components\util;
- use Yii;
- use GatewayClient\Gateway;
- class ChatController extends BaseController
- {
-
- public function beforeAction($action)
- {
- return parent::beforeAction($action);
- }
-
- //聊天首页,前端使用
- public function actionIndex()
- {
- return $this->renderPartial('index');
- }
-
- //绑定 shish 2019.12.28
- public function actionBind()
- {
- $post = Yii::$app->request->post();
- $clientId = isset($post['clientId']) ? $post['clientId'] : '';
- $userId = $this->userId;
- Gateway::bindUid($clientId, $userId);
- }
-
- //发消息给老板 shish 2019.12.28
- public function actionSend()
- {
- $post = Yii::$app->request->post();
- $msg = isset($post['msg']) ? $post['msg'] : '';
- $id = 'merchantChat_' . $this->merchantId;
- $data = json_encode(array(
- 'type' => 'msg',
- 'msg' => $msg,
- ));
- $merchantId = $this->merchantId;
- $userId = $this->userId;
- $userId = rand(111, 99999);
- ChatService::addUnReplyUser($merchantId,$userId);
- $r = ChatService::getUnReplyUserList($merchantId);
- dd($r);
- die;
- $chatOnline = Gateway::getClientIdByUid($id);
- if ($chatOnline) {
- //直接发送
- Gateway::sendToUid($id, json_encode($data));
- util::success($data);
- }
- $consoleId = 'merchantConsole_' . $this->merchantId;
- $consoleOnline = Gateway::getClientIdByUid($consoleId);
- if ($consoleOnline) {
- //通知打开的控制台有新消息
- $data = json_encode(array(
- 'type' => 'msg',
- 'msg' => $msg,
- ));
- Gateway::sendToUid($consoleId, json_encode($data));
- }
-
- }
-
- }
|