Commit 7da23c5a by 王昆

gsb

parent 8e83344a
...@@ -70,7 +70,7 @@ class APIBase extends DocBase { ...@@ -70,7 +70,7 @@ class APIBase extends DocBase {
async doexec(gname, methodname, pobj, query, req) { async doexec(gname, methodname, pobj, query, req) {
var requestid = this.getUUID(); var requestid = this.getUUID();
try { try {
var rtn = await this[methodname](pobj, query, req); var rtn = await this[methodname](pobj, query, req) || {};
rtn.requestid = requestid; rtn.requestid = requestid;
this.oplogSve.createDb({ this.oplogSve.createDb({
......
...@@ -12,6 +12,9 @@ class ActionAPI extends APIBase { ...@@ -12,6 +12,9 @@ class ActionAPI extends APIBase {
this.businessmenSve = system.getObject("service.business.businessmenSve"); this.businessmenSve = system.getObject("service.business.businessmenSve");
this.businessmencontractSve = system.getObject("service.business.businessmencontractSve"); this.businessmencontractSve = system.getObject("service.business.businessmencontractSve");
this.oorderSve = system.getObject("service.order.oorderSve");
} }
/** /**
* 接口跳转 * 接口跳转
...@@ -38,8 +41,19 @@ class ActionAPI extends APIBase { ...@@ -38,8 +41,19 @@ class ActionAPI extends APIBase {
async handleRequest(action_process, action_type, action_body) { async handleRequest(action_process, action_type, action_body) {
var opResult = null; var opResult = null;
try{
} catch (e) {
}
switch (action_type) { switch (action_type) {
// 订单 // 订单
case "addSourceOrder": //创建订单
opResult = await this.oorderSve.addSourceOrder(action_body);
break;
// 订单
case "createOrder": //创建订单 case "createOrder": //创建订单
opResult = await this.iborderbaseSve.apiCreateOrder(action_body); opResult = await this.iborderbaseSve.apiCreateOrder(action_body);
break; break;
......
...@@ -35,17 +35,21 @@ class Dao { ...@@ -35,17 +35,21 @@ class Dao {
} }
//批量插入 //批量插入
async bulkCreate(objs) { async bulkCreate(objs, t) {
if (!objs || objs.length == 0) { if (!objs || objs.length == 0) {
return; return;
} }
for (var obj of objs) { for (var obj of objs) {
if (!obj.id) { if (!obj.id && !obj.autoIncrement) {
obj.id = await this.redisClient.genrateId(this.modelName); obj.id = await this.redisClient.genrateId(this.modelName);
} }
} }
if (t) {
return await this.model.bulkCreate(objs, { transaction: t });
} else {
return await this.model.bulkCreate(objs); return await this.model.bulkCreate(objs);
} }
}
static getModelName(ClassObj) { static getModelName(ClassObj) {
return ClassObj["name"].substring(0, ClassObj["name"].lastIndexOf("Dao")).toLowerCase() return ClassObj["name"].substring(0, ClassObj["name"].lastIndexOf("Dao")).toLowerCase()
......
...@@ -5,15 +5,26 @@ class OprocessDao extends Dao { ...@@ -5,15 +5,26 @@ class OprocessDao extends Dao {
super(Dao.getModelName(OprocessDao)); super(Dao.getModelName(OprocessDao));
} }
async findMapByIds(ids) { async findMapByIds(ids, attrs) {
var result = {}; var result = {};
if (!ids || ids.length == 0) { if (!ids || ids.length == 0) {
return result; return result;
} }
attrs = attrs || "*";
var sql = "SELECT " + attrs + " FROM `o_process` WHERE id IN (:ids)";
var sql = "SELECT "; var list = await this.customQuery(sql, {
ids: ids
});
if (!list || list.length == 0) {
return result;
} }
for (var item of list) {
result[item.id] = item;
}
return result;
}
} }
module.exports = OprocessDao; module.exports = OprocessDao;
\ No newline at end of file
...@@ -39,8 +39,8 @@ class OproductprocessDao extends Dao { ...@@ -39,8 +39,8 @@ class OproductprocessDao extends Dao {
} }
sql.push("ORDER BY sort ASC"); sql.push("ORDER BY sort ASC");
let list = await this.customQuery(sql, {productPid: productPid, productIds: productIds}); let list = await this.customQuery(sql.join(" "), {productPid: productPid, productIds: productIds});
if (!list || list.length) { if (!list || list.length == 0) {
return result; return result;
} }
...@@ -51,7 +51,7 @@ class OproductprocessDao extends Dao { ...@@ -51,7 +51,7 @@ class OproductprocessDao extends Dao {
items = []; items = [];
} }
items.push(item); items.push(item);
result[key] = items; result[productId] = items;
} }
return result; return result;
} }
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
module.exports = function (db, DataTypes) { module.exports = function (db, DataTypes) {
return db.define('oorder', { return db.define('oorder', {
merchant_id: {type: DataTypes.STRING, field: 'merchant_id', allowNull: true, defaultValue:'',comment:'商户id, 为了兼容司机宝' }, merchant_id: {type: DataTypes.STRING, field: 'merchant_id', allowNull: true, defaultValue:'',comment:'商户id, 为了兼容司机宝' },
order_id: {type: DataTypes.STRING, field: 'order_id', allowNull: true, comment:'订单ID' },
busi_type: {type: DataTypes.STRING, field: 'busi_type', allowNull: true,defaultValue:'', comment:'业务类型 1个体户 2...暂不知道' }, busi_type: {type: DataTypes.STRING, field: 'busi_type', allowNull: true,defaultValue:'', comment:'业务类型 1个体户 2...暂不知道' },
busi_id: { type: DataTypes.STRING, field: 'busi_id', allowNull: false,defaultValue:'', comment:'业务id'}, busi_id: { type: DataTypes.STRING, field: 'busi_id', allowNull: false,defaultValue:'', comment:'业务id'},
product_id: {type: DataTypes.BIGINT, field: 'product_id', allowNull: true,defaultValue:0, comment:'产品id'}, product_id: {type: DataTypes.BIGINT, field: 'product_id', allowNull: true,defaultValue:0, comment:'产品id'},
...@@ -27,7 +26,7 @@ module.exports = function (db, DataTypes) { ...@@ -27,7 +26,7 @@ module.exports = function (db, DataTypes) {
deleted_at: { type: DataTypes.DATE, field: 'deleted_at', allowNull: true } deleted_at: { type: DataTypes.DATE, field: 'deleted_at', allowNull: true }
}, },
{ {
timestamps: true, timestamps: false,
underscore: true, underscore: true,
paranoid: true, paranoid: true,
version: true, version: true,
......
...@@ -20,7 +20,7 @@ module.exports = function (db, DataTypes) { ...@@ -20,7 +20,7 @@ module.exports = function (db, DataTypes) {
deleted_at: { type: DataTypes.DATE, field: 'deleted_at', allowNull: true }, deleted_at: { type: DataTypes.DATE, field: 'deleted_at', allowNull: true },
}, },
{ {
timestamps: true, timestamps: false,
underscore: true, underscore: true,
paranoid: true, paranoid: true,
version: true, version: true,
......
...@@ -10,7 +10,7 @@ module.exports = function (db, DataTypes) { ...@@ -10,7 +10,7 @@ module.exports = function (db, DataTypes) {
deleted_at: { type: DataTypes.DATE, field: 'deleted_at', allowNull: true } deleted_at: { type: DataTypes.DATE, field: 'deleted_at', allowNull: true }
}, },
{ {
timestamps: true, timestamps: false,
underscore: true, underscore: true,
paranoid: true, paranoid: true,
version: true, version: true,
......
...@@ -15,7 +15,7 @@ module.exports = function (db, DataTypes) { ...@@ -15,7 +15,7 @@ module.exports = function (db, DataTypes) {
deleted_at: { type: DataTypes.DATE, field: 'deleted_at', allowNull: true }, deleted_at: { type: DataTypes.DATE, field: 'deleted_at', allowNull: true },
}, },
{ {
timestamps: true, timestamps: false,
underscore: true, underscore: true,
paranoid: true, paranoid: true,
version: true, version: true,
......
...@@ -26,42 +26,58 @@ class OorderService extends ServiceBase { ...@@ -26,42 +26,58 @@ class OorderService extends ServiceBase {
async addSourceOrder(params) { async addSourceOrder(params) {
// 整理参数 // 整理参数
let order = { let order = {
merchantId: "", merchant_id: "",
channelOrderNo: "", channel_order_no: "",
busi_type: 1, busi_type: 1,
busi_id: "", busi_id: "",
price: 0, price: 0,
}; };
order.productId = Number(params.productId); order.product_id = Number(params.product_id);
order.sourceId = Number(params.sourceId); order.source_id = Number(params.source_id);
order.sourceNo = this.trim(params.sourceNo); order.source_no = this.trim(params.source_no);
order.notes = this.trim(params.notes); order.notes = this.trim(params.notes);
order.contactMobile = this.trim(params.contactMobile); order.contact_mobile = this.trim(params.contact_mobile);
// 验证订单是否存在
let exists = await this.dao.findOne({source_id: order.source_id, source_no: order.source_no});
if (exists) {
return system.getResult(null, `订单号${order.source_no}已存在`);
}
// 验证来源 // 验证来源
let source = await this.osourceDao.findById(order.sourceId); let source = await this.osourceDao.findById(order.source_id);
if (!source) { if (!source) {
return system.getResult(null, "来源错误"); return system.getResult(null, "来源错误");
} }
// 验证产品 // 验证产品
let product = await this.oproductDao.findById(order.productId); let product = await this.oproductDao.findById(order.product_id);
if (!product) { if (!product) {
return system.getResult(null, "产品错误"); return system.getResult(null, "产品错误");
} }
// 获取产品状态 // 构建订单流程列表
await this.getProductProcessList(productId, ); let orderProcessList = await this.buildOrderProcess(order.product_id);
if (!orderProcessList || orderProcessList.length == 0) {
// 查询产品订单状态 return system.getResult(null, "产品流程未配置");
}
// 合并订单状态
order.status = orderProcessList[0].status;
// 开启事务 // 开启事务
var self = this;
await this.db.transaction(async function (t) {
// 插入订单数据 // 插入订单数据
order = await self.dao.create(order, t);
// 插入订单状态数据 // 插入订单状态数据
for (let op of orderProcessList) {
op.order_id = order.id;
}
await self.oorderprocessDao.bulkCreate(orderProcessList, t);
return order;
});
return order;
} }
/** /**
...@@ -85,7 +101,7 @@ class OorderService extends ServiceBase { ...@@ -85,7 +101,7 @@ class OorderService extends ServiceBase {
* @param chooseProductIds * @param chooseProductIds
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async getProductProcessList(productPid, chooseProductIds) { async buildOrderProcess(productPid, chooseProductIds) {
// 查询所有产品子项 // 查询所有产品子项
let productList = await this.oproductDao.findListByPid(productPid); let productList = await this.oproductDao.findListByPid(productPid);
...@@ -93,7 +109,7 @@ class OorderService extends ServiceBase { ...@@ -93,7 +109,7 @@ class OorderService extends ServiceBase {
let productIds = []; let productIds = [];
for (let product of productList) { for (let product of productList) {
// 过滤未选择产品 // 过滤未选择产品
if(product.is_choose && chooseProductIds && chooseProductIds.indexOf(product.id) == -1) { if (product.is_choose && chooseProductIds && chooseProductIds.indexOf(product.id) == -1) {
continue; continue;
} }
productIds.push(product.id); productIds.push(product.id);
...@@ -103,17 +119,57 @@ class OorderService extends ServiceBase { ...@@ -103,17 +119,57 @@ class OorderService extends ServiceBase {
} }
// 查询产品流程 // 查询产品流程
let processMap = await this.oproductprocessDao.findMapByProductProductIds(productPid, productIds); let productProcessMap = await this.oproductprocessDao.findMapByProductProductIds(productPid, productIds);
// 产品流程ids
let processIds = [];
for (var idx in productProcessMap) {
let plist = productProcessMap[idx];
if (!plist) {
continue;
}
for (let p of plist) {
processIds.push(p.process_id);
}
}
// 批量查流程
let processMap = await this.oprocessDao.findMapByIds(processIds);
let orderProcessList = []; let orderProcessList = [];
for (let productId of productIds) { for (let productId of productIds) {
let currentProcess = processMap[productId]; // 产品子项流程列表
let orderProcess = {}; let productProcessList = productProcessMap[productId];
if (processList.length > 0) { if (!productProcessList || productProcessList.length == 0) {
let lastProcess = productList[processList.length - 1]; continue;
}
} }
for (let idx = 0; idx < productProcessList.length; idx++) {
// 风还钻该处理每一个子项流程 变为 订单流程对象
let productProcess = productProcessList[idx];
let process = processMap[productProcess.process_id];
let orderProcess = {
product_id: productPid,
name: process.name,
status: process.status,
func: productProcess.func,
next_status: productProcess.next_status,
name1: productProcess.name1,
name2: productProcess.name2,
name3: productProcess.name3,
name4: productProcess.name4,
sort: productProcess.sort,
autoIncrement: true
};
// 上一个产品流程于当前产品流程连接
if (idx == 0 && orderProcessList.length > 0) {
let lastProcess = orderProcessList[orderProcessList.length - 1];
lastProcess.next_status = productProcess.process_id;
}
orderProcessList.push(orderProcess);
}
}
return orderProcessList;
} }
} }
......
...@@ -6,7 +6,7 @@ var settings={ ...@@ -6,7 +6,7 @@ var settings={
db:10, db:10,
}, },
database:{ database:{
dbname : "xgg-order", dbname : "xgg-order2",
user: "write", user: "write",
password: "write", password: "write",
config: { config: {
......
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