Commit 3207e98e by 孙亚楠

Merge branch 'xggsve-order-dev' of gitlab.gongsibao.com:jiangyong/zhichan into xggsve-order-dev

parents 6ce71df0 aea9b21b
......@@ -70,7 +70,7 @@ class APIBase extends DocBase {
async doexec(gname, methodname, pobj, query, req) {
var requestid = this.getUUID();
try {
var rtn = await this[methodname](pobj, query, req);
var rtn = await this[methodname](pobj, query, req) || {};
rtn.requestid = requestid;
this.oplogSve.createDb({
......
......@@ -17,7 +17,6 @@ class ActionAPI extends APIBase {
this.oorderSve = system.getObject("service.order.oorderSve");
this.oorderdeliverSve = system.getObject("service.order.oorderdeliverSve");
}
/**
* 接口跳转
......@@ -44,6 +43,12 @@ class ActionAPI extends APIBase {
async handleRequest(action_process, action_type, action_body) {
var opResult = null;
try{
} catch (e) {
}
switch (action_type) {
case "orders": //订单列表
......@@ -59,6 +64,11 @@ class ActionAPI extends APIBase {
//******************************************************************** */
// 订单
case "addSourceOrder": //创建订单
opResult = await this.oorderSve.addSourceOrder(action_body);
break;
// 订单
case "createOrder": //创建订单
opResult = await this.iborderbaseSve.apiCreateOrder(action_body);
break;
......
......@@ -35,16 +35,20 @@ class Dao {
}
//批量插入
async bulkCreate(objs) {
async bulkCreate(objs, t) {
if (!objs || objs.length == 0) {
return;
}
for (var obj of objs) {
if (!obj.id) {
if (!obj.id && !obj.autoIncrement) {
obj.id = await this.redisClient.genrateId(this.modelName);
}
}
return await this.model.bulkCreate(objs);
if (t) {
return await this.model.bulkCreate(objs, { transaction: t });
} else {
return await this.model.bulkCreate(objs);
}
}
static getModelName(ClassObj) {
......
......@@ -5,15 +5,26 @@ class OprocessDao extends Dao {
super(Dao.getModelName(OprocessDao));
}
async findMapByIds(ids) {
async findMapByIds(ids, attrs) {
var result = {};
if (!ids || ids.length == 0) {
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;
\ No newline at end of file
......@@ -39,8 +39,8 @@ class OproductprocessDao extends Dao {
}
sql.push("ORDER BY sort ASC");
let list = await this.customQuery(sql, {productPid: productPid, productIds: productIds});
if (!list || list.length) {
let list = await this.customQuery(sql.join(" "), {productPid: productPid, productIds: productIds});
if (!list || list.length == 0) {
return result;
}
......@@ -51,7 +51,7 @@ class OproductprocessDao extends Dao {
items = [];
}
items.push(item);
result[key] = items;
result[productId] = items;
}
return result;
}
......
......@@ -27,7 +27,7 @@ module.exports = function (db, DataTypes) {
deleted_at: { type: DataTypes.DATE, field: 'deleted_at', allowNull: true }
},
{
timestamps: true,
timestamps: false,
underscore: true,
paranoid: true,
version: true,
......
......@@ -20,7 +20,7 @@ module.exports = function (db, DataTypes) {
deleted_at: { type: DataTypes.DATE, field: 'deleted_at', allowNull: true },
},
{
timestamps: true,
timestamps: false,
underscore: true,
paranoid: true,
version: true,
......
......@@ -26,42 +26,58 @@ class OorderService extends ServiceBase {
async addSourceOrder(params) {
// 整理参数
let order = {
merchantId: "",
channelOrderNo: "",
merchant_id: "",
channel_order_no: "",
busi_type: 1,
busi_id: "",
price: 0,
};
order.productId = Number(params.productId);
order.sourceId = Number(params.sourceId);
order.sourceNo = this.trim(params.sourceNo);
order.product_id = Number(params.product_id);
order.source_id = Number(params.source_id);
order.source_no = this.trim(params.source_no);
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) {
return system.getResult(null, "来源错误");
}
// 验证产品
let product = await this.oproductDao.findById(order.productId);
let product = await this.oproductDao.findById(order.product_id);
if (!product) {
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 {
* @param chooseProductIds
* @returns {Promise<void>}
*/
async getProductProcessList(productPid, chooseProductIds) {
async buildOrderProcess(productPid, chooseProductIds) {
// 查询所有产品子项
let productList = await this.oproductDao.findListByPid(productPid);
......@@ -93,7 +109,7 @@ class OorderService extends ServiceBase {
let productIds = [];
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;
}
productIds.push(product.id);
......@@ -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 = [];
for (let productId of productIds) {
let currentProcess = processMap[productId];
let orderProcess = {};
if (processList.length > 0) {
let lastProcess = productList[processList.length - 1];
// 产品子项流程列表
let productProcessList = productProcessMap[productId];
if (!productProcessList || productProcessList.length == 0) {
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;
}
/**
......
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