|
|
@ -12,7 +12,7 @@ async function getReceivedDetail(ctx) { |
|
|
|
} |
|
|
|
let findOption = { |
|
|
|
where: where, |
|
|
|
order: [['id', 'DESC']] |
|
|
|
order: [['id', 'ASC']] |
|
|
|
} |
|
|
|
if (!toExport) {//非导出时考虑分页
|
|
|
|
if (limit) { |
|
|
@ -102,7 +102,7 @@ async function exportReceivedDetail(ctx, dataList) { |
|
|
|
exportData.push(item) |
|
|
|
} |
|
|
|
const fileName = `回款明细表_${moment().format('YYYYMMDDHHmmss')}` + '.xlsx' |
|
|
|
const filePath = await simpleExcelDown({ data: exportData, header, fileName: fileName }) |
|
|
|
const filePath = await simpleExcelDown({ data: exportData, header, fileName: fileName, needIndexCell: false }) |
|
|
|
const fileData = fs.readFileSync(filePath); |
|
|
|
ctx.status = 200; |
|
|
|
ctx.set('Content-Type', 'application/x-xls'); |
|
|
@ -132,7 +132,7 @@ async function getAchievementDetail(ctx) { |
|
|
|
} |
|
|
|
let findOption = { |
|
|
|
where: where, |
|
|
|
order: [['id', 'DESC']] |
|
|
|
order: [['id', 'ASC']] |
|
|
|
} |
|
|
|
if (!toExport) {//非导出时考虑分页
|
|
|
|
if (limit) { |
|
|
@ -225,20 +225,20 @@ async function exportAchievementDetail(ctx, dataList) { |
|
|
|
title: '是否可复制的业务路径', |
|
|
|
key: 'reproducible', |
|
|
|
}, { |
|
|
|
title: '省外业务1.1', |
|
|
|
title: '省外业务', |
|
|
|
key: 'outProvince', |
|
|
|
}, { |
|
|
|
title: '复购业务1.05', |
|
|
|
title: '复购业务', |
|
|
|
key: 'repurchase', |
|
|
|
}, { |
|
|
|
title: '可复制的业务路径1.1', |
|
|
|
title: '可复制的业务路径', |
|
|
|
key: 'isreproduce', |
|
|
|
}] |
|
|
|
const { utils: { simpleExcelDown } } = ctx.app.fs; |
|
|
|
let exportData = [] |
|
|
|
for (let { dataValues: item } of dataList) { |
|
|
|
item.isApproval = item.isApproval ? '是' : '否'; |
|
|
|
item.reproducible = item.reproducible ? '是' : '否'; |
|
|
|
item.isApproval = JSON.stringify(item.isApproval) === 'null' ? '-' : item.isApproval ? '是' : '否'; |
|
|
|
item.reproducible = JSON.stringify(item.reproducible) === 'null' ? '-' : item.reproducible ? '是' : '否'; |
|
|
|
exportData.push(item) |
|
|
|
} |
|
|
|
const fileName = `业绩明细表_${moment().format('YYYYMMDDHHmmss')}` + '.xlsx' |
|
|
@ -256,11 +256,17 @@ async function exportAchievementDetail(ctx, dataList) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询明细表已存在编号数据,回款、合同、开票通用 |
|
|
|
* @param {*} ctx ctx ctx.query:{tableModel表模型名} |
|
|
|
*/ |
|
|
|
async function getReceivedNumbers(ctx) { |
|
|
|
let errorMsg = { name: 'FindError', message: '查询失败' }; |
|
|
|
try { |
|
|
|
const { tableModel } = ctx.query; |
|
|
|
const models = ctx.fs.dc.models; |
|
|
|
let list = await models.ReceivableDetail.findAll({//查编号
|
|
|
|
let modelName = tableModel || 'ReceivableDetail' |
|
|
|
let list = await models[modelName].findAll({//查编号
|
|
|
|
attributes: ['number'] |
|
|
|
}); |
|
|
|
ctx.status = 200 |
|
|
@ -268,20 +274,23 @@ async function getReceivedNumbers(ctx) { |
|
|
|
} catch (error) { |
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = { |
|
|
|
message: typeof error == 'string' ? error : undefined |
|
|
|
} |
|
|
|
ctx.body = errorMsg; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 导入明细表数据,回款、合同、开票通用 |
|
|
|
* @param {*} ctx ctx ctx.query:{tableModel表模型名} |
|
|
|
*/ |
|
|
|
async function importBackDetails(ctx) { |
|
|
|
let errorMsg = { message: '导入回款明细失败' }; |
|
|
|
let errorMsg = { message: '导入失败' }; |
|
|
|
const transaction = await ctx.fs.dc.orm.transaction(); |
|
|
|
try { |
|
|
|
const models = ctx.fs.dc.models; |
|
|
|
const data = ctx.request.body; |
|
|
|
const { tableModel } = ctx.query; |
|
|
|
let modelName = tableModel || 'ReceivableDetail' |
|
|
|
let addArr = []; |
|
|
|
let dataList = await models.ReceivableDetail.findAll({//查编号
|
|
|
|
let dataList = await models[modelName].findAll({//查编号
|
|
|
|
attributes: ['number'] |
|
|
|
}); |
|
|
|
data.map(d => { |
|
|
@ -292,7 +301,7 @@ async function importBackDetails(ctx) { |
|
|
|
}) |
|
|
|
//只处理新增的
|
|
|
|
if (addArr.length) { |
|
|
|
await models.ReceivableDetail.bulkCreate(addArr); |
|
|
|
await models[modelName].bulkCreate(addArr, { transaction }); |
|
|
|
} |
|
|
|
await transaction.commit(); |
|
|
|
ctx.status = 204; |
|
|
@ -340,7 +349,7 @@ async function getContractDetail(ctx) { |
|
|
|
where: where, |
|
|
|
offset: Number(page) * Number(limit), |
|
|
|
limit: Number(limit), |
|
|
|
order: [['id', 'DESC']] |
|
|
|
order: [['id', 'ASC']] |
|
|
|
}); |
|
|
|
ctx.status = 200 |
|
|
|
ctx.body = contractDetail; |
|
|
@ -367,7 +376,7 @@ async function getInvoicingDetail(ctx) { |
|
|
|
where: where, |
|
|
|
offset: Number(page) * Number(limit), |
|
|
|
limit: Number(limit), |
|
|
|
order: [['id', 'DESC']] |
|
|
|
order: [['id', 'ASC']] |
|
|
|
}); |
|
|
|
ctx.status = 200 |
|
|
|
ctx.body = invoiceDetail; |
|
|
@ -385,7 +394,7 @@ async function exportContractDetail(ctx) { |
|
|
|
try { |
|
|
|
const { models } = ctx.fs.dc; |
|
|
|
let exportData = await models.ContractDetail.findAll({ |
|
|
|
order: [['id', 'DESC']] |
|
|
|
order: [['id', 'ASC']] |
|
|
|
}); |
|
|
|
const { utils: { simpleExcelDown, contractDetailsColumnKeys } } = ctx.app.fs; |
|
|
|
let header = []; |
|
|
@ -414,7 +423,7 @@ async function exportInvoicingDetail(ctx) { |
|
|
|
try { |
|
|
|
const { models } = ctx.fs.dc; |
|
|
|
let exportData = await models.InvoiceDetail.findAll({ |
|
|
|
order: [['id', 'DESC']] |
|
|
|
order: [['id', 'ASC']] |
|
|
|
}); |
|
|
|
const { utils: { simpleExcelDown, invoicingDetailsColumnKeys } } = ctx.app.fs; |
|
|
|
let header = []; |
|
|
@ -438,8 +447,8 @@ module.exports = { |
|
|
|
getReceivedDetail,//回款
|
|
|
|
getAchievementDetail,//业绩
|
|
|
|
|
|
|
|
getReceivedNumbers,//查询回款明细表 已有的所有编号
|
|
|
|
importBackDetails,//导入回款明细
|
|
|
|
getReceivedNumbers,//查询回款、合同、开票明细表 已有的所有编号
|
|
|
|
importBackDetails,//导入回款、合同、开票明细
|
|
|
|
importAchieveDetails,//导入业绩明细
|
|
|
|
getContractDetail, |
|
|
|
getInvoicingDetail, |
|
|
|