|
@@ -855,19 +855,14 @@ module.exports = app => {
|
|
|
try {
|
|
|
await this._getStageAuditViewData(ctx);
|
|
|
const renderData = await this._getDefaultRenderData(ctx);
|
|
|
- const dealPay = await ctx.service.stagePay.getStagePays(ctx.stage);
|
|
|
+ renderData.dealPay = await ctx.service.stagePay.getStagePays(ctx.stage);
|
|
|
+ const payAtt = await ctx.service.payAtt.getStageData({ sid: ctx.stage.id });
|
|
|
+ console.log(payAtt);
|
|
|
// 附件不取下载地址
|
|
|
- for (const index in dealPay) {
|
|
|
- if (dealPay[index].attachment !== null) {
|
|
|
- const attachments = JSON.parse(dealPay[index].attachment);
|
|
|
- for (const att_index in attachments) {
|
|
|
- delete attachments[att_index].filepath;
|
|
|
- attachments[att_index].username = (await ctx.service.projectAccount.getAccountInfoById(attachments[att_index].uid)).name;
|
|
|
- }
|
|
|
- dealPay[index].attachment = attachments;
|
|
|
- }
|
|
|
+ for (const dp of renderData.dealPay) {
|
|
|
+ dp.attachment = payAtt.filter(x => { return x.pid === dp.pid });
|
|
|
+ console.log(dp.attachment);
|
|
|
}
|
|
|
- renderData.dealPay = dealPay;
|
|
|
renderData.calcBase = await ctx.service.stage.getStagePayCalcBase(ctx.stage, ctx.tender.info);
|
|
|
renderData.jsFiles = this.app.jsFiles.common.concat(this.app.jsFiles.stage.pay);
|
|
|
renderData.whiteList = this.ctx.app.config.multipart.whitelist;
|
|
@@ -879,17 +874,13 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
// 用户有无权限上传和删除附件
|
|
|
- renderData.uploadPermission = (!(ctx.stage.readOnly || ctx.stage.revising) && ((ctx.stage.status === auditConst.status.uncheck || ctx.stage.status === auditConst.status.checkNo) && ctx.session.sessionUser.accountId === ctx.stage.user_id) ||
|
|
|
- (ctx.stage.status === auditConst.status.checkNoPre && ctx.session.sessionUser.accountId === ctx.stage.curAuditor.aid) ||
|
|
|
- (ctx.stage.status === auditConst.status.checking && ctx.stage.curAuditor && ctx.stage.curAuditor.aid === ctx.session.sessionUser.accountId)) ||
|
|
|
- (ctx.tender.isTourist && ctx.tender.touristPermission.file);
|
|
|
+ renderData.uploadPermission = !ctx.tender.isTourist || ctx.tender.touristPermission.file;
|
|
|
|
|
|
if (!ctx.stage.readOnly || ctx.tender.isTourist) {
|
|
|
// 计算 本期金额
|
|
|
const payCalculator = new PayCalculator(ctx, ctx.stage, ctx.tender.info);
|
|
|
await payCalculator.calculateAll(renderData.dealPay);
|
|
|
await this._updateStageCache(ctx, payCalculator);
|
|
|
- // renderData.calcBase = payCalculator.bases;
|
|
|
}
|
|
|
await this.layout('stage/pay.ejs', renderData, 'stage/pay_modal.ejs');
|
|
|
} catch (err) {
|
|
@@ -1736,6 +1727,7 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 合同支付上传附件
|
|
|
* @param {Object} ctx - egg全局变量
|
|
@@ -1749,9 +1741,6 @@ module.exports = app => {
|
|
|
};
|
|
|
let stream;
|
|
|
try {
|
|
|
- // this._checkStageCanModify(ctx);
|
|
|
- this._checkStageCanModifyRe(ctx);
|
|
|
-
|
|
|
const parts = ctx.multipart({ autoFields: true });
|
|
|
const files = [];
|
|
|
let index = 0;
|
|
@@ -1774,23 +1763,22 @@ module.exports = app => {
|
|
|
await sendToWormhole(stream);
|
|
|
// 插入到stage_pay对应的附件列表中
|
|
|
const attData = {
|
|
|
+ tid: this.ctx.tender.id,
|
|
|
+ sid: this.ctx.stage.id,
|
|
|
+ uid: ctx.session.sessionUser.accountId,
|
|
|
+ pid: parts.field.pay_id,
|
|
|
filename: fileInfo.name,
|
|
|
fileext: fileInfo.ext,
|
|
|
filesize: Array.isArray(parts.field.size) ? parts.field.size[index] : parts.field.size,
|
|
|
filepath: path.join(dirName, fileName),
|
|
|
- uid: ctx.session.sessionUser.accountId,
|
|
|
in_time: moment(create_time * 1000).format('YYYY-MM-DD'),
|
|
|
+ renew: this.ctx.stage.status === auditConst.status.checked,
|
|
|
};
|
|
|
- const result = await ctx.service.stagePay.saveAtt(parts.field.pay_id, attData);
|
|
|
- if (!result) {
|
|
|
- throw '导入数据库保存失败';
|
|
|
- }
|
|
|
- delete attData.filepath;
|
|
|
attData.username = ctx.session.sessionUser.name;
|
|
|
files.length !== 0 ? files.unshift(attData) : files.push(attData);
|
|
|
++index;
|
|
|
}
|
|
|
- responseData.data = files;
|
|
|
+ responseData.data = await ctx.service.payAtt.addFiles(files);
|
|
|
} catch (err) {
|
|
|
this.log(err);
|
|
|
// 失败需要消耗掉stream 以防卡死
|
|
@@ -1810,38 +1798,33 @@ module.exports = app => {
|
|
|
* @return {void}
|
|
|
*/
|
|
|
async payDownloadFile(ctx) {
|
|
|
- const id = ctx.params.pid;
|
|
|
- const index = ctx.params.index;
|
|
|
- if (id && index) {
|
|
|
- try {
|
|
|
- const payInfo = await ctx.service.stagePay.getDataById(id);
|
|
|
- if (payInfo !== undefined && payInfo.attachment !== null) {
|
|
|
- const fileInfo = JSON.parse(payInfo.attachment)[index];
|
|
|
- const fileName = path.join(this.app.baseDir, fileInfo.filepath);
|
|
|
- // 解决中文无法下载问题
|
|
|
- const userAgent = (ctx.request.header['user-agent'] || '').toLowerCase();
|
|
|
- let disposition = '';
|
|
|
- if (userAgent.indexOf('msie') >= 0 || userAgent.indexOf('chrome') >= 0) {
|
|
|
- disposition = 'attachment; filename=' + encodeURIComponent(fileInfo.filename + fileInfo.fileext);
|
|
|
- } else if (userAgent.indexOf('firefox') >= 0) {
|
|
|
- disposition = 'attachment; filename*="utf8\'\'' + encodeURIComponent(fileInfo.filename + fileInfo.fileext) + '"';
|
|
|
- } else {
|
|
|
- /* safari等其他非主流浏览器只能自求多福了 */
|
|
|
- disposition = 'attachment; filename=' + new Buffer(fileInfo.filename + fileInfo.fileext).toString('binary');
|
|
|
- }
|
|
|
- ctx.response.set({
|
|
|
- 'Content-Type': 'application/octet-stream',
|
|
|
- 'Content-Disposition': disposition,
|
|
|
- 'Content-Length': fileInfo.filesize,
|
|
|
- });
|
|
|
- ctx.body = await fs.createReadStream(fileName);
|
|
|
- } else {
|
|
|
- throw '不存在该文件';
|
|
|
- }
|
|
|
- } catch (err) {
|
|
|
- this.log(err);
|
|
|
- this.setMessage(err.toString(), this.messageType.ERROR);
|
|
|
+ const id = ctx.params.id;
|
|
|
+ try {
|
|
|
+ if (!id) throw '数据错误';
|
|
|
+ const fileInfo = ctx.service.payAtt.getDataById(id);
|
|
|
+ if (!fileInfo) throw '不存在该文件';
|
|
|
+
|
|
|
+ const fileName = path.join(this.app.baseDir, fileInfo.filepath);
|
|
|
+ // 解决中文无法下载问题
|
|
|
+ const userAgent = (ctx.request.header['user-agent'] || '').toLowerCase();
|
|
|
+ let disposition = '';
|
|
|
+ if (userAgent.indexOf('msie') >= 0 || userAgent.indexOf('chrome') >= 0) {
|
|
|
+ disposition = 'attachment; filename=' + encodeURIComponent(fileInfo.filename + fileInfo.fileext);
|
|
|
+ } else if (userAgent.indexOf('firefox') >= 0) {
|
|
|
+ disposition = 'attachment; filename*="utf8\'\'' + encodeURIComponent(fileInfo.filename + fileInfo.fileext) + '"';
|
|
|
+ } else {
|
|
|
+ /* safari等其他非主流浏览器只能自求多福了 */
|
|
|
+ disposition = 'attachment; filename=' + new Buffer(fileInfo.filename + fileInfo.fileext).toString('binary');
|
|
|
}
|
|
|
+ ctx.response.set({
|
|
|
+ 'Content-Type': 'application/octet-stream',
|
|
|
+ 'Content-Disposition': disposition,
|
|
|
+ 'Content-Length': fileInfo.filesize,
|
|
|
+ });
|
|
|
+ ctx.body = await fs.createReadStream(fileName);
|
|
|
+ } catch (err) {
|
|
|
+ this.log(err);
|
|
|
+ this.setMessage(err.toString(), this.messageType.ERROR);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1851,41 +1834,20 @@ module.exports = app => {
|
|
|
* @return {void}
|
|
|
*/
|
|
|
async payDeleteFile(ctx) {
|
|
|
- const responseData = {
|
|
|
- err: 0,
|
|
|
- msg: '',
|
|
|
- data: '',
|
|
|
- };
|
|
|
try {
|
|
|
- // this._checkStageCanModify(ctx);
|
|
|
- this._checkStageCanModifyRe(ctx);
|
|
|
-
|
|
|
const data = JSON.parse(ctx.request.body.data);
|
|
|
- const payInfo = await ctx.service.stagePay.getDataById(data.id);
|
|
|
- if (payInfo !== undefined) {
|
|
|
- const fileInfo = JSON.parse(payInfo.attachment)[data.index];
|
|
|
- // 先删除文件
|
|
|
- await fs.unlinkSync(path.join(this.app.baseDir, fileInfo.filepath));
|
|
|
- // 再删除数据库
|
|
|
- const attachment = JSON.parse(payInfo.attachment);
|
|
|
- attachment.splice(data.index, 1);
|
|
|
- const result = await ctx.service.stagePay.deleteAtt(data.id, attachment);
|
|
|
- responseData.data = '';
|
|
|
- } else {
|
|
|
- throw '不存在该文件';
|
|
|
- }
|
|
|
+ const fileInfo = await ctx.service.payAtt.getDataById(data.id);
|
|
|
+ if (!fileInfo) throw '不存在该文件';
|
|
|
|
|
|
- // if (data.tid === undefined || data.uci === undefined || data.uc === undefined || data.ac === undefined) {
|
|
|
- // throw '参数有误';
|
|
|
- // }
|
|
|
- // const [addCompany, selectCompany] = await ctx.service.changeCompany.setCompanyList(data);
|
|
|
- // responseData.data = { add: addCompany, select: selectCompany };
|
|
|
+ const result = await ctx.service.payAtt.delFiles(data.id);
|
|
|
+ if (fs.existsSync(path.join(ctx.app.baseDir, fileInfo.filepath))) {
|
|
|
+ await fs.unlinkSync(path.join(ctx.app.baseDir, fileInfo.filepath));
|
|
|
+ }
|
|
|
+ ctx.body = { err: 0, msg: '', data: result };
|
|
|
} catch (err) {
|
|
|
- responseData.err = 1;
|
|
|
- responseData.msg = err;
|
|
|
+ ctx.log(err);
|
|
|
+ ctx.ajaxErrorBody(err, '删除文件错误');
|
|
|
}
|
|
|
-
|
|
|
- ctx.body = responseData;
|
|
|
}
|
|
|
|
|
|
|