MaiXinRong před 3 roky
rodič
revize
fadb438ad1
2 změnil soubory, kde provedl 14 přidání a 5 odebrání
  1. 1 1
      app/service/stage.js
  2. 13 4
      app/service/stage_change.js

+ 1 - 1
app/service/stage.js

@@ -453,7 +453,7 @@ module.exports = app => {
             const param = tenderInfo.deal_param;
             for (const cb of calcBase) {
                 const sum = await this.ctx.service.stageBills.getSumTotalPrice(stage);
-                const bg = await this.ctx.service.stageChange.getQualityTotalPrice(stage.id);
+                const bg = await this.ctx.service.stageChange.getQualityTotalPrice(stage);
                 switch (cb.code) {
                     case 'htj':
                         cb.value = param.contractPrice;

+ 13 - 4
app/service/stage_change.js

@@ -395,23 +395,32 @@ module.exports = app => {
             return this.ctx.helper.filterLastestData(data, ['lid', 'pid', 'cid', 'cbid']);
         }
 
-        async getQualityTotalPrice(sid) {
+        async _getTender(stage) {
+            if (this.ctx.tender) return this.ctx.tender;
+            const tender = { id: stage.tid };
+            tender.data = await this.ctx.service.tender.getTender(stage.tid);
+            tender.info = await this.service.tenderInfo.getTenderInfo(tender.id);
+            return tender;
+        }
+
+        async getQualityTotalPrice(stage) {
             const helper = this.ctx.helper;
+            const tender = await this._getTender(stage);
             const sql = 'SELECT sc.*, c.quality FROM ' + this.tableName + ' sc' +
                 '  LEFT JOIN ' + this.ctx.service.change.tableName + ' c ON sc.cid = c.cid' +
                 '  WHERE sid = ?';
-            const data = await this.db.query(sql, [sid]);
+            const data = await this.db.query(sql, [stage.id]);
             const bqData = [];
             for (const d of data) {
                 if (!d.qty) continue;
                 let bd = bqData.find(x => { return x.lid === d.lid && x.quality === d.quality; });
                 if (!bd) {
-                    const bills = await this.ctx.service.ledger.getDataById(d.lid);
+                    const bills = await this.db.get(this.ctx.service.ledger.departTableName(tender.id), { id: d.lid });
                     if (!bills) continue;
                     bd = { lid: d.lid, quality: d.quality, unit_price: bills.unit_price };
                     bqData.push(bd);
                 }
-                const tp = this.ctx.helper.mul(d.qty, bd.unit_price, this.ctx.tender.info.decimal.tp);
+                const tp = this.ctx.helper.mul(d.qty, bd.unit_price, tender.info.decimal.tp);
                 bd.tp = this.ctx.helper.add(bd.tp, tp);
             }
             const result = {};