ソースを参照

审批通过,重置下一期合同支付数据

MaiXinRong 1 年間 前
コミット
8fc45d9180
2 ファイル変更30 行追加0 行削除
  1. 1 0
      app/service/stage_audit.js
  2. 29 0
      app/service/stage_pay.js

+ 1 - 0
app/service/stage_audit.js

@@ -576,6 +576,7 @@ module.exports = app => {
                                 pre_sf_tp: this.ctx.helper.add(this.ctx.stage.pre_sf_tp, stageTp.sf_tp),
                             };
                             await transaction.updateRows(this.ctx.service.stage.tableName, nextStages.map(x => { return { id: x.id, ...preStageTp }; }));
+                            await this.ctx.service.stagePay.reInitialStageData(this.ctx.stage, nextStages[0], transaction);
                         }
 
                         // 添加短信通知-审批通过提醒功能

+ 29 - 0
app/service/stage_pay.js

@@ -134,6 +134,35 @@ module.exports = app => {
             }
             return result.affectedRows === stagePays.length;
         }
+        async reInitialStageData(preStage, stage, transaction) {
+            if (!stage || !preStage || !transaction) throw '检查合同支付数据失败';
+
+            const basesReg = new RegExp(payConst.calcBase.map(x => {return '(' + x.code + ')'}).join('|'));
+            const orderReg = /f\d+/im;
+
+            let pays = await this.ctx.service.pay.getAllDataByCondition({where: { tid: this.ctx.tender.id } });
+            const stagePays = [];
+            const prePays = await this.getStageLastestPays(preStage);
+            for (const pp of prePays) {
+                const p = this._.find(pays, {id: pp.pid});
+                if (!p.valid) continue;
+                stagePays.push({
+                    tid: p.tid, sid: stage.id, pid: p.id,
+                    stimes: stage.times, sorder: 0,
+                    name: pp.name,
+                    expr: (p.ptype === payConst.payType.normal || p.ptype === payConst.payType.sf)
+                        ? (basesReg.test(pp.expr) || orderReg.test(pp.expr) ? pp.expr : null)
+                        : (p.type === payConst.wc ? pp.expr : null),
+                    pause: pp.pause,
+                    pre_tp: pp.end_tp,
+                    pre_used: pp.pre_used || !this.ctx.helper.checkZero(pp.tp),
+                    pre_finish: pp.pre_finish || (pp.rprice ? pp.end_tp === pp.rprice : false),
+                    start_stage_order: pp.start_stage_order,
+                });
+            }
+            await transaction.delete(this.tableName, { sid: stage.id });
+            await transaction.insert(this.tableName, stagePays);
+        }
 
         async getStagePay(stage, pid) {
             return await this.getAuditorStagePay(pid, stage.id, stage.curTimes, stage.curOrder);