Browse Source

期删除bug

laiguoran 5 years ago
parent
commit
612fffdbd3
1 changed files with 6 additions and 2 deletions
  1. 6 2
      app/service/stage.js

+ 6 - 2
app/service/stage.js

@@ -308,7 +308,9 @@ module.exports = app => {
                         if (pt.attachment !== null && pt.attachment !== '') {
                         if (pt.attachment !== null && pt.attachment !== '') {
                             const payAttList = JSON.parse(pt.attachment);
                             const payAttList = JSON.parse(pt.attachment);
                             for (const pat of payAttList) {
                             for (const pat of payAttList) {
-                                await fs.unlinkSync(path.join(this.app.baseDir, pat.filepath));
+                                if (fs.existsSync(path.join(this.app.baseDir, pat.filepath))) {
+                                    await fs.unlinkSync(path.join(this.app.baseDir, pat.filepath));
+                                }
                             }
                             }
                         }
                         }
                     }
                     }
@@ -318,7 +320,9 @@ module.exports = app => {
                 const attList = await this.ctx.service.stageAtt.getAllDataByCondition({ where: { sid: id } });
                 const attList = await this.ctx.service.stageAtt.getAllDataByCondition({ where: { sid: id } });
                 if (attList.length !== 0) {
                 if (attList.length !== 0) {
                     for (const att of attList) {
                     for (const att of attList) {
-                        await fs.unlinkSync(path.join(this.app.baseDir, att.filepath));
+                        if (fs.existsSync(path.join(this.app.baseDir, att.filepath))) {
+                            await fs.unlinkSync(path.join(this.app.baseDir, att.filepath));
+                        }
                     }
                     }
                 }
                 }
                 await transaction.delete(this.ctx.service.stageAtt.tableName, { sid: id });
                 await transaction.delete(this.ctx.service.stageAtt.tableName, { sid: id });