Commit bb302cc5 by 孙亚楠

dd

parents fb55a5e9 04a0b5e9
......@@ -5,6 +5,10 @@ class ActionAPI extends APIBase {
constructor() {
super();
this.iinvoiceSve = system.getObject("service.invoice.iinvoiceSve");
this.iproductSve = system.getObject("service.product.iproductSve");
this.iprocessSve = system.getObject("service.product.iprocessSve");
}
/**
* 接口跳转
......@@ -40,9 +44,8 @@ class ActionAPI extends APIBase {
case "productDics": // 查询产品字典
// opResult = await this.oproductSve.productDics(action_body);
break;
case "allProcess": // 查询业务进度
// opResult = await this.oprocessSve.allNames(action_body);
opResult = await this.iprocessSve.allNames(action_body);
break;
// case "verificationAndCalculation": // 发票试算接口
......
......@@ -5,83 +5,78 @@ class IInvoiceDao extends Dao {
constructor() {
super(Dao.getModelName(IInvoiceDao));
}
async findByChannelAndApplyNo(channel_id,apply_no){
let sql =`select count(1) as total from i_invoice where channel_id = "${channel_id}" and apply_no = "${apply_no}"`;
var counts = await this.customQuery(sql);
return counts[0];
async countByParams(params) {
var sql = [];
sql.push("SELECT");
sql.push("COUNT(1) as total");
sql.push("FROM `i_invoice` t1");
sql.push("WHERE 1 = 1 ");
this.setCondition(params, sql);
var counts = await this.customQuery(sql.join(" "), params);
if(!counts || counts.length == 0) {
return 0;
}
return counts[0].total || 0;
}
async pageByParams(params, startRow, pageSize) {
var sql = [];
sql.push("SELECT");
sql.push("t1.*");
sql.push("FROM `i_invoice` t1");
sql.push("WHERE 1 = 1 ");
// async countByParams(params) {
// var sql = [];
// sql.push("SELECT");
// sql.push("COUNT(1) as total");
// sql.push("FROM `invoice` t1");
// sql.push("INNER JOIN `invoice_apply` t2 ON t1.`id` = t2.`id`");
// sql.push("WHERE 1 = 1 and t2.status in('1070','1080','1090')");
// this.setCondition(params, sql);
// var counts = await this.customQuery(sql.join(" "), params);
// if(!counts || counts.length == 0) {
// return 0;
// }
// return counts[0].total || 0;
// }
this.setCondition(params, sql);
// async pageByParams(params, startRow, pageSize) {
// var sql = [];
// sql.push("SELECT");
// sql.push("t1.*");
// sql.push("FROM `invoice` t1");
// sql.push("INNER JOIN `invoice_apply` t2 ON t1.`id` = t2.`id`");
// sql.push("WHERE 1 = 1 ");
// this.setCondition(params, sql);
// sql.push("ORDER BY id DESC");
// sql.push("LIMIT :startRow, :pageSize");
// params.startRow = startRow || 0;
// params.pageSize = pageSize || 10;
// return await this.customQuery(sql.join(" "), params);
// }
// setCondition(params, sql) {
// var complateTax = params.complateTax;
// if (complateTax != "-1") {
// params.complateTax = Number(complateTax);
// sql.push("AND t1.`complate_tax` = :complateTax");
// }
// // invoiceTimeBegin 2019-01-01 2019-01-01 00:00:00
// // invoiceTimeEnd 2019-11-01 2019-11-01 23:59:59
// if(params.invoiceTimeBegin) {
// sql.push("AND t1.`invoice_time` >= :invoiceTimeBegin");
// }
// if(params.invoiceTimeEnd) {
// sql.push("AND t1.`invoice_time` <= :invoiceTimeEnd");
// }
// if(params.invoiceTime){
// sql.push("AND t1.`invoice_time` >= :invoiceTime");
// }
// if(params.applyNo) {
// sql.push("AND t2.`apply_no` = :applyNo");
// }
// if(params.redStatus) {
// sql.push("AND t1.`red_status` = :redStatus");
// }
sql.push("ORDER BY id DESC");
sql.push("LIMIT :startRow, :pageSize");
params.startRow = startRow || 0;
params.pageSize = pageSize || 10;
return await this.customQuery(sql.join(" "), params);
}
// if (params.type) {
// sql.push("AND t2.`type` = :type");
// }
// if(params.statuses && params.statuses.length > 0){
// sql.push("AND t2.`status` in (:statuses)");
// }
// }
setCondition(params, sql) {
if(params.apply_no) {
sql.push("AND t2.`apply_no` = :apply_no");
}
if(params.status) {
sql.push("AND t2.`status` = :status");
}
if(params.statuses && params.statuses.length > 0){
sql.push("AND t2.`status` in (:statuses)");
}
if(params.invoice_type) {
sql.push("AND t2.`invoice_type` = :invoice_type");
}
if(params.invoiceTimeBegin) {
sql.push("AND t1.`invoice_time` >= :invoiceTimeBegin");
}
if(params.invoiceTimeEnd) {
sql.push("AND t1.`invoice_time` <= :invoiceTimeEnd");
}
if(params.red_status) {
sql.push("AND t1.`red_status` = :red_status");
}
if(params.deliver_id) {
sql.push("AND t2.`deliver_id` = :deliver_id");
}
if(params.bd_id) {
sql.push("AND t2.`bd_id` = :bd_id");
}
if(params.bd_path) {
params.bd_path_like = params.bd_path + "%";
sql.push("AND t2.`bd_path` = :bd_path_like");
}
}
async findByChannelAndApplyNo(channel_id,apply_no){
let sql =`select count(1) as total from i_invoice where channel_id = "${channel_id}" and apply_no = "${apply_no}"`;
var counts = await this.customQuery(sql);
return counts[0];
}
// /**
// * 红冲列表总计
......
......@@ -6,6 +6,21 @@ class IinvoicedeliverDao extends Dao {
this.tableName = this.model.tableName;
}
async findMapByIds(ids) {
var result = {};
var sql = `SELECT * FROM ${this.tableName} WHERE id IN (:ids)`;
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;
}
//交付商业务概览
async countStat(params) {
var sql = [];
......
......@@ -7,16 +7,16 @@ class IInvoiceprocessDao extends Dao {
this.tableName = this.model.tableName;
}
async delByOrderId(order_id) {
if (!order_id) {
async delByInvoiceId(invoice_id) {
if (!invoice_id) {
return;
}
let sql = `DELETE FROM ${this.tableName} WHERE order_id = :order_id`;
await this.customUpdate(sql, {order_id: order_id});
let sql = `DELETE FROM ${this.tableName} WHERE invoice_id = :invoice_id`;
await this.customUpdate(sql, {invoice_id: invoice_id});
}
async findByOrderIdAndStatus(orderId, status) {
if (!orderId || !status) {
async findByInvoiceIdAndStatus(invoiceId, status) {
if (!invoiceId || !status) {
return null;
}
let sql = [];
......@@ -24,19 +24,19 @@ class IInvoiceprocessDao extends Dao {
sql.push("*");
sql.push("FROM");
sql.push(this.tableName);
sql.push("WHERE order_id = :orderId");
sql.push("WHERE invoice_id = :invoiceId");
sql.push("AND `status` = :status");
let list = await this.customQuery(sql.join(" "), {orderId: orderId, status: status});
let list = await this.customQuery(sql.join(" "), {invoiceId: invoiceId, status: status});
if (!list || list.length == 0) {
return null;
}
return list[0];
}
async listByOrderIdsAndStatus(orderIds, statuses) {
async listByInvoiceIdsAndStatus(invoiceIds, statuses) {
var result = {};
if (!orderIds || orderIds.length == 0 || !statuses || statuses.length == 0) {
if (!invoiceIds || invoiceIds.length == 0 || !statuses || statuses.length == 0) {
return result;
}
let sql = [];
......@@ -44,21 +44,21 @@ class IInvoiceprocessDao extends Dao {
sql.push("*");
sql.push("FROM");
sql.push(this.tableName);
sql.push("WHERE order_id IN (:orderIds)");
sql.push("WHERE invoice_id IN (:invoiceIds)");
sql.push("AND `status` IN (:statuses)");
return await this.customQuery(sql.join(" "), {orderIds: orderIds, statuses: statuses});
return await this.customQuery(sql.join(" "), {invoiceIds: invoiceIds, statuses: statuses});
}
async mapByOrderIdsAndStatus(orderIds, statuses) {
async mapByInvoiceIdsAndStatus(invoiceIds, statuses) {
var result = {};
let list = await this.listByOrderIdsAndStatus(orderIds, statuses);
let list = await this.listByInvoiceIdsAndStatus(invoiceIds, statuses);
if (!list || list.length == 0) {
return result;
}
for (let item of list) {
result[item.order_id + "_" + item.status] = item;
result[item.invoice_id + "_" + item.status] = item;
}
return result;
}
......
......@@ -49,10 +49,16 @@ module.exports = (db, DataTypes) => {
bd_path:{ type: DataTypes.STRING(200), allowNull: true, defaultValue: null ,comment:"业务员权限"},
channel_id:{ type: DataTypes.STRING(32), allowNull: true ,delaultValue:'',comment:"渠道ID"},
product_id:{ type: DataTypes.STRING(32), allowNull: true ,delaultValue:'',comment:"商品ID"},
<<<<<<< HEAD
created_at: { type: DataTypes.DATE, field: 'created_at', allowNull: false, defaultValue: DataTypes.NOW },
updated_at: { type: DataTypes.DATE, field: 'updated_at', allowNull: false, defaultValue: DataTypes.NOW },
deleted_at: { type: DataTypes.DATE, field: 'deleted_at', allowNull: true },
version: { type: DataTypes.INTEGER, allowNull: true, defaultValue: 0 }
=======
created_at: { type: DataTypes.DATE, allowNull: true },
updated_at: { type: DataTypes.DATE, allowNull: true },
deleted_at: { type: DataTypes.DATE, allowNull: true },
>>>>>>> 04a0b5e93a1f0074627779a207d7a1380983e60f
}, {
timestamps: false,
paranoid: true,
......
......@@ -135,7 +135,92 @@ class IInvoiceService extends ServiceBase {
}
}
/*
async invoicePage(params) {
params.currentPage = Number(params.currentPage || 1);
params.pageSize = Number(params.pageSize || 10);
params.startRow = Number((params.currentPage - 1) * params.pageSize);
let total = await this.dao.countByParams(params);
if (total == 0) {
return { count: 0, rows: [] };
}
let list = await this.dao.pageByParams(params);
if (list) {
for (var item of list) {
this.handleDate(item, ['updated_at', 'created_at'], 'YYYY-MM-DD HH:mm:ss');
}
//格式化订单产品
await this.setDeliver(list);
//格式化业务员
await this.setStatus(list);
await this.setProduct(list);
}
return { count: total, rows: list };
}
/**
* 格式化订单产品
* @param {*} list
*/
async setProduct(list) {
let productIdList = [];
for (let item of list) {
if (item.product_id) {
productIdList.push(item.product_id);
}
}
let productMap = await this.iproductDao.mapByIds(productIdList);
for (let item of list) {
item.oproduct = productMap[item.product_id] || {}
}
}
async setDeliver(list) {
if (!list || list.length == 0) {
return;
}
let ids = [];
for (let item of list) {
if (!item.invoice_deliver_id) {
continue;
}
ids.push(item.invoice_deliver_id)
}
let map = await this.iinvoicedeliverDao.findMapByIds(ids);
for (let item of list) {
item.invoice_deliver = map[item.invoice_deliver_id] || {};
}
}
/**
* 处理状态数据
* @param list
* @returns {Promise<void>}
*/
async setStatus(list) {
let ids = [];
let statuses = [];
for (let item of list) {
ids.push(item.id);
statuses.push(item.status);
}
let map = await this.iinvoiceprocessDao.mapByInvoiceIdsAndStatus(ids, statuses);
for (let item of list) {
let key = item.id + "_" + item.status;
let v = map[key] || {};
item.status_name = v.name;
item.next_status = JSON.parse(v.next_status || "[]");
}
console.log(list);
}
/**
* 构建产品流程对象
* @param productPid
* @param chooseProductIds
......@@ -183,6 +268,7 @@ class IInvoiceService extends ServiceBase {
invoiceProcessList.push(orderProcess);
}
// await this.iinvoiceprocessDao.model.bulkCreate(invoiceProcessList);
return invoiceProcessList;
}
......
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