|
|
@@ -2,7 +2,10 @@
|
|
|
|
|
|
namespace client\controllers;
|
|
|
|
|
|
+use biz\goods\services\GoodsService;
|
|
|
+use biz\merchant\services\MerchantService;
|
|
|
use biz\MQ\services\ChatService;
|
|
|
+use common\components\business;
|
|
|
use common\components\util;
|
|
|
use Yii;
|
|
|
use GatewayClient\Gateway;
|
|
|
@@ -22,7 +25,7 @@ class ChatController extends BaseController
|
|
|
}
|
|
|
|
|
|
//绑定 shish 2019.12.28
|
|
|
- public function actionBind()
|
|
|
+ public function actionBindUser()
|
|
|
{
|
|
|
$post = Yii::$app->request->post();
|
|
|
$clientId = isset($post['clientId']) ? $post['clientId'] : '';
|
|
|
@@ -34,36 +37,69 @@ class ChatController extends BaseController
|
|
|
public function actionSend()
|
|
|
{
|
|
|
$post = Yii::$app->request->post();
|
|
|
- $msg = isset($post['msg']) ? $post['msg'] : '';
|
|
|
+ $type = isset($post['type']) ? $post['type'] : 'text';
|
|
|
+ $arr = [];
|
|
|
+ $arr['type'] = $type;
|
|
|
+ $arr['source'] = 'user';
|
|
|
+ $arr['time'] = '12:51';
|
|
|
+ switch ($type) {
|
|
|
+ case 'text':
|
|
|
+ //文字
|
|
|
+ $content = $post['content'];
|
|
|
+ $arr['content'] = $content;
|
|
|
+ break;
|
|
|
+ case 'img':
|
|
|
+ //图片
|
|
|
+ $shortUrl = $post['shortUrl'];
|
|
|
+ $return = business::formatUploadImg($shortUrl);
|
|
|
+ $arr['url'] = $return['url'];
|
|
|
+ $arr['smallUrl'] = $return['smallUrl'];
|
|
|
+ break;
|
|
|
+ case 'link':
|
|
|
+ //常用链接
|
|
|
+ $id = $post['linkId'];
|
|
|
+ $respond = MerchantService::getCommonUrl($id);
|
|
|
+ $arr['name'] = $respond['name'];
|
|
|
+ $arr['img'] = $respond['img'];
|
|
|
+ $arr['url'] = $respond['url'];
|
|
|
+ break;
|
|
|
+ case 'goods':
|
|
|
+ //商品
|
|
|
+ $id = $post['goodsId'];
|
|
|
+ $info = GoodsService::getGoodsInfo($id);
|
|
|
+ GoodsService::valid($info, $this->merchantId);
|
|
|
+ $arr['goodsName'] = $info['goodsName'];
|
|
|
+ $arr['img'] = isset($info['smallImgList'][0]) ? $info['smallImgList'][0] : '';
|
|
|
+ $arr['price'] = isset($info['price']) ? $info['price'] : 300;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ $data[] = $arr;
|
|
|
+
|
|
|
$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,
|
|
|
- ));
|
|
|
+ $data = ['type' => 'newMessage', 'status' => 1];
|
|
|
Gateway::sendToUid($consoleId, json_encode($data));
|
|
|
}
|
|
|
-
|
|
|
+ util::success($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ //关闭当前链接
|
|
|
+ public function actionClose()
|
|
|
+ {
|
|
|
+ $post = Yii::$app->request->post();
|
|
|
+ $clientId = isset($post['clientId']) ? $post['clientId'] : '';
|
|
|
+ Gateway::closeClient($clientId);
|
|
|
}
|
|
|
|
|
|
}
|