Procházet zdrojové kódy

TASK #3939 工程量清单模式,计量台账进行添加计量单元导致台账金额发生变化时,期望标段管理-金额概况界面的0号台账、标段概况的0号台账合同等数据能实时同步

MaiXinRong před 3 roky
rodič
revize
0596c99214
2 změnil soubory, kde provedl 37 přidání a 15 odebrání
  1. 21 14
      app/controller/tender_controller.js
  2. 16 1
      app/service/stage_audit.js

+ 21 - 14
app/controller/tender_controller.js

@@ -130,14 +130,9 @@ module.exports = app => {
                     const tenderInfo = await this.ctx.service.tenderInfo.getTenderInfo(t.id);
                     t.contract_price = tenderInfo.deal_param.contractPrice;
 
-                    if (t.user_id === this.ctx.session.sessionUser.accountId && (
-                        t.ledger_status === auditConst.ledger.status.checkNo || t.ledger_status === auditConst.ledger.status.uncheck)) {
-                        const sum = await this.ctx.service.ledger.addUp({ tender_id: t.id/* , is_leaf: true*/ });
-                        t.total_price = sum.total_price;
-                        t.deal_tp = sum.deal_tp;
-                    }
+                    let bCalcTp = t.user_id === this.ctx.session.sessionUser.accountId && (
+                        t.ledger_status === auditConst.ledger.status.checkNo || t.ledger_status === auditConst.ledger.status.uncheck);
                     t.advance_tp = await this.ctx.service.advance.getSumAdvance(t.id);
-
                     if (t.ledger_status === auditConst.ledger.status.checked) {
                         t.lastStage = await this.ctx.service.stage.getLastestStage(t.id, true);
                         if (t.lastStage && t.lastStage.status === auditConst.stage.status.uncheck &&
@@ -146,6 +141,15 @@ module.exports = app => {
                         }
                         if (t.lastStage) await this.ctx.service.stage.checkStageGatherData(t.lastStage);
                         t.completeStage = await this.ctx.service.stage.getLastestCompleteStage(t.id);
+                        if ((!bCalcTp) && t.measure_type === measureType.gcl.value) {
+                            bCalcTp = t.lastStage && t.lastStage.status !== auditConst.stage.status.checked && !t.lastStage.readOnly;
+                        }
+                    }
+
+                    if (bCalcTp) {
+                        const sum = await this.ctx.service.ledger.addUp({ tender_id: t.id/* , is_leaf: true*/ });
+                        t.total_price = sum.total_price;
+                        t.deal_tp = sum.deal_tp;
                     }
 
                     if (t.lastStage) {
@@ -390,12 +394,8 @@ module.exports = app => {
         async tenderInfo(ctx) {
             try {
                 const tender = ctx.tender.data;
-                if (tender.user_id === this.ctx.session.sessionUser.accountId && (
-                    tender.ledger_status === auditConst.ledger.status.checkNo || tender.ledger_status === auditConst.ledger.status.uncheck)) {
-                    const sum = await this.ctx.service.ledger.addUp({ tender_id: tender.id/* , is_leaf: true*/ });
-                    tender.total_price = sum.total_price;
-                    tender.deal_tp = sum.deal_tp;
-                }
+                let bCalcTp = tender.user_id === this.ctx.session.sessionUser.accountId && (
+                    tender.ledger_status === auditConst.ledger.status.checkNo || tender.ledger_status === auditConst.ledger.status.uncheck);
                 const stages = await ctx.service.stage.getValidStages(ctx.tender.id);
                 const lastStage = stages.length > 0 ? stages[0] : null; // await ctx.service.stage.getLastestStage(ctx.tender.id);
                 if (lastStage) {
@@ -435,6 +435,9 @@ module.exports = app => {
                         const times = lastStage.status === auditConst.stage.status.checkNo ? lastStage.times - 1 : lastStage.times;
                         lastStage.auditors = await ctx.service.stageAudit.getFinalAuditGroup(lastStage.id, times);
                     }
+                    if ((!bCalcTp) && tender.measure_type === measureType.gcl.value) {
+                        bCalcTp = lastStage.status !== auditConst.stage.status.checked && !lastStage.readOnly;
+                    }
                 } else {
                     if (tender.ledger_status !== auditConst.ledger.status.uncheck) {
                         const status_name = await this.ctx.service.ledgerAudit.getStatusName(tender.id, tender.ledger_times);
@@ -446,6 +449,11 @@ module.exports = app => {
                         tender.status_users = status_name ? status_name.name : '';
                     }
                 }
+                if (bCalcTp) {
+                    const sum = await this.ctx.service.ledger.addUp({ tender_id: tender.id/* , is_leaf: true*/ });
+                    tender.total_price = sum.total_price;
+                    tender.deal_tp = sum.deal_tp;
+                }
                 const tiModel = new tenderInfoModel(ctx);
                 const gclChapter = await tiModel.gatherChapter();
 
@@ -974,7 +982,6 @@ module.exports = app => {
                     await ctx.service.ledgerCooperation.changeAllStatus(status);
                 }
                 // }
-                // console.log(postData);
                 await ctx.service.tenderInfo.saveTenderInfo(ctx.tender.id, { shenpi: postData });
                 let auditList = [];
                 if (data.status === shenpiConst.sp_status.gdspl) {

+ 16 - 1
app/service/stage_audit.js

@@ -17,6 +17,7 @@ const shenpiConst = require('../const/shenpi');
 const payConst = require('../const/deal_pay');
 const pushType = require('../const/audit').pushType;
 const syncApiConst = require('../const/sync_api');
+const measureType = require('../const/tender').measureType;
 
 module.exports = app => {
     class StageAudit extends app.BaseService {
@@ -244,6 +245,16 @@ module.exports = app => {
             return true;
         }
 
+        async _updateTender(transaction) {
+            if (!this.ctx.tender) return;
+            if (this.ctx.tender.data.measure_type !== measureType.gcl.value) return;
+
+            const sum = await this.ctx.service.ledger.addUp({ tender_id: this.ctx.tender.id/* , is_leaf: true*/ });
+            await transaction.update(this.ctx.service.tender.tableName, {
+                id: this.ctx.tender.id, total_price: sum.total_price, deal_tp: sum.deal_tp
+            });
+        }
+
         /**
          * 开始审批
          *
@@ -263,6 +274,7 @@ module.exports = app => {
 
             const transaction = await this.db.beginTransaction();
             try {
+                await this._updateTender(transaction);
                 await transaction.update(this.tableName, {
                     id: audit.id,
                     status: auditConst.status.checking,
@@ -365,6 +377,7 @@ module.exports = app => {
             const transaction = await this.db.beginTransaction();
 
             try {
+                await this._updateTender(transaction);
                 // 添加推送
                 const noticeContent = await this.getNoticeContent(pid, audit.tid, stageId, audit.aid);
                 const auditors = await this.getAuditGroupByListWithOwner(stageId, times);
@@ -548,6 +561,7 @@ module.exports = app => {
 
             const transaction = await this.db.beginTransaction();
             try {
+                await this._updateTender(transaction);
                 // 添加推送
                 const noticeContent = await this.getNoticeContent(pid, audit.tid, stageId, audit.aid);
                 const records = [
@@ -680,6 +694,7 @@ module.exports = app => {
             const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
             const transaction = await this.db.beginTransaction();
             try {
+                await this._updateTender(transaction);
                 // 添加推送
                 const noticeContent = await this.getNoticeContent(pid, audit.tid, stageId, audit.aid);
                 const records = [
@@ -1246,6 +1261,7 @@ module.exports = app => {
                     order++;
                 }
 
+                await this._updateTender(transaction);
                 // 拷贝新一次审核流程列表
                 await transaction.insert(this.tableName, auditors);
 
@@ -1264,7 +1280,6 @@ module.exports = app => {
                 const yfPay = stagePay.find(function(x) {
                     return x.ptype === payConst.payType.yf;
                 });
-                console.log(stagePay);
                 const sfPay = stagePay.find(function(x) {
                     return x.ptype === payConst.payType.sf;
                 });