Commit 852a3b62 by 王昆

gsb

parent 3207e98e
......@@ -5,6 +5,28 @@ class OorderprocessDao extends Dao {
super(Dao.getModelName(OorderprocessDao));
}
async mapByOrderIdsAndStatus(orderIds, statuses) {
var result = {};
if(!orderIds || orderIds.length == 0 || !statuses || statuses.length == 0) {
return result;
}
let sql = [];
sql.push("SELECT");
sql.push("*");
sql.push("FROM `o_order_process`");
sql.push("WHERE order_id IN (:orderIds)");
sql.push("AND `status` IN (:statuses)");
let list = await this.customQuery(sql.join(" "), {orderIds: orderIds, statuses: statuses});
if (!list || list.length == 0) {
return result;
}
for (let item of list) {
result[item.order_id + "_" + item.status] = item;
}
return result;
}
}
module.exports = OorderprocessDao;
\ No newline at end of file
module.exports = OorderprocessDao;
......@@ -5,6 +5,20 @@ class OprocessDao extends Dao {
super(Dao.getModelName(OprocessDao));
}
async mapAll(attrs) {
var result = {};
attrs = attrs || "*";
var sql = "SELECT " + attrs + " FROM `o_process`";
var list = await this.customQuery(sql);
if (!list || list.length == 0) {
return result;
}
for (var item of list) {
result[item.id] = item;
}
return result;
}
async findMapByIds(ids, attrs) {
var result = {};
if (!ids || ids.length == 0) {
......
......@@ -57,7 +57,7 @@ class OorderService extends ServiceBase {
}
// 构建订单流程列表
let orderProcessList = await this.buildOrderProcess(order.product_id);
let orderProcessList = await this.buildOrderProcess(order.product_id, [10010200, 10010500]);
if (!orderProcessList || orderProcessList.length == 0) {
return system.getResult(null, "产品流程未配置");
}
......@@ -120,20 +120,9 @@ class OorderService extends ServiceBase {
// 查询产品流程
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 processMap = await this.oprocessDao.mapAll();
let orderProcessList = [];
......@@ -148,23 +137,35 @@ class OorderService extends ServiceBase {
// 风还钻该处理每一个子项流程 变为 订单流程对象
let productProcess = productProcessList[idx];
let process = processMap[productProcess.process_id];
let nextArr = this.trim(productProcess.next_status).split(",");
let nextStatus = [];
for (var nextId of nextArr) {
nextId = Number(nextId || 0);
let nextObj = processMap[nextId];
if (!nextObj) {
continue;
}
nextStatus.push({next_status: nextObj.status, next_name: nextObj.name});
}
let orderProcess = {
product_id: productPid,
name: process.name,
status: process.status,
func: productProcess.func,
next_status: productProcess.next_status,
next_status: JSON.stringify(nextStatus),
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;
let nextObj = processMap[productProcess.process_id];
lastProcess.next_status = JSON.stringify([{next_status: nextObj.status, next_name: nextObj.name}]);
}
orderProcessList.push(orderProcess);
}
......@@ -174,28 +175,28 @@ class OorderService extends ServiceBase {
/**
* 订单管理列表
* @param {*} params
* @param {*} params
*/
async orders(params){
async orders(params) {
let where = {};
if(params.id){
if (params.id) {
where.id = this.trim(params.id);
}
if(params.progress){
if (params.progress) {
where.progress = this.trim(params.progress);
}
if(params.beginDate && params.endDate){
if (params.beginDate && params.endDate) {
where.beginDate = this.trim(params.beginDate);
where.endDate = this.trim(params.endDate);
}
if(params.deliver_id){
if (params.deliver_id) {
where.deliver_id = this.trim(params.deliver_id);
}
where.currentPage = Number(params.currentPage || 1);
where.pageSize = Number(params.pageSize || 10);
where.startRow = (where.currentPage-1)*where.pageSize;
where.startRow = (where.currentPage - 1) * where.pageSize;
try {
let ordersCountRes = await this.dao.ordersCount(where);
let count = ordersCountRes[0]['orderCount'];
......@@ -207,30 +208,30 @@ class OorderService extends ServiceBase {
//格式化交付商
this.formateDeliver(rows);
//格式化业务员
let res = {
count,rows
count, rows
};
return system.getResult(res);
} catch (error) {
console.log(error);
return system.getResult(null,`系统错误 错误信息 ${error}`);
return system.getResult(null, `系统错误 错误信息 ${error}`);
}
}
/**
* 格式化列表来源数据
* @param {*} orderList
* @param {*} orderList
*/
async formateSource(orderList){
let sourceIdList=[];
async formateSource(orderList) {
let sourceIdList = [];
for (let item of orderList) {
if(item.source_id){
if (item.source_id) {
sourceIdList.push(item.source_id);
}
}
let sourceMap = await this.osourceDao.mapByIds(sourceIdList);
for (let item of orderList) {
item.osource = sourceMap[item.source_id] || {}
......@@ -239,16 +240,16 @@ class OorderService extends ServiceBase {
/**
* 格式化订单产品
* @param {*} orderList
* @param {*} orderList
*/
async formateProduct(orderList){
let productIdList=[];
async formateProduct(orderList) {
let productIdList = [];
for (let item of orderList) {
if(item.product_id){
if (item.product_id) {
productIdList.push(item.product_id);
}
}
let productMap = await this.oproductDao.mapByIds(productIdList);
for (let item of productMap) {
item.oproduct = productMap[item.product_id] || {}
......@@ -257,71 +258,104 @@ class OorderService extends ServiceBase {
/**
* 格式化订单交付商
* @param {*} orderList
* @param {*} orderList
*/
async formateDeliver(orderList){
let deliverIdList=[];
async formateDeliver(orderList) {
let deliverIdList = [];
for (let item of orderList) {
if(item.deliver_id){
if (item.deliver_id) {
deliverIdList.push(item.deliver_id);
}
}
let deliverMap = await this.oorderdeliverDao.mapByIds(deliverIdList);
for (let item of deliverMap) {
item.odeliver = deliverMap[item.deliver_id] || {}
}
}
/**
* 处理订单状态数据
* @param orderList
* @returns {Promise<void>}
*/
async formateStatus(orderList) {
let ids = [];
let statuses = [];
for (let item of orderList) {
ids.push(item.id);
statuses.push(item.status);
}
let map = await this.oorderprocessDao.mapByOrderIdsAndStatus(ids, statuses);
for (let item of orderList) {
let key = item.id + "_" + item.status;
let v = map[key] || {};
item.statusName = v.name;
item.next_status = JSON.parse(v.next_status || "[]");
}
console.log(orderList);
}
/**
* 获取订单状态对象
* @param order_id
* @param status
* @returns {Promise<*|{}>}
*/
async getOrderProcessStatus(order_id, status) {
let map = await this.oorderprocessDao.mapByOrderIdsAndStatus([order_id], [status]);
return map[order_id + "_" + status] || {};
}
/**
* 分配业务员
* @param {*} params
* @param {*} params
* @id String 订单ID
* @bd_id String 业务员ID
*/
async assignSalesman (params){
if(!params.bd_id){
return system.getResult(null,`参数错误 业务员ID不能为空`);
async assignSalesman(params) {
if (!params.bd_id) {
return system.getResult(null, `参数错误 业务员ID不能为空`);
}
try {
let _order= await this.findById(params.id);
let _order = await this.findById(params.id);
_order.bd_id = this.trim(params.bd_id);
let res = await _order.save();
return system.getResult(res);
} catch (error) {
console.log(error);
return system.getResult(null,`系统错误 错误信息 ${error}`);
return system.getResult(null, `系统错误 错误信息 ${error}`);
}
}
/**
* 分配交付商
* @param {*} params
* @param {*} params
* @id String 订单ID
*
*
*
*
*
*
*/
async assignDeliver(params){
async assignDeliver(params) {
//参数验证
if(!params.id){
if (!params.id) {
return system.getResult(null, `参数错误 订单ID不能为空`);
}
if(!params.deliver_id){
if (!params.deliver_id) {
return system.getResult(null, `参数错误 交付商ID不能为空`);
}
if(!params.hasOwnProperty(`deliver_divide`)){
if (!params.hasOwnProperty(`deliver_divide`)) {
return system.getResult(null, `参数错误 交付商分成不能为空`);
}
//创建orderdeliver记录
//更新oorder订单记录
}
}
......
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