|  | @ -23,6 +23,7 @@ const CONTENT_TYPES = require('../include/commons').CONTENT_TYPE;
 | 
	
		
			
				|  |  | let clientCache = require('./socket.io/client.cache').clientCache();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | let doctorRepo = require('../repository/doctor.repo');
 | 
	
		
			
				|  |  | let groupRepo = require('../repository/group.repo');
 | 
	
		
			
				|  |  | let wechatUtil = require('../util/wechatUtil');
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | class Patient extends BaseModel {
 | 
	
	
		
			
				|  | @ -109,6 +110,54 @@ class Patient extends BaseModel {
 | 
	
		
			
				|  |  |      * @param message
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     sendConsultWechatReplyTempMsg(message) {
 | 
	
		
			
				|  |  |         let selt = this;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 发送微信消息
 | 
	
		
			
				|  |  |         function sendWxMessage(openid, name, consult){
 | 
	
		
			
				|  |  |             var replyContent = message.content;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             switch(Number.parseInt(message.contentType)){
 | 
	
		
			
				|  |  |                 case CONTENT_TYPES.Image:
 | 
	
		
			
				|  |  |                     replyContent = "[图片]";
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case CONTENT_TYPES.Audio:
 | 
	
		
			
				|  |  |                     replyContent = "[语音]";
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case CONTENT_TYPES.Article:
 | 
	
		
			
				|  |  |                     replyContent = "[文章]";
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case CONTENT_TYPES.GoTo:
 | 
	
		
			
				|  |  |                     return;
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case CONTENT_TYPES.SessionBegin:
 | 
	
		
			
				|  |  |                     return;
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case CONTENT_TYPES.SessionEnd:
 | 
	
		
			
				|  |  |                     return;
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 default:
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             // 模板消息数据
 | 
	
		
			
				|  |  |             var msg = {
 | 
	
		
			
				|  |  |                 touser: openid,
 | 
	
		
			
				|  |  |                 template_id: config.wechatConfig.template.consultTemplate,
 | 
	
		
			
				|  |  |                 url: config.wechatConfig.baseUrl + "/wx/html/yszx/html/consulting-doctor.html?openid=" + openid +
 | 
	
		
			
				|  |  |                 "&consult=" + consult.consult + "&toUser=" + message.to,
 | 
	
		
			
				|  |  |                 data: {
 | 
	
		
			
				|  |  |                     first: {value: "您的健康咨询有新的回复", color: "#000000"}
 | 
	
		
			
				|  |  |                     , remark: {value: "", color: "#000000"}
 | 
	
		
			
				|  |  |                     , keyword1: {value: consult.symptoms, color: "#000000"}
 | 
	
		
			
				|  |  |                     , keyword2: {value: replyContent, color: "#000000"}
 | 
	
		
			
				|  |  |                     , keyword3: {value: name, color: "#000000"}
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             };
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             // 发送模板消息
 | 
	
		
			
				|  |  |             wechatUtil.sendWxTemplateMessage(msg);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 查询居民openid
 | 
	
		
			
				|  |  |         patientRepo.getPatientOpenid(message.to, function (err, result) {
 | 
	
		
			
				|  |  |             if (err) {
 | 
	
	
		
			
				|  | @ -125,64 +174,37 @@ class Patient extends BaseModel {
 | 
	
		
			
				|  |  |                         modelUtil.emitDbError(self.eventEmitter, "get doctor info failed", err);
 | 
	
		
			
				|  |  |                         return;
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     if (result && result.length > 0) {
 | 
	
		
			
				|  |  |                         var name = result[0].name;
 | 
	
		
			
				|  |  |                         // 查询医生与居民对应的咨询信息
 | 
	
		
			
				|  |  |                         patientRepo.getPatientDoctorConsult(message.to, message.from, function (err, result) {
 | 
	
		
			
				|  |  |                             if (err) {
 | 
	
		
			
				|  |  |                                 modelUtil.emitDbError(self.eventEmitter, "get patient and doctor consult info failed", err);
 | 
	
		
			
				|  |  |                                 return;
 | 
	
		
			
				|  |  |                             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                             var consult = result && result.length > 0 ? result[0] : "";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                             if (consult) {
 | 
	
		
			
				|  |  |                                 var replyContent = message.content;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                                 switch(message.contentType){
 | 
	
		
			
				|  |  |                                     case CONTENT_TYPES.Image:
 | 
	
		
			
				|  |  |                                         replyContent = "[图片]";
 | 
	
		
			
				|  |  |                                         break;
 | 
	
		
			
				|  |  |                                     case CONTENT_TYPES.Audio:
 | 
	
		
			
				|  |  |                                         replyContent = "[语音]";
 | 
	
		
			
				|  |  |                                         break;
 | 
	
		
			
				|  |  |                                     case CONTENT_TYPES.Article:
 | 
	
		
			
				|  |  |                                         replyContent = "[文章]";
 | 
	
		
			
				|  |  |                                         break;
 | 
	
		
			
				|  |  |                                     case CONTENT_TYPES.GoTo:
 | 
	
		
			
				|  |  |                                         replyContent = "[链接]";
 | 
	
		
			
				|  |  |                                         break;
 | 
	
		
			
				|  |  |                                     case CONTENT_TYPES.SessionBegin:
 | 
	
		
			
				|  |  |                                         return;
 | 
	
		
			
				|  |  |                                         break;
 | 
	
		
			
				|  |  |                                     case CONTENT_TYPES.SessionEnd:
 | 
	
		
			
				|  |  |                                         return;
 | 
	
		
			
				|  |  |                                         break;
 | 
	
		
			
				|  |  |                                     default:
 | 
	
		
			
				|  |  |                                         return;
 | 
	
		
			
				|  |  |                                         break;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                         if (message.group) {
 | 
	
		
			
				|  |  |                             groupRepo.getGroupConsultInfo(message.group, function(err, result){
 | 
	
		
			
				|  |  |                                 if (err) {
 | 
	
		
			
				|  |  |                                     modelUtil.emitDbError(self.eventEmitter, "get patient and doctor consult info failed", err);
 | 
	
		
			
				|  |  |                                     return;
 | 
	
		
			
				|  |  |                                 }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                                 var consult = result && result.length > 0 ? result[0] : "";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                                 if (consult) {
 | 
	
		
			
				|  |  |                                     sendWxMessage(openid, name, consult);
 | 
	
		
			
				|  |  |                                 }
 | 
	
		
			
				|  |  |                             });
 | 
	
		
			
				|  |  |                         } else {
 | 
	
		
			
				|  |  |                             // 查询医生与居民对应的咨询信息
 | 
	
		
			
				|  |  |                             patientRepo.getPatientDoctorConsult(message.to, message.from, function (err, result) {
 | 
	
		
			
				|  |  |                                 if (err) {
 | 
	
		
			
				|  |  |                                     modelUtil.emitDbError(self.eventEmitter, "get patient and doctor consult info failed", err);
 | 
	
		
			
				|  |  |                                     return;
 | 
	
		
			
				|  |  |                                 }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                                 // 模板消息数据
 | 
	
		
			
				|  |  |                                 var msg = {
 | 
	
		
			
				|  |  |                                     touser: openid,
 | 
	
		
			
				|  |  |                                     template_id: config.wechatConfig.template.consultTemplate,
 | 
	
		
			
				|  |  |                                     url: config.wechatConfig.baseUrl + "/wx/html/yszx/html/consulting-doctor.html?openid=" + openid +
 | 
	
		
			
				|  |  |                                     "&consult=" + consult.consult + "&toUser=" + message.to,
 | 
	
		
			
				|  |  |                                     data: {
 | 
	
		
			
				|  |  |                                         first: {value: "您的健康咨询有新的回复", color: "#000000"}
 | 
	
		
			
				|  |  |                                         , remark: {value: "", color: "#000000"}
 | 
	
		
			
				|  |  |                                         , keyword1: {value: consult.symptoms, color: "#000000"}
 | 
	
		
			
				|  |  |                                         , keyword2: {value: replyContent, color: "#000000"}
 | 
	
		
			
				|  |  |                                         , keyword3: {value: name, color: "#000000"}
 | 
	
		
			
				|  |  |                                     }
 | 
	
		
			
				|  |  |                                 };
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                                 // 发送模板消息
 | 
	
		
			
				|  |  |                                 wechatUtil.sendWxTemplateMessage(msg);
 | 
	
		
			
				|  |  |                             }
 | 
	
		
			
				|  |  |                         });
 | 
	
		
			
				|  |  |                                 var consult = result && result.length > 0 ? result[0] : "";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                                 if (consult) {
 | 
	
		
			
				|  |  |                                     sendWxMessage(openid, name, consult);
 | 
	
		
			
				|  |  |                                 }
 | 
	
		
			
				|  |  |                             });
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                     } else {
 | 
	
		
			
				|  |  |                         modelUtil.emitDbError(self.eventEmitter, "can not find doctor info", err);
 | 
	
		
			
				|  |  |                     }
 |