|
@@ -519,7 +519,19 @@ module.exports = app => {
|
|
|
try {
|
|
|
await this._getStageAuditViewData(ctx);
|
|
|
const renderData = await this._getDefaultRenderData(ctx);
|
|
|
- renderData.dealPay = await ctx.service.stagePay.getStagePays(ctx.stage);
|
|
|
+ const dealPay = await ctx.service.stagePay.getStagePays(ctx.stage);
|
|
|
+ // 附件不取下载地址
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ renderData.dealPay = dealPay;
|
|
|
// if (dealPay && dealPay.length > 0) {
|
|
|
// renderData.dealPay = dealPay;
|
|
|
// } else {
|
|
@@ -529,6 +541,7 @@ module.exports = app => {
|
|
|
// }
|
|
|
renderData.calcBase = await ctx.service.stage.getStagePayCalcBase();
|
|
|
renderData.jsFiles = this.app.jsFiles.common.concat(this.app.jsFiles.stage.pay);
|
|
|
+ renderData.whiteList = this.ctx.app.config.multipart.whitelist;
|
|
|
|
|
|
// 计算 本期金额
|
|
|
const payCalculator = new PayCalculator(this.ctx, this.ctx.tender.info.decimal);
|
|
@@ -1155,6 +1168,141 @@ module.exports = app => {
|
|
|
}
|
|
|
ctx.body = responseData;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 合同支付上传附件
|
|
|
+ * @param {Object} ctx - egg全局变量
|
|
|
+ * @return {void}
|
|
|
+ */
|
|
|
+ async payUploadFile(ctx) {
|
|
|
+ const responseData = {
|
|
|
+ err: 0,
|
|
|
+ msg: '',
|
|
|
+ data: [],
|
|
|
+ };
|
|
|
+ let stream;
|
|
|
+ try {
|
|
|
+ stream = await ctx.getFileStream();
|
|
|
+ const create_time = Date.parse(new Date()) / 1000;
|
|
|
+ const fileInfo = path.parse(stream.filename);
|
|
|
+ const dirName = 'app/public/upload/pay/' + moment().format('YYYYMMDD');
|
|
|
+ const fileName = 'pay' + create_time + fileInfo.ext;
|
|
|
+
|
|
|
+ // 判断文件夹是否存在,不存在则直接创建文件夹
|
|
|
+ if (!fs.existsSync(path.join(this.app.baseDir, dirName))) {
|
|
|
+ await fs.mkdirSync(path.join(this.app.baseDir, dirName));
|
|
|
+ }
|
|
|
+ // 保存文件
|
|
|
+ await ctx.helper.saveStreamFile(stream, path.join(this.app.baseDir, dirName, fileName));
|
|
|
+ // 插入到stage_pay对应的附件列表中
|
|
|
+ const attData = {
|
|
|
+ filename: fileInfo.name,
|
|
|
+ fileext: fileInfo.ext,
|
|
|
+ filesize: stream.fields.size,
|
|
|
+ filepath: path.join(dirName, fileName),
|
|
|
+ uid: ctx.session.sessionUser.accountId,
|
|
|
+ in_time: moment(create_time * 1000).format('YYYY-MM-DD'),
|
|
|
+ };
|
|
|
+ const result = await ctx.service.stagePay.saveAtt(stream.fields.pay_id, attData);
|
|
|
+ if (!result) {
|
|
|
+ throw '导入数据库保存失败';
|
|
|
+ }
|
|
|
+ delete attData.filepath
|
|
|
+ attData.username = ctx.session.sessionUser.name;
|
|
|
+ responseData.data = attData;
|
|
|
+ } catch (err) {
|
|
|
+ this.log(err);
|
|
|
+ // 失败需要消耗掉stream 以防卡死
|
|
|
+ if (stream) {
|
|
|
+ await sendToWormhole(stream);
|
|
|
+ }
|
|
|
+ this.setMessage(err.toString(), this.messageType.ERROR);
|
|
|
+ responseData.err = 1;
|
|
|
+ responseData.msg = err.toString();
|
|
|
+ }
|
|
|
+ ctx.body = responseData;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 合同支付下载附件
|
|
|
+ * @param {Object} ctx - egg全局变量
|
|
|
+ * @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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 合同支付删除附件
|
|
|
+ * @param {Object} ctx - egg全局变量
|
|
|
+ * @return {void}
|
|
|
+ */
|
|
|
+ async payDeleteFile(ctx) {
|
|
|
+ const responseData = {
|
|
|
+ err: 0,
|
|
|
+ msg: '',
|
|
|
+ data: '',
|
|
|
+ };
|
|
|
+ try {
|
|
|
+ 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 '不存在该文件';
|
|
|
+ }
|
|
|
+
|
|
|
+ // 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 };
|
|
|
+ } catch (err) {
|
|
|
+ responseData.err = 1;
|
|
|
+ responseData.msg = err;
|
|
|
+ }
|
|
|
+
|
|
|
+ ctx.body = responseData;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return StageController;
|