Jelajahi Sumber

feat: 变更附件删除逻辑优化

lanjianrong 4 tahun lalu
induk
melakukan
b47642819c

+ 7 - 0
app/controller/change_controller.js

@@ -630,6 +630,8 @@ module.exports = app => {
                 const parts = ctx.multipart({ autoFields: true });
                 const files = [];
                 let index = 0;
+                const change = await ctx.service.change.getDataByCondition({ cid: ctx.params.cid });
+                const extra_upload = change.status === audit.flow.status.checked;
                 while ((stream = await parts()) !== undefined) {
                     // 判断用户是否选择上传文件
                     if (!stream.filename) {
@@ -657,6 +659,7 @@ module.exports = app => {
                         fileext: fileInfo.ext,
                         filesize: Array.isArray(parts.field.size) ? parts.field.size[index] : parts.field.size,
                         filepath,
+                        extra_upload,
                     };
                     const result = await ctx.service.changeAtt.save(parts.field, fileData, ctx.session.sessionUser.accountId);
                     if (!result) {
@@ -777,7 +780,11 @@ module.exports = app => {
             };
             try {
                 const data = JSON.parse(ctx.request.body.data);
+                const change = await ctx.service.change.getDataByCondition({ cid: ctx.params.cid });
                 const fileInfo = await ctx.service.changeAtt.getDataById(data.id);
+                if (!fileInfo.extra_upload && change.status === audit.flow.status.checked) {
+                    throw '无权限删除';
+                }
                 if (fileInfo !== undefined && fileInfo !== '') {
                     // 先删除文件
                     await fs.unlinkSync(path.join(this.app.baseDir, fileInfo.filepath));

+ 7 - 6
app/public/js/change_detail.js

@@ -74,7 +74,7 @@ $(document).ready(() => {
             formData.append('size', filesize);
             formData.append('file[]', file);
         }
-        postDataWithFile('/change/upload/file', formData, function (data) {
+        postDataWithFile(window.location.pathname + '/file/upload', formData, function (data) {
             $('#addfujian').modal('hide');
             let html = '';
             let index = $('#attList tr').length + 1;
@@ -85,10 +85,11 @@ $(document).ready(() => {
                     `<td><a href="javascript: void(0);" class="file-atn" f-id="${fileInfo.id}">${fileInfo.filename}${fileInfo.fileext}</a></td>`+
                     '<td>' + fileInfo.filesize + '</td> ' +
                     '<td>' + fileInfo.in_time + '</td> ' +
-                    `<td>
-                        <a href="/change/download/file/${fileInfo.id}" class="btn btn-light btn-sm" title="下载"><span class="fa fa-download text-primary"></span></a>
-                        <a class="btn btn-light btn-sm delete-file" data-attid="${fileInfo.id}"  title="删除附件"><span class="fa fa-trash text-danger"></span></a>
-                    </td>`+
+                    `<td><a href="/change/download/file/${fileInfo.id}" class="btn btn-light btn-sm" title="下载"><span class="fa fa-download text-primary"></span></a>`+
+                    ( auditStatus === 4 ?
+                        fileInfo.extra_upload ? `<a class="btn btn-light btn-sm delete-file" data-attid="${fileInfo.id}"  title="删除附件"><span class="fa fa-trash text-danger"></span></a>` : ''
+                        : ` <a class="btn btn-light btn-sm delete-file" data-attid="${fileInfo.id}"  title="删除附件"><span class="fa fa-trash text-danger"></span></a>`)+
+                    `</td>`+
                     // '<td> <a class="btn btn-light btn-sm delete-file" data-attid="' + fileInfo.id + '"  title="删除附件"><span class="fa fa-trash text-danger"></span></a> </td> ' +
                     '</tr>';
                 ++index;
@@ -106,7 +107,7 @@ $(document).ready(() => {
         let attid = $(this).data('attid');
         let self = $(this);
         const data = {id: attid};
-        postData('/change/delete/file', data, function (result) {
+        postData(window.location.pathname + '/file/delete', data, function (result) {
             self.parents('tr').remove();
             // 重新排序
             let newsort = 1;

+ 2 - 2
app/router.js

@@ -306,10 +306,10 @@ module.exports = app => {
     app.post('/tender/:id/change/add', sessionAuth, tenderCheck, uncheckTenderCheck, 'changeController.add');
     app.post('/tender/:id/change/defaultBills', sessionAuth, tenderCheck, uncheckTenderCheck, 'changeController.defaultBills');
     app.get('/tender/:id/change/:cid/info', sessionAuth, tenderCheck, uncheckTenderCheck, 'changeController.info');
-    app.post('/change/upload/file', sessionAuth, 'changeController.uploadFile');
+    app.post('/tender/:id/change/:cid/info/file/upload', sessionAuth, 'changeController.uploadFile');
     app.get('/change/download/file/:id', sessionAuth, 'changeController.downloadFile');
     app.post('/change/download/file/:id', sessionAuth, 'changeController.checkFile');
-    app.post('/change/delete/file', sessionAuth, 'changeController.deleteFile');
+    app.post('/tender/:id/change/:cid/info/file/delete', sessionAuth, 'changeController.deleteFile');
     app.get('/tender/:id/change/:cid/download/compresse-file', sessionAuth, tenderCheck, uncheckTenderCheck, 'changeController.downloadZip');
     app.post('/tender/:id/change/delete', sessionAuth, tenderCheck, uncheckTenderCheck, 'changeController.delete');
     app.post('/tender/:id/change/bills', sessionAuth, tenderCheck, uncheckTenderCheck, 'changeController.bills');

+ 2 - 1
app/view/change/info.ejs

@@ -725,7 +725,7 @@
                     <td><%- moment(att.in_time * 1000).format('YYYY-MM-DD') %></td>
                     <td>
                         <a href="/change/download/file/<%- att.id %>" class="btn btn-light btn-sm" title="下载"><span class="fa fa-download text-primary"></span></a>
-                        <% if (att.uid === uid && (auditStatus === 1 || auditStatus === 2 || auditStatus === 6)) { %>
+                        <% if (att.uid === uid && (auditStatus === 4 ? Boolean(att.extra_upload) : true )) { %>
                         <a class="btn btn-light btn-sm delete-file" data-attid="<%- att.id %>" title="删除附件"><span class="fa fa-trash text-danger"></span></a>
                         <% } %>
                     </td>
@@ -745,6 +745,7 @@
     const accountId = '<%- uid %>';
     const ledgeStatus = '<%- tender.ledger_status %>';
     const ledgerConsts = JSON.parse('<%- JSON.stringify(ledgerConsts) %>');
+    const auditStatus = '<%- auditStatus %>'
     autoFlashHeight();
     $('a[href="#sub-ap"').click(function() {
         if (parseInt(ledgeStatus) === ledgerConsts.uncheck) {

+ 3 - 0
sql/update.sql

@@ -12,3 +12,6 @@ MODIFY COLUMN `dagl_status`  int(4) NULL DEFAULT -1 COMMENT '档案管理-状态
 
 ALTER TABLE `zh_stage_attachment`
 CHANGE COLUMN `re_upload` `extra_upload` TINYINT(1) NOT NULL DEFAULT '0' COMMENT '是否为审核通过后再次上传的文件,0为否' ;
+
+ALTER TABLE `zh_change_attachment`
+ADD COLUMN `extra_upload` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否为审核通过后再次上传的文件,0为否' AFTER `in_time`;