Selaa lähdekoodia

消息已读未读

shish 6 vuotta sitten
vanhempi
commit
9caf266be7

+ 9 - 1
app/business/controllers/ChatController.php

@@ -31,8 +31,16 @@ class ChatController extends BaseController
 		$clientId = isset($post['clientId']) ? $post['clientId'] : '';
 		$id = 'merchantChat_' . $this->merchantId;
 		Gateway::bindUid($clientId, $id);
+		
+		//连接就将新消息置为已读
+		$consoleId = 'merchantConsole_' . $this->merchantId;
+		$consoleOnline = Gateway::getClientIdByUid($consoleId);
+		if ($consoleOnline) {
+			$data = ['type' => 'newMessage', 'status' => 0];
+			Gateway::sendToUid($consoleId, json_encode($data));
+		}
 	}
-	
+
 	//关闭当前链接
 	public function actionClose()
 	{

+ 5 - 1
app/business/views/main/index.php

@@ -16,7 +16,11 @@
                     $.post('http://api.b.hhb.com/chat/bind-console', {clientId: clientId}, function (data) {
                     }, 'json');
                 case 'newMessage':
-                    console.log('您有新消息,请注意查收');
+                    if (data.status == 1) {
+                        console.log('您有新消息,请注意查收');
+                    } else {
+                        console.log('消息已读');
+                    }
                     break;
                 default :
             }