|
@@ -10,6 +10,8 @@
|
|
|
|
|
|
const auditConst = require('../const/audit').stage;
|
|
|
const payConst = require('../const/deal_pay.js');
|
|
|
+const fs = require('fs');
|
|
|
+const path = require('path');
|
|
|
|
|
|
module.exports = app => {
|
|
|
class Stage extends app.BaseService {
|
|
@@ -269,7 +271,53 @@ module.exports = app => {
|
|
|
const result = await this.db.update(this.tableName, {id: sid, check_detail: check});
|
|
|
return result.affectedRows === 1;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除计量期
|
|
|
+ *
|
|
|
+ * @param {Number} id - 期Id
|
|
|
+ * @returns {Promise<void>}
|
|
|
+ */
|
|
|
+ async deleteStage(id) {
|
|
|
+ const transaction = await this.db.beginTransaction();
|
|
|
+ try {
|
|
|
+ await transaction.delete(this.tableName, { id });
|
|
|
+ await transaction.delete(this.ctx.service.stageAudit.tableName, { sid: id });
|
|
|
+ await transaction.delete(this.ctx.service.stageBills.tableName, { sid: id });
|
|
|
+ await transaction.delete(this.ctx.service.stageChange.tableName, { sid: id });
|
|
|
+ await transaction.delete(this.ctx.service.stagePos.tableName, { sid: id });
|
|
|
+ await transaction.delete(this.ctx.service.stageDetail.tableName, { sid: id });
|
|
|
+ await transaction.delete(this.ctx.service.stagePosFinal.tableName, { sid: id });
|
|
|
+ await transaction.delete(this.ctx.service.stageBillsFinal.tableName, { sid: id });
|
|
|
+ // 删除计量合同支付附件
|
|
|
+ const payList = await this.ctx.service.stagePay.getAllDataByCondition({ where: { sid: id } });
|
|
|
+ if (payList) {
|
|
|
+ for (const pt of payList) {
|
|
|
+ if (pt.attachment !== null && pt.attachment !== '') {
|
|
|
+ const payAttList = JSON.parse(pt.attachment);
|
|
|
+ for (const pat of payAttList) {
|
|
|
+ await fs.unlinkSync(path.join(this.app.baseDir, pat.filepath));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ await transaction.delete(this.ctx.service.stagePay.tableName, { sid: id });
|
|
|
+ // 删除计量附件文件
|
|
|
+ const attList = await this.ctx.service.stageAtt.getAllDataByCondition({ where: { sid: id } });
|
|
|
+ if (attList.length !== 0) {
|
|
|
+ for (const att of attList) {
|
|
|
+ await fs.unlinkSync(path.join(this.app.baseDir, att.filepath));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ await transaction.delete(this.ctx.service.StageAtt.tableName, { sid: id });
|
|
|
+ await transaction.commit();
|
|
|
+ return true;
|
|
|
+ } catch (err) {
|
|
|
+ await transaction.rollback();
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return Stage;
|
|
|
-};
|
|
|
+};
|