shish 6 лет назад
Родитель
Сommit
73c47a483b

+ 26 - 7
app/business/controllers/ChatController.php

@@ -17,7 +17,7 @@ class ChatController extends BaseController
 		$userId = isset($get['userId']) ? $get['userId'] : 0;
 		$user = UserService::getById($userId);
 		UserService::valid($user, $this->merchantId);
-		return $this->renderPartial('index',['userId'=>$userId]);
+		return $this->renderPartial('index', ['userId' => $userId]);
 	}
 	
 	//绑定 shish 2019.12.28
@@ -33,15 +33,34 @@ 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';
 		$userId = isset($post['userId']) ? $post['userId'] : 0;
 		$user = UserService::getById($userId);
 		UserService::valid($user, $this->merchantId);
-		$m = json_encode(array(
-			'type' => 'msg',
-			'msg' => $msg,
-		));
-		Gateway::sendToUid($userId, $m);
+		$arr = [];
+		$arr['type'] = $type;
+		
+		switch ($type) {
+			case 'text':
+				break;
+			case 'img':
+				break;
+			case 'link':
+				break;
+			case 'goods':
+				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));
 	}
 	
 }

+ 29 - 9
app/business/views/chat/index.php

@@ -3,22 +3,42 @@
 <script>
     ws = new WebSocket("ws://127.0.0.1:8282");
     //服务端主动推送消息时会触发这里
-    ws.onmessage = function(e){
-        var data = eval("("+e.data+")");
+    ws.onmessage = function (e) {
+        var data = eval("(" + e.data + ")");
         var type = data.type || '';
-        switch(type){
+        switch (type) {
             case 'init':
                 //当前发起的聊天会员与当前登陆用户绑定关系
-                $.post('http://api.b.hhb.com/chat/bind', {clientId: data.client_id}, function(data){}, 'json');
-                break;
+                $.post('http://api.b.hhb.com/chat/bind', {clientId: data.client_id}, function (data) {
+                }, 'json');
             default :
-                console.log(e.data);
         }
     };
 
-    function send()
-    {
-        $.post('http://api.b.hhb.com/chat/send', {msg: '您好',userId:<?= $userId ?>}, function(data){}, 'json');
+    function send() {
+        var type = 'text';
+        var data = {type: type, userId:<?= $userId ?>}
+        switch (type) {
+            case 'text':
+                //发文字
+                data.content = 'aaa';
+                break;
+            case 'img':
+                //发图片
+                data.imgUrl = 'http://www.baidu.com/a.jpg';
+                break;
+            case 'link':
+                data.id = 1;
+                //发链接
+                break;
+            case 'goods':
+                data.id = 160;
+                //发商品
+                break;
+            default:
+        }
+        $.post('http://api.b.hhb.com/chat/send', data, function (data) {
+        }, 'json');
     }
 
 </script>

+ 3 - 3
biz/merchant/classes/MerchantClass.php

@@ -12,9 +12,9 @@ class MerchantClass extends BaseClass
 	
 	//常用链接
 	public static $commonUrl = [
-		['id' => 0, 'url' => '/mall/index?account=12358', 'sign' => 'mall', 'name' => '商城'],
-		['id' => 1, 'url' => '/mall/index?account=12358', 'sign' => 'mall', 'name' => '申请会员'],
-		['id' => 2, 'url' => '/mall/index?account=12358', 'sign' => 'mall', 'name' => '点我付款'],
+		['id' => 1, 'url' => '/mall/index?account=12358', 'sign' => 'mall', 'name' => '商城'],
+		['id' => 2, 'url' => '/mall/index?account=12358', 'sign' => 'mall', 'name' => '申请会员'],
+		['id' => 3, 'url' => '/mall/index?account=12358', 'sign' => 'mall', 'name' => '点我付款'],
 	];
 	
 	//商家信息组合 shish 2019.12.20