Commit 5ccbe000 by 宋毅

tj

parent 3e1c402f
...@@ -27,6 +27,8 @@ class ProductAPI extends APIBase { ...@@ -27,6 +27,8 @@ class ProductAPI extends APIBase {
switch (action_type) { switch (action_type) {
case "addOrder"://创建订单 case "addOrder"://创建订单
opResult = await this.utilsOrderSve.addOrder(pobj, pobj.actionBody); opResult = await this.utilsOrderSve.addOrder(pobj, pobj.actionBody);
await this.pushInfo(opResult, pobj, pobj.actionBody, "pushBusiness");
await this.pushInfo(opResult, pobj, pobj.actionBody, "pushOrder");
break; break;
case "getOrderInfo"://获取订单列表信息 case "getOrderInfo"://获取订单列表信息
opResult = await this.utilsOrderSve.getOrderInfo(pobj, pobj.actionBody); opResult = await this.utilsOrderSve.getOrderInfo(pobj, pobj.actionBody);
...@@ -43,5 +45,44 @@ class ProductAPI extends APIBase { ...@@ -43,5 +45,44 @@ class ProductAPI extends APIBase {
} }
return opResult; return opResult;
} }
async pushInfo(orderResult, pobj, actionBody, opType) {
if (orderResult.status != 0) {
return "";
}
var interface_list = actionBody.product_info.interface_info;
if (!interface_list) {
return "";
}
var interface_info = null;
var interface_list_temp = interface_list.filter(f => f.op_type == opType)
if (interface_list_temp && interface_list_temp.length > 0) {
interface_info = interface_list_temp[0];
}
if (!interface_info) {
return "";
}
pobj.actionBody.add_order_info = orderResult.data;
var refOpResult = this.reflexAction(interface_info, pobj);
return refOpResult;
}
async reflexAction(interface_info, pobj) {
var refResult = null;
if (interface_info.interface_type == "bd") {
if (!interface_info.method_name) {
return system.getResult(null, "产品接口参数信息有误,20110");
}//操作的方法名称
var invokeObj = system.getObject(interface_info.interface_url);
if (!invokeObj[interface_info.method_name]) {
return system.getResult(null, "产品接口参数方法信息有误,20130");
}
pobj.interface_params = interface_info.params;
var params = [pobj];
refResult = await invokeObj[interface_info.method_name].apply(invokeObj, params);
}
else if (interface_info.interface_type == "yc") {
}
return refResult;
}
} }
module.exports = ProductAPI; module.exports = ProductAPI;
\ No newline at end of file
...@@ -57,5 +57,46 @@ class AppServiceBase { ...@@ -57,5 +57,46 @@ class AppServiceBase {
var result = JSON.parse(rtn.stdout); var result = JSON.parse(rtn.stdout);
return result; return result;
} }
/*
返回20位业务订单号
prefix:业务前缀
*/
async getBusUid(prefix) {
prefix = (prefix || "");
if (prefix) {
prefix = prefix.toUpperCase();
}
var prefixlength = prefix.length;
var subLen = 8 - prefixlength;
var uidStr = "";
if (subLen > 0) {
uidStr = await this.getUidInfo(subLen, 60);
}
var timStr = moment().format("YYYYMMDDHHmm");
return prefix + timStr + uidStr;
}
/*
len:返回长度
radix:参与计算的长度,最大为62
*/
async getUidInfo(len, radix) {
var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');//长度62,到yz长度为长36
var uuid = [], i;
radix = radix || chars.length;
if (len) {
for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
} else {
var r;
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
uuid[14] = '4';
for (i = 0; i < 36; i++) {
if (!uuid[i]) {
r = 0 | Math.random() * 16;
uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
}
}
}
return uuid.join('');
}
} }
module.exports = AppServiceBase; module.exports = AppServiceBase;
var system = require("../../../system");
var settings = require("../../../../config/settings");
const AppServiceBase = require("../../app.base");
const logCtl = system.getObject("service.common.oplogSve");
const aliyunClient = system.getObject("util.aliyunClient");
class UtilsFqAliyunSve extends AppServiceBase {
constructor() {
super();
}
async pushBusiness(pobj) {
var add_order_info = pobj.actionBody.add_order_info;
if (pobj.appInfo.pay_type != "00") {
if (!add_order_info.orderStatus || Number(add_order_info.orderStatus) < 2) {
return "";
}
}
var orderContact = pobj.actionBody.orderContact;
var product_info = pobj.actionBody.product_info;
if (!pobj.interface_params) {
return "";
}
var interface_params_info = JSON.parse(pobj.interface_params);
if (!interface_params_info || !interface_params_info.opUrl || !interface_params_info.key || !interface_params_info.secret) {
return "";
}
var url = "https://yunfuapi-dev.gongsibao.com" + pobj.interface_params;
var params = {
idempotentId: add_order_info.orderNo,// 是 业务 ID
idempotentSource: product_info.service_business_code,// 是 业务来源(ic_jdyun、ic_ali)
idempotentSourceName: product_info.service_business_code,// 是 京东云应用、阿里云应用
city: "",// 否 所属城市
phone: orderContact.mobile,// 是 手机号
userId: pobj.userInfo.channelUserId,// 否 用户 ID
companyName: "",// 否 公司名称
orderPrice: pobj.actionBody.totalSum,// 是 订单金额
productId: product_info.price_item.service_code,// 是 产品 ID
productQuantity: pobj.actionBody.quantity,// 是 产品数量
};
var result = this.opAliyunClientPost("pushBusiness", interface_params_info.opUrl, interface_params_info.key, interface_params_info.secret, params);
}
async opAliyunClientPost(methodName, url, key, secret, params) {
try {
var rc = system.getObject("util.aliyunClient");
var rtn = = await rc.post(url, key, secret, params);
this.logCtl.info({
appid: pobj.appInfo.uapp_id,
appkey: pobj.appInfo.uappKey,
requestId: req.requestId || "",
op: "center-channel/app/base/service/impl/utilsSve/utilsFqAliyunSve.js/" + methodName,
content: "请求地址:" + url + ",参数:" + JSON.stringify(params) + ",返回结果:" + JSON.stringify(rtn),
clientIp: pobj.clientIp,
optitle: "推送订单商机到FQ信息--again",
});
if (rtn.code != 200 && rtn.success != true) {
return system.getResult(null, "推送失败,失败原因:" + rtn.errorMsg + ",selfrequestId=" + req.requestId + ",requestId=" + rtn.requestId);
}
return system.getResultSuccess(null, "推送成功");
} catch (e) {
//日志记录
this.logCtl.error({
appid: pobj.appInfo.uapp_id,
appkey: pobj.appInfo.uappKey,
requestId: req.requestId || "",
op: "center-channel/app/base/service/impl/utilsSve/utilsFqAliyunSve.js/" + methodName,
content: "error:" + e.stack,
clientIp: pobj.clientIp,
optitle: "推送操作出错->opAliyunClientPost",
});
}
}
}
module.exports = UtilsFqAliyunSve;
...@@ -46,13 +46,13 @@ class UtilsOrderService extends AppServiceBase { ...@@ -46,13 +46,13 @@ class UtilsOrderService extends AppServiceBase {
return system.getResult(null, "产品编码有误,10010"); return system.getResult(null, "产品编码有误,10010");
} }
if (!actionBody.payCode) { if (!actionBody.payCode) {
return system.getResult(null, "支付价格payCode有误,10030"); return system.getResult(null, "支付价格payCode不能为空,10030");
} }
if (!actionBody.quantity || Number(actionBody.quantity) <= 0) { if (!actionBody.quantity || Number(actionBody.quantity) <= 0) {
return system.getResult(null, "订单数量有误,10050"); return system.getResult(null, "订单数量为空或有误,10050");
} }
var url = settings.centerAppUrl() + "action/opProduct/springBoard";
pobj.actionType = "getProductDetail"; pobj.actionType = "getProductDetail";
var url = settings.centerAppUrl() + "action/opProduct/springBoard";
var productItemResult = await this.restPostUrl(pobj, url); var productItemResult = await this.restPostUrl(pobj, url);
if (productItemResult.status != 0) { if (productItemResult.status != 0) {
return productItemResult; return productItemResult;
...@@ -62,20 +62,18 @@ class UtilsOrderService extends AppServiceBase { ...@@ -62,20 +62,18 @@ class UtilsOrderService extends AppServiceBase {
if (verifyResult.status != 0) { if (verifyResult.status != 0) {
return verifyResult; return verifyResult;
} }
pobj.actionType = "getProductInterface"; pobj.actionType = "getProductInterface";
pobj.actionBody.productPriceId = pobj.actionBody.product_info.price_item.id; pobj.actionBody.productPriceId = pobj.actionBody.product_info.price_item.id;
var productItemInterfaceResult = await this.restPostUrl(pobj, url); var productItemInterfaceResult = await this.restPostUrl(pobj, url);
// if (productItemInterfaceResult.status != 0) { // if (productItemInterfaceResult.status != 0) {
// return productItemInterfaceResult; // return productItemInterfaceResult;
// } // }
productItemResult.data.interface_info = productItemInterfaceResult.data; pobj.actionBody.product_info.interface_info = productItemInterfaceResult.data;
pobj.actionType = "addOrder"; pobj.actionType = "addOrder";
var reqUrl = this.centerOrderUrl + "action/order/springBoard"; var reqUrl = this.centerOrderUrl + "action/order/springBoard";
console.log(pobj); console.log(pobj);
var result = await this.restPostUrl(pobj, reqUrl); var result = await this.restPostUrl(pobj, reqUrl);
result.serviceCode = pobj.actionBody.product_info.price_item.service_code;
result.totalSum = actionBody.totalSum; result.totalSum = actionBody.totalSum;
return result; return result;
} }
......
const Client = require('aliyun-api-gateway').Client; const Client = require('aliyun-api-gateway').Client;
var RPCClient = require('@alicloud/pop-core').RPCClient;
// const client = new Client('203756805', 'crkyej0xlmqa6bmvqijun6ltxparllyn');//开发
const client = new Client('203763771', 'e5e2ytnn6nrkr9qnqk4w5e6z0xlhkznu');//线上
class aliyunClient { class aliyunClient {
constructor() { constructor() {
// this.aliReqUrl = "https://aliapi.gongsibao.com/tm/springboard";
this.aliclient = new RPCClient({
accessKeyId: 'LTAI4FmyipY1wuLHjLhMWiPa',
accessKeySecret: 'hp4FF18IDCSym1prqzxrAjnnhNH3ju',
endpoint: 'https://trademark.aliyuncs.com',
apiVersion: '2018-07-24'
});
} }
async post(aliReqUrl, actionBody) { async post(aliReqUrl, key, secret, actionBody) {
// var reqParam = {}; const client = new Client(key, secret);
// reqParam["ActionProcess"] = "AliTm";
// reqParam["ActionType"] = actionType;
// reqParam["ActionBody"] = actionBody;
// if (!actionBody.reqOnlyCode) {
// actionBody["reqOnlyCode"] = await this.getCreateOrderNum();
// }
var param = { var param = {
data: actionBody, data: actionBody,
timeout: 20000, timeout: 20000,
...@@ -36,10 +18,15 @@ class aliyunClient { ...@@ -36,10 +18,15 @@ class aliyunClient {
} }
//阿里接口 //阿里接口
async reqbyget(obj, cbk) { async reqbyget(obj, cbk) {
var self = this; const aliclient = new RPCClient({
accessKeyId: 'LTAI4FmyipY1wuLHjLhMWiPa',
accessKeySecret: 'hp4FF18IDCSym1prqzxrAjnnhNH3ju',
endpoint: 'https://trademark.aliyuncs.com',
apiVersion: '2018-07-24'
});
var action = obj.action; var action = obj.action;
var reqbody = obj.reqbody; var reqbody = obj.reqbody;
return self.aliclient.request(action, reqbody, { return this.aliclient.request(action, reqbody, {
timeout: 3000, // default 3000 ms timeout: 3000, // default 3000 ms
formatAction: true, // default true, format the action to Action formatAction: true, // default true, format the action to Action
formatParams: true, // default true, format the parameter name to first letter upper case formatParams: true, // default true, format the parameter name to first letter upper case
...@@ -48,30 +35,5 @@ class aliyunClient { ...@@ -48,30 +35,5 @@ class aliyunClient {
}); });
} }
// async getCreateOrderNum() {
// var createOrderNum = await this.getUidStr(5, 36);//====================订单号生成
// return createOrderNum + "" + Date.now();
// }
// async getUidStr(len, radix) {
// var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
// var uuid = [], i;
// radix = radix || chars.length;
// if (len) {
// for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
// } else {
// var r;
// uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
// uuid[14] = '4';
// for (i = 0; i < 36; i++) {
// if (!uuid[i]) {
// r = 0 | Math.random() * 16;
// uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
// }
// }
// }
// return uuid.join('');
// }
} }
module.exports = aliyunClient; module.exports = aliyunClient;
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