Browse Source

修复撤回bug及整合代码

laiguoran 2 years ago
parent
commit
6da09d668a

+ 37 - 37
app/service/stage_audit.js

@@ -993,6 +993,7 @@ module.exports = app => {
             const time = new Date();
             try {
                 await this._updateTender(transaction);
+                let newTimes, newOrder, newSaid, oldTimes, oldOrder, oldSaid = '';
                 if (this.ctx.stage.cancancel === 1) {
                     // 原报撤回,判断是否为多次,多次则为退回状态
                     // 整理当前流程审核人状态更新
@@ -1037,15 +1038,12 @@ module.exports = app => {
                     await this.ctx.service.stagePay.deleteAuditStagePays(this.ctx.stage, this.ctx.stage.times, 0, transaction);
                     await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times, 0, transaction, this.ctx.stage.times, 1);
                     await this.ctx.service.stagePay.deleteAuditStagePays(this.ctx.stage, this.ctx.stage.times, 1, 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.stageSafeProd.updateHistory(this.ctx.stage, transaction);
-                    await this.ctx.service.stageTempLand.updateHistory(this.ctx.stage, transaction);
-                    // 先覆盖再删除
-                    await this.ctx.service.stageBills.updateAuditStageBills(stageId, this.ctx.stage.user_id, this.ctx.stage.times, 0, curAudit.aid, this.ctx.stage.times, 1, transaction);
-                    await this.ctx.service.stagePos.updateAuditStagePos(stageId, this.ctx.stage.user_id, this.ctx.stage.times, 0, curAudit.aid, this.ctx.stage.times, 1, transaction);
-                    await this.ctx.service.stageDetail.updateAuditStageDetail(stageId, this.ctx.stage.times, 0, this.ctx.stage.times, 1, transaction);
+                    newTimes = this.ctx.stage.times;
+                    newOrder = 0;
+                    newSaid = this.ctx.stage.user_id;
+                    oldTimes = this.ctx.stage.times;
+                    oldOrder = 1;
+                    oldSaid = curAudit.aid;
                 } else if (this.ctx.stage.cancancel === 2) {
                     const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
                     // 整理当前流程审核人状态更新
@@ -1116,16 +1114,12 @@ module.exports = app => {
                     await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
                     // 复制一份最新数据给下一人
                     await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times, curAudit.order + 1, transaction, this.ctx.stage.times, this.ctx.stage.curOrder + 1);
-                    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.stageSafeProd.updateHistory(this.ctx.stage, transaction);
-                    await this.ctx.service.stageTempLand.updateHistory(this.ctx.stage, transaction);
-
-                    // 先覆盖再删除
-                    await this.ctx.service.stageBills.updateAuditStageBills(stageId, preAudit.aid, this.ctx.stage.times, curAudit.order + 1, curAudit.aid, this.ctx.stage.times, curAudit.order, transaction);
-                    await this.ctx.service.stagePos.updateAuditStagePos(stageId, preAudit.aid, this.ctx.stage.times, curAudit.order + 1, curAudit.aid, this.ctx.stage.times, curAudit.order, transaction);
-                    await this.ctx.service.stageDetail.updateAuditStageDetail(stageId, this.ctx.stage.times, curAudit.order + 1, this.ctx.stage.times, curAudit.order, transaction);
+                    newTimes = this.ctx.stage.times;
+                    newOrder = curAudit.order + 1;
+                    newSaid = preAudit.aid;
+                    oldTimes = this.ctx.stage.times;
+                    oldOrder = curAudit.order;
+                    oldSaid = curAudit.aid;
                     // 锁定本人数据,保留锁定数据相关确认状态
                     // await this.ctx.service.stageAuditAss.lockConfirm4CheckNoPre(this.ctx.stage, curAudit.aid, preAudit.aid, transaction);
                 } else if (this.ctx.stage.cancancel === 3) {
@@ -1199,16 +1193,14 @@ module.exports = app => {
                     await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
                     // 复制一份最新数据给下一人
                     await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times, curAudit.order + 1, transaction, this.ctx.stage.times, this.ctx.stage.curOrder + 1);
-                    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.stageSafeProd.updateHistory(this.ctx.stage, transaction);
-                    await this.ctx.service.stageTempLand.updateHistory(this.ctx.stage, transaction);
 
-                    // 先覆盖再删除
-                    await this.ctx.service.stageBills.updateAuditStageBills(stageId, preAudit.aid, this.ctx.stage.times, curAudit.order + 1, curAudit.aid, this.ctx.stage.times, curAudit.order, transaction);
-                    await this.ctx.service.stagePos.updateAuditStagePos(stageId, preAudit.aid, this.ctx.stage.times, curAudit.order + 1, curAudit.aid, this.ctx.stage.times, curAudit.order, transaction);
-                    await this.ctx.service.stageDetail.updateAuditStageDetail(stageId, this.ctx.stage.times, curAudit.order + 1, this.ctx.stage.times, curAudit.order, transaction);
+                    newTimes = this.ctx.stage.times;
+                    newOrder = curAudit.order + 1;
+                    newSaid = preAudit.aid;
+                    oldTimes = this.ctx.stage.times;
+                    oldOrder = curAudit.order;
+                    oldSaid = curAudit.aid;
+
                     // 锁定本人数据,保留锁定数据相关确认状态
                     // await this.ctx.service.stageAuditAss.lockConfirm4CheckNoPre(this.ctx.stage, curAudit.aid, preAudit.aid, transaction);
                 } else if (this.ctx.stage.cancancel === 4) {
@@ -1279,17 +1271,25 @@ module.exports = app => {
                     await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times - 1, curAudit.order + 1, transaction, this.ctx.stage.times, 0);
                     await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times - 1, curAudit.order + 2, transaction, this.ctx.stage.times, 0);
                     await this.ctx.service.stagePay.deleteAuditStagePays(this.ctx.stage, this.ctx.stage.times, 0, 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.stageSafeProd.updateHistory(this.ctx.stage, transaction);
-                    await this.ctx.service.stageTempLand.updateHistory(this.ctx.stage, transaction);
 
-                    // 先覆盖再删除
-                    await this.ctx.service.stageBills.updateAuditStageBills(stageId, curAudit.aid, this.ctx.stage.times - 1, curAudit.order + 2, this.ctx.stage.user_id, this.ctx.stage.times, 0, transaction);
-                    await this.ctx.service.stagePos.updateAuditStagePos(stageId, curAudit.aid, this.ctx.stage.times - 1, curAudit.order + 2, this.ctx.stage.user_id, this.ctx.stage.times, 0, transaction);
-                    await this.ctx.service.stageDetail.updateAuditStageDetail(stageId, this.ctx.stage.times - 1, curAudit.order + 2, this.ctx.stage.times, 0, transaction);
+                    newTimes = this.ctx.stage.times - 1;
+                    newOrder = curAudit.order + 2;
+                    newSaid = curAudit.aid;
+                    oldTimes = this.ctx.stage.times;
+                    oldOrder = 0;
+                    oldSaid = this.ctx.stage.user_id;
                 }
+                // 先覆盖再删除
+                await this.ctx.service.stageBills.updateStageBills4CheckCancel(stageId, newSaid, newTimes, newOrder, oldSaid, oldTimes, oldOrder, transaction);
+                await this.ctx.service.stagePos.updateStagePos4CheckCancel(stageId, newSaid, newTimes, newOrder, oldSaid, oldTimes, oldOrder, transaction);
+                await this.ctx.service.stageDetail.updateStageDetail4CheckCancel(stageId, newTimes, newOrder, oldTimes, oldOrder, transaction);
+
+                await this.ctx.service.stageJgcl.updateHistory4CheckCancel(this.ctx.stage, newTimes, newOrder, transaction);
+                await this.ctx.service.stageBonus.updateHistory4CheckCancel(this.ctx.stage, newTimes, newOrder, transaction);
+                await this.ctx.service.stageOther.updateHistory4CheckCancel(this.ctx.stage, newTimes, newOrder, transaction);
+                await this.ctx.service.stageSafeProd.updateHistory4CheckCancel(this.ctx.stage, newTimes, newOrder, transaction);
+                await this.ctx.service.stageTempLand.updateHistory4CheckCancel(this.ctx.stage, newTimes, newOrder, transaction);
+
                 // 上报/审批 - 检查三方特殊推送
                 await this.ctx.service.specMsg.addStageMsg(transaction, this.ctx.session.sessionProject.id, this.ctx.stage, pushOperate.stage.flow);
                 await transaction.commit();

+ 1 - 1
app/service/stage_bills.js

@@ -126,7 +126,7 @@ module.exports = app => {
             return stageBills[0];
         }
 
-        async updateAuditStageBills(sid, newSaid, newTimes, newOrder, oldSaid, oldTimes, oldOrder, transaction) {
+        async updateStageBills4CheckCancel(sid, newSaid, newTimes, newOrder, oldSaid, oldTimes, oldOrder, transaction) {
             const oldSBLists = await this.getAllDataByCondition({ where: { sid, times: oldTimes, order: oldOrder } });
             const newSBLists = await this.getAllDataByCondition({ where: { sid, times: newTimes, order: newOrder } });
             const delidList = [];

+ 23 - 3
app/service/stage_bonus.js

@@ -34,9 +34,9 @@ module.exports = app => {
             }
         }
 
-        async getStageData(sid) {
+        async getStageData(sid, cancel = false) {
             const data = await this.getAllDataByCondition({where: { sid: sid }});
-            if (this.ctx.stage && this.ctx.stage.readOnly && !this.ctx.tender.isTourist && this.ctx.stage.status !== auditConst.status.checked) {
+            if (!cancel && this.ctx.stage && this.ctx.stage.readOnly && !this.ctx.tender.isTourist && this.ctx.stage.status !== auditConst.status.checked) {
                 for (const d of data) {
                     const his = d.shistory ? JSON.parse(d.shistory) : [];
                     const h = this.ctx.helper._.find(his, {
@@ -178,7 +178,7 @@ module.exports = app => {
                 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;
+                        && x.sorder !== undefined && x.sorder !== null && x.sorder === order;
                 });
                 if (his) {
                     his.tp = d.tp;
@@ -190,6 +190,26 @@ module.exports = app => {
             await transaction.updateRows(this.tableName, updateDatas);
         }
 
+        async updateHistory4CheckCancel(stage, newTimes, newOrder, transaction) {
+            const datas = await this.getStageData(stage, true);
+            if (datas.length === 0) return;
+
+            const updateDatas = [];
+            for (const d of datas) {
+                const history = d.shistory && d.shistory !== '' ? JSON.parse(d.shistory) : [];
+                const his = history.find(function (x) {
+                    return x.stimes === newTimes && x.sorder === newOrder;
+                });
+                if (his) {
+                    his.tp = d.tp;
+                } else {
+                    history.push({ stimes: newTimes, sorder: newOrder, tp: d.tp });
+                }
+                updateDatas.push({ id: d.id, shistory: JSON.stringify(history) });
+            }
+            await transaction.updateRows(this.tableName, updateDatas);
+        }
+
         async updateHistory4CheckAgain(stage, transaction) {
             const datas = await this.getStageData(stage.id);
             if (datas.length === 0) return;

+ 1 - 1
app/service/stage_detail.js

@@ -82,7 +82,7 @@ module.exports = app => {
             }
         }
 
-        async updateAuditStageDetail(sid, newTimes, newOrder, oldTimes, oldOrder, transaction) {
+        async updateStageDetail4CheckCancel(sid, newTimes, newOrder, oldTimes, oldOrder, transaction) {
             const oldSBLists = await this.getAllDataByCondition({ where: { sid, times: oldTimes, order: oldOrder } });
             const newSBLists = await this.getAllDataByCondition({ where: { sid, times: newTimes, order: newOrder } });
             const delidList = [];

+ 31 - 3
app/service/stage_jgcl.js

@@ -22,9 +22,9 @@ module.exports = app => {
             this.tableName = 'stage_jgcl';
         }
 
-        async getStageData(stage) {
+        async getStageData(stage, cancel = false) {
             const data = await this.getAllDataByCondition({where: { sid: stage.id }});
-            if (stage && stage.readOnly && !this.ctx.tender.isTourist && stage.status !== auditConst.status.checked) {
+            if (!cancel && stage && stage.readOnly && !this.ctx.tender.isTourist && stage.status !== auditConst.status.checked) {
                 for (const d of data) {
                     const his = d.shistory ? JSON.parse(d.shistory) : [];
                     const h = this.ctx.helper._.find(his, {
@@ -204,7 +204,7 @@ module.exports = app => {
                 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;
+                        && x.sorder !== undefined && x.sorder !== null && x.sorder === order;
                 });
                 if (his) {
                     his.arrive_qty = d.arrive_qty;
@@ -223,6 +223,34 @@ module.exports = app => {
             await transaction.updateRows(this.tableName, updateDatas);
         }
 
+        async updateHistory4CheckCancel(stage, newTimes, newOrder, transaction) {
+            const datas = await this.getStageData(stage, true);
+            if (datas.length === 0) return;
+
+            const updateDatas = [];
+            for (const d of datas) {
+                const history = d.shistory && d.shistory !== '' ? JSON.parse(d.shistory) : [];
+                const his = history.find(function (x) {
+                    return x.stimes === newTimes && x.sorder === newOrder;
+                });
+                console.log(his, newTimes, newOrder);
+                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: newTimes, sorder: newOrder,
+                        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 updateHistory4CheckAgain(stage, transaction) {
             const datas = await this.getStageData(stage);
             if (datas.length === 0) return;

+ 26 - 3
app/service/stage_other.js

@@ -22,9 +22,9 @@ module.exports = app => {
             this.tableName = 'stage_other';
         }
 
-        async getStageData(stage) {
+        async getStageData(stage, cancel = false) {
             const data = await this.getAllDataByCondition({where: { sid: stage.id }});
-            if (stage && stage.readOnly && !this.ctx.tender.isTourist && stage.status !== auditConst.status.checked) {
+            if (!cancel && stage && stage.readOnly && !this.ctx.tender.isTourist && stage.status !== auditConst.status.checked) {
                 for (const d of data) {
                     const his = d.shistory ? JSON.parse(d.shistory) : [];
                     const h = this.ctx.helper._.find(his, {
@@ -174,7 +174,7 @@ module.exports = app => {
                 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;
+                        && x.sorder !== undefined && x.sorder !== null && x.sorder === order;
                 });
                 if (his) {
                     his.tp = d.tp;
@@ -189,6 +189,29 @@ module.exports = app => {
             await transaction.updateRows(this.tableName, updateDatas);
         }
 
+        async updateHistory4CheckCancel(stage, newTimes, newOrder, transaction) {
+            const datas = await this.getStageData(stage, true);
+            if (datas.length === 0) return;
+
+            const updateDatas = [];
+            for (const d of datas) {
+                const history = d.shistory && d.shistory !== '' ? JSON.parse(d.shistory) : [];
+                const his = history.find(function (x) {
+                    return x.stimes === newTimes && x.sorder === newOrder;
+                });
+                if (his) {
+                    his.tp = d.tp;
+                    if (d.sid === d.add_sid) his.total_price = d.total_price;
+                } else {
+                    const nHis = { stimes: newTimes, sorder: newOrder, 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 updateHistory4CheckAgain(stage, transaction) {
             const datas = await this.getStageData(stage);
             if (datas.length === 0) return;

+ 1 - 1
app/service/stage_pos.js

@@ -125,7 +125,7 @@ module.exports = app => {
             return this._filterLastestData(stagePos);
         }
 
-        async updateAuditStagePos(sid, newSaid, newTimes, newOrder, oldSaid, oldTimes, oldOrder, transaction) {
+        async updateStagePos4CheckCancel(sid, newSaid, newTimes, newOrder, oldSaid, oldTimes, oldOrder, transaction) {
             const oldSBLists = await this.getAllDataByCondition({ where: { sid, times: oldTimes, order: oldOrder } });
             const newSBLists = await this.getAllDataByCondition({ where: { sid, times: newTimes, order: newOrder } });
             const delidList = [];

+ 34 - 4
app/service/stage_safe_prod.js

@@ -23,9 +23,9 @@ module.exports = app => {
             this.tableName = 'stage_safe_prod';
         }
 
-        async getStageData(stage) {
+        async getStageData(stage, cancel) {
             const data = await this.getAllDataByCondition({where: { sid: stage.id }});
-            if (stage && stage.readOnly && !this.ctx.tender.isTourist && stage.status !== auditConst.status.checked) {
+            if (!cancel && stage && stage.readOnly && !this.ctx.tender.isTourist && stage.status !== auditConst.status.checked) {
                 for (const d of data) {
                     const his = d.shistory ? JSON.parse(d.shistory) : [];
                     const h = this.ctx.helper._.find(his, {
@@ -186,7 +186,7 @@ module.exports = app => {
                 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;
+                        && x.sorder !== undefined && x.sorder !== null && x.sorder === order;
                 });
                 if (his) {
                     his.qty = d.qty;
@@ -208,6 +208,36 @@ module.exports = app => {
             await transaction.updateRows(this.tableName, updateDatas);
         }
 
+        async updateHistory4CheckCancel(stage, newTimes, newOrder, transaction) {
+            const datas = await this.getStageData(stage, true);
+            if (datas.length === 0) return;
+
+            const updateDatas = [];
+            for (const d of datas) {
+                const history = d.shistory && d.shistory !== '' ? JSON.parse(d.shistory) : [];
+                const his = history.find(function (x) {
+                    return x.stimes === newTimes && x.sorder === newOrder;
+                });
+                if (his) {
+                    his.qty = d.qty;
+                    his.tp = d.tp;
+                    if (d.sid === d.add_sid) {
+                        his.quantity = d.quantity;
+                        his.total_price = d.total_price;
+                    }
+                } else {
+                    const nHis = { stimes: newTimes, sorder: newOrder, qty: d.qty, tp: d.tp };
+                    if (d.sid === d.add_sid) {
+                        nHis.quantity = d.quantity;
+                        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 updateHistory4CheckAgain(stage, transaction) {
             const datas = await this.getStageData(stage);
             if (datas.length === 0) return;
@@ -288,4 +318,4 @@ module.exports = app => {
     }
 
     return StageSafeProd;
-};
+};

+ 26 - 4
app/service/stage_temp_land.js

@@ -23,9 +23,9 @@ module.exports = app => {
             this.tableName = 'stage_temp_land';
         }
 
-        async getStageData(stage) {
+        async getStageData(stage, cancel = false) {
             const data = await this.getAllDataByCondition({where: { sid: stage.id }});
-            if (stage && stage.readOnly && !this.ctx.tender.isTourist && stage.status !== auditConst.status.checked) {
+            if (!cancel && stage && stage.readOnly && !this.ctx.tender.isTourist && stage.status !== auditConst.status.checked) {
                 for (const d of data) {
                     const his = d.shistory ? JSON.parse(d.shistory) : [];
                     const h = this.ctx.helper._.find(his, {
@@ -177,7 +177,7 @@ module.exports = app => {
                 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;
+                        && x.sorder !== undefined && x.sorder !== null && x.sorder === order;
                 });
                 if (his) {
                     his.qty = d.qty;
@@ -191,6 +191,28 @@ module.exports = app => {
             await transaction.updateRows(this.tableName, updateDatas);
         }
 
+        async updateHistory4CheckCancel(stage, newTimes, newOrder, transaction) {
+            const datas = await this.getStageData(stage, true);
+            if (datas.length === 0) return;
+
+            const updateDatas = [];
+            for (const d of datas) {
+                const history = d.shistory && d.shistory !== '' ? JSON.parse(d.shistory) : [];
+                const his = history.find(function (x) {
+                    return x.stimes === newTimes && x.sorder === newOrder;
+                });
+                if (his) {
+                    his.qty = d.qty;
+                    his.tp = d.tp;
+                } else {
+                    const nHis = { stimes: newTimes, sorder: newOrder, qty: d.qty, tp: d.tp };
+                    history.push(nHis);
+                }
+                updateDatas.push({ id: d.id, shistory: JSON.stringify(history) });
+            }
+            await transaction.updateRows(this.tableName, updateDatas);
+        }
+
         async updateHistory4CheckAgain(stage, transaction) {
             const datas = await this.getStageData(stage);
             if (datas.length === 0) return;
@@ -263,4 +285,4 @@ module.exports = app => {
     }
 
     return StageTempLand;
-};
+};