Ethan 6 лет назад
Родитель
Сommit
7ce26f87bc

+ 3 - 1
application/service/controller/Index.php

@@ -93,8 +93,10 @@ class Index extends Common
 
     public function index()
     {
+        $getUserInfo = $this->getUserInfo();
+
         // 客服信息
-        $userInfo = db('users')->where('id', cookie('l_user_id'))->find();
+        $userInfo = db('users')->where('id', 1)->find();
 
         $this->assign([
             'uinfo' => $userInfo,

+ 4 - 3
public/static/customer/js/whisper-cli.js

@@ -25,9 +25,9 @@ if(config != undefined && config.socket != undefined){
     socket.onopen = function(res) {
         console.log('握手成功');
         // 登录
-        var login_data = '{"type":"userInit", "uid": 1, "name" : "' + config.name +
+        var login_data = '{"type":"userInit", "uid": "' + config.uid + '", "name" : "' + config.name +
             '", "avatar" : "' + config.avatar + '", "group" : ' + config.group + '}';
-        //socket.send(login_data);
+        socket.send(login_data);
 
         // 解锁
         unlockTextarea();
@@ -219,7 +219,8 @@ function sendMsg(sendMsg){
     // 发送消息
     socket.send(JSON.stringify({
         type: 'chatMessage',
-        data: {to_id: kf_id, content: msg, from_id: config.uid}
+        data: {to_id: kf_id, to_name: kf_name, content: msg, from_name: config.name,
+            from_id: config.uid, from_avatar: config.avatar, conversationId: 1}
     }));
 
     // 储存我发出的信息

+ 1 - 1
public/static/service/js/whisper.js

@@ -291,7 +291,7 @@ function sendMessage(sendMsg) {
     socket.send(JSON.stringify({
         type: 'chatMessage',
         data: {to_id: uid, to_name: uname, content: msg, from_name: uinfo.username,
-            from_id: uinfo.id, from_avatar: uinfo.avatar}
+            from_id: uinfo.id, from_avatar: uinfo.avatar, conversationId: 1}
     }));
 
     $("#u-" + uid).append(word);

+ 26 - 26
vendor/GatewayWorker_windows/Applications/whisper/Events.php

@@ -123,10 +123,6 @@ class Events
      */
     public static function onMessage($client_id, $message)
     {
-        if ($message!='{"type":"ping"}'){
-            echo "onMessage: ".$message."\r\n";
-           // print_r([self::$global->kfList,self::$global->userList,  self::$global->uidSimpleList]);
-        }
 
         $message = json_decode($message, true);
         switch ($message['type']) {
@@ -213,7 +209,6 @@ class Events
                 break;
             // 聊天
             case 'chatMessage':
-
                 $client = Gateway::getClientIdByUid($message['data']['to_id']);
                 if(!empty($client)){
                     $chat_message = [
@@ -237,6 +232,7 @@ class Events
                         'to_id' => $message['data']['to_id'],
                         'to_name' => $message['data']['to_name'],
                         'content' => $message['data']['content'],
+                        'servicelog_id' => $message['data']['conversationId'],
                         'time_line' => time()
                     ];
 
@@ -651,26 +647,6 @@ class Events
                 $res['data']['0']
             ];
             self::$global->userToKf = $userToKf;
-            // 通知会员发送信息绑定客服的id
-            $noticeUser = [
-                'message_type' => 'connect',
-                'data' => [
-                    'kf_id' => $res['data']['0'],
-                    'kf_name' => $res['data']['1']
-                ]
-            ];
-            Gateway::sendToClient($client_id, json_encode($noticeUser));
-            unset($noticeUser);
-
-            // 通知客服端绑定会员的信息
-            $noticeKf = [
-                'message_type' => 'connect',
-                'data' => [
-                    'user_info' => $res['data']['3']
-                ]
-            ];
-            Gateway::sendToClient($res['data']['2'], json_encode($noticeKf));
-            unset($noticeKf);
 
             // 服务信息入库
             $serviceLog = [
@@ -689,9 +665,33 @@ class Events
                 'end_time' => 0
             ];
 
-            self::$db->insert('ws_service_log')->cols($serviceLog)->query();
+            $conversationId = self::$db->insert('ws_service_log')->cols($serviceLog)->query();
             unset($serviceLog);
 
+
+            // 通知会员发送信息绑定客服的id
+            $noticeUser = [
+                'message_type' => 'connect',
+                'data' => [
+                    'kf_id' => $res['data']['0'],
+                    'conversationId' => $conversationId,
+                    'kf_name' => $res['data']['1']
+                ]
+            ];
+            Gateway::sendToClient($client_id, json_encode($noticeUser));
+            unset($noticeUser);
+
+            // 通知客服端绑定会员的信息
+            $noticeKf = [
+                'message_type' => 'connect',
+                'data' => [
+                    'user_info' => $res['data']['3'],
+                    'conversationId' => $conversationId,
+                ]
+            ];
+            Gateway::sendToClient($res['data']['2'], json_encode($noticeKf));
+            unset($noticeKf);
+
             // 写入接入值
             $key = date('Ymd') . 'success_in';
             self::$global->$key = 0;