Commit aa51c37a by 宋毅

增加订单推送状态修改

parent c0cc7f46
...@@ -7,14 +7,16 @@ const cryptoJS = require('crypto-js'); ...@@ -7,14 +7,16 @@ const cryptoJS = require('crypto-js');
class AppServiceBase { class AppServiceBase {
constructor() { constructor() {
this.dingClient = system.getObject("util.dingClient");
this.restClient = system.getObject("util.restClient"); this.restClient = system.getObject("util.restClient");
this.execClientNew = system.getObject("util.execClientNew"); this.execClientNew = system.getObject("util.execClientNew");
this.execClient = system.getObject('util.execClient'); this.execClient = system.getObject('util.execClient');
this.cacheManager = system.getObject("db.common.cacheManager"); this.cacheManager = system.getObject("db.common.cacheManager");
this.pushlogSve = system.getObject("service.common.pushlogSve"); this.pushlogSve = system.getObject("service.common.pushlogSve");
this.pushlogFailType = { OLDRPC: 1, NEWRPC: 2, FAILLOG: 3, FQ: 4 }; this.pushlogFailType = {OLDRPC: 1, NEWRPC: 2, FAILLOG: 3, FQ: 4};
this.logCtl = system.getObject("service.common.oplogSve"); this.logCtl = system.getObject("service.common.oplogSve");
} }
/** /**
* 验证签名 * 验证签名
* @param {*} params 要验证的参数 * @param {*} params 要验证的参数
...@@ -48,6 +50,7 @@ class AppServiceBase { ...@@ -48,6 +50,7 @@ class AppServiceBase {
} }
return system.getResultSuccess(); return system.getResultSuccess();
} }
async restPostUrl(pobj, url) { async restPostUrl(pobj, url) {
try { try {
var rtn = await this.restClient.execPost(pobj, url); var rtn = await this.restClient.execPost(pobj, url);
...@@ -71,6 +74,7 @@ class AppServiceBase { ...@@ -71,6 +74,7 @@ class AppServiceBase {
return system.getResult(null, errorMsg); return system.getResult(null, errorMsg);
} }
} }
async restPostWithHValueUrl(pobj, url, hValue) {//curl请求带请求头信息 async restPostWithHValueUrl(pobj, url, hValue) {//curl请求带请求头信息
try { try {
if (!hValue) { if (!hValue) {
...@@ -97,6 +101,7 @@ class AppServiceBase { ...@@ -97,6 +101,7 @@ class AppServiceBase {
return system.getResult(null, errorMsg); return system.getResult(null, errorMsg);
} }
} }
async restPostWithHAuthorizationUrl(pobj, userToken, url) {//curl请求带请求头信息 async restPostWithHAuthorizationUrl(pobj, userToken, url) {//curl请求带请求头信息
try { try {
var rtn = await this.restClient.restPostWithHAuthorizationUrl(userToken, url); var rtn = await this.restClient.restPostWithHAuthorizationUrl(userToken, url);
...@@ -120,6 +125,7 @@ class AppServiceBase { ...@@ -120,6 +125,7 @@ class AppServiceBase {
return system.getResult(null, errorMsg); return system.getResult(null, errorMsg);
} }
} }
async execPostUrl(pobj, url) { async execPostUrl(pobj, url) {
try { try {
var rtn = await this.execClient.execPost(pobj, url); var rtn = await this.execClient.execPost(pobj, url);
...@@ -143,6 +149,7 @@ class AppServiceBase { ...@@ -143,6 +149,7 @@ class AppServiceBase {
return system.getResult(null, errorMsg); return system.getResult(null, errorMsg);
} }
} }
async opAliyunRpcVerifyParam(pobj) {//参数信息验证 async opAliyunRpcVerifyParam(pobj) {//参数信息验证
var verify = system.getResultSuccess(); var verify = system.getResultSuccess();
if (!pobj.interface_params) { if (!pobj.interface_params) {
...@@ -155,6 +162,7 @@ class AppServiceBase { ...@@ -155,6 +162,7 @@ class AppServiceBase {
verify.data = interface_params_info; verify.data = interface_params_info;
return verify; return verify;
} }
/** /**
* 阿里RPC调用 * 阿里RPC调用
* @param {*} pobj {action: rpcParam.action,reqbody: pobj.actionBody,rpcParam: rpcParam} * @param {*} pobj {action: rpcParam.action,reqbody: pobj.actionBody,rpcParam: rpcParam}
...@@ -183,6 +191,7 @@ class AppServiceBase { ...@@ -183,6 +191,7 @@ class AppServiceBase {
return system.getResult(null, errorMsg); return system.getResult(null, errorMsg);
} }
} }
// /** // /**
// * 阿里RPC调用-post请求 // * 阿里RPC调用-post请求
// * @param {*} pobj {action: rpcParam.action,reqbody: pobj.actionBody,rpcParam: rpcParam} // * @param {*} pobj {action: rpcParam.action,reqbody: pobj.actionBody,rpcParam: rpcParam}
...@@ -219,41 +228,35 @@ class AppServiceBase { ...@@ -219,41 +228,35 @@ class AppServiceBase {
* @param {*} failType this.pushlogFailType * @param {*} failType this.pushlogFailType
*/ */
async disposePushResult(pobj, result, opTitleDesc, failType) {//处理结果信息--内部使用 async disposePushResult(pobj, result, opTitleDesc, failType) {//处理结果信息--内部使用
var opType = pobj.opType || ""; let opType = pobj.opType || "";
let content = JSON.stringify(pobj);
if (result.status != 0) { if (result.status != 0) {
this.pushlogSve.createFailLogDb({ return this.disposePushResultFail(pobj, result, opTitleDesc, failType);
appid: pobj.appInfo ? pobj.appInfo.uapp_id || "" : "",
appkey: pobj.appInfo ? pobj.appInfo.uapp_key || "" : "",
requestId: pobj.requestId || "",
content: JSON.stringify(pobj),//推送的参数信息
resultInfo: JSON.stringify(result),
clientIp: pobj.clientIp || "",
failType: failType || 3,
opTitle: opType + "推送操作失败->" + opTitleDesc,
pushNumber: pobj.pushNumber || 1
});
result.data = null;
return result;
} }
this.pushlogSve.createDb({ this.pushlogSve.createDb({
appid: pobj.appInfo ? pobj.appInfo.uapp_id || "" : "", appid: pobj.appInfo ? pobj.appInfo.uapp_id || "" : "",
appkey: pobj.appInfo ? pobj.appInfo.uapp_key || "" : "", appkey: pobj.appInfo ? pobj.appInfo.uapp_key || "" : "",
requestId: pobj.requestId || "", requestId: pobj.requestId || "",
op: "推送业务类型:" + opType, op: "推送业务类型:" + opType,
content: JSON.stringify(pobj),//推送的参数信息 content: content,//推送的参数信息
resultInfo: JSON.stringify(result), resultInfo: JSON.stringify(result),
returnType: '1', returnType: '1',
opTitle: opType + "数据推送成功->" + opTitleDesc opTitle: opType + "数据推送成功->" + opTitleDesc
}); });
// TODO 更改需求推送状态 // 更改需求推送状态
if (opType.indexOf('Need') >=0 && opType.indexOf('Business')>=0){ if (opType.indexOf('Need') >= 0 && opType.indexOf('Business') >= 0) {
pobj.actionType = 'updateNeedPushStatus'; pobj.actionType = 'updateNeedPushStatus';
let url = settings.centerOrderUrl() + 'action/opNeed/springBoard'; let url = settings.centerOrderUrl() + 'action/opNeed/springBoard';
let result = await this.execPostByTimeOut(null,pobj,url,null,null,60); this.execPostByTimeOut(null, pobj, url, null, null, 60);
}
if (["pushOrder", "pushOrderBusiness", "pushOrderICPBusiness"].includes(opType) && pobj.actionBody && pobj.actionBody.orderNo) {
pobj.actionBody.pushNumber = pobj.pushNumber || 1;
pobj.actionBody.pushStatus = 3;//推送状态0待推送2推送失败3已成功推送
this.disposeOrderPush(pobj);
} }
// result.data = null;
return result; return result;
} }
/** /**
* 处理失败的结果信息--内部使用 * 处理失败的结果信息--内部使用
* @param {*} pobj * @param {*} pobj
...@@ -263,20 +266,48 @@ class AppServiceBase { ...@@ -263,20 +266,48 @@ class AppServiceBase {
*/ */
async disposePushResultFail(pobj, result, opTitleDesc, failType) {//处理失败的结果信息--内部使用 async disposePushResultFail(pobj, result, opTitleDesc, failType) {//处理失败的结果信息--内部使用
var opType = pobj.opType || ""; var opType = pobj.opType || "";
let pushNumber = pobj.pushNumber || 1;
let resultInfo = JSON.stringify(result);
this.pushlogSve.createFailLogDb({ this.pushlogSve.createFailLogDb({
appid: pobj.appInfo ? pobj.appInfo.uapp_id || "" : "", appid: pobj.appInfo ? pobj.appInfo.uapp_id || "" : "",
appkey: pobj.appInfo ? pobj.appInfo.uapp_key || "" : "", appkey: pobj.appInfo ? pobj.appInfo.uapp_key || "" : "",
requestId: pobj.requestId || "", requestId: pobj.requestId || "",
content: JSON.stringify(pobj),//推送的参数信息 content: JSON.stringify(pobj),//推送的参数信息
resultInfo: JSON.stringify(result), resultInfo: resultInfo,
clientIp: pobj.clientIp || "", clientIp: pobj.clientIp || "",
failType: failType || 3, failType: failType || 3,
opTitle: opType + "推送操作失败->" + opTitleDesc, opTitle: opType + "推送操作失败->" + opTitleDesc,
pushNumber: pobj.pushNumber || 1 pushNumber: pushNumber
}); });
result.data = null; result.data = null;
if (pushNumber == 10 && resultInfo.indexOf("订单产品查询出来产品与传递得产品数量不一致,请重新选择") >= 0) {
pobj.actionBody.pushNumber = pushNumber;
pobj.actionBody.pushStatus = 2;//推送状态0待推送2推送失败3已成功推送
this.disposeOrderPushFailSendDing(pobj);
this.disposeOrderPush(pobj);
}
return result; return result;
} }
async disposeOrderPushFailSendDing(pobj) {
let params = {
orderNo: pobj.actionBody.orderNo,
city: pobj.actionBody.city,
area: pobj.actionBody.area,
companyCategory: pobj.actionBody.companyCategory,
appName: pobj.actionBody.appName,
sku: pobj.actionBody.sku,
error: "订单产品查询出来产品与传递得产品数量不一致,请重新选择!"
}
this.dingClient.businessPushFqByChannel(params);
}
async disposeOrderPush(pobj) {
pobj.actionType = 'updateOrderPushStatus';
let url = settings.centerOrderUrl() + 'action/order/springBoard';
this.execPostByTimeOut(null, pobj, url, null, null, 60);
}
async getAliossjavaFileUrl(pobj, params) {//上传ali oss 文件调用 async getAliossjavaFileUrl(pobj, params) {//上传ali oss 文件调用
var opType = pobj.opType || ""; var opType = pobj.opType || "";
try { try {
...@@ -329,7 +360,8 @@ class AppServiceBase { ...@@ -329,7 +360,8 @@ class AppServiceBase {
var rtn = await this.ossClient.upfile(upFileName, saveFilePath); var rtn = await this.ossClient.upfile(upFileName, saveFilePath);
result.data = rtn; result.data = rtn;
//删除本地文件 //删除本地文件
fs.unlink(saveFilePath, function (err) { }); fs.unlink(saveFilePath, function (err) {
});
} catch (e) { } catch (e) {
result.code = -200; result.code = -200;
result.message = "通过flowId获取到的文件url下载操作异常异常error"; result.message = "通过flowId获取到的文件url下载操作异常异常error";
...@@ -350,7 +382,7 @@ class AppServiceBase { ...@@ -350,7 +382,7 @@ class AppServiceBase {
var getProductInterfaceObj = { var getProductInterfaceObj = {
"actionType": "getProductInterface", "actionType": "getProductInterface",
"appInfo": appInfo, "appInfo": appInfo,
"actionBody": { "product_id": product_id } "actionBody": {"product_id": product_id}
}; };
var productItemInterfaceResult = await this.restPostUrl(getProductInterfaceObj, getProductInterfaceUrl); var productItemInterfaceResult = await this.restPostUrl(getProductInterfaceObj, getProductInterfaceUrl);
return productItemInterfaceResult; return productItemInterfaceResult;
...@@ -370,6 +402,7 @@ class AppServiceBase { ...@@ -370,6 +402,7 @@ class AppServiceBase {
} }
return result; return result;
} }
/* /*
返回20位业务订单号 返回20位业务订单号
prefix:业务前缀 prefix:业务前缀
...@@ -388,6 +421,7 @@ class AppServiceBase { ...@@ -388,6 +421,7 @@ class AppServiceBase {
var timStr = moment().format("YYYYMMDDHHmm"); var timStr = moment().format("YYYYMMDDHHmm");
return prefix + timStr + uidStr; return prefix + timStr + uidStr;
} }
/* /*
len:返回长度 len:返回长度
radix:参与计算的长度,最大为62 radix:参与计算的长度,最大为62
...@@ -411,11 +445,13 @@ class AppServiceBase { ...@@ -411,11 +445,13 @@ class AppServiceBase {
} }
return uuid.join(''); return uuid.join('');
} }
getUUID() { getUUID() {
var uuid = uuidv4(); var uuid = uuidv4();
var u = uuid.replace(/\-/g, ""); var u = uuid.replace(/\-/g, "");
return u; return u;
} }
/** /**
* 加密信息 * 加密信息
* @param {*} encrypt_key * @param {*} encrypt_key
...@@ -428,9 +464,10 @@ class AppServiceBase { ...@@ -428,9 +464,10 @@ class AppServiceBase {
} }
let keyHex = cryptoJS.enc.Utf8.parse(encrypt_key); let keyHex = cryptoJS.enc.Utf8.parse(encrypt_key);
let ivHex = cryptoJS.enc.Utf8.parse(encrypt_secret.substring(0, 8)); let ivHex = cryptoJS.enc.Utf8.parse(encrypt_secret.substring(0, 8));
var cipherStr = cryptoJS.TripleDES.encrypt(opStr, keyHex, { iv: ivHex }).toString(); var cipherStr = cryptoJS.TripleDES.encrypt(opStr, keyHex, {iv: ivHex}).toString();
return cipherStr; return cipherStr;
} }
/** /**
* 解密信息 * 解密信息
* @param {*} encrypt_key * @param {*} encrypt_key
...@@ -456,6 +493,7 @@ class AppServiceBase { ...@@ -456,6 +493,7 @@ class AppServiceBase {
return system.getResultFail(-200, "解密异常:" + opStr); return system.getResultFail(-200, "解密异常:" + opStr);
} }
} }
/** /**
* 带超时时间的post请求 * 带超时时间的post请求
* @param {*} req 请求信息 * @param {*} req 请求信息
...@@ -469,11 +507,12 @@ class AppServiceBase { ...@@ -469,11 +507,12 @@ class AppServiceBase {
const result = await this.execClientNew.execPostTimeOutByBusiness('sve.base', params, url, ContentType, headData, timeOut, req); const result = await this.execClientNew.execPostTimeOutByBusiness('sve.base', params, url, ContentType, headData, timeOut, req);
return result; return result;
} }
/** /**
* 验证签名 * 验证签名
* @param {*} params 要验证的参数 * @param {*} params 要验证的参数
* @param {*} app_secret 应用的校验key * @param {*} app_secret 应用的校验key
*/ */
async verifySign(params, app_secret) { async verifySign(params, app_secret) {
if (!params) { if (!params) {
return system.getResult(null, "请求参数为空"); return system.getResult(null, "请求参数为空");
...@@ -506,7 +545,8 @@ class AppServiceBase { ...@@ -506,7 +545,8 @@ class AppServiceBase {
} }
return system.getResultSuccess(); return system.getResultSuccess();
} }
async getFQbossSign(pobj){
async getFQbossSign(pobj) {
var signArr = []; var signArr = [];
var keys = Object.keys(pobj).sort(); var keys = Object.keys(pobj).sort();
for (let k = 0; k < keys.length; k++) { for (let k = 0; k < keys.length; k++) {
...@@ -519,4 +559,5 @@ class AppServiceBase { ...@@ -519,4 +559,5 @@ class AppServiceBase {
return md5(resultSignStr).toUpperCase(); return md5(resultSignStr).toUpperCase();
} }
} }
module.exports = AppServiceBase; module.exports = AppServiceBase;
const system = require("../system"); const system = require("../system");
class dingClient { class dingClient {
constructor() { constructor() {
this.execClient = system.getObject('util.execClient'); this.execClient = system.getObject('util.execClient');
this.gatewayurl = "https://oapi.dingtalk.com/robot/send?access_token=2f1ada261ea84f6c621db487ac18d11eba8984202bd82adda8810770a8240572" this.gatewayurl = "https://oapi.dingtalk.com/robot/send?access_token=2f1ada261ea84f6c621db487ac18d11eba8984202bd82adda8810770a8240572"
this.businessToFqUrl = "https://oapi.dingtalk.com/robot/send?access_token=9e215f0f1d77980ee6b39e88a82a7c6e5d290775f76d9a8346e97697f8df9788" this.businessToFqUrl = "https://oapi.dingtalk.com/robot/send?access_token=9e215f0f1d77980ee6b39e88a82a7c6e5d290775f76d9a8346e97697f8df9788"
} }
//推送峰擎异常提醒 //推送峰擎异常提醒
async gatewayPushError(err) { async gatewayPushError(err) {
if (process.env.APP_ENV === "prod") { if (process.env.APP_ENV === "prod") {
...@@ -20,7 +22,7 @@ class dingClient { ...@@ -20,7 +22,7 @@ class dingClient {
} }
//渠道钉钉提醒 //渠道钉钉提醒
async gatewayPushByChannel(orderNo,appInfo){ async gatewayPushByChannel(orderNo, appInfo) {
let gatewayUrl = setttings.dingRobotUrl(appInfo.uapp_id); let gatewayUrl = setttings.dingRobotUrl(appInfo.uapp_id);
if (settings.env != "dev" && gatewayUrl) { if (settings.env != "dev" && gatewayUrl) {
let c = `注意提醒:${appInfo.app_name}->有订单待处理,订单号${orderNo},老板们加油,加油,加油 !!!` let c = `注意提醒:${appInfo.app_name}->有订单待处理,订单号${orderNo},老板们加油,加油,加油 !!!`
...@@ -33,16 +35,17 @@ class dingClient { ...@@ -33,16 +35,17 @@ class dingClient {
}); });
} }
} }
//渠道订单到峰擎--sku没有查询到 //渠道订单到峰擎--sku没有查询到
async businessPushFqByChannel(params){ async businessPushFqByChannel(params) {
if (process.env.APP_ENV != "dev") { if (process.env.APP_ENV != "dev") {
let c = `注意提醒:${appInfo.app_name}->有订单待处理,sku为空,参数:${JSON.stringify(params)},老板们加油,加油,加油 !!!` let c = `注意提醒:${appInfo.app_name}->有订单待处理,渠道下sku查询不到,参数:${JSON.stringify(params)},老板们加油,加油,加油 !!!`
let t = new Date().toLocaleString() let t = new Date().toLocaleString()
this.execClient.execPost({ this.execClient.execPost({
"msgtype": "text", "msgtype": "text",
"text": {"content": t + c}, "text": {"content": t + c},
at: { at: {
atMobiles: ["13051727697","13453222948","18201231253"]//孟令强、王斌、郭峰 atMobiles: ["13051727697", "13453222948", "18201231253"]//孟令强、王斌、郭峰
}, },
}, this.businessToFqUrl).catch(err => { }, this.businessToFqUrl).catch(err => {
console.log(err) console.log(err)
...@@ -50,4 +53,5 @@ class dingClient { ...@@ -50,4 +53,5 @@ class dingClient {
} }
} }
} }
module.exports = dingClient; module.exports = dingClient;
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