Commit b5d893cb by 庄冰

baiduIcp

parent 1b928dbe
var APIBase = require("../../api.base");
var system = require("../../../system");
var settings = require("../../../../config/settings");
const uuidv4 = require('uuid/v4');
/**
* icp通知接口(百度icp接入)
* 庄冰 2020.10.22
*/
class IcpNotify extends APIBase {
constructor() {
super();
this.gatewaypushlogSve = system.getObject("service.common.gatewaypushlogSve");
}
getUUID() {
var uuid = uuidv4();
var u = uuid.replace(/\-/g, "");
return u;
}
getResultSuccess(requestId) {
return {
"requestId": requestId,
"success": true,
"errorMsg": "",
"errorCode": "ok"
}
}
getResultFail(errmsg) {
var self = this;
return {
"requestId": self.getUUID(),
"success": false,
"errorMsg": errmsg,
"errorCode": "ok"
};
}
//icp需求提交
async icpSubmitNeed(pobj,obj,req) {
var self = this;
if(!pobj.appInfo || !pobj.appInfo.uapp_key || !pobj.appInfo.uapp_secret){
return self.getResultFail("未知应用或应用未启用");
}
if (!pobj.intentionBizId) {
return self.getResultFail("intentionBizId不能为空");
}
if (!pobj.phone) {
return self.getResultFail("mobile不能为空");
}
if (!pobj.consultType) {
return self.getResultFail("consultType不能为空");
}
pobj.type = pobj.consultType;
pobj.mobile = pobj.phone;
pobj.action_type = "submitIcpNeed";
if (pobj.area) {
switch (pobj.area) {
case "1":
pobj.area = "北京";
break;
case "2":
pobj.area = "上海";
break;
case "3":
pobj.area = "福建";
break;
case "4":
pobj.area = "广西";
break;
case "5":
pobj.area = "广东";
break;
case "6":
pobj.area = "安徽";
break;
case "7":
pobj.area = "河南";
break;
case "8":
pobj.area = "湖北";
break;
case "9":
pobj.area = "浙江";
break;
case "10":
pobj.area = "江苏";
break;
case "11":
pobj.area = "山东";
break;
case "12":
pobj.area = "陕西";
break;
case "13":
pobj.area = "宁夏";
break;
case "14":
pobj.area = "甘肃";
break;
case "15":
pobj.area = "新疆";
break;
case "16":
pobj.area = "青海";
break;
case "17":
pobj.area = "天津";
break;
case "18":
pobj.area = "重庆";
break;
case "19":
pobj.area = "河北";
break;
case "20":
pobj.area = "山西";
break;
case "21":
pobj.area = "辽宁";
break;
case "22":
pobj.area = "吉林";
break;
case "23":
pobj.area = "黑龙江";
break;
case "24":
pobj.area = "江西";
break;
case "25":
pobj.area = "湖南";
break;
case "26":
pobj.area = "四川";
break;
case "27":
pobj.area = "贵州";
break;
case "28":
pobj.area = "云南";
break;
case "29":
pobj.area = "内蒙古";
break;
case "30":
pobj.area = "西藏";
break;
case "31":
pobj.area = "含外资";
break;
case "32":
pobj.area = "全外资";
break;
case "33":
pobj.area = "香港";
break;
case "34":
pobj.area = "海南";
break;
default:
pobj.area = "";
break;
}
}
if (!pobj.area) {
return self.getResultFail("area参数错误");
}
var param = {
requestId: req.requestId || self.getUUID(),
requestUrl: "/icp/consultation/submit",
requestjson: JSON.stringify(pobj),//请求地址
pushUrl: "/action/intentionapi/springBoard",//调用地址
pushActionType: "submitIcpNeed",//调用参数
pushtimes: 0,//推送次数
pushStatus: "wts",//推送状态
}
await self.gatewaypushlogSve.create(param);
return self.getResultSuccess(param.requestId);
}
//icp需求反馈
async icpFeedbackSubmit(pobj,obj,req) {
var self = this;
if(!pobj.appInfo || !pobj.appInfo.uapp_key || !pobj.appInfo.uapp_secret){
return self.getResultFail("未知应用或应用未启用");
}
if (!pobj.intentionBizId) {
return self.getResultFail("intentionBizId不能为空");
}
if (!pobj.description) {
return self.getResultFail("description不能为空");
}
if (!pobj.intentionStatus) {
return self.getResultFail("intentionStatus不能为空");
}
var param = {
requestId: req.requestId || self.getUUID(),
requestUrl: "/icp/feedback/submit",
requestjson: JSON.stringify(pobj),//请求地址
pushUrl: "/action/intentionapi/springBoard",//调用地址
pushActionType: "icpFeedbackSubmit",//调用参数
pushtimes: 0,//推送次数
pushStatus: "wts",//推送状态
}
await self.gatewaypushlogSve.create(param);
return self.getResultSuccess(param.requestId);
}
//icp状态变更
async icpNotify(pobj,obj,req) {
var self = this;
if(!pobj.appInfo || !pobj.appInfo.uapp_key || !pobj.appInfo.uapp_secret){
return self.getResultFail("未知应用或应用未启用");
}
if (!pobj.orderNo) {
return self.getResultFail("orderNo不能为空");
}
if(!pobj.isDirectBuy || pobj.isDirectBuy=="0"){
pobj.isDirectBuy=0;
}
pobj.status = 1;
if (pobj.isDirectBuy==0 && !pobj.bizId) {
return self.getResultFail("非直接下单bizId不能为空");
}
if (pobj.isDirectBuy==1 && !pobj.phone) {
return self.getResultFail("直接下单phone不能为空");
}
if (pobj.isDirectBuy==1 && !pobj.consultType) {
return self.getResultFail("直接下单consultType不能为空");
}
pobj.action_type = "icpOrderStatus";
var param = {
requestId: req.requestId || self.getUUID(),
requestUrl: "/icp/order/notify",
requestjson: JSON.stringify(pobj),//请求地址
pushUrl: "/action/intentionapi/springBoard",//调用地址
pushActionType: "icpNotifyNew",//调用参数
pushtimes: 0,//推送次数
pushStatus: "wts",//推送状态
}
await self.gatewaypushlogSve.create(param);
return self.getResultSuccess(param.requestId);
}
}
module.exports = IcpNotify;
\ No newline at end of file
...@@ -91,6 +91,21 @@ class Need extends APIBase { ...@@ -91,6 +91,21 @@ class Need extends APIBase {
case "testsymq": case "testsymq":
opResult = await this.utilsNeedSve.testsymq(pobj); opResult = await this.utilsNeedSve.testsymq(pobj);
break; break;
//-----------接入百度ICP------start----zhuangbing--2020.10.22----------------------------
case "submitIcpNeed"://提交需求
opResult = await this.utilsNeedSve.submitNeed2(pobj, pobj.actionBody);
break;
case "icpFeedbackSubmitNew"://icp接收方案反馈信息
pobj.actionType = "receiveIcpFeedback";
opResult = await this.utilsNeedSve.reqCenterOrderQcApi(pobj);
break;
case "icpNotifyNew"://icp方案更新
opResult = await this.utilsNeedSve.icpNotifyNew(pobj, pobj.actionBody);
if (opResult.status == 0 && pobj.actionBody.status == 1) {
opResult = await self.centerorderSve.icppaysuccessNew(pobj, pobj.actionBody);
}
break;
//-----------接入百度ICP------end----------------------------------
default: default:
opResult = system.getResult(null, "action_type参数错误"); opResult = system.getResult(null, "action_type参数错误");
break; break;
......
...@@ -538,6 +538,101 @@ class CenterorderService extends AppServiceBase { ...@@ -538,6 +538,101 @@ class CenterorderService extends AppServiceBase {
return system.getResult(null, "生成logo操作异常"); return system.getResult(null, "生成logo操作异常");
} }
} }
//-----------接入百度ICP------start-------zhuangbing--2020.10.22-------------------------
async icppaysuccessNew(pobj) {
var sobj = {
actionType: "getaliicpProduce",
// actionBody: { typeCode: itemResult.data.channelTypeCode, province: itemResult.data.province },
actionBody: { typeCode: pobj.actionBody.channelTypeCode, province: pobj.actionBody.province },
appInfo: pobj.appInfo,
actionProcess: pobj.actionProcess
}
var url = settings.centerAppUrl() + "action/opProduct/springBoard";
var rtn = await this.execClient.execPost(sobj, url);
if (!rtn || !rtn.stdout) {
return system.getResultFail(-5010, "产品查询失败");
}
var data = JSON.parse(rtn.stdout);
if (data.status != 0) {
return system.getResultFail(-5010, "产品查询失败");
}
// pobj.actionBody = data.data;
// pobj.actionBody.orderNo = pobj.actionBody.bizId;
pobj.actionBody.totalSum = data.data.price;
pobj.actionBody.orderPrice = data.data.price;
pobj.actionBody.payTotalSum = data.data.price;
pobj.actionBody.payCode = data.data.payCode;
pobj.actionBody.channelItemCode = data.data.channelItemCode;
pobj.actionBody.channelNeedNo = data.data.channelNeedNo;
pobj.actionBody.needNo = data.data.needNo;
pobj.actionBody.quantity = 1;
pobj.actionBody.channelOrder = {
channelServiceNo: pobj.actionBody.orderNo,
channelOrderNo: pobj.actionBody.orderNo,
orderStatus: 2
}
var orderrtn = await this.utilsOrderSve.addOrder(pobj, pobj.actionBody);
if (orderrtn.status != 0 && orderrtn.status != -1) {
return system.getResultFail(-5012, "订单创建失败");
}
if (orderrtn.data) {
pobj.actionBody.orderNo = orderrtn.data.orderNo;
}
pobj.actionBody.channelSolutionNo = pobj.actionBody.bizId;
pobj.actionType = "receiveSolutionPayInfo";
var url = settings.centerOrderUrl() + "action/icapi/springBoard";
var solutionrtn = await this.execClient.execPost(pobj, url);
if (!solutionrtn || !solutionrtn.stdout) {
return system.getResultFail(-5011, "方案查询失败");
}
var solutiondata = JSON.parse(solutionrtn.stdout);
if (solutiondata.status != 0) {
return system.getResultFail(-5011, "方案查询失败");
}
if (!solutiondata.data) {
return system.getResultFail(-5012, "方案查询数据为空");
}
if (solutiondata.data && solutiondata.data.channelNeedNo) {
pobj.actionBody.needId = solutiondata.data.channelNeedNo;
}
if (pobj.actionBody.channelItemCode == '5') {
pobj.actionBody.regType = "baidu.icp";
} else if (pobj.actionBody.channelItemCode == '7') {
pobj.actionBody.regType = "baidu.edi";
}
var fqobj = {
actionBody: {
area: pobj.actionBody.province,
city: pobj.actionBody.province,
regType: pobj.actionBody.regType,
orderNo: pobj.actionBody.channelOrder.channelOrderNo,
orderPrice: Number(pobj.actionBody.orderPrice / 100),
phone: pobj.actionBody.publishMobile,
needId: solutiondata.data.channelNeedNo,
companyName:solutiondata.data.solutionContent.solution.CompanyName || ''
},
appInfo: pobj.appInfo
}
var deliveryObj = {
actionBody: {
orderNo: orderrtn.data.orderNo,//pobj.actionBody.channelOrder.channelOrderNo,
needsolution: solutiondata.data.solutionContent,
channelNeedNo: solutiondata.data.channelNeedNo,
channelSolutionNo: solutiondata.data.channelSolutionNo,
skuCode: data.data.payCode,
servicer: {
code: 'gsb',
name: '公司宝'
}
},
appInfo: pobj.appInfo
}
this.utilsPushSve.aliBusiness2Fq(fqobj, "pushOrderICPBusiness");
this.utilsPushSve.aliBusiness2Delivery(deliveryObj, "pushDeliveryOrder");
return system.getResultSuccess();
}
} }
module.exports = CenterorderService; module.exports = CenterorderService;
// var task = new CenterorderService(); // var task = new CenterorderService();
......
...@@ -98,7 +98,6 @@ class UtilsNeedService extends AppServiceBase { ...@@ -98,7 +98,6 @@ class UtilsNeedService extends AppServiceBase {
} }
//调用center-order icp需求反馈 //调用center-order icp需求反馈
async reqCenterOrderQcApi(pobj, reqUrl) { async reqCenterOrderQcApi(pobj, reqUrl) {
var url = this.centerOrderUrl + "action/qcapi/springBoard"; var url = this.centerOrderUrl + "action/qcapi/springBoard";
...@@ -1304,6 +1303,135 @@ class UtilsNeedService extends AppServiceBase { ...@@ -1304,6 +1303,135 @@ class UtilsNeedService extends AppServiceBase {
} }
return rtn return rtn
} }
//-----------接入百度ICP------start--------zhuangbing----2020.10.22----------------------
/**
* 提交需求
* @param {*} pobj
* @param {*} actionBody
*/
async submitNeed2(pobj, actionBody) {
if(actionBody.type == "esp.wangwen" || actionBody.type == "esp.food") {
actionBody.area = this.wangwenAreaChange(actionBody.area)
}
if (!actionBody.intentionBizId) {
return system.getResult(null, "actionBody.intentionBizId can not be empty,100380");
}
var sobj = pobj;
sobj.actionType = "getProductTypeInfo";
var url = settings.centerAppUrl() + "action/opProduct/springBoard";
var rtn = await this.execClient.execPost(sobj, url);
if (!rtn || !rtn.stdout) {
return system.getResultFail(-5015, "需求類型查询失败");
}
var data = JSON.parse(rtn.stdout);
if (data.status != 0) {
return system.getResultFail(-5015, "需求類型查询失败");
}
pobj.actionBody.type_code = data.data.type_code;
pobj.actionBody.type_name = data.data.type_name;
pobj.actionBody.channel_type_code = data.data.channel_type_code;
pobj.actionBody.channel_type_name = data.data.channel_type_name;
pobj.actionBody.type = pobj.actionBody.channel_type_code;
if (pobj.actionBody.channel_type_code == 5) {
pobj.actionBody.type = "baidu.icp";
} else if (pobj.actionBody.channel_type_code == 7) {
pobj.actionBody.type = "baidu.edi";
} else if (pobj.actionBody.channel_type_code == "tmjy") {
pobj.actionBody.type = "baidu.tmd";
}
if (pobj.actionBody.description && pobj.actionBody.description.indexOf("备#") < 0) {
pobj.actionBody.level = "A";
} else {
var levelurl = "http://106.13.228.212:8000/recProbability";
var levelresult = await this.restPostUrl({ intentionBizId: pobj.actionBody.intentionBizId, type: pobj.actionBody.type, note: pobj.actionBody.description }, levelurl);
if (levelresult.status == 0) {
pobj.actionBody.level = levelresult.data.level;
pobj.actionBody.probability = levelresult.data.per;
} else {
pobj.actionBody.level = "C"
}
}
if(pobj.actionBody.phone=="17319425791"){
pobj.actionBody.level = "F";
}
pobj.actionType = "submitNeed";
var reqUrl = this.centerOrderUrl + "action/need/springBoard";
var result = await this.restPostUrl(pobj, reqUrl);
if (result.status == 0) {
if (pobj.actionBody.channel_type_code == "esp.companyreg") {
this.utilsPushSve.aliBusiness2Fq(pobj, "pushNeedBusiness");
} else {
var reqParams = {
actionBody: pobj.actionBody,
appInfo: pobj.appInfo
}
this.utilsPushSve.aliBusiness2Delivery(reqParams, "addChance");
pobj.actionBody.description = pobj.actionBody.description + " 成交概率:" + pobj.actionBody.level
if (pobj.actionBody.probability) {
pobj.actionBody.description = pobj.actionBody.description + "(" + pobj.actionBody.probability + ") "
}
this.utilsPushSve.aliBusiness2Fq(pobj, "pushNeedICPBusiness");
}
}
return result;
}
//状态更新
async icpNotifyNew(pobj) {
var actionBody = pobj.actionBody;
var self = this;
if (!actionBody.bizId) {
return system.getResult(null, "actionBody.bizId can not be empty,100495");
}
actionBody.BizId = actionBody.bizId;
if (!actionBody.status) {
return system.getResult(null, "actionBody.status can not be empty,100495");
}
pobj.actionType = "receiveIcpStatusNotify";
var url = settings.centerOrderUrl() + "action/qcapi/springBoard";
var rtn = await this.restPostUrl(pobj, url);
if (actionBody.status == 2) {
var deliveryObj = {
actionBody: {
orderNo: rtn.data.orderNo,//pobj.actionBody.channelOrder.channelOrderNo,
needsolution: rtn.data.solutionContent,
channelNeedNo: rtn.data.channelNeedNo,
channelSolutionNo: rtn.data.channelSolutionNo,
servicer: {
code: 'gsb',
name: '公司宝'
}
},
appInfo: pobj.appInfo
}
this.utilsPushSve.aliBusiness2Delivery(deliveryObj, "pushDeliveryOrder");
}
if (rtn.status == 0 && actionBody.status != 1 && actionBody.status != 2 && rtn.data) {
var tmpObj = {
actionBody: {
orderNo: rtn.data.orderNo,
channelNeedNo: rtn.data.channelNeedNo,
needsolution: rtn.data.solutionContent
},
appInfo: pobj.appInfo
}
this.utilsPushSve.aliBusiness2Delivery(tmpObj, "pushDeliveryStatusNotify");
pobj.actionBody.orderNo = rtn.data.orderNo;
if (actionBody.status == 11) {
var orderrtn = await self.utilsOrderSve.delOrder(pobj, pobj.actionBody);
if (orderrtn.status < 0) {
return system.getResultFail(-5022, "订单关闭失败");
}
tmpObj.actionBody.orderNo = rtn.data.channelSolutionNo;
self.utilsPushSve.aliBusiness2Fq(tmpObj, "pushOrderICPClose");
}
}//通知更新状态
return rtn;
}
//-----------接入百度ICP------end----------------------------------
} }
module.exports = UtilsNeedService; module.exports = UtilsNeedService;
......
...@@ -492,4 +492,80 @@ module.exports = function (app) { ...@@ -492,4 +492,80 @@ module.exports = function (app) {
}); });
//-----------------------新的模式---------api---------结束 //-----------------------新的模式---------api---------结束
//-----------------------新的模式---------ICP---------开始
app.all("/icp/*", async function (req, res, next) {
var result = system.getResult(null, "req method must is post");
if (req.method != "POST") {
res.end(JSON.stringify(result));
return;
}
var token = req.headers["token"] || "";
if (!token) {
var resfail = {
"success": false,
"errorMsg": "req headers token can not be empty",
"errorCode": "ok"
};
res.end(JSON.stringify(resfail));
return;
}
var cacheManager = system.getObject("db.common.cacheManager");
var result = await cacheManager["AppTokenByHostsCache"].getCache(token, system.exTime);
if (result.status != 0) {
var resfail = {
"success": false,
"errorMsg": result.msg || "token error",
"errorCode": "ok"
};
res.end(JSON.stringify(resfail));
// res.end(JSON.stringify(result));
return;
}
req.appInfo = result.data;
req.body.appInfo = result.data;
req.actionProcess = result.data.app_code;
next();
});
//icp需求推送
app.post('/icp/consultation/submit', function (req, res) {
var p = null;
var params = ["icpnotify","icpSubmitNeed",req.body,req.query,req];
// gname, methodname, pobj, query, req
var invokeObj = system.getObject("api.action.icpnotify");
if (invokeObj["doexecMethod"]) {
p = invokeObj["doexecMethod"].apply(invokeObj, params);
}
p.then(r => {
res.end(JSON.stringify(r));
});
});
//⽤户反馈需求通知服务商
app.post('/icp/feedback/submit', function (req, res) {
var p = null;
req.body.action_type = "icpFeedbackSubmit";
var params = ["icpnotify","icpFeedbackSubmit",req.body,req.query,req];
// gname, methodname, pobj, query, req
var invokeObj = system.getObject("api.action.icpnotify");
if (invokeObj["doexecMethod"]) {
p = invokeObj["doexecMethod"].apply(invokeObj, params);
}
p.then(r => {
res.end(JSON.stringify(r));
});
});
//推送订单信息
app.post('/icp/order/notify', function (req, res) {
var p = null;
req.body.action_type = "icpNotify";
var params = ["icpnotify","icpNotify",req.body,req.query,req];
// gname, methodname, pobj, query, req
var invokeObj = system.getObject("api.action.icpnotify");
if (invokeObj["doexecMethod"]) {
p = invokeObj["doexecMethod"].apply(invokeObj, params);
}
p.then(r => {
res.end(JSON.stringify(r));
});
});
//-----------------------新的模式---------ICP---------结束
}; };
\ No newline at end of file
...@@ -151,7 +151,7 @@ var settings = { ...@@ -151,7 +151,7 @@ var settings = {
}, },
gatewayUrl: function () { gatewayUrl: function () {
if (this.env == "dev") { if (this.env == "dev") {
return "http://192.168.0.106:4005/"; return "http://localhost:4005/";
} else { } else {
return "https://channelgateway-api.gongsibao.com/"; return "https://channelgateway-api.gongsibao.com/";
} }
......
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