Browse Source

重新审批,其他台账数据问题

MaiXinRong 4 years ago
parent
commit
cbd09013fd
4 changed files with 78 additions and 3 deletions
  1. 3 3
      app/service/stage_audit.js
  2. 21 0
      app/service/stage_bonus.js
  3. 29 0
      app/service/stage_jgcl.js
  4. 25 0
      app/service/stage_other.js

+ 3 - 3
app/service/stage_audit.js

@@ -882,9 +882,9 @@ module.exports = app => {
                 // 复制一份最新数据给下一人
                 await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times, audit.order + 1, transaction);
                 await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times, audit.order + 2, transaction);
-                await this.ctx.service.stageJgcl.updateHistory(this.ctx.stage, transaction);
-                await this.ctx.service.stageBonus.updateHistory(this.ctx.stage, transaction);
-                await this.ctx.service.stageOther.updateHistory(this.ctx.stage, transaction);
+                await this.ctx.service.stageJgcl.updateHistory4CheckAgain(this.ctx.stage, transaction);
+                await this.ctx.service.stageBonus.updateHistory4CheckAgain(this.ctx.stage, transaction);
+                await this.ctx.service.stageOther.updateHistory4CheckAgain(this.ctx.stage, transaction);
 
                 // 本期结束
                 // 生成截止本期数据 final数据

+ 21 - 0
app/service/stage_bonus.js

@@ -192,6 +192,27 @@ module.exports = app => {
             await transaction.updateRows(this.tableName, updateDatas);
         }
 
+        async updateHistory(stage, transaction) {
+            const datas = await this.getStageData(stage.id);
+            if (datas.length === 0) return;
+
+            const updateDatas = [];
+            const times = this.ctx.stage.curTimes, order = this.ctx.stage.curOrder + 1;
+            for (const d of datas) {
+                const history = d.shistory && d.shistory !== '' ? JSON.parse(d.shistory) : [];
+                const his = history.find(function (x) {
+                    return x.stimes && x.stimes === times
+                        && x.sorder && x.sorder === order;
+                });
+                if (his) {
+                    his.tp = d.tp;
+                } else {
+                    history.push({ stimes: times, sorder: order, tp: d.tp });
+                }
+                updateDatas.push({ id: d.id, shistory: JSON.stringify(history) });
+            }
+            await transaction.updateRows(this.tableName, updateDatas);
+        }
 
         async deleteStageTimesData(sid, times, transaction) {
             const datas = await this.getAllDataByCondition({where: { sid: sid }});

+ 29 - 0
app/service/stage_jgcl.js

@@ -223,6 +223,35 @@ module.exports = app => {
             await transaction.updateRows(this.tableName, updateDatas);
         }
 
+        async updateHistory4CheckAgain(stage, transaction) {
+            const datas = await this.getStageData(stage);
+            if (datas.length === 0) return;
+
+            const updateDatas = [];
+            const times = this.ctx.stage.curTimes, order = this.ctx.stage.curOrder + 1;
+            for (const d of datas) {
+                const history = d.shistory && d.shistory !== '' ? JSON.parse(d.shistory) : [];
+                const his = history.find(function (x) {
+                    return x.stimes && x.stimes === times
+                        && x.sorder && x.sorder === order;
+                });
+                if (his) {
+                    his.arrive_qty = d.arrive_qty;
+                    his.arrive_tp = d.arrive_tp;
+                    his.deduct_qty = d.deduct_qty;
+                    his.deduct_tp = d.deduct_tp;
+                } else {
+                    history.push({
+                        stimes: times, sorder: order,
+                        arrive_qty: d.arrive_qty, arrive_tp: d.arrive_tp,
+                        deduct_qty: d.deduct_qty, deduct_tp: d.deduct_tp
+                    });
+                }
+                updateDatas.push({ id: d.id, shistory: JSON.stringify(history) });
+            }
+            await transaction.updateRows(this.tableName, updateDatas);
+        }
+
         async addInitialStageData(stage, preStage, transaction) {
             if (!stage || !preStage) {
                 throw '标段数据有误';

+ 25 - 0
app/service/stage_other.js

@@ -189,6 +189,31 @@ module.exports = app => {
             await transaction.updateRows(this.tableName, updateDatas);
         }
 
+        async updateHistory4CheckAgain(stage, transaction) {
+            const datas = await this.getStageData(stage);
+            if (datas.length === 0) return;
+
+            const updateDatas = [];
+            const times = this.ctx.stage.curTimes, order = this.ctx.stage.curOrder + 1;
+            for (const d of datas) {
+                const history = d.shistory && d.shistory !== '' ? JSON.parse(d.shistory) : [];
+                const his = history.find(function (x) {
+                    return x.stimes && x.stimes === times
+                        && x.sorder && x.sorder === order;
+                });
+                if (his) {
+                    his.tp = d.tp;
+                    if (d.sid === d.add_sid) his.total_price = d.total_price;
+                } else {
+                    const nHis = { stimes: times, sorder: order, tp: d.tp };
+                    if (d.sid === d.add_sid) nHis.total_price = d.total_price;
+                    history.push(nHis);
+                }
+                updateDatas.push({ id: d.id, shistory: JSON.stringify(history) });
+            }
+            await transaction.updateRows(this.tableName, updateDatas);
+        }
+
         async addInitialStageData(stage, preStage, transaction) {
             if (!stage || !preStage) {
                 throw '标段数据有误';