|
@ -218,25 +218,41 @@ class WechatClient extends RedisModel {
|
|
|
async.waterfall([
|
|
|
// 获取微信openid
|
|
|
function (callback) {
|
|
|
PatientRepo.findWechatOpenId(targetUserId, function (err, result) {
|
|
|
PatientRepo.findWechatOpenIds(targetUserId, function (err, res) {
|
|
|
if (err) {
|
|
|
ModelUtil.logError("Get wechat openid failed", err);
|
|
|
return;
|
|
|
}
|
|
|
var map = new Map();
|
|
|
res.forEach(function (participant) {
|
|
|
let openid = participant.openid;
|
|
|
if (targetUserId==participant.code) {
|
|
|
if (!openid) {
|
|
|
ModelUtil.logError("User haven't bound with wechat, user id: " + targetUserId);
|
|
|
}else {
|
|
|
map.set("openid",participant);
|
|
|
}
|
|
|
}else {
|
|
|
if(!map.has(openid)){
|
|
|
map.set(openid,participant);
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
|
|
|
let openid = result && result.length > 0 ? result[0].openid : null;
|
|
|
if (!openid) {
|
|
|
ModelUtil.logError("User haven't bound with wechat, user id: " + targetUserId);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
log.warn("Send via wechat message template, user id: " + targetUserId + ", openid: " + openid);
|
|
|
//
|
|
|
// let openid = result && result.length > 0 ? result[0].openid : null;
|
|
|
// if (!openid) {
|
|
|
// ModelUtil.logError("User haven't bound with wechat, user id: " + targetUserId);
|
|
|
// return;
|
|
|
// }
|
|
|
//
|
|
|
// log.warn("Send via wechat message template, user id: " + targetUserId + ", openid: " + openid);
|
|
|
|
|
|
callback(null, openid);
|
|
|
callback(null, map);
|
|
|
});
|
|
|
},
|
|
|
// 获取议题信息
|
|
|
function (openid, callback) {
|
|
|
function (map, callback) {
|
|
|
TopicRepo.findLastTopicStatus(message.session_id, function (err, res) {
|
|
|
if (err) {
|
|
|
ModelUtil.logError("Get topic failed", err);
|
|
@ -247,12 +263,11 @@ class WechatClient extends RedisModel {
|
|
|
ModelUtil.logError("Unable to find session last topic");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
callback(null, openid, message.sender_name, res[0]);
|
|
|
callback(null, map, message.sender_name, res[0]);
|
|
|
});
|
|
|
},
|
|
|
// 发送消息
|
|
|
function (openid, senderName, topic, callback) {
|
|
|
function (map, senderName, topic,callback) {
|
|
|
let replyContent = message.content;
|
|
|
switch (Number.parseInt(message.content_type)) {
|
|
|
case CONTENT_TYPES.Image:
|
|
@ -265,29 +280,102 @@ class WechatClient extends RedisModel {
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
let first = "您的健康咨询有新的回复";
|
|
|
if(message.receiver&&message.receiver != targetUserId){
|
|
|
first = "您的家人("+message.receiverName+")的健康咨询有新的回复";
|
|
|
}else {
|
|
|
message.receiver = targetUserId;
|
|
|
}
|
|
|
var patient = map.get("openid");
|
|
|
map.delete("openid");
|
|
|
let mainOpenId = patient.openid;
|
|
|
let agent = topic.agent;
|
|
|
if(agent){//代理人发起的议题
|
|
|
var agentOpenid = "";
|
|
|
if(map.size>0){
|
|
|
for(var key of map.keys()){
|
|
|
var member = map.get(key);
|
|
|
if(agent == member.code){
|
|
|
agentOpenid = key;
|
|
|
var openid = key;
|
|
|
var first = "您的家人("+patient.name+")的健康咨询有新的回复";
|
|
|
// 发送模板消息
|
|
|
WechatSDK.sendTemplateMessage({
|
|
|
touser: openid,
|
|
|
template_id: config.wechatConfig.template.consultTemplate,
|
|
|
url: config.wechatConfig.baseUrl + "/wx/html/yszx/html/consulting-doctor.html?openid=" + openid +
|
|
|
"&consult=" + topic.id + "&toUser=" + member.code + "&toName=" + member.name+"&represented="+patient.code,
|
|
|
data: {
|
|
|
first: {value: first, color: "#000000"}
|
|
|
, remark: {value: "", color: "#000000"}
|
|
|
, keyword1: {value: topic.description, color: "#000000"}
|
|
|
, keyword2: {value: replyContent, color: "#000000"}
|
|
|
, keyword3: {value: senderName, color: "#000000"}
|
|
|
}
|
|
|
}, function (err, res) {
|
|
|
err ? log.error(err) : log.info(res);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if(mainOpenId!=agentOpenid){
|
|
|
var openid = mainOpenId;
|
|
|
var first = "您的健康咨询有新的回复";
|
|
|
// 发送模板消息
|
|
|
WechatSDK.sendTemplateMessage({
|
|
|
touser: openid,
|
|
|
template_id: config.wechatConfig.template.consultTemplate,
|
|
|
url: config.wechatConfig.baseUrl + "/wx/html/yszx/html/consulting-doctor.html?openid=" + openid +
|
|
|
"&consult=" + topic.id + "&toUser=" + targetUserId + "&toName=" + targetUserName+"&represented="+patient.code,
|
|
|
data: {
|
|
|
first: {value: first, color: "#000000"}
|
|
|
, remark: {value: "", color: "#000000"}
|
|
|
, keyword1: {value: topic.description, color: "#000000"}
|
|
|
, keyword2: {value: replyContent, color: "#000000"}
|
|
|
, keyword3: {value: senderName, color: "#000000"}
|
|
|
}
|
|
|
}, function (err, res) {
|
|
|
err ? log.error(err) : log.info(res);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 发送模板消息
|
|
|
WechatSDK.sendTemplateMessage({
|
|
|
touser: openid,
|
|
|
template_id: config.wechatConfig.template.consultTemplate,
|
|
|
url: config.wechatConfig.baseUrl + "/wx/html/yszx/html/consulting-doctor.html?openid=" + openid +
|
|
|
"&consult=" + topic.id + "&toUser=" + targetUserId + "&toName=" + targetUserName+"&represented="+message.receiver,
|
|
|
data: {
|
|
|
first: {value: first, color: "#000000"}
|
|
|
, remark: {value: "", color: "#000000"}
|
|
|
, keyword1: {value: topic.description, color: "#000000"}
|
|
|
, keyword2: {value: replyContent, color: "#000000"}
|
|
|
, keyword3: {value: senderName, color: "#000000"}
|
|
|
}else {//自己发起的议题
|
|
|
// 发送模板消息
|
|
|
WechatSDK.sendTemplateMessage({
|
|
|
touser: mainOpenId,
|
|
|
template_id: config.wechatConfig.template.consultTemplate,
|
|
|
url: config.wechatConfig.baseUrl + "/wx/html/yszx/html/consulting-doctor.html?openid=" + mainOpenId +
|
|
|
"&consult=" + topic.id + "&toUser=" + targetUserId + "&toName=" + targetUserName+"&represented="+patient.code,
|
|
|
data: {
|
|
|
first: {value: "您的健康咨询有新的回复", color: "#000000"}
|
|
|
, remark: {value: "", color: "#000000"}
|
|
|
, keyword1: {value: topic.description, color: "#000000"}
|
|
|
, keyword2: {value: replyContent, color: "#000000"}
|
|
|
, keyword3: {value: senderName, color: "#000000"}
|
|
|
}
|
|
|
}, function (err, res) {
|
|
|
err ? log.error(err) : log.info(res);
|
|
|
});
|
|
|
if(map.size>0){
|
|
|
for(var key of map.keys()){
|
|
|
if(key!=mainOpenId){
|
|
|
var member = map.get(key);
|
|
|
var openid = key;
|
|
|
var first = "您的家人("+patient.name+")的健康咨询有新的回复";
|
|
|
// 发送模板消息
|
|
|
WechatSDK.sendTemplateMessage({
|
|
|
touser: openid,
|
|
|
template_id: config.wechatConfig.template.consultTemplate,
|
|
|
url: config.wechatConfig.baseUrl + "/wx/html/yszx/html/consulting-doctor.html?openid=" + openid +
|
|
|
"&consult=" + topic.id + "&toUser=" + member.code + "&toName=" + member.name+"&represented="+patient.code,
|
|
|
data: {
|
|
|
first: {value: first, color: "#000000"}
|
|
|
, remark: {value: "", color: "#000000"}
|
|
|
, keyword1: {value: topic.description, color: "#000000"}
|
|
|
, keyword2: {value: replyContent, color: "#000000"}
|
|
|
, keyword3: {value: senderName, color: "#000000"}
|
|
|
}
|
|
|
}, function (err, res) {
|
|
|
err ? log.error(err) : log.info(res);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}, function (err, res) {
|
|
|
err ? log.error(err) : log.info(res);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
callback(null, null);
|
|
|
}
|