Commit 8b2ba20a by 宋毅

tj

parent 70a39091
...@@ -22,14 +22,11 @@ class OpProductAPI extends APIBase { ...@@ -22,14 +22,11 @@ class OpProductAPI extends APIBase {
async opActionProcess(pobj, action_type, req) { async opActionProcess(pobj, action_type, req) {
var opResult = null; var opResult = null;
switch (action_type) { switch (action_type) {
case "getCAProductListByTypeCode"://通过产品类别编码获取产品列表 case "getProductList"://通过产品类别编码获取产品列表
opResult = await this.productSve.findByTypeCode(pobj.actionBody, pobj.appInfo); opResult = await this.productSve.getProductList(pobj.actionBody, pobj.appInfo);
break; break;
case "getCAProductListByTypeOneCode"://通过产品大类编码获取产品列表 case "getProductDetail"://获取产品详情
opResult = await this.productSve.findByTypeOneCode(pobj.actionBody, pobj.appInfo); opResult = await this.productSve.getProductDetail(pobj.actionBody, pobj.appInfo);
break;
case "getCAProductDetail"://获取产品详情
opResult = await this.productSve.getProductDetailByCode(pobj.actionBody.channelItemCode, pobj.appInfo.uapp_id);
break; break;
default: default:
opResult = system.getResult(null, "action_type参数错误"); opResult = system.getResult(null, "action_type参数错误");
......
...@@ -4,5 +4,28 @@ class ProductDao extends Dao { ...@@ -4,5 +4,28 @@ class ProductDao extends Dao {
constructor() { constructor() {
super(Dao.getModelName(ProductDao)); super(Dao.getModelName(ProductDao));
} }
async getItemByChannelItemCode(channelItemCode, uapp_id) {
return this.model.findOne({
where: {
uapp_id: uapp_id,
channel_item_code: channelItemCode
},
attributes: [
"id",
"uapp_id",
"path_code",
"path_name",
"item_code",
"item_name",
"channel_item_code",
"channel_item_name",
"pic_url",
"product_desc",
"desc_url",
"icon_url",
"productType_id"],
raw: true
});
}
} }
module.exports = ProductDao; module.exports = ProductDao;
...@@ -3,6 +3,7 @@ const settings = require("../../../../config/settings"); ...@@ -3,6 +3,7 @@ const settings = require("../../../../config/settings");
const uiconfig = system.getUiConfig2(settings.appKey); const uiconfig = system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => { module.exports = (db, DataTypes) => {
return db.define("producttype", { return db.define("producttype", {
uapp_id: DataTypes.INTEGER, //应用id
p_id: DataTypes.INTEGER, //父id p_id: DataTypes.INTEGER, //父id
type_code: DataTypes.STRING(64), type_code: DataTypes.STRING(64),
type_name: DataTypes.STRING(64), type_name: DataTypes.STRING(64),
......
...@@ -8,49 +8,35 @@ class ProductService extends ServiceBase { ...@@ -8,49 +8,35 @@ class ProductService extends ServiceBase {
this.productpriceDao = system.getObject("db.dbproduct.productpriceDao"); this.productpriceDao = system.getObject("db.dbproduct.productpriceDao");
} }
/** /**
* 获取产品详情 * 通过产品类别编码路径获取产品列表
* @param {*} channelItemCode 渠道产品码 * @param {*} actionBody pathCode 为类别编码路径,一级类下产品列表 sbfu,二级类下产品列表sbfu/sbzc
* @param {*} uappid 渠道id * @param {*} appInfo 应用信息
*/ */
async getProductDetailByCode(channelItemCode, uappid) { async getProductList(actionBody, appInfo) {
var sql = "select * from v_product where uapp_id=" + uappid + " and channel_item_code='" + channelItemCode + "'"; var sql = "select * from v_product where uapp_id=" + appInfo.uapp_id + " and path_code like '" + actionBody.pathCode + "%'";
var tmpResult = await this.customQuery(sql); var list = await this.customQuery(sql);
if (tmpResult && tmpResult.length > 0) { return system.getResultSuccess(list);
for (var i = 0; i < tmpResult.length; i++) {
var pro = tmpResult[i];
if (pro.id) {
var ppList = await this.productpriceDao.model.findAll({
where: { product_id: pro.id },
attributes: ["price", "supply_price", "service_charge", "public_expense", "is_default", "price_type", "price_type_name",
"sort", "price_desc", "min_qty", "max_qty"
],
raw: true
});
pro.productPriceList = ppList;
}
}
}
return system.getResultSuccess(tmpResult);
}
/**
* 通过产品类别编码获取产品列表
* @param {*} actionBody
*/
async findByTypeCode(actionBody, appInfo) {
var sql = "select * from v_product where uapp_id=" + appInfo.uapp_id + " and type_code='" + actionBody.typeCode + "'";
var tmpResult = await this.customQuery(sql);
return system.getResultSuccess(tmpResult);
} }
/** /**
* 通过产品大类编码获取产品列表 * 通过渠道产品编码获取产品详情
* @param {*} actionBody * @param {*} actionBody channelItemCode 渠道产品编码
* @param {*} appInfo 应用信息
*/ */
async findByTypeOneCode(actionBody, appInfo) { async getProductDetail(actionBody, appInfo) {
var sql = "select * from v_product where uapp_id=" + appInfo.uapp_id + " and p_type_code='" + actionBody.typeOneCode + "'"; var item = await this.dao.getItemByChannelItemCode(actionBody.channelItemCode, appInfo.uapp_id);
var tmpResult = await this.customQuery(sql); if (!item) {
return system.getResultSuccess(tmpResult); return system.getResult(null, "item is data empty");
}
var pList = await this.productpriceDao.model.findAll({
where: { product_id: item.id },
attributes: ["id", "price", "supply_price", "service_charge", "public_expense", "is_default", "price_type", "price_type_name",
"sort", "price_desc", "min_qty", "max_qty"
],
raw: true
});
item.price_list = pList;
return system.getResultSuccess(item);
} }
} }
module.exports = ProductService; module.exports = ProductService;
...@@ -7,11 +7,11 @@ var settings={ ...@@ -7,11 +7,11 @@ var settings={
}, },
database:{ database:{
dbname : "center_app", dbname : "center_app",
user: "write", user: "root",
password: "write", password: "root",
config: { config: {
host: '43.247.184.35', host: '121.36.3.35',
port: 8899, port: 3306,
dialect: 'mysql', dialect: 'mysql',
operatorsAliases: false, operatorsAliases: false,
pool: { pool: {
......
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