更新redis->mongo
This commit is contained in:
parent
653870a991
commit
20eed6c531
90
io/io.js
90
io/io.js
@ -53,7 +53,24 @@ function ioServer(io) {
|
|||||||
//获取管理员 socket
|
//获取管理员 socket
|
||||||
let kefuData =await sessoionModel.find(gongHao);
|
let kefuData =await sessoionModel.find(gongHao);
|
||||||
if(kefuData){ // 找到客服数据
|
if(kefuData){ // 找到客服数据
|
||||||
|
let location = Common.getIpLocation(msg.ip);
|
||||||
|
let socket = socket.id;
|
||||||
|
let type = 'customer';
|
||||||
|
let kefu_id = gongHao;
|
||||||
|
|
||||||
|
let clientInfo = {
|
||||||
|
"uid": uid,
|
||||||
|
"name": location + ' 客户',
|
||||||
|
"type": 'online'
|
||||||
|
};
|
||||||
|
// 添加客户到 对应的客服
|
||||||
|
sessoionModel.create({
|
||||||
|
uid,
|
||||||
|
socket:socket.id,
|
||||||
|
type:'customer',
|
||||||
|
kefu_id:gongHao,
|
||||||
|
nickname:clientInfo.name,
|
||||||
|
})
|
||||||
// 给管理员发送通知
|
// 给管理员发送通知
|
||||||
io.to(kefuData.socket).emit('update-users', info);
|
io.to(kefuData.socket).emit('update-users', info);
|
||||||
}
|
}
|
||||||
@ -61,74 +78,15 @@ function ioServer(io) {
|
|||||||
//TODO 失败重发机制
|
//TODO 失败重发机制
|
||||||
console.log('给管理员发送通知失败');
|
console.log('给管理员发送通知失败');
|
||||||
}
|
}
|
||||||
// 给管理员发送通知
|
|
||||||
redis.get(AppConfig.KF_PREFIX + gongHao, function (err, sid) {
|
|
||||||
if (err) {
|
|
||||||
console.error(err);
|
|
||||||
}
|
|
||||||
console.log('sid=>', sid)
|
|
||||||
if (sid) {
|
|
||||||
redis.get('online_count', function (err, val) {
|
|
||||||
if (err) {
|
|
||||||
console.error(err);
|
|
||||||
}
|
|
||||||
if (!val) {
|
|
||||||
val = 0;
|
|
||||||
}
|
|
||||||
if (typeof val == 'string') {
|
|
||||||
val = parseInt(val);
|
|
||||||
}
|
|
||||||
|
|
||||||
//var ip = socket.request.connection.remoteAddress;
|
|
||||||
//此处获取IP可能会有延迟,建议改成自己的IP库
|
|
||||||
Common.getIpLocation(msg.ip, function (err, location) {
|
|
||||||
if (err) {
|
|
||||||
location = '';
|
|
||||||
}
|
|
||||||
var info = {
|
|
||||||
"uid": uid,
|
|
||||||
"name": location + ' 客户',
|
|
||||||
"type": 'online'
|
|
||||||
};
|
|
||||||
//将用户添加到
|
|
||||||
console.log(info);
|
|
||||||
redis.get('user-uuids', function (err, uuids) {
|
|
||||||
if (err) {
|
|
||||||
console.error(err);
|
|
||||||
}
|
|
||||||
if (uuids) {
|
|
||||||
uuids = JSON.parse(uuids);
|
|
||||||
} else {
|
|
||||||
uuids = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (__uuids.indexOf(uid) == -1) {
|
|
||||||
__uuids.push(uid);
|
|
||||||
var d_user = {"uid": uid, "name": location + ' 客户'};
|
|
||||||
uuids.push(d_user);
|
|
||||||
uuids = JSON.stringify(uuids);
|
|
||||||
redis.set('user-uuids', uuids, null, function (err, ret) {
|
|
||||||
if (err) {
|
|
||||||
console.error(err);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
//让客服更新用户
|
|
||||||
io.to(sid).emit('update-users', info);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//将用户id和socket进行保定
|
//将用户id和socket进行保定
|
||||||
redis.set(uid, socket.id, 3600 * 3, function (err, ret) {
|
// redis.set(uid, socket.id, 3600 * 3, function (err, ret) {
|
||||||
if (err) {
|
// if (err) {
|
||||||
console.error(err);
|
// console.error(err);
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
|
||||||
// redis.set(socket.id,uid,null,function (err,ret) {
|
// redis.set(socket.id,uid,null,function (err,ret) {
|
||||||
// if(err){
|
// if(err){
|
||||||
@ -142,7 +100,7 @@ function ioServer(io) {
|
|||||||
socket.on('disconnect', function () {
|
socket.on('disconnect', function () {
|
||||||
console.log("与服务其断开");
|
console.log("与服务其断开");
|
||||||
|
|
||||||
_self.updateOnlieCount(false);
|
_self.updateOnlineCount(false);
|
||||||
|
|
||||||
redis.get(socket.id, function (err, val) {
|
redis.get(socket.id, function (err, val) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -250,7 +208,7 @@ function ioServer(io) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
this.updateOnlieCount = function (isConnect) {
|
this.updateOnlineCount = function (isConnect) {
|
||||||
//记录在线客户连接数
|
//记录在线客户连接数
|
||||||
redis.get('online_count', function (err, val) {
|
redis.get('online_count', function (err, val) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -12,7 +12,7 @@ var SessionSchema = new Schema({
|
|||||||
// 客服编号
|
// 客服编号
|
||||||
kefu_id: {type: String},
|
kefu_id: {type: String},
|
||||||
nickname: {type: String},
|
nickname: {type: String},
|
||||||
status: {type: Number},
|
status: {type: Number,default:1},
|
||||||
create_at: {type: Date, default: Date.now}
|
create_at: {type: Date, default: Date.now}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ layui.use(['layer', 'form', 'jquery'], function () {
|
|||||||
msg_notification(msg);
|
msg_notification(msg);
|
||||||
});
|
});
|
||||||
|
|
||||||
//后端推送来消息时
|
//后端推送来消息时,更新用户
|
||||||
socket.on('update-users', function (msg) {
|
socket.on('update-users', function (msg) {
|
||||||
if (msg.type == 'offline') {
|
if (msg.type == 'offline') {
|
||||||
//arrayRemove(uuids,msg.uid);
|
//arrayRemove(uuids,msg.uid);
|
||||||
|
@ -10,21 +10,13 @@ function getClientIp(req) {
|
|||||||
req.connection.socket.remoteAddress;
|
req.connection.socket.remoteAddress;
|
||||||
};
|
};
|
||||||
|
|
||||||
function getIpLocation(ip, callback) {
|
function getIpLocation(ip) {
|
||||||
return setTimeout(() => {
|
let data = qqwry.searchIP(ip)
|
||||||
try {
|
if (!data) {
|
||||||
let data = qqwry.searchIP(ip)
|
return ip;
|
||||||
if (!data) {
|
}
|
||||||
callback(new Error('get ip exception'), ip);
|
let area = data.Area.trim().toLowerCase().replace('cz88.net', '');
|
||||||
} else {
|
return data.Country + ' ' + area;
|
||||||
let area = data.Area.trim().toLowerCase().replace('cz88.net', '');
|
|
||||||
callback(false, data.Country + ' ' + area);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
callback(e, ip);
|
|
||||||
|
|
||||||
}
|
|
||||||
}, 10);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.getClientIp = getClientIp;
|
exports.getClientIp = getClientIp;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
var mongoose = require("mongoose");
|
var mongoose = require("mongoose");
|
||||||
const DB_URL = 'mongodb://192.168.10.80:27017/kefu';
|
const DB_URL = 'mongodb://192.168.10.123:27017/kefu';
|
||||||
mongoose.connect(DB_URL);
|
mongoose.connect(DB_URL);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
<title>Document</title>
|
<title>Document</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Error</h1>
|
<h1><%= message %></h1>
|
||||||
|
<h2><%= error.status %></h2>
|
||||||
|
<pre><%= error.stack %></pre>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -22,11 +22,14 @@
|
|||||||
<div class="message-sender">
|
<div class="message-sender">
|
||||||
<div class="message-emoji-picture" id="btn-uploader">
|
<div class="message-emoji-picture" id="btn-uploader">
|
||||||
<i id="emojiBtn" class="layui-icon" style="font-size: 25px; color: #969faa;"></i>
|
<i id="emojiBtn" class="layui-icon" style="font-size: 25px; color: #969faa;"></i>
|
||||||
<i id="pickfiles" class="layui-icon picture-upload" style="font-size: 25px; color: #969faa;margin-left: 10px;"></i>
|
<i id="pickfiles" class="layui-icon picture-upload"
|
||||||
|
style="font-size: 25px; color: #969faa;margin-left: 10px;"></i>
|
||||||
</div>
|
</div>
|
||||||
<div class="sender-editor">
|
<div class="sender-editor">
|
||||||
<textarea placeholder="请输入消息内容,Enter快捷发送,Ctrl+Enter换行" id="msg-send-textarea" disabled></textarea>
|
<textarea placeholder="请输入消息内容,Enter快捷发送,Ctrl+Enter换行" id="msg-send-textarea" disabled></textarea>
|
||||||
<div class="layui-btn layui-btn-normal btnMsgSend layui-btn-disabled" title="Enter快捷发送,Ctrl+Enter换行">发送</div>
|
<div class="layui-btn layui-btn-normal btnMsgSend layui-btn-disabled" title="Enter快捷发送,Ctrl+Enter换行">
|
||||||
|
发送
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="emoji-list">
|
<div class="emoji-list">
|
||||||
@ -43,6 +46,80 @@
|
|||||||
<li title="表情8">😊</li>
|
<li title="表情8">😊</li>
|
||||||
<li title="表情9">😋</li>
|
<li title="表情9">😋</li>
|
||||||
<li title="表情10">😌</li>
|
<li title="表情10">😌</li>
|
||||||
|
<li>😍</li>
|
||||||
|
<li>😎</li>
|
||||||
|
<li>😏</li>
|
||||||
|
<li>
|
||||||
|
😐
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
😑
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
😒
|
||||||
|
</li>
|
||||||
|
<li>😓
|
||||||
|
</li>
|
||||||
|
<li>😔
|
||||||
|
</li>
|
||||||
|
<li>😕
|
||||||
|
</li>
|
||||||
|
<li>😖
|
||||||
|
</li>
|
||||||
|
<li>😗</li>
|
||||||
|
<li>
|
||||||
|
😘
|
||||||
|
</li>
|
||||||
|
<li>😙</li>
|
||||||
|
<li>
|
||||||
|
😚
|
||||||
|
</li>
|
||||||
|
<li>😛
|
||||||
|
</li>
|
||||||
|
<li>😜
|
||||||
|
</li>
|
||||||
|
<li>😝
|
||||||
|
</li>
|
||||||
|
<li>😞
|
||||||
|
</li>
|
||||||
|
<li>😟
|
||||||
|
</li>
|
||||||
|
<li>😠
|
||||||
|
</li>
|
||||||
|
<li>😡
|
||||||
|
</li>
|
||||||
|
<li>😢
|
||||||
|
</li>
|
||||||
|
<li>😣
|
||||||
|
</li>
|
||||||
|
<li>😤
|
||||||
|
</li>
|
||||||
|
<li>😥
|
||||||
|
</li>
|
||||||
|
<li>😦
|
||||||
|
</li>
|
||||||
|
<li>😧
|
||||||
|
</li>
|
||||||
|
<li>😨
|
||||||
|
</li>
|
||||||
|
<li>😩
|
||||||
|
</li>
|
||||||
|
<li>😪
|
||||||
|
</li>
|
||||||
|
<li>😫
|
||||||
|
</li>
|
||||||
|
<li>😬
|
||||||
|
</li>
|
||||||
|
<li>😭
|
||||||
|
</li>
|
||||||
|
<li>😮
|
||||||
|
</li>
|
||||||
|
<li>😯</li>
|
||||||
|
<li>😰</li>
|
||||||
|
<li>😱</li>
|
||||||
|
<li>😲</li>
|
||||||
|
<li>😳</li>
|
||||||
|
<li>😴</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -50,6 +127,6 @@
|
|||||||
<script src="/layui/layui.js"></script>
|
<script src="/layui/layui.js"></script>
|
||||||
<script src="/socket.io/socket.io.js"></script>
|
<script src="/socket.io/socket.io.js"></script>
|
||||||
<script type='text/javascript' src='js/common.js' charset='utf-8'></script>
|
<script type='text/javascript' src='js/common.js' charset='utf-8'></script>
|
||||||
<script src="/js/server/index.js"> </script>
|
<script src="/js/server/index.js"></script>
|
||||||
|
|
||||||
<% include footer.ejs %>
|
<% include footer.ejs %>
|
Loading…
x
Reference in New Issue
Block a user