Browse Source

聊天系统 70%

shish 6 years ago
parent
commit
e30844fd6a

+ 11 - 5
app/business/controllers/ChatController.php

@@ -45,16 +45,19 @@ class ChatController extends BaseController
 		
 		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'];
@@ -62,23 +65,26 @@ class ChatController extends BaseController
 				$arr['url'] = $respond['url'];
 				break;
 			case 'goods':
+				//商品
 				$id = $post['id'];
-				$info = GoodsService::getGoodsInfo($id);dd($info);
+				$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;
-		
+
 		//每隔三分钟显示时间
 		$minute = (int)date("i");
 		if ($minute % 3 == 0) {
 			$time = date("i:s");
 			$data[] = ['type' => 'time', 'time' => $time];
 		}
-		
 		Gateway::sendToUid($userId, json_encode($data));
+		util::success($data);
 	}
-	
+
 }

+ 3 - 3
app/business/views/chat/index.php

@@ -16,16 +16,16 @@
     };
 
     function send() {
-        var type = 'goods';
+        var type = 'text';
         var data = {type: type, userId:<?= $userId ?>}
         switch (type) {
             case 'text':
                 //发文字
-                data.content = 'aaa';
+                data.content = '您好,有什么可以为你服务?';
                 break;
             case 'img':
                 //发图片
-                data.imgUrl = 'http://www.baidu.com/a.jpg';
+                data.shortUrl = '/uploads/201905/25/jpg/19052591518_12358.jpg';
                 break;
             case 'link':
                 data.id = 1;

+ 1 - 1
app/client/controllers/ChatController.php

@@ -29,7 +29,7 @@ class ChatController extends BaseController
 		$userId = $this->userId;
 		Gateway::bindUid($clientId, $userId);
 	}
-	
+
 	//发消息给老板 shish 2019.12.28
 	public function actionSend()
 	{