| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace ghs\controllers;
- use bizHd\goods\services\GoodsService;
- use biz\sj\services\MerchantService;
- use bizHd\message\services\ChatService;
- use bizHd\user\services\UserService;
- use common\components\business;
- use Yii;
- use common\components\util;
- use GatewayClient\Gateway;
- class ChatController extends BaseController
- {
-
- //聊天 ssh 2019.12.28
- public function actionIndex()
- {
- $get = Yii::$app->request->get();
- $userId = isset($get['userId']) ? $get['userId'] : 0;
- $user = UserService::getById($userId);
- UserService::valid($user, $this->sjId);
- return $this->renderPartial('index', ['userId' => $userId]);
- }
- //聊天双方的用户信息 ssh 2019.12.30
- public function actionBegin()
- {
- $id = Yii::$app->request->get('id', 0);
- $user = UserService::getUserInfo($id);
- UserService::valid($user, $this->sjId);
- //新增最近联系人
- ChatService::addRecentlyUser($this->sjId, $id);
- //获取最近联系人
- $recentlyUser = ChatService::getRecentlyUserList($this->sjId);
- util::success(['merchant' => $this->sj->attributes, 'user' => $user, 'recentlyUser' => $recentlyUser]);
- }
-
- //绑定 ssh 2019.12.28
- public function actionBindMerchant()
- {
- $post = Yii::$app->request->post();
- $clientId = isset($post['clientId']) ? $post['clientId'] : '';
- $id = 'merchantChat_' . $this->sjId;
- Gateway::bindUid($clientId, $id);
-
- //连接就将新消息置为已读
- $consoleId = 'merchantConsole_' . $this->sjId;
- $consoleOnline = Gateway::getClientIdByUid($consoleId);
- if ($consoleOnline) {
- $data = ['type' => 'newMessage', 'status' => 0];
- Gateway::sendToUid($consoleId, json_encode($data));
- }
- }
-
- //关闭当前链接
- public function actionClose()
- {
- $post = Yii::$app->request->post();
- $clientId = isset($post['clientId']) ? $post['clientId'] : '';
- Gateway::closeClient($clientId);
- }
-
- public function actionBindConsole()
- {
- $post = Yii::$app->request->post();
- $clientId = isset($post['clientId']) ? $post['clientId'] : '';
- $id = 'merchantConsole_' . $this->sjId;
- Gateway::bindUid($clientId, $id);
- }
- //最近联系人 ssh 2019.12.29
- public function actionRecentlyUser()
- {
- $respond = ChatService::getRecentlyUserList($this->sjId);
- util::success($respond);
- }
-
- //最近聊天的内容 ssh 2019.12.29
- public function actionRecentlyMessage()
- {
- //商品 图片 快捷链接 文字
- $id = Yii::$app->request->get('id');
- $info = UserService::getById($id);
- UserService::valid($info, $this->sjId);
- $respond = ChatService::getMessageList($id);
- util::success($respond);
- }
-
- }
|