Pārlūkot izejas kodu

新增一起计量时,缓存截止上期实付数据

MaiXinRong 4 gadi atpakaļ
vecāks
revīzija
06b7a3d928
2 mainītis faili ar 18 papildinājumiem un 2 dzēšanām
  1. 16 0
      app/service/stage.js
  2. 2 2
      app/service/stage_jgcl.js

+ 16 - 0
app/service/stage.js

@@ -298,6 +298,16 @@ module.exports = app => {
             return stages;
         }
 
+        async _getSumTp(condition, ...field) {
+            const fieldSql = [];
+            for (const f of field) {
+                fieldSql.push('SUM(`' + f + '`) as ' + '`' + f + '`');
+            }
+
+            const sql = 'SELECT ' + fieldSql.join(', ') + ' FROM ' + this.tableName + ' ' + this.ctx.helper.whereSql(condition);
+            return await this.db.queryOne(sql);
+        }
+
         /**
          *
          * @param tenderId - 标段id
@@ -337,6 +347,12 @@ module.exports = app => {
                 newStage.pre_contract_tp = this.ctx.helper.add(preStage.pre_contract_tp, preStage.contract_tp);
                 newStage.pre_qc_tp = this.ctx.helper.add(preStage.pre_qc_tp, preStage.qc_tp);
                 newStage.pre_yf_tp = this.ctx.helper.add(preStage.pre_yf_tp, preStage.yf_tp);
+                if (preStage.order === 1 || preStage.pre_sf_tp) {
+                    newStage.pre_sf_tp = this.ctx.helper.add(preStage.pre_sf_tp, preStage.sf_tp);
+                } else {
+                    const sumTp = await this._getSumTp({tid: preStage.tid}, 'sf_tp');
+                    newStage.pre_sf_tp = sumTp.sf_tp || 0;
+                }
             }
             const transaction = await this.db.beginTransaction();
             try {

+ 2 - 2
app/service/stage_jgcl.js

@@ -89,7 +89,7 @@ module.exports = app => {
                 nd.order = d.order;
                 if (d.unit) nd.unit = d.unit;
                 if (d.unit_price) nd.unit_price = d.unit_price;
-                const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, d.unit_price);
+                const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, d.unit);
                 if (d.arrive_qty) {
                     nd.arrive_qty = this.ctx.helper.round(d.arrive_qty, precision.value);
                     nd.arrive_tp = this.ctx.helper.mul(nd.unit_price, nd.arrive_qty, tpDecimal);
@@ -142,7 +142,7 @@ module.exports = app => {
                 } else {
                     nd.unit_price = od.unit_price;
                 }
-                const precision = this.ctx.helper.findPrecision(info.precision, d.unit_price);
+                const precision = this.ctx.helper.findPrecision(info.precision, d.unit);
                 if (d.arrive_qty !== undefined) {
                     nd.arrive_qty = this.ctx.helper.round(d.arrive_qty, precision.value);
                     nd.arrive_tp = this.ctx.helper.mul(nd.unit_price, nd.arrive_qty, tpDecimal);