Selaa lähdekoodia

fix: 材料调差删除附件bug修复

lanjianrong 5 vuotta sitten
vanhempi
commit
9947d7ce12
2 muutettua tiedostoa jossa 6 lisäystä ja 8 poistoa
  1. 3 4
      app/controller/material_controller.js
  2. 3 4
      app/service/material.js

+ 3 - 4
app/controller/material_controller.js

@@ -618,24 +618,23 @@ module.exports = app => {
          */
         async upload(ctx) {
             let stream;
-            console.log(await fs.readdirSync(path.join(this.app.baseDir, 'app', 'public/upload/2647/tc')));
             try {
                 this._checkMaterialFileCanModify(ctx);
                 const parts = this.ctx.multipart({
                     autoFields: true,
                 });
                 const files = [];
+                const create_time = Date.parse(new Date()) / 1000;
                 let idx = 0;
-                while ((stream = await parts()) != null) {
+                while ((stream = await parts()) !== undefined) {
                     if (!stream.filename) {
                         // 如果没有传入直接返回
                         return;
                     }
-                    const create_time = Date.parse(new Date()) / 1000;
                     const fileInfo = path.parse(stream.filename);
                     // const filepath = path.join('public/upload', this.ctx.tender.id.toString(), 'tc', 'fujian_' + create_time + fileInfo.ext);
                     const filepath = `public/upload/${this.ctx.tender.id.toString()}/tc/fujian_${create_time + idx + fileInfo.ext}`;
-                    await ctx.helper.saveStreamFile(stream, path.join(this.app.baseDir, 'app', filepath));
+                    await ctx.helper.saveStreamFile(stream, path.resolve(this.app.baseDir, 'app', filepath));
                     files.push({ filepath, name: stream.filename });
                     idx++;
                 }

+ 3 - 4
app/service/material.js

@@ -9,7 +9,6 @@
  */
 
 const auditConst = require('../const/audit').material;
-
 module.exports = app => {
     class Material extends app.BaseService {
         /**
@@ -174,6 +173,9 @@ module.exports = app => {
         async deleteMaterial(id) {
             const transaction = await this.db.beginTransaction();
             try {
+                // 删除文件
+                const attList = await this.ctx.service.materialFile.getAllMaterialFiles(this.ctx.tender.id, id);
+                await this.ctx.helper.delFiles(attList);
                 await transaction.delete(this.ctx.service.materialAudit.tableName, { mid: id });
                 await transaction.delete(this.ctx.service.materialBills.tableName, { mid: id });
                 await transaction.delete(this.ctx.service.materialList.tableName, { mid: id });
@@ -192,9 +194,6 @@ module.exports = app => {
                 }
                 await transaction.delete(this.tableName, { id });
                 await transaction.commit();
-                // 删除期第一个参数不用传,第二个为期数
-                const attList = await this.ctx.service.materialFile.getAllMaterialFiles('', id);
-                await this.ctx.helper.delFiles(attList);
                 return true;
             } catch (err) {
                 await transaction.rollback();