Commit bd4aae1d by 宋毅

tj

parent 1c2ab05b
File mode changed from 100644 to 100755
const system = require("../system"); const system = require("../system");
const settings = require("../../config/settings"); const settings = require("../../config/settings");
const axios = require('axios');
const moment = require('moment'); const moment = require('moment');
const { json } = require("sequelize");
const uuid = require('uuid'); const uuid = require('uuid');
class APIBase { class APIBase {
...@@ -26,7 +24,7 @@ class APIBase { ...@@ -26,7 +24,7 @@ class APIBase {
"GetQualificationCertificateDetail": "getQualificationCertificateDetail", "GetQualificationCertificateDetail": "getQualificationCertificateDetail",
"RefusalSolution": "refusalSolution", "RefusalSolution": "refusalSolution",
"SendVerificationCode": "sendVerificationCode", "SendVerificationCode": "sendVerificationCode",
}; };
} }
//-----------------------新的模式------------------开始 //-----------------------新的模式------------------开始
...@@ -46,16 +44,19 @@ class APIBase { ...@@ -46,16 +44,19 @@ class APIBase {
result = system.getResult(null, "请求的方法返回值为空"); result = system.getResult(null, "请求的方法返回值为空");
} }
result.requestId = result.requestId || uuid.v1(); result.requestId = result.requestId || uuid.v1();
this.execClient.execLogs("reqPath:" + req.path + "执行结果", param, "brg-user-center-apibase", result, null);
if (req.body.Action && this.userCenterAction[req.body.Action]) { if (req.body.Action && this.userCenterAction[req.body.Action]) {
return await this.handleTxResult(result); result = await this.handleTxResult(result);
delete req.body["ActionBody"];
delete req.body["Action"];
}//处理tx返回数据 }//处理tx返回数据
this.execClient.execLogs("reqPath:" + req.path + "执行结果", param, "brg-user-center-apibase", result, null);
return result; return result;
} catch (e) { } catch (error) {
console.log(e.stack, "api调用出现异常,请联系管理员..........") var stackStr = error.stack ? error.stack : JSON.stringify(error);
var rtnerror = system.getResultFail(-200, "出现异常,error:" + e.stack); console.log(stackStr, "api调用出现异常,请联系管理员..........")
var rtnerror = system.getResultFail(-200, "出现异常,error:" + stackStr);
rtnerror.requestId = uuid.v1(); rtnerror.requestId = uuid.v1();
this.execClient.execLogs("reqPath:" + req.path + "执行异常", param, "brg-user-center-apibase", null, e.stack); this.execClient.execLogs("reqPath:" + req.path + "执行异常", param, "brg-user-center-apibase", null,stackStr);
if (req.body.Action && this.userCenterAction[req.body.Action]) { if (req.body.Action && this.userCenterAction[req.body.Action]) {
return { return {
"Response": { "Response": {
......
...@@ -35,6 +35,9 @@ class CommonMsgSend extends APIBase { ...@@ -35,6 +35,9 @@ class CommonMsgSend extends APIBase {
case "sendVerificationCode"://发送验证码 case "sendVerificationCode"://发送验证码
opResult = await this.utilsMsgSendSve.sendVerificationCode(actionBody.PhoneNumber); opResult = await this.utilsMsgSendSve.sendVerificationCode(actionBody.PhoneNumber);
break; break;
case "sendManage":
opResult = await this.utilsMsgSendSve.sendMessageVerify(actionBody);
break;
default: default:
opResult = system.getResult(null, "actionType参数错误"); opResult = system.getResult(null, "actionType参数错误");
break; break;
......
...@@ -85,6 +85,12 @@ class Order extends APIBase { ...@@ -85,6 +85,12 @@ class Order extends APIBase {
case "getQualificationCertificateDetail"://用户获取资质证照详情 case "getQualificationCertificateDetail"://用户获取资质证照详情
opResult = await this.qualificationCertificateSve.getQualificationCertificateDetail(pobj); opResult = await this.qualificationCertificateSve.getQualificationCertificateDetail(pobj);
break; break;
case "refundOrder"://退款接口
opResult = await this.orderinfoSve.refundOrder(pobj.actionBody);
break;
case "jftime"://计费时间修改
opResult = await this.orderinfoSve.jftime(pobj.actionBody);
break;
default: default:
opResult = system.getResult(null, "action_type参数错误"); opResult = system.getResult(null, "action_type参数错误");
break; break;
......
...@@ -6,6 +6,12 @@ var glob = require("glob"); ...@@ -6,6 +6,12 @@ var glob = require("glob");
class DbFactory { class DbFactory {
constructor() { constructor() {
const dbConfig = settings.database(); const dbConfig = settings.database();
dbConfig.reconnect = {
max_retries: 10,
onRetry: function (count) {
console.log("connection lost, trying to reconnect (" + count + ")");
}
};
this.db = new Sequelize(dbConfig.dbname, this.db = new Sequelize(dbConfig.dbname,
dbConfig.user, dbConfig.user,
dbConfig.password, dbConfig.password,
...@@ -18,38 +24,42 @@ class DbFactory { ...@@ -18,38 +24,42 @@ class DbFactory {
async initModels() { async initModels() {
var self = this; var self = this;
var modelpath = path.normalize(path.join(__dirname, '../..')) + "/models/"; var modelpath = path.normalize(path.join(__dirname, '../..')) + "/models/";
// console.log(modelpath);
var models = glob.sync(modelpath + "/**/*.js"); var models = glob.sync(modelpath + "/**/*.js");
// console.log(models.length);
models.forEach(function (m) { models.forEach(function (m) {
self.db.import(m); self.db.import(m);
}); });
console.log("init models....");
} }
async initRelations() { async initRelations() {
/**
一个账户对应多个登陆用户
一个账户对应一个commany
一个APP对应多个登陆用户
一个APP有多个角色
登陆用户和角色多对多
**/
/*建立账户和用户之间的关系*/
//account--不属于任何一个app,是统一用户
//用户登录时首先按照用户名和密码检查account是否存在,如果不存在则提示账号或密码不对,如果
//存在则按照按照accountid和应用key,查看user,后台实现对应user登录
} }
//async getCon(){,用于使用替换table模型内字段数据使用 //async getCon(){,用于使用替换table模型内字段数据使用
getCon() { getCon() {
var that = this;
// await this.db.authenticate().then(()=>{
// console.log('Connection has been established successfully.');
// }).catch(err => {
// console.error('Unable to connect to the database:', err);
// throw err;
// });
//同步模型 //同步模型
if (settings.env == "dev") { if (settings.env == "dev") {
//console.log(pa);
// pconfigObjs.forEach(p=>{
// console.log(p.get({plain:true}));
// });
// await this.db.models.user.create({nickName:"dev","description":"test user",openId:"testopenid",unionId:"testunionid"})
// .then(function(user){
// var acc=that.db.models.account.build({unionId:"testunionid",nickName:"dev"});
// acc.save().then(a=>{
// user.setAccount(a);
// });
// });
} }
return this.db; return this.db;
} }
getConhb() {
var that = this;
if (settings.env == "dev") {
}
return this.dbhb;
}
} }
module.exports = DbFactory; module.exports = DbFactory;
\ No newline at end of file
...@@ -29,7 +29,7 @@ class OrderInfoDao extends Dao{ ...@@ -29,7 +29,7 @@ class OrderInfoDao extends Dao{
}; };
var sqlcount = "select count(1) as dataCount from v_order_oproduct_odelivery where product_type=:product_type and user_id=:user_id"; var sqlcount = "select count(1) as dataCount from v_order_oproduct_odelivery where product_type=:product_type and user_id=:user_id";
var sql = "SELECT order_num,delivery_status,updated_at,order_snapshot "+ var sql = "SELECT order_num,region_name,region_id,total_sum,delivery_status,pay_time,end_time,time_span,time_unit,updated_at,order_snapshot "+
" from v_order_oproduct_odelivery where product_type=:product_type and user_id=:user_id"; " from v_order_oproduct_odelivery where product_type=:product_type and user_id=:user_id";
if(ab.ProductType=="/ic/gsreg/"){//公司注册筛选条件 if(ab.ProductType=="/ic/gsreg/"){//公司注册筛选条件
if(ab.CompanyProperties){//公司性质 if(ab.CompanyProperties){//公司性质
......
...@@ -15,11 +15,11 @@ class OrderProductDao extends Dao { ...@@ -15,11 +15,11 @@ class OrderProductDao extends Dao {
}; };
var sql = "SELECT order_num,product_type_name,product_type,delivery_status,delivery_status_name,"+ var sql = "SELECT order_num,product_type_name,product_type,delivery_status,delivery_status_name,"+
"updated_at,order_snapshot FROM `v_order_oproduct_odelivery` where user_id=:user_id and "+ "updated_at,order_snapshot FROM `v_order_oproduct_odelivery` where user_id=:user_id and "+
"((deliver_content->'$.companyInfo' is not null and deliver_content->'$.companyInfo.creditCode'=:creditCode) "+ "(deliver_content->'$.companyInfo' is not null and deliver_content->'$.companyInfo.creditCode'=:creditCode) "+
" or "+ // " or "+
"( deliver_content -> '$.proposerInfo' IS NOT NULL "+ // "( deliver_content -> '$.proposerInfo' IS NOT NULL "+
"AND deliver_content -> '$.proposerInfo.businessLicense' IS NOT NULL "+ // "AND deliver_content -> '$.proposerInfo.businessLicense' IS NOT NULL "+
"AND deliver_content -> '$.proposerInfo.businessLicense.enterpriseCode' = :creditCode2 ))"+ // "AND deliver_content -> '$.proposerInfo.businessLicense.enterpriseCode' = :creditCode2 ))"+
"order by updated_at desc"; "order by updated_at desc";
var list = await this.customQuery(sql, params); var list = await this.customQuery(sql, params);
return list; return list;
......
const system = require("../../../system");
const Dao = require("../../dao.base");
class OrderRefundDao extends Dao {
constructor() {
super(Dao.getModelName(OrderRefundDao));
}
}
module.exports = OrderRefundDao;
...@@ -16,7 +16,7 @@ module.exports = (db, DataTypes) => { ...@@ -16,7 +16,7 @@ module.exports = (db, DataTypes) => {
version: true, version: true,
freezeTableName: true, freezeTableName: true,
timestamps: true, timestamps: true,
updatedAt: false, // updatedAt: false,
//freezeTableName: true, //freezeTableName: true,
// define the table's name // define the table's name
tableName: 'b_need_solution', tableName: 'b_need_solution',
......
...@@ -16,6 +16,9 @@ module.exports = (db, DataTypes) => { ...@@ -16,6 +16,9 @@ module.exports = (db, DataTypes) => {
time_span: DataTypes.STRING, //计费数量 time_span: DataTypes.STRING, //计费数量
time_unit: DataTypes.STRING, //计费周期 年:y,月:m,日:d,时:h,分:M,秒:s,一次性购买:p time_unit: DataTypes.STRING, //计费周期 年:y,月:m,日:d,时:h,分:M,秒:s,一次性购买:p
end_time: DataTypes.DATE, //到期时间 end_time: DataTypes.DATE, //到期时间
start_time: DataTypes.DATE, //开始时间
status: DataTypes.STRING, //1正常,2隔离,3销毁
isolated_time: DataTypes.DATE, //隔离时间
servicer_code: DataTypes.STRING, //服务商 servicer_code: DataTypes.STRING, //服务商
servicer_name: DataTypes.STRING servicer_name: DataTypes.STRING
}, { }, {
......
...@@ -18,16 +18,17 @@ class TxPushLogService extends ServiceBase { ...@@ -18,16 +18,17 @@ class TxPushLogService extends ServiceBase {
} }
//发货回调
async createCbsInstance(pobj, req) { async createCbsInstance(pobj, req) {
var self=this; var self = this;
if (!pobj.interface.para.dealName) { if (!pobj.interface.para.dealName) {
return self.returnTX(-1, "cgateway", "参数错误", null) return self.returnTX(-1, "cgateway", "参数错误", null)
} }
var loginfo = await this.findOne({ deal_name: pobj.interface.para.dealName, push_action_type: "orderPayNotify" }); var loginfo = await this.findOne({ deal_name: pobj.interface.para.dealName, push_action_type: "orderPayNotify" });
if (loginfo) { if (loginfo) {
return self.returnTX(1, "cgateway", "ok", {"flowId":loginfo.flow_id,"resourceIds":[pobj.interface.para.dealName]}) return self.returnTX(1, "cgateway", "ok", { "flowId": loginfo.flow_id, "resourceIds": [pobj.interface.para.dealName] })
} }
var flow_id=await this.getBusUid("f"); var flow_id = await this.getBusUid("f");
var newobj = { var newobj = {
flow_id: flow_id, flow_id: flow_id,
deal_name: pobj.interface.para.dealName, deal_name: pobj.interface.para.dealName,
...@@ -37,11 +38,11 @@ class TxPushLogService extends ServiceBase { ...@@ -37,11 +38,11 @@ class TxPushLogService extends ServiceBase {
push_action_type: "orderPayNotify", push_action_type: "orderPayNotify",
push_status: "2", push_status: "2",
} }
var creatlog= await this.create(newobj); var creatlog = await this.create(newobj);
if(!creatlog){ if (!creatlog) {
return self.returnTX(-1, "cgateway", "参数错误", null) return self.returnTX(-1, "cgateway", "参数错误", null)
} }
pobj.logId=creatlog.dataValues.id; pobj.logId = creatlog.dataValues.id;
var pushobj = { var pushobj = {
"actionType": "produceData",// Y 功能名称 "actionType": "produceData",// Y 功能名称
"actionBody": { "actionBody": {
...@@ -52,11 +53,12 @@ class TxPushLogService extends ServiceBase { ...@@ -52,11 +53,12 @@ class TxPushLogService extends ServiceBase {
identifyCode: "orderPayNotify" identifyCode: "orderPayNotify"
} }
}; };
this.execPostByTimeOut(pushobj, settings.apiconfig.opPushUrl()); this.execPostByTimeOut(pushobj, settings.opPushUrl());
return self.returnTX(1, "cgateway", "ok", {"flowId":creatlog.flow_id,"resourceIds":[pobj.interface.para.dealName]}) return self.returnTX(1, "cgateway", "ok", { "flowId": creatlog.flow_id, "resourceIds": [pobj.interface.para.dealName] })
} }
//发货检查
async queryFlow(pobj) { async queryFlow(pobj) {
if (!pobj.interface.para.flowId) { if (!pobj.interface.para.flowId) {
return self.returnTX(-1, "cgateway", "参数错误", null) return self.returnTX(-1, "cgateway", "参数错误", null)
...@@ -65,48 +67,112 @@ class TxPushLogService extends ServiceBase { ...@@ -65,48 +67,112 @@ class TxPushLogService extends ServiceBase {
if (!loginfo) { if (!loginfo) {
return self.returnTX(-1, "cgateway", "产品不存在", null) return self.returnTX(-1, "cgateway", "产品不存在", null)
} }
var orderInfo=await this.orderInfoDao.findOne({order_num:loginfo.dataValues.dealName}); var orderInfo = await this.orderInfoDao.findOne({ order_num: loginfo.dataValues.dealName });
if(!orderInfo){ if (!orderInfo) {
return self.returnTX(-1, "cgateway", "资源不存在", null) return self.returnTX(-1, "cgateway", "资源不存在", null)
} }
var status=0; var status = 0;
if(orderInfo.status==302){ if (orderInfo.status == 302) {
status=3; status = 3;
} }
return self.returnTX(1, "cgateway", "ok", {"status":status}) return self.returnTX(1, "cgateway", "ok", { "status": status })
} }
//资源拉取
async queryResources(pobj) { async queryResources(pobj) {
if (!pobj.interface.para.resourceIds[0]) { if (!pobj.interface.para.resourceIds[0]) {
return self.returnTX(-1, "cgateway", "参数错误", null) return self.returnTX(-1, "cgateway", "参数错误", null)
} }
var loginfo = await this.findOne({ flow_id: pobj.interface.para.flowId, push_action_type: "orderPayNotify" }); var orderProduct = await this.orderProductDao.findOne({ order_num: loginfo.dataValues.dealName });
if (!loginfo) { if (!orderProduct) {
return self.returnTX(-1, "cgateway", "产品不存在", null)
}
var orderInfo=await this.orderInfoDao.findOne({order_num:loginfo.dataValues.dealName});
if(!orderInfo){
return self.returnTX(-1, "cgateway", "资源不存在", null) return self.returnTX(-1, "cgateway", "资源不存在", null)
} }
var status=0; var r = {
if(orderInfo.status==302){ "eventId": 186993048,
status=3; "version": 1,
"componentName": "cgateway",
"timestamp": 1500912302,
"returnValue": 0,
"returnCode": 0,
"returnMessage": "ok",
"data": {
"resources": [
{
"appId": appId,
"uin": ownerUin,
"resourceId": tx_order_snapshot,//站内信自定义字段层级和此字段同一层级
"projectId": 0,
"autoRenewFlag": 0,
"region": 1,
"zoneId": 200001,
"status": orderProduct.status,
"payMode": 1, // 必传,1预付费 0后付费
"isolatedTimestamp": orderProduct.isolated_timestamp || "0000-00-00 00:00:00",
"createTime": orderProduct.start_time,
"expireTime": orderProduct.end_time || "0000-00-00 00:00:00",
"goodsDetail": orderProduct.tx_order_snapshot.goodsDetail
}
]
}
} }
return self.returnTX(1, "cgateway", "ok", {"status":loginfo.push_status}) return self.returnTX(1, "cgateway", "ok", { "status": loginfo.push_status })
} }
async isolateResource(pobj){
// {
// "version": "1.0",
// "caller": "mall_logic",
// "componentName": "mall_logic",
// "password": "mall_logic",
// "callee": "cdb",
// "eventId": 843836670,
// "seqId": "1501802577.465723597230350480",
// "spanId": "logical;1",
// "timestamp": 1501802577,
// "interface": {
// "interfaceName": "qcloud.PRODUCT_NAME.isolateResource",
// "para": {
// "appId": 123,
// "uin": "123",
// "operateUin": "123",
// "type": "cdb",
// "region": 4,
// "resourceId": "cdb-dfe8t7i9"
// "renewFlag": 0,
// "newDeadline": "2016-10-22 12:00:00",
// "billingIsolateType": "refund",
// "billingExtParam":{
// "sv_xxx":"sv_xxx"// 查询用量时业务返回的数据
// }
// }
// }
// }
//隔离资源
async isolateResource(pobj) {
if (!pobj.interface.para.resourceId) { if (!pobj.interface.para.resourceId) {
return self.returnTX(-1, "cgateway", "参数错误", null) return self.returnTX(-1, "mall_logic", "参数错误", null)
} }
} }
async queryResources(pobj){
//新购参数检查
async checkCreate(pobj) {
if (!pobj.interface || !pobj.interface.para || !pobj.interface.para.goodsDetail) {
return self.returnTX(-1, "qcloud_domain_register", "参数错误", null)
}
if (pobj.interface.para.goodsDetail.goodsNum > 1) {
return this.returnTX(0, "qcloud_domain_register", "ok", { "status": 2 })
}
return this.returnTX(0, "qcloud_domain_register", "ok", { "status": 0 })
} }
} }
module.exports = TxPushLogService; module.exports = TxPushLogService;
...@@ -94,7 +94,8 @@ class NeedInfoService extends ServiceBase { ...@@ -94,7 +94,8 @@ class NeedInfoService extends ServiceBase {
notes: actionBody.Notes, notes: actionBody.Notes,
servicer_code: actionBody.ServicerCode, servicer_code: actionBody.ServicerCode,
servicer_name: actionBody.ServicerName, servicer_name: actionBody.ServicerName,
status: 1 status: 1,
user_name: actionBody.UserName
} }
if (actionBody.CompanyName) { if (actionBody.CompanyName) {
datavalue.need_info = { datavalue.need_info = {
...@@ -111,12 +112,12 @@ class NeedInfoService extends ServiceBase { ...@@ -111,12 +112,12 @@ class NeedInfoService extends ServiceBase {
"actionBody": { "actionBody": {
notifyUrl: "http://192.168.1.113:4011/api/receive/notifyApi/springBoard", notifyUrl: "http://192.168.1.113:4011/api/receive/notifyApi/springBoard",
actionType: "needSubmit", actionType: "needSubmit",
pushUrl: settings.apiconfig.deliveryUrl() + "/entService/consultation/springBoard", pushUrl: settings.deliveryUrl() + "/entService/consultation/springBoard",
messageBody: actionBody, messageBody: actionBody,
identifyCode: "needSubmit" identifyCode: "needSubmit"
} }
}; };
var r = await this.execPostByTimeOut(pushobj, settings.apiconfig.opPushUrl()); var r = await this.execPostByTimeOut(pushobj, settings.opPushUrl());
if (r.status < 1) { if (r.status < 1) {
return system.getResultFail(-102, "Post error"); return system.getResultFail(-102, "Post error");
} }
......
const system = require("../../../system"); const system = require("../../../system");
const ServiceBase = require("../../sve.base"); const ServiceBase = require("../../sve.base");
const settings = require("../../../../config/settings"); const settings = require("../../../../config/settings");
const {PDICT,MsgTemplate} = require("../../../../config/platform");
class NeedSolutionService extends ServiceBase { class NeedSolutionService extends ServiceBase {
constructor() { constructor() {
super("need", ServiceBase.getDaoName(NeedSolutionService)); super("need", ServiceBase.getDaoName(NeedSolutionService));
this.needInfoDao = system.getObject("db.need.needInfoDao"); this.needInfoDao = system.getObject("db.need.needInfoDao");
this.utilsMsgSendSve = system.getObject("service.utilsSve.utilsMsgSendSve");
}
/**
* 发送短信通知
* @param {*} mobile 接收人手机号
* @param {*} userId 用户id
* @param {*} consultType 产品类型
* @param {*} consultName 产品类型名称
* @param {*} status 状态
*/
async sendSmsNotification(mobile,userId,consultType,consultName,status){
try {
var nameArr = consultName?consultName.split("/"):[];
var productName = null;
if(nameArr && nameArr.length==4){
productName = nameArr[2];
}
var params = {phoneNumber:mobile,messageBody:null};
var webinfoParams = {"title":null,"subAccount":userId,"messageBody":null};//站内信通知参数
var messageBody = null;
var webinfoMessageBody = null;
if(consultType.indexOf("/ic/")>=0){//工商产品
messageBody=MsgTemplate.ic.need[status] && MsgTemplate.ic.need[status].sms?MsgTemplate.ic.need[status].sms:"";
messageBody = messageBody.replace(/{productName}/g,productName);
webinfoMessageBody=MsgTemplate.ic.need[status] && MsgTemplate.ic.need[status].webinfo?MsgTemplate.ic.need[status].webinfo:"";
webinfoMessageBody = webinfoMessageBody.replace(/{productName}/g,productName);
webinfoParams.title = MsgTemplate.ic.need[status] && MsgTemplate.ic.need[status].webinfotitle?MsgTemplate.ic.need[status].webinfotitle:"";
}
if(consultType.indexOf("/qcfw/")>=0){//资质证照产品
}
// console.log(messageBody,"ddddddddd");
if(userId && webinfoParams.title && messageBody && messageBody.indexOf("{")<0 && messageBody.indexOf("}")<0 && webinfoMessageBody && webinfoMessageBody.indexOf("{")<0 && webinfoMessageBody.indexOf("}")<0 ){
params.messageBody =messageBody;
webinfoParams.messageBody = webinfoMessageBody;
// await this.utilsMsgSendSve.sendMessageByPhone(params);//发送短信
await this.utilsMsgSendSve.sendMessageVerify({phoneList:[params],subAccountList:[webinfoParams]});
}
return;
} catch (e) {
this.execClient.execLogs("needSolutionSve.js/sendSmsNotification(发送短信通知)方法出现异常", {mobile:mobile,consultType:consultType,consultName:consultName,status:status}, "", null, e.stack);
return;
}
} }
//服务商提交/修改方案 //服务商提交/修改方案
async submitSolution(pobj) { async submitSolution(pobj) {
...@@ -53,6 +100,8 @@ class NeedSolutionService extends ServiceBase { ...@@ -53,6 +100,8 @@ class NeedSolutionService extends ServiceBase {
return await self.db.transaction(async function (t) { return await self.db.transaction(async function (t) {
await self.dao.update(updateObj, t); await self.dao.update(updateObj, t);
await self.needInfoDao.update({ id: needinfo.id, status: "3" }, t); await self.needInfoDao.update({ id: needinfo.id, status: "3" }, t);
//发送短信通知
self.sendSmsNotification("15675201933",needinfo.user_id,needinfo.consult_type,needinfo.consult_type_name,3);
return system.getResultSuccess(); return system.getResultSuccess();
}); });
...@@ -76,6 +125,8 @@ class NeedSolutionService extends ServiceBase { ...@@ -76,6 +125,8 @@ class NeedSolutionService extends ServiceBase {
return await self.db.transaction(async function (t) { return await self.db.transaction(async function (t) {
await self.needInfoDao.update({ id: needinfo.id, status: "3" }, t); await self.needInfoDao.update({ id: needinfo.id, status: "3" }, t);
await self.dao.create(createObj, t); await self.dao.create(createObj, t);
//发送短信通知
self.sendSmsNotification("15675201933",needinfo.consult_type,needinfo.consult_type_name,3);
return system.getResultSuccess(solution_num); return system.getResultSuccess(solution_num);
}); });
...@@ -111,12 +162,12 @@ class NeedSolutionService extends ServiceBase { ...@@ -111,12 +162,12 @@ class NeedSolutionService extends ServiceBase {
"actionBody": { "actionBody": {
notifyUrl: "", notifyUrl: "",
actionType: "needClose", actionType: "needClose",
pushUrl: settings.apiconfig.deliveryUrl() + "/entService/consultation/springBoard", pushUrl: settings.deliveryUrl() + "/entService/consultation/springBoard",
messageBody: actionBody, messageBody: actionBody,
identifyCode: "needClose" identifyCode: "needClose"
} }
}; };
var r = await self.execPostByTimeOut(pushobj, settings.apiconfig.opPushUrl()); var r = await self.execPostByTimeOut(pushobj, settings.opPushUrl());
if (r.status < 1) { if (r.status < 1) {
return system.getResultFail(-102, "Post error"); return system.getResultFail(-102, "Post error");
} }
...@@ -127,3 +178,7 @@ class NeedSolutionService extends ServiceBase { ...@@ -127,3 +178,7 @@ class NeedSolutionService extends ServiceBase {
} }
} }
module.exports = NeedSolutionService; module.exports = NeedSolutionService;
// var task = new NeedSolutionService();
// task.sendSmsNotification("15675201933","/ic/cpreg/","/工商服务/云上园区注册/",3).then(d=>{
// console.log("eeeeeeeeeeeeee"+d);
// })
\ No newline at end of file
var system = require("../../../system"); var system = require("../../../system");
var settings = require("../../../../config/settings"); var settings = require("../../../../config/settings");
const AppServiceBase = require("../../app.base"); const AppServiceBase = require("../../app.base");
const sha256 = require('sha256');
class UtilsMsgSendService extends AppServiceBase { class UtilsMsgSendService extends AppServiceBase {
constructor() { constructor() {
super(); super();
this.redisClient = system.getObject("util.redisClient"); this.redisClient = system.getObject("util.redisClient");
this.prefix = "sendCode:"; this.prefix = "brg-user-center:sendCode:";
} }
/** /**
* 发送验证码 * 发送验证码
...@@ -20,7 +22,10 @@ class UtilsMsgSendService extends AppServiceBase { ...@@ -20,7 +22,10 @@ class UtilsMsgSendService extends AppServiceBase {
} }
var randomInt = await this.getUidInfo(6, 10); var randomInt = await this.getUidInfo(6, 10);
params.messageBody = "验证码为" + randomInt + "(切勿将验证码告知他人),请在页面中60秒内输入完成验证"; params.messageBody = "验证码为" + randomInt + "(切勿将验证码告知他人),请在页面中60秒内输入完成验证";
var sendResult = await this.sendMessageByPhone(params); var tmpParams = {
phoneList: [params]
}
var sendResult = await this.sendMessageVerify(tmpParams);
if (sendResult.status === 1) { if (sendResult.status === 1) {
this.redisClient.setWithEx(key, randomInt, 60); this.redisClient.setWithEx(key, randomInt, 60);
} }
...@@ -41,10 +46,22 @@ class UtilsMsgSendService extends AppServiceBase { ...@@ -41,10 +46,22 @@ class UtilsMsgSendService extends AppServiceBase {
return await this.redisClient.getCache(key); return await this.redisClient.getCache(key);
} }
/** /**
* 发送短信信息 * 发送信息
* @param {*} params 格式:{phoneNumber:手机号,messageBody:消息内容} * @param {*} params 格式:
{
phoneList:[{phoneNumber:手机号,messageBody:消息内容}],
subAccountList:[{title:标题,subAccount:子账号,messageBody:消息内容-站内信}],
wechatList:[{title:标题,wechatNumber:微信号,messageBody:消息内容}],
emailList:[{email:邮箱,messageBody:消息内容}]
}
* @param {*} setCacheEx 设置缓存时间,多久不能再次请求
*/ */
async sendMessageByPhone(params) { async sendMessageVerify(params, setCacheEx = 3) {
var shaStr = await sha256(JSON.stringify(params));
var existsKey = await this.redisClient.exists(shaStr);
if (existsKey) {
return system.getResult(null, "操作过于频繁,请稍后再试");
}
if (!params) { if (!params) {
return system.getResult(null, "params参数不能为空"); return system.getResult(null, "params参数不能为空");
} }
...@@ -52,24 +69,115 @@ class UtilsMsgSendService extends AppServiceBase { ...@@ -52,24 +69,115 @@ class UtilsMsgSendService extends AppServiceBase {
if (keyCount === 0) { if (keyCount === 0) {
return system.getResult(null, "params参数不能为空!"); return system.getResult(null, "params参数不能为空!");
} }
if (!params.phoneNumber) { var verifyResult = null;
return system.getResult(null, "手机号不能为空"); var reqParam = {
titleTpl: [],
smsTpl: [],
siteTpl: [],
wechatTpl: [],
emailTpl: [],
phoneList: [],
subAccountList: [],
wechatList: [],
emailList: []
} }
if (!(/^1[3|4|5|6|7|8|9][0-9]\d{8}$/.test(params.phoneNumber))) { if (params.phoneList && params.phoneList.length > 0) {
return system.getResult(null, "手机号有误,请输入正确手机号"); for (let index = 0; index < params.phoneList.length; index++) {
var element = params.phoneList[index];
if (element) {
if (!element.phoneNumber) {
verifyResult = system.getResult(null, "手机号不能为空");
break;
}
if (!(/^1[3|4|5|6|7|8|9][0-9]\d{8}$/.test(element.phoneNumber))) {
verifyResult = system.getResult(null, "手机号有误,请输入正确手机号");
break;
}
if (!element.messageBody) {
verifyResult = system.getResult(null, "消息主体不能为空");
break;
}
params.phoneList[index].phoneNumber = element.phoneNumber.indexOf("86+") >= 0 ? element.phoneNumber : "86+" + element.phoneNumber;
reqParam.smsTpl.push(element.messageBody);
reqParam.phoneList.push(params.phoneList[index].phoneNumber);
}
}
} }
if (!params.messageBody) { if (verifyResult) {
return system.getResult(null, "消息主体不能为空"); return verifyResult;
} }
params.phoneNumber = params.phoneNumber.indexOf("86+") >= 0 ? params.phoneNumber : "86+" + params.phoneNumber; if (params.subAccountList && params.subAccountList.length > 0) {
var existSend = await this.redisClient.exists(params.phoneNumber); for (let index = 0; index < params.subAccountList.length; index++) {
if (existSend) { var element = params.subAccountList[index];
return system.getResult(null, "操作过于频繁,请稍后再试"); if (element) {
if (!element.title) {
verifyResult = system.getResult(null, "站内信标题不能为空");
break;
}
if (!element.subAccount) {
verifyResult = system.getResult(null, "子账号不能为空");
break;
}
if (!element.messageBody) {
verifyResult = system.getResult(null, "站内信消息主体不能为空");
break;
}
reqParam.titleTpl.push(element.title);
reqParam.siteTpl.push(element.messageBody);
reqParam.subAccountList.push(element.subAccount);
}
}
}
if (verifyResult) {
return verifyResult;
}
if (params.wechatList && params.wechatList.length > 0) {
for (let index = 0; index < params.wechatList.length; index++) {
var element = params.wechatList[index];
if (element) {
if (!element.title) {
verifyResult = system.getResult(null, "微信标题不能为空");
break;
}
if (!element.wechatNumber) {
verifyResult = system.getResult(null, "微信号不能为空");
break;
}
if (!element.messageBody) {
verifyResult = system.getResult(null, "微信消息主体不能为空");
break;
}
reqParam.titleTpl.push(element.title);
reqParam.wechatTpl.push(element.messageBody);
reqParam.wechatList.push(element.wechatNumber);
}
}
} }
var sendResult = await this.sendPhoneMsg(params); var sendResult = await this.sendMessage(reqParam);
if (sendResult.status == 1) {
this.redisClient.setWithEx(shaStr, 1, setCacheEx);
}
console.log(sendResult,"发送通知消息-----------------------------------------------");
return sendResult; return sendResult;
} }
async sendPhoneMsg(obj) { /**
* 发送消息模板
* @param {*} obj
{
titleTpl: [],
smsTpl: [],
siteTpl: [],
wechatTpl: [],
emailTpl: [],
phoneList: [],
subAccountList: [],
wechatList: [],
emailList: []
}
*/
async sendMessage(obj) {
var params = { var params = {
"version": 1, "version": 1,
"caller": "postman", "caller": "postman",
...@@ -81,24 +189,20 @@ class UtilsMsgSendService extends AppServiceBase { ...@@ -81,24 +189,20 @@ class UtilsMsgSendService extends AppServiceBase {
"ownerUin": 798950673, "ownerUin": 798950673,
"themeId": 364, "themeId": 364,
"tplParams": { "tplParams": {
"smsTpl": [ "titleTpl": obj.titleTpl,
obj.messageBody "smsTpl": obj.smsTpl,
] "siteTpl": obj.siteTpl,
"wechatTpl": obj.wechatTpl,
"emailTpl": obj.emailTpl
}, },
"receiver": { "receiver": {
"wechatList": [ "phoneList": obj.phoneList,
], "subAccountList": obj.subAccountList,
"phoneList": [ "wechatList": obj.wechatList,
obj.phoneNumber "emailList": obj.emailList
],
"emailList": [
],
"subAccountList": [
""
]
}, },
"lang": "zh", "lang": "zh",
"sendChannel": 4 "sendChannel": 5
} }
} }
} }
......
...@@ -56,6 +56,15 @@ class ExecClient { ...@@ -56,6 +56,15 @@ class ExecClient {
reqResult = system.getResult(null, "执行execPostTimeOutByBusiness存在错误"); reqResult = system.getResult(null, "执行execPostTimeOutByBusiness存在错误");
} }
reqResult.requestId = uuid.v1(); reqResult.requestId = uuid.v1();
if (result.headers) {
delete result["headers"];
}
if (result.request) {
delete result["request"];
}
if (result.config) {
delete result["config"];
}
this.execLogs(execFile + "执行execPostTimeOutByBusiness", params, params.identifyCode, reqResult, result); this.execLogs(execFile + "执行execPostTimeOutByBusiness", params, params.identifyCode, reqResult, result);
return reqResult; return reqResult;
} }
...@@ -86,19 +95,20 @@ class ExecClient { ...@@ -86,19 +95,20 @@ class ExecClient {
* @param {*} errorInfo 错误信息 * @param {*} errorInfo 错误信息
*/ */
async execLogs(opTitle, params, identifyCode, resultInfo, errorInfo) { async execLogs(opTitle, params, identifyCode, resultInfo, errorInfo) {
var reqUrl = settings.apiconfig.opLogUrl(); var reqUrl = settings.opLogUrl();
var param = { var param = {
"actionType": "produceLogsData",// Y 功能名称 actionType: "produceLogsData",// Y 功能名称
"actionBody": { actionBody: {
"opTitle": opTitle || "",// N 操作的业务标题 opTitle: opTitle || "",// N 操作的业务标题
"identifyCode": identifyCode || "brg-user-center",// Y 操作的业务标识 identifyCode: identifyCode || "brg-user-center",// Y 操作的业务标识
"messageBody": params, //日志的描述信息 indexName: "brg-user-center",// Y es索引值,同一个项目用一个值
"resultInfo": resultInfo,//返回信息 messageBody: params, //日志的描述信息
"errorInfo": errorInfo,//错误信息 resultInfo: resultInfo,//返回信息
"requestId": resultInfo.requestId || "" errorInfo: errorInfo,//错误信息
requestId: resultInfo.requestId || ""
} }
}; };
this.execPostTimeOut(params, reqUrl, 'application/json', null, 20); this.execPostTimeOut(param, reqUrl, 'application/json', null, 20);
} }
/** /**
* get请求 * get请求
...@@ -183,8 +193,25 @@ class ExecClient { ...@@ -183,8 +193,25 @@ class ExecClient {
if (!ContentType) { if (!ContentType) {
ContentType = "application/json"; ContentType = "application/json";
} }
var data = typeof params === 'object' ? JSON.stringify(params) : params; var data = null;
if (typeof params === 'object') {
// 声明cache变量,便于匹配是否有循环引用的情况
var cache = [];
data = JSON.stringify(params, function (key, value) {
if (typeof value === 'object' && value !== null) {
if (cache.indexOf(value) !== -1) {
// 移除
return;
}
// 收集所有的值
cache.push(value);
}
return value;
});
cache = null; // 清空变量,便于垃圾回收机制回收
} else {
data = params;
}
var cmdStr = "curl -k -H 'Content-type:" + ContentType + "'"; var cmdStr = "curl -k -H 'Content-type:" + ContentType + "'";
if (headData) { if (headData) {
var headDataKeys = Object.keys(headData); var headDataKeys = Object.keys(headData);
......
...@@ -7,26 +7,35 @@ var ENVINPUT = { ...@@ -7,26 +7,35 @@ var ENVINPUT = {
REDIS_HOST: process.env.REDIS_HOST, REDIS_HOST: process.env.REDIS_HOST,
REDIS_PORT: process.env.REDIS_PORT, REDIS_PORT: process.env.REDIS_PORT,
REDIS_PWD: process.env.REDIS_PWD, REDIS_PWD: process.env.REDIS_PWD,
DB_NAME: process.env.CENTER_CHANNEL_DB_NAME, DB_NAME: process.env.BRG_USER_CENTER_DB_NAME,
REDIS_DB: process.env.CENTER_CHANNEL_REDIS_DB, REDIS_DB: process.env.BRG_USER_CENTER_REDIS_DB,
APP_ENV: process.env.APP_ENV ? process.env.APP_ENV : "dev" APP_ENV: process.env.APP_ENV ? process.env.APP_ENV : "dev"
}; };
var settings = { var settings = {
env: ENVINPUT.APP_ENV, env: ENVINPUT.APP_ENV,
usertimeout: 3600,//单位秒 usertimeout: 3600,//单位秒
basepath: path.normalize(path.join(__dirname, '../..')), basepath: path.normalize(path.join(__dirname, '../..')),
port: process.env.NODE_PORT || 4011, port: process.env.NODE_PORT || 4011,
opLogUrl: function () {
apiconfig: { if (this.env == "dev" || this.env == "test") {
opLogUrl: function () { return "http://192.168.1.128:4019/api/queueAction/producer/springBoard";
return "http://60.205.209.94:4019/api/queueAction/producer/springBoard"; } else {
}, return "http://logs-sytxpublic-msgq-service/api/queueAction/producer/springBoard";
opPushUrl: function () { }
},
opPushUrl: function () {
if (this.env == "dev" || this.env == "test") {
return "http://192.168.1.128:4018/api/queueAction/producer/springBoard"; return "http://192.168.1.128:4018/api/queueAction/producer/springBoard";
}, } else {
deliveryUrl: function () { return "http://sytxpublic-msgq-service/api/queueAction/producer/springBoard";
}
},
deliveryUrl: function () {
if (this.env == "dev" || this.env == "test") {
return "http://tx.g.com:8000"; return "http://tx.g.com:8000";
}, } else {
return "http://tx.brg.tencentyun.com";
}
}, },
redis: function () { redis: function () {
if (this.env == "dev" || this.env == "test") { if (this.env == "dev" || this.env == "test") {
...@@ -60,6 +69,7 @@ var settings = { ...@@ -60,6 +69,7 @@ var settings = {
acquire: 90000000, acquire: 90000000,
idle: 1000000 idle: 1000000
}, },
timezone: '+08:00',
debug: false, debug: false,
dialectOptions: { dialectOptions: {
requestTimeout: 999999, requestTimeout: 999999,
......
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
"sequelize-cli": "^4.1.1", "sequelize-cli": "^4.1.1",
"serve-favicon": "^2.4.5", "serve-favicon": "^2.4.5",
"sha1": "^1.1.1", "sha1": "^1.1.1",
"sha256": "^0.2.0",
"socket.io": "^2.1.1", "socket.io": "^2.1.1",
"uuid": "^3.4.0" "uuid": "^3.4.0"
}, },
......
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment