Parcourir la source

fix: 材料调差-多附件上传bug修复

lanjianrong il y a 5 ans
Parent
commit
ce4a50446e
1 fichiers modifiés avec 5 ajouts et 3 suppressions
  1. 5 3
      app/controller/material_controller.js

+ 5 - 3
app/controller/material_controller.js

@@ -624,17 +624,19 @@ module.exports = app => {
                     autoFields: true,
                 });
                 const files = [];
-                const create_time = Date.parse(new Date()) / 1000;
+                let idx = 0;
                 while ((stream = await parts()) != null) {
                     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 + 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));
                     files.push({ filepath, name: stream.filename });
+                    idx++;
                 }
                 const upload_time = this.ctx.helper.dateTran(new Date());
                 const payload = files.map(file => {
@@ -698,7 +700,7 @@ module.exports = app => {
                 const fileInfo = await ctx.service.materialFile.getMaterialFileById(id);
                 if (fileInfo) {
                     // 先删除文件
-                    await fs.unlinkSync(path.join(this.app.baseDir, './app', fileInfo.filepath));
+                    await fs.unlinkSync(path.resolve(this.app.baseDir, './app', fileInfo.filepath));
                     // 再删除数据库
                     await ctx.service.materialFile.delete(id);
                 } else {