| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace business\controllers;
- use biz\goods\services\GoodsService;
- use biz\merchant\services\MerchantService;
- use biz\user\services\UserService;
- use common\components\business;
- use Yii;
- use common\components\util;
- use GatewayClient\Gateway;
- class ChatController extends BaseController
- {
-
- //聊天 shish 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->merchantId);
- return $this->renderPartial('index', ['userId' => $userId]);
- }
-
- //绑定 shish 2019.12.28
- public function actionBind()
- {
- $post = Yii::$app->request->post();
- $clientId = isset($post['clientId']) ? $post['clientId'] : '';
- $id = 'merchant_' . $this->merchantId;
- Gateway::bindUid($clientId, $id);
- }
-
- //发消息给客户 shish 2019.12.28
- public function actionSend()
- {
- $post = Yii::$app->request->post();
- $type = isset($post['type']) ? $post['type'] : 'text';
- $userId = isset($post['userId']) ? $post['userId'] : 0;
- $user = UserService::getById($userId);
- UserService::valid($user, $this->merchantId);
- $arr = [];
- $arr['type'] = $type;
-
- 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['id'];
- $respond = MerchantService::getCommonUrl($id);
- $arr['name'] = $respond['name'];
- $arr['img'] = $respond['img'];
- $arr['url'] = $respond['url'];
- break;
- case 'goods':
- $id = $post['id'];
- $info = GoodsService::getGoodsInfo($id);dd($info);
- GoodsService::valid($info, $this->merchantId);
- $arr['goodsName'] = $info['goodsName'];
- break;
- }
-
- $data[] = $arr;
-
- //每隔三分钟显示时间
- $minute = (int)date("i");
- if ($minute % 3 == 0) {
- $time = date("i:s");
- $data[] = ['type' => 'time', 'time' => $time];
- }
-
- Gateway::sendToUid($userId, json_encode($data));
- }
-
- }
|