Commit 32765cbf by linboxuan

lin add productType

parent 5040f82b
...@@ -2,62 +2,71 @@ var WEBBase = require("../../web.base"); ...@@ -2,62 +2,71 @@ var WEBBase = require("../../web.base");
var system = require("../../../system"); var system = require("../../../system");
var settings = require("../../../../config/settings"); var settings = require("../../../../config/settings");
class ProductAPI extends WEBBase { class ProductAPI extends WEBBase {
constructor() { constructor() {
super(); super();
this.utilsProductSve = system.getObject("service.utilsSve.utilsProductSve"); this.utilsProductSve = system.getObject("service.utilsSve.utilsProductSve");
this.utils360Sve = system.getObject("service.utilsSve.utils360Sve"); this.utils360Sve = system.getObject("service.utilsSve.utils360Sve");
}
/**
* 接口跳转-POST请求
* action_process 执行的流程
* action_type 执行的类型
* action_body 执行的参数
*/
async springBoard(pobj, qobj, req) {
if (!pobj.actionProcess) {
return system.getResult(null, "actionProcess参数不能为空");
} }
/** if (!pobj.actionType) {
* 接口跳转-POST请求 return system.getResult(null, "actionType参数不能为空");
* action_process 执行的流程
* action_type 执行的类型
* action_body 执行的参数
*/
async springBoard(pobj, qobj, req) {
if (!pobj.actionProcess) {
return system.getResult(null, "actionProcess参数不能为空");
}
if (!pobj.actionType) {
return system.getResult(null, "actionType参数不能为空");
}
var result = await this.opActionProcess(pobj, pobj.actionType, req);
return result;
} }
async opActionProcess(pobj, action_type, req) { var result = await this.opActionProcess(pobj, pobj.actionType, req);
var opResult = null; return result;
switch (action_type) { }
case "getProductList"://通过产品类别编码路径获取产品列表 async opActionProcess(pobj, action_type, req) {
opResult = await this.utilsProductSve.getProductList(pobj, pobj.actionBody); var opResult = null;
break; switch (action_type) {
case "getProductListH5"://通过产品类别编码路径获取产品列表 case "getProductList"://通过产品类别编码路径获取产品列表
opResult = await this.utilsProductSve.getProductListH5(pobj, pobj.actionBody); opResult = await this.utilsProductSve.getProductList(pobj, pobj.actionBody);
break; break;
case "getProductDetail"://根据渠道产品编码获取产品详情 case "getProductListH5"://通过产品类别编码路径获取产品列表
opResult = await this.utilsProductSve.getProductDetail(pobj, pobj.actionBody); opResult = await this.utilsProductSve.getProductListH5(pobj, pobj.actionBody);
break; break;
case "getProductPrice": case "getProductDetail"://根据渠道产品编码获取产品详情
opResult = await this.utilsProductSve.getProductPrice(pobj,pobj.actionBody) opResult = await this.utilsProductSve.getProductDetail(pobj, pobj.actionBody);
break; break;
case "getProductRecommend": case "getProductPrice":
opResult = await this.utilsProductSve.getProductRecommend(pobj,pobj.actionBody); opResult = await this.utilsProductSve.getProductPrice(pobj, pobj.actionBody)
break; break;
// case "updateProductPrice": case "getProductRecommend":
// opResult = await this.utilsProductSve.updateProductPrice(pobj,pobj.actionBody); opResult = await this.utilsProductSve.getProductRecommend(pobj, pobj.actionBody);
// break; break;
case "getGoodsLowestPrice": // case "updateProductPrice":
opResult = await this.utils360Sve.getGoodsLowestPrice(pobj.actionBody); // opResult = await this.utilsProductSve.updateProductPrice(pobj,pobj.actionBody);
break; // break;
case "getRegProducePrice": case "getGoodsLowestPrice":
opResult = await this.utilsProductSve.getRegProducePrice(pobj,pobj.actionBody) opResult = await this.utils360Sve.getGoodsLowestPrice(pobj.actionBody);
break; break;
case "getAllProducts": case "getRegProducePrice":
opResult = await this.utilsProductSve.getAllProducts(pobj); opResult = await this.utilsProductSve.getRegProducePrice(pobj, pobj.actionBody)
break; break;
default: case "getAllProducts":
opResult = system.getResult(null, "action_type参数错误"); opResult = await this.utilsProductSve.getAllProducts(pobj);
} break;
return opResult; case "getAllProductType":// 获取产品大类
opResult = await this.utilsProductSve.getAllProductType(pobj);
break;
case "submitProductType":// 创建产品大类
opResult = await this.utilsProductSve.submitProductType(pobj);
break;
case "editProductType":// 修改产品大类
opResult = await this.utilsProductSve.editProductType(pobj);
break;
default:
opResult = system.getResult(null, "action_type参数错误");
} }
return opResult;
}
} }
module.exports = ProductAPI; module.exports = ProductAPI;
\ No newline at end of file
...@@ -121,7 +121,7 @@ class AccessAuthAPI extends WEBBase { ...@@ -121,7 +121,7 @@ class AccessAuthAPI extends WEBBase {
case "submitService"://创建渠道(app) case "submitService"://创建渠道(app)
opResult = await this.utilsAuthSve.submitService(pobj); opResult = await this.utilsAuthSve.submitService(pobj);
break; break;
case "editService"://创建渠道(app) case "editService"://修改渠道(app)
opResult = await this.utilsAuthSve.editService(pobj); opResult = await this.utilsAuthSve.editService(pobj);
break; break;
default: default:
......
...@@ -314,7 +314,7 @@ class UtilsAuthService extends AppServiceBase { ...@@ -314,7 +314,7 @@ class UtilsAuthService extends AppServiceBase {
} }
/** /**
* 创建渠道(信息更全一些) * 创建渠道
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async submitService(pobj) { async submitService(pobj) {
...@@ -324,7 +324,7 @@ class UtilsAuthService extends AppServiceBase { ...@@ -324,7 +324,7 @@ class UtilsAuthService extends AppServiceBase {
} }
/** /**
* 修改渠道(信息更全一些) * 修改渠道
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async editService(pobj) { async editService(pobj) {
......
...@@ -19,7 +19,7 @@ class UtilsProductService extends AppServiceBase { ...@@ -19,7 +19,7 @@ class UtilsProductService extends AppServiceBase {
if (!actionBody.pathCode) { if (!actionBody.pathCode) {
return system.getResult(null, "actionBody.pathCode can not be empty,100330"); return system.getResult(null, "actionBody.pathCode can not be empty,100330");
} }
if(actionBody.name){ if (actionBody.name) {
pobj.actionBody.productName = actionBody.name; pobj.actionBody.productName = actionBody.name;
} }
pobj.actionBody.pathCode = "/" + actionBody.pathCode + "/"; pobj.actionBody.pathCode = "/" + actionBody.pathCode + "/";
...@@ -41,15 +41,15 @@ class UtilsProductService extends AppServiceBase { ...@@ -41,15 +41,15 @@ class UtilsProductService extends AppServiceBase {
pobj.actionBody.pathCode = "/" + actionBody.pathCode + "/"; pobj.actionBody.pathCode = "/" + actionBody.pathCode + "/";
var url = settings.centerAppUrl() + "action/opProduct/springBoard"; var url = settings.centerAppUrl() + "action/opProduct/springBoard";
let list = await this.restPostUrl(pobj, url); let list = await this.restPostUrl(pobj, url);
if(!list.data){ if (!list.data) {
return system.getResult(null,'product data is empty') return system.getResult(null, 'product data is empty')
} }
for(let item of list.data){ for (let item of list.data) {
pobj.actionType = 'getMinPrice'; pobj.actionType = 'getMinPrice';
pobj.actionBody = { pobj.actionBody = {
product_id:item.product_id product_id: item.product_id
} }
let re = await this.restPostUrl(pobj,url); let re = await this.restPostUrl(pobj, url);
item.price = re.data ? re.data.price : 0; item.price = re.data ? re.data.price : 0;
} }
return list; return list;
...@@ -75,7 +75,7 @@ class UtilsProductService extends AppServiceBase { ...@@ -75,7 +75,7 @@ class UtilsProductService extends AppServiceBase {
* @param actionBody * @param actionBody
* @returns {Promise<{msg: *, data, bizmsg: *|string, status: number}>} * @returns {Promise<{msg: *, data, bizmsg: *|string, status: number}>}
*/ */
async getProductPrice(pobj,actionBody){ async getProductPrice(pobj, actionBody) {
pobj.actionType = 'getProductPrice' pobj.actionType = 'getProductPrice'
let url = settings.centerAppUrl() + "action/opProduct/springBoard"; let url = settings.centerAppUrl() + "action/opProduct/springBoard";
return await this.restPostUrl(pobj, url); return await this.restPostUrl(pobj, url);
...@@ -87,7 +87,7 @@ class UtilsProductService extends AppServiceBase { ...@@ -87,7 +87,7 @@ class UtilsProductService extends AppServiceBase {
* @param actionBody * @param actionBody
* @returns {Promise<{msg: *, data, bizmsg: *|string, status: number}>} * @returns {Promise<{msg: *, data, bizmsg: *|string, status: number}>}
*/ */
async getRegProducePrice(pobj,actionBody){ async getRegProducePrice(pobj, actionBody) {
pobj.actionType = 'getRegProducePrice' pobj.actionType = 'getRegProducePrice'
let url = settings.centerAppUrl() + "action/opProduct/springBoard"; let url = settings.centerAppUrl() + "action/opProduct/springBoard";
return await this.restPostUrl(pobj, url); return await this.restPostUrl(pobj, url);
...@@ -98,35 +98,35 @@ class UtilsProductService extends AppServiceBase { ...@@ -98,35 +98,35 @@ class UtilsProductService extends AppServiceBase {
* @param actionBody * @param actionBody
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async getProductRecommend(pobj,actionBody){ async getProductRecommend(pobj, actionBody) {
const type = actionBody.type; const type = actionBody.type;
if(!type){ if (!type) {
return system.getResult(-1,'type can be not empty') return system.getResult(-1, 'type can be not empty')
} }
switch (type) { switch (type) {
case 1: case 1:
if(!actionBody.companyName){ if (!actionBody.companyName) {
return system.getResultFail(-1,'companyName can be not empty') return system.getResultFail(-1, 'companyName can be not empty')
} }
break; break;
case 2: case 2:
if(!actionBody.companyName){ if (!actionBody.companyName) {
return system.getResultFail(-1,'companyName can be not empty') return system.getResultFail(-1, 'companyName can be not empty')
} }
if(!actionBody.productCode){ if (!actionBody.productCode) {
return system.getResultFail(-1,'productCode can be not empty') return system.getResultFail(-1, 'productCode can be not empty')
} }
break; break;
case 3: case 3:
if(!actionBody.productCode){ if (!actionBody.productCode) {
return system.getResultFail(-1,'productCode can be not empty') return system.getResultFail(-1, 'productCode can be not empty')
} }
break; break;
default: default:
return system.getResultFail(-1,'type 参数错误'); return system.getResultFail(-1, 'type 参数错误');
} }
let url = settings.centerAppUrl() + "action/opProduct/springBoard"; let url = settings.centerAppUrl() + "action/opProduct/springBoard";
return await this.restPostUrl(pobj,url); return await this.restPostUrl(pobj, url);
} }
/** /**
...@@ -135,22 +135,55 @@ class UtilsProductService extends AppServiceBase { ...@@ -135,22 +135,55 @@ class UtilsProductService extends AppServiceBase {
* @param actionBody * @param actionBody
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async updateProductPrice(pobj,actionBody){ async updateProductPrice(pobj, actionBody) {
if(!actionBody.data || actionBody.data.length == 0){ if (!actionBody.data || actionBody.data.length == 0) {
return system.getResultFail(-1,'data is empty!'); return system.getResultFail(-1, 'data is empty!');
} }
let url = settings.centerAppUrl() + "action/opProduct/springBoard"; let url = settings.centerAppUrl() + "action/opProduct/springBoard";
return await this.restPostUrl(pobj,url); return await this.restPostUrl(pobj, url);
} }
/** /**
* 获取全部产品 * 获取全部产品
* @returns {Promise<{msg: string, data, bizmsg: *|string, status: number}|any>} * @returns {Promise<{msg: string, data, bizmsg: *|string, status: number}|any>}
*/ */
async getAllProducts(pobj){ async getAllProducts(pobj) {
let url = settings.centerAppUrl() + 'action/opProduct/springBoard'; let url = settings.centerAppUrl() + 'action/opProduct/springBoard';
pobj.actionType = 'getAllProducts' pobj.actionType = 'getAllProducts'
let result = await this.restPostUrl(pobj,url); let result = await this.restPostUrl(pobj, url);
return result;
}
/**
* 获取全部产品大类
* @returns {Promise<{msg: string, data, bizmsg: *|string, status: number}|any>}
*/
async getAllProductType(pobj) {
let url = settings.centerAppUrl() + 'action/opProduct/springBoard';
pobj.actionType = 'getAllProductType'
let result = await this.restPostUrl(pobj, url);
return result;
}
/**
* 创建产品大类
* @returns {Promise<{msg: string, data, bizmsg: *|string, status: number}|any>}
*/
async submitProductType(pobj) {
let url = settings.centerAppUrl() + 'action/opProduct/springBoard';
pobj.actionType = 'submitProductType'
let result = await this.restPostUrl(pobj, url);
return result;
}
/**
* 修改产品大类
* @returns {Promise<{msg: string, data, bizmsg: *|string, status: number}|any>}
*/
async editProductType(pobj) {
let url = settings.centerAppUrl() + 'action/opProduct/springBoard';
pobj.actionType = 'editProductType'
let result = await this.restPostUrl(pobj, url);
return result; return result;
} }
...@@ -159,32 +192,32 @@ class UtilsProductService extends AppServiceBase { ...@@ -159,32 +192,32 @@ class UtilsProductService extends AppServiceBase {
* @param pobj * @param pobj
* @returns {Promise<{msg: string, data, bizmsg: *|string, status: number}|any>} * @returns {Promise<{msg: string, data, bizmsg: *|string, status: number}|any>}
*/ */
async getAllPathName(pobj){ async getAllPathName(pobj) {
let url = settings.centerAppUrl() + 'action/opProduct/springBoard'; let url = settings.centerAppUrl() + 'action/opProduct/springBoard';
pobj.actionType = 'getAllPathName'; pobj.actionType = 'getAllPathName';
let result = await this.restPostUrl(pobj,url); let result = await this.restPostUrl(pobj, url);
if(result.status !=0){ if (result.status != 0) {
return system.getResultFail(-1,'获取数据失败,请稍后再试!'); return system.getResultFail(-1, '获取数据失败,请稍后再试!');
} }
let data = result.data; let data = result.data;
let map = new Map(); let map = new Map();
for(let i =0;i<data.length;i++){ for (let i = 0; i < data.length; i++) {
let item = data[i]; let item = data[i];
let strs = item.path_name.split('/'); let strs = item.path_name.split('/');
let classOne = strs[1]; let classOne = strs[1];
let classTwo = strs[2]; let classTwo = strs[2];
if(map.has(classOne)){ if (map.has(classOne)) {
let val = map.get(classOne); let val = map.get(classOne);
val.push(classTwo) val.push(classTwo)
map.set(classOne,val); map.set(classOne, val);
}else{ } else {
let arr = []; let arr = [];
arr.push(classTwo) arr.push(classTwo)
map.set(classOne,arr); map.set(classOne, arr);
} }
} }
let resultData = []; let resultData = [];
map.forEach((v,k) =>{ map.forEach((v, k) => {
let obj = {}; let obj = {};
obj['key'] = k; obj['key'] = k;
obj['data'] = v; obj['data'] = v;
......
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