Commit 7e3af1e1 by 庄冰

hebing

parents f4abece9 da7129e0
var WEBBase = require("../../web.base");
var system = require("../../../system");
var settings = require("../../../../config/settings");
class NameAPI extends WEBBase{
class NameAPI extends WEBBase {
constructor() {
super();
this.redisClient = system.getObject("util.redisClient");
......@@ -29,17 +29,17 @@ class NameAPI extends WEBBase{
opResult = await this.getCache();
break;
case "getPreference"://偏好
opResult=await this.getPreference();
opResult = await this.getPreference();
break;
case "createName"://起名
opResult =await this.addOrderDelivery(pobj,pobj.actionBody);
opResult = await this.addOrderDelivery(pobj, pobj.actionBody);
break;
case "getNameDetail"://详情
opResult = await this.getNameDetail(pobj);
break;
case "getNames"://详情
opResult = await this.getNames(pobj,pobj.actionBody);
break;
opResult = await this.getNames(req, pobj.actionBody);
break;
default:
opResult = system.getResult(null, "action_type参数错误");
break;
......@@ -51,7 +51,7 @@ class NameAPI extends WEBBase{
* 获取行业类别数据 後期可提出為一個service文件
* @returns {Promise<{}>}
*/
async getCache(){
async getCache() {
let cacheResult = {};
cacheResult.cache = cacheJson
return system.getResult(cacheResult);
......@@ -61,17 +61,17 @@ class NameAPI extends WEBBase{
* 获取偏好信息 後期可提出為一個service文件
* @returns {Promise<{}>}
*/
async getPreference(){
async getPreference() {
let preResult = {};
const key = 'qmbpreference';
let result = await this.redisClient.get(key)
if(result){
if (result) {
preResult.preference = JSON.parse(result);
return system.getResult(preResult);
}else{
const data = await this.restPostUrl({},this.centerCacheUrl+"preference_select");
if(data.code == 200){
await this.redisClient.set(key,JSON.stringify(data.data),2*3600)
} else {
const data = await this.restPostUrl({}, this.centerCacheUrl + "preference_select");
if (data.code == 200) {
await this.redisClient.set(key, JSON.stringify(data.data), 2 * 3600)
preResult.preference = data.data
return system.getResult(preResult);
}
......@@ -84,7 +84,7 @@ class NameAPI extends WEBBase{
* @param actionBody
* @returns {Promise<{msg: string, data: (*|null), bizmsg: *, status: number}|{msg: *, data: *, status: *}|{msg: *, data: (*|null), status: number}>}
*/
async addOrderDelivery(pobj,actionBody){
async addOrderDelivery(pobj, actionBody) {
if (!actionBody.orderId) {
return system.getResult(null, "orderId参数不能为空");
}
......@@ -106,46 +106,43 @@ class NameAPI extends WEBBase{
if (!actionBody.preference) {
return system.getResult(null, "preference参数不能为空");
}
await this.redisClient.set("ch"+JSON.stringify(actionBody.orderId),JSON.stringify(actionBody));
await this.redisClient.set("ch" + JSON.stringify(actionBody.orderId), JSON.stringify(actionBody));
return system.getResultSuccess();
}
//获取取名结果,并保存到数据库
async getNameDetail(pobj){
async getNameDetail(pobj) {
pobj.actionType = 'getOrderDeliveryInfo';
const opResult = await this.utilsOrderSve.getOrderDeliveryInfo(pobj, pobj.actionBody);
if(opResult.status != 0){
return system.getResult(null,opResult.msg);
const opResult = await this.utilsOrderSve.getOrderDeliveryInfo(pobj, pobj.actionBody);
if (opResult.status != 0) {
return system.getResult(null, opResult.msg);
}
if(opResult.data.hasOwnProperty('result_name')){
return system.getResult(opResult.data,'操作成功');
if (opResult.data.hasOwnProperty('result_name')) {
return system.getResult(opResult.data, '操作成功');
}
let actionBody =await this.redisClient.get('ch'+ JSON.stringify(pobj.actionBody.orderNo));
if(!actionBody){
let actionBody = await this.redisClient.get('ch' + JSON.stringify(pobj.actionBody.orderNo));
if (!actionBody) {
return system.getResult(null)
}
let nameResult = await this.restPostUrl(JSON.parse(actionBody),this.centerCacheUrl+"treasure_name");
if(nameResult.code == 200){
let nameResult = await this.restPostUrl(JSON.parse(actionBody), this.centerCacheUrl + "treasure_name");
if (nameResult.code == 200) {
pobj.actionType = 'addOrderDelivery';
pobj.actionBody = nameResult.data;
//取名结果存储
let result = await this.restPostUrl(pobj,this.centerOrderUrl + "action/nameOrder/springBoard");
return system.getResult(nameResult.data,"操作成功");
let result = await this.restPostUrl(pobj, this.centerOrderUrl + "action/nameOrder/springBoard");
return system.getResult(nameResult.data, "操作成功");
}
return system.getResult(null,'try again');
return system.getResult(null, 'try again');
}
async getNames(pobj,actionBody){
let rtn = await this.restClient.execPost(actionBody,this.aliGetNamesjavaUrl);
if (!rtn.stdout) {
return system.getResultFail();
}
var result = JSON.parse(rtn.stdout);
if(result) {
return system.getResultSuccess(result);
}
return system.getResultFail(result);
async getNames(req, actionBody) {
const result = await this.execPostByTimeOut(req, actionBody, this.aliGetNamesjavaUrl);
if (result.status != 0) {
return result;
}
const tmpData = result.data ? result.data.companyName : [];
return system.getResultSuccess(tmpData);
}
}
......@@ -153,7 +150,7 @@ const cacheJson = {
"科技类": ["网络科技", "电子商务", "信息技术", "游戏", "电子", "软件", "新材料", "生物科技", "教育科技", "环保科技", "信息科技"],
"许可类": ["投资管理", "金融", "资产", "商业保理", "融资租赁", "医疗器械", "人力资源", "食品", "劳务派遣"],
"服务类": ["广告", "文化传媒", "建筑装潢", "设计", "美容美发", "房地产中介", "物业管理", "商务咨询", "企业管理"],
"其他": ["贸易","实业","制造","服饰","化妆品","工程","农业","餐饮管理","物流"],
"其他": ["贸易", "实业", "制造", "服饰", "化妆品", "工程", "农业", "餐饮管理", "物流"],
}
......
......@@ -5,6 +5,7 @@ const md5 = require("MD5");
class WEBBase {
constructor() {
this.restClient = system.getObject("util.restClient");
this.execClientNew = system.getObject("util.execClientNew");
this.cacheManager = system.getObject("db.common.cacheManager");
this.logCtl = system.getObject("service.common.oplogSve");
this.toolSve = system.getObject("service.trademark.toolSve");
......@@ -68,10 +69,23 @@ class WEBBase {
async restPostUrl(pobj, url) {
var rtn = await this.restClient.execPost(pobj, url);
if (!rtn || !rtn.stdout) {
return system.getResult(null, "restPost data is empty");
return system.getResult(null, "restPost data is empty");
}
var result = JSON.parse(rtn.stdout);
return result;
}
}
/**
* 带超时时间的post请求
* @param {*} req 请求信息
* @param {*} params 请求数据-json格式
* @param {*} url 请求地址
* @param {*} ContentType 请求头类型,默认application/json
* @param {*} headData 请求头内容-json格式,如:请求头中传递token,格式:{token:"9098902q849q0434q09439"}
* @param {*} timeOut 超时时间
*/
async execPostByTimeOut(req, params, url, ContentType, headData, timeOut = 60) {
const result = await this.execClientNew.execPostTimeOutByBusiness('sve.base', params, url, ContentType, headData, timeOut, req);
return result;
}
}
module.exports = WEBBase;
......@@ -1252,17 +1252,6 @@ class UtilsOrderService extends AppServiceBase {
if (actionBody.quantity !=actionBody.deliveryData.nclones.length || Number(actionBody.quantity) !=actionBody.deliveryData.nclones.length) {
return system.getResult(null, "订单数量有误,100030");
}
pobj.actionType = "getProductDetail";
var url = settings.centerAppUrl() + "action/opProduct/springBoard";
var productItemResult = await this.restPostUrl(pobj, url);
if (productItemResult.status != 0) {
return productItemResult;
}
pobj.actionBody.product_info = productItemResult.data;
pobj.actionType = "getProductInterface";
pobj.actionBody.product_id = productItemResult.data.id;
var productItemInterfaceResult = await this.restPostUrl(pobj, url);
pobj.actionBody.product_info.interface_info = productItemInterfaceResult.data;
let nclones = actionBody.deliveryData.nclones;//大项集合
let product_item = [];//产品项
for(let i = 0;i < nclones.length ; i ++){
......@@ -1276,7 +1265,6 @@ class UtilsOrderService extends AppServiceBase {
actionBody.totalSum = 0;
actionBody.quantity = 1;
actionBody.deliveryData.nclones = [nclone]
var verifyResult = await this.isOrderVerify(pobj, pobj.actionBody);
actionBody.payTotalSum = actionBody.totalSum;
let saveResult = await this.addOrder(pobj,actionBody);
if(saveResult.status !=0){
......
......@@ -204,10 +204,12 @@ module.exports = function (app) {
app.use('/orderNotify/channelPayNotify', async function (req, res) {
try {
var client_ip = system.get_client_ip(req);
if (req.body.orderNo.startWith('CN')) {
var result = await utilsOrderSve.channelOrdersPayNotify(req.body, client_ip);
} else {
var result = await utilsOrderSve.channelPayNotify(req.body, client_ip);
let result ={};
const orderNo = req.body.orderNo;
if(orderNo.indexOf('CN') ==0){
result = await utilsOrderSve.channelOrdersPayNotify(req.body,client_ip);
}else{
result = await utilsOrderSve.channelPayNotify(req.body, client_ip);
}
logCtl.info({
optitle: (new Date()).Format("yyyy-MM-dd hh:mm:ss") + "渠道支付订单通知 api层",
......@@ -648,7 +650,7 @@ module.exports = function (app) {
//icp需求推送
app.post('/icp/consultation/submit', function (req, res) {
var p = null;
var params = ["icpnotify", "icpSubmitNeed", req.body, req.query, req];
var params = ["icpnotify","icpSubmitNeed",req.body,req.query,req];
// gname, methodname, pobj, query, req
var invokeObj = system.getObject("api.action.icpnotify");
if (invokeObj["doexecMethod"]) {
......@@ -662,7 +664,7 @@ module.exports = function (app) {
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];
var params = ["icpnotify","icpFeedbackSubmit",req.body,req.query,req];
// gname, methodname, pobj, query, req
var invokeObj = system.getObject("api.action.icpnotify");
if (invokeObj["doexecMethod"]) {
......@@ -676,7 +678,7 @@ module.exports = function (app) {
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];
var params = ["icpnotify","icpNotify",req.body,req.query,req];
// gname, methodname, pobj, query, req
var invokeObj = system.getObject("api.action.icpnotify");
if (invokeObj["doexecMethod"]) {
......
......@@ -60,7 +60,7 @@ var settings = {
},
aliGetNamesjavaUrl: function () {
if (this.env == "dev") {
return "192.168.210.240:80/getNames";
return "http://localhost:80/getNames";
} else {
return "http://aliossjava-service/getNames";
}
......
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