MaiXinRong 3 lat temu
rodzic
commit
9b3e09032c

+ 1 - 1
app/controller/stage_controller.js

@@ -347,7 +347,7 @@ module.exports = app => {
                             responseData.data.changeData = await this._getStageChangeData(ctx);
                             break;
                         case 'import_change':
-                            responseData.data.import_change = await this.ctx.service.stageImportChange.getAllDataByCondition({ where: { sid: this.ctx.stage.id } });
+                            responseData.data.import_change = await this.ctx.service.stageImportChange.getStageImportData(this.ctx.stage);
                             break;
                         case 'dealBills':
                             responseData.data.dealBills = await ctx.service.dealBills.getAllDataByCondition({

+ 2 - 0
app/controller/tender_controller.js

@@ -1306,6 +1306,8 @@ module.exports = app => {
                         break;
                     case 'stage':
                         const stageData = await this.ctx.service.stageBills.sumLoad(data.lid, data.tenders, data.cover);
+                        stageData.import_change = { target: { import_lid: data.lid } };
+                        stageData.import_change.data = await this.ctx.service.stageImportChange.getLeafXmjStageImportData(this.ctx.stage, data.lid);
                         ctx.body = {err: 0, msg: '', data: stageData};
                         break;
                     default:

+ 6 - 0
app/lib/stage_im.js

@@ -120,6 +120,7 @@ class StageIm {
         } else {
             this.changes = await this.ctx.service.stageChange.getLastestAllStageData(this.ctx.tender.id, this.ctx.stage.id);
         }
+        this.import_changes = await this.ctx.service.stageImportChange.getStageImportData(this.ctx.stage);
     }
 
     // 检查汇总节点
@@ -497,6 +498,7 @@ class StageIm {
                         im.changes.push(c);
                     }
                 }
+                this.import_changes.forEach(x => { if (x.lid === p.id) im.changes.push(x) });
             } else {
                 for (const pp of posRange) {
                     if ((!pp.qc_qty || pp.qc_qty === 0)) {
@@ -728,6 +730,7 @@ class StageIm {
                         imDefault.changes.push(c);
                     }
                 }
+                this.import_changes.forEach(x => { if (x.lid === p.id) imDefault.changes.push(x) });
 
                 imDefault.contract_jl = this.ctx.helper.add(imDefault.contract_jl, p.contract_qty);
                 imDefault.qc_jl = this.ctx.helper.add(imDefault.qc_jl, p.qc_qty);
@@ -810,6 +813,7 @@ class StageIm {
                     im.changes.push(c);
                 }
             }
+            this.import_changes.forEach(x => { if (x.lid === node.id) im.changes.push(x) });
         } else {
             for (const p of posRange) {
                 if ((!p.qc_qty || p.qc_qty === 0)) {
@@ -984,6 +988,7 @@ class StageIm {
                             im.changes.push(c);
                         }
                     }
+                    this.import_changes.forEach(x => { if (x.lid === p.id) im.changes.push(x) });
                 }
             }
         }
@@ -1061,6 +1066,7 @@ class StageIm {
         this.stage = stage;
         this.details = details;
         this.changes = changes;
+        this.import_changes = [];
 
         const self = this;
         // 初始化

+ 9 - 6
app/public/js/stage.js

@@ -1457,6 +1457,10 @@ $(document).ready(() => {
         type: 'stage',
         afterLoad: function (result, select) {
             const nodes = stageTree.loadPostStageData(result);
+            const posterity = stageTree.getPosterity(select);
+            for (const p of posterity) {
+                p.is_import = !!result.import_change.data.find(x => { return x.lid === p.id });
+            }
             stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
             if (detail) {
                 detail.loadStageLedgerUpdateData(result, nodes);
@@ -2027,7 +2031,7 @@ $(document).ready(() => {
     });
 
     // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
-    postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;change;tag;cooperation' }, function (result) {
+    postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;change;import_change;tag;cooperation' }, function (result) {
         // 加载树结构
         stageTree.loadDatas(result.ledgerData);
         checkShowLast(result.ledgerData.length);
@@ -2053,7 +2057,7 @@ $(document).ready(() => {
         SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
         // 加载中间计量
         stageIm.init(stage, imType, tenderInfo.decimal);
-        stageIm.loadData(result.ledgerData, result.posData, result.detailData, result.changeData, result.detailAtt);
+        stageIm.loadData(result.ledgerData, result.posData, result.detailData, result.changeData, result.import_change, result.detailAtt);
 
         errorList.loadHisErrorData();
         checkList.loadHisCheckData();
@@ -3789,7 +3793,7 @@ $(document).ready(() => {
             postData(window.location.pathname + '/change/data', null, function (result) {
                 self.changes = [];
                 result.changes.forEach(x => { x.is_import = 0; self.changes.push(x); });
-                result.import_changes.forEach(x => { x.is_import = 1; self.changes.push(x); });
+                result.import_changes.forEach(x => { x.is_import = 1; delete x.total_price; self.changes.push(x); });
                 if (result.changes.length > 0) self.analyzeChange(result.changes[0]);
                 if (result.import_changes.length > 0) self.analyzeChange(result.import_changes[0]);
                 SpreadJsObj.loadSheetData(self.changeSheet, SpreadJsObj.DataType.Data, self.changes);
@@ -3821,9 +3825,8 @@ $(document).ready(() => {
                     return x.rela_cbid === b.id;
                 });
                 if (eub) b.used_qty = eub.rela_qty;
-                b.qty = _.toNumber(b.samount);
-                b.valid_qty = ZhCalc.sub(b.qty, b.used_qty);
-                b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
+                delete b.unit_price;
+                delete b.bwmx;
                 b.pos = _.filter(change.detail.curUsedBills, { rela_cbid: b.id });
                 b.cur_qty = 0;
                 for (const p of b.pos) {

+ 9 - 4
app/public/js/stage_change.js

@@ -60,9 +60,14 @@ class ChangeAnalysis {
                 return x.rela_cbid === b.id;
             });
             if (eub) b.used_qty = ZhCalc.sum(eub.map(x => { return x.rela_qty }));
-            b.qty = _.toNumber(b.samount);
-            b.valid_qty = ZhCalc.sub(b.qty, b.used_qty);
-            b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
+
+            // 移除单价、部位,不计算数量、金额、未变更
+            delete b.unit_price;
+            delete b.bwmx;
+            // b.qty = _.toNumber(b.samount);
+            // b.valid_qty = ZhCalc.sub(b.qty, b.used_qty);
+            // b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
+
             b.pos = _.filter(change.detail.curUsedBills, { rela_cbid: b.id });
             b.cur_qty = 0;
             for (const p of b.pos) {
@@ -354,7 +359,7 @@ $(document).ready(() => {
         tenderInfo = result.tenderInfo;
         changes = [];
         result.changes.forEach(x => { x.is_import = 0; changes.push(x); });
-        result.import_changes.forEach(x => { x.is_import = 1; changes.push(x); });
+        result.import_changes.forEach(x => { x.is_import = 1; delete x.total_price; changes.push(x); });
         usedChangesId = [...result.usedChangesId, ...result.used_import_cid];
         ledger = result.ledger;
         // ------------begin 预处理数据

+ 26 - 18
app/public/js/stage_im.js

@@ -13,7 +13,7 @@ const stageIm = (function () {
     const resetFields = ['peg', 'bw', 'xm', 'drawing_code', 'calc_memo', 'position', 'jldy'];
     const splitChar = '-';
     const mergeChar = ';';
-    let stage, imType, decimal, details, changes, detailsAtt, ImData, pre, orgImData;
+    let stage, imType, decimal, details, changes, importChanges, detailsAtt, ImData, pre, orgImData;
     let up_field = 'unit_price';
     const gsTreeSetting = {
         id: 'ledger_id',
@@ -67,7 +67,7 @@ const stageIm = (function () {
         }
     }
 
-    function loadData (ledger, pos, stageDetail, stageChange, stageDetailAtt) {
+    function loadData (ledger, pos, stageDetail, stageChange, stageImportChange, stageDetailAtt) {
         up_field = 'unit_price';
         gsTree.loadDatas(ledger);
         treeCalc.calculateAll(gsTree);
@@ -79,6 +79,7 @@ const stageIm = (function () {
         details = stageDetail;
 
         changes = stageChange;
+        importChanges = stageImportChange;
 
         detailsAtt = stageDetailAtt;
     }
@@ -94,6 +95,7 @@ const stageIm = (function () {
         details = stageDetail;
 
         changes = stageChange;
+        importChanges = [];
 
         detailsAtt = stageDetailAtt;
     }
@@ -515,6 +517,7 @@ const stageIm = (function () {
                         im.changes.push(c);
                     }
                 }
+                importChanges.forEach(x => { if (x.lid === p.id) im.changes.push(x); });
             } else {
                 for (const pp of posRange) {
                     if ((!pp.qc_qty || pp.qc_qty === 0)) {
@@ -706,6 +709,7 @@ const stageIm = (function () {
                             imDefault.changes.push(c);
                         }
                     }
+                    importChanges.forEach(x => { if (x.lid === p.id) imDefault.changes.push(x); });
 
                     imDefault.contract_jl = ZhCalc.add(imDefault.contract_jl, p.contract_tp);
                     imDefault.qc_jl = ZhCalc.add(imDefault.qc_jl, p.qc_tp);
@@ -784,11 +788,10 @@ const stageIm = (function () {
                     im.changes.push(c);
                 }
             }
+            importChanges.forEach(x => { if (x.lid === node.id) im.changes.push(x); });
         } else {
             for (const p of posRange) {
-                if ((!p.qc_qty || p.qc_qty === 0)) {
-                    continue;
-                }
+                if ((!p.qc_qty || p.qc_qty === 0)) continue;
                 for (const c of changes) {
                     if (c.lid === node.id && c.pid === p.id && c.qty && c.qty !== 0) {
                         im.changes.push(c);
@@ -910,6 +913,7 @@ const stageIm = (function () {
                             im.changes.push(c);
                         }
                     }
+                    importChanges.forEach(x => { if (x.lid === p.id) im.changes.push(x); });
                 }
             }
         }
@@ -1101,20 +1105,10 @@ const stageIm = (function () {
                 changes.push(c);
             }
         }
-        return refreshImData(refreshNodes);
-    }
-    function loadUpdatePosData(data, refreshNodes) {
-        if (data.pos) {
-            if (data.pos.pos && data.pos.pos.length > 0 && typeof data.pos.pos[0] === 'string') {
-                gsPos.removeDatas(data.pos.pos);
-            } else {
-                gsPos.updateDatas(data.pos.pos);
-            }
-            if (data.pos.curStageData) {
-                gsPos.loadCurStageData(data.pos.curStageData);
-            }
+        if (data.import_change) {
+            _.remove(importChanges, data.import_change.target);
+            data.import_change.data.forEach(x => { importChanges.push(x) });
         }
-        gsTree.loadPostStageData(data.ledger);
         return refreshImData(refreshNodes);
     }
     function loadUpdateChangeData(data, refreshNodes) {
@@ -1130,6 +1124,20 @@ const stageIm = (function () {
         }
         return refreshImData(refreshNodes);
     }
+    function loadUpdatePosData(data, refreshNodes) {
+        if (data.pos) {
+            if (data.pos.pos && data.pos.pos.length > 0 && typeof data.pos.pos[0] === 'string') {
+                gsPos.removeDatas(data.pos.pos);
+            } else {
+                gsPos.updateDatas(data.pos.pos);
+            }
+            if (data.pos.curStageData) {
+                gsPos.loadCurStageData(data.pos.curStageData);
+            }
+        }
+        gsTree.loadPostStageData(data.ledger);
+        return refreshImData(refreshNodes);
+    }
 
     function getParentCheckNode(node) {
         let parent = node;

+ 1 - 1
app/router.js

@@ -630,7 +630,7 @@ module.exports = app => {
     // 总分包
     app.post('/tender/:id/ledger/sumLoad', sessionAuth, tenderCheck, uncheckTenderCheck, 'tenderController.sumLoad');
     app.post('/tender/:id/measure/stage/:order/sumLoad', sessionAuth, tenderCheck, uncheckTenderCheck, stageCheck, 'tenderController.sumLoad');
-    app.post('/tender/:id/revise/info/sumLoad', sessionAuth, tenderCheck, uncheckTenderCheck, reviseCheck, 'tenderController.sumLoad');
+    app.post('/tender/:id/revise/:rid/info/sumLoad', sessionAuth, tenderCheck, uncheckTenderCheck, reviseCheck, 'tenderController.sumLoad');
 
     // 扫码登录
     app.get('/wxAuth', 'loginController.wxAuth');

+ 2 - 0
app/service/report_memory.js

@@ -1380,7 +1380,9 @@ module.exports = app => {
             for (const c of this.changeInfo) {
                 c.cur_used = usedChangesId.indexOf(c.cid) >= 0;
                 c.used_ratio = c.used_pt;
+                c.is_import = 0;
             }
+            const importChange = await this.ctx.service.stageImportChange.get
             return this.changeInfo;
         }
 

+ 14 - 2
app/service/stage.js

@@ -440,6 +440,17 @@ module.exports = app => {
             }
         }
 
+        async getChangeSubtotal(stage) {
+            const result = {};
+            const bg = await this.ctx.service.stageChange.getSubtotal(stage);
+            const importBg = await this.ctx.service.stageImportChange.getSubtotal(stage);
+            console.log(bg, importBg);
+            result.common = this.ctx.helper.add(bg.common, importBg.common);
+            result.great = this.ctx.helper.add(bg.great, importBg.great);
+            result.more = this.ctx.helper.add(bg.more, importBg.more);
+            return result;
+        }
+
         /**
          * 获取 当期的 计算基数
          * @return {Promise<any>}
@@ -447,9 +458,9 @@ module.exports = app => {
         async getStagePayCalcBase(stage, tenderInfo) {
             const calcBase = JSON.parse(JSON.stringify(payConst.calcBase));
             const param = tenderInfo.deal_param;
+            const sum = await this.ctx.service.stageBills.getSumTotalPrice(stage);
+            const bg = await this.getChangeSubtotal(stage);
             for (const cb of calcBase) {
-                const sum = await this.ctx.service.stageBills.getSumTotalPrice(stage);
-                const bg = await this.ctx.service.stageChange.getQualityTotalPrice(stage);
                 switch (cb.code) {
                     case 'htj':
                         cb.value = param.contractPrice;
@@ -533,6 +544,7 @@ module.exports = app => {
                 await transaction.delete(this.ctx.service.stageAudit.tableName, { sid: id });
                 await transaction.delete(this.ctx.service.stageBills.tableName, { sid: id });
                 await transaction.delete(this.ctx.service.stageChange.tableName, { sid: id });
+                await transaction.delete(this.ctx.service.stageImportChange.tableName, { sid: id });
                 await transaction.delete(this.ctx.service.stagePos.tableName, { sid: id });
                 await transaction.delete(this.ctx.service.stageDetail.tableName, { sid: id });
                 await transaction.delete(this.ctx.service.stagePosFinal.tableName, { sid: id });

+ 1 - 1
app/service/stage_change.js

@@ -379,7 +379,7 @@ module.exports = app => {
             return tender;
         }
 
-        async getQualityTotalPrice(stage) {
+        async getSubtotal(stage) {
             const helper = this.ctx.helper;
             const tender = await this._getTender(stage);
             const sql = 'SELECT sc.*, c.quality FROM ' + this.tableName + ' sc' +

+ 94 - 41
app/service/stage_import_change.js

@@ -8,6 +8,8 @@
  * @version
  */
 
+const changeConst = require('../const/change');
+
 module.exports = app => {
 
     class StageImportChange extends app.BaseService {
@@ -48,13 +50,35 @@ module.exports = app => {
             return await this.db.query(sql, [sid]);
         }
 
-        async getEndStageImportChange(stage) {
-            const sql = 'SELECT scf.* ' +
+        async getStageImportData(stage) {
+            const sql = 'SELECT scf.*, ' +
+                '    oc.p_code As c_code, oc.new_code As c_new_code, oc.quality, ocb.code as b_code, ocb.name, ocb.unit' +
+                '  FROM ' + this.tableName + ' scf ' +
+                '  LEFT JOIN ' + this.ctx.service.change.tableName + ' oc ON scf.rela_cid = oc.cid ' +
+                '  LEFT JOIN ' + this.ctx.service.changeAuditList.tableName + ' ocb ON scf.rela_cbid = ocb.id ' +
+                '  WHERE scf.sid = ?';
+            return await this.db.query(sql, [stage.id]);
+        }
+
+        async getEndStageImportData(stage) {
+            const sql = 'SELECT scf.*, ' +
+                '    oc.p_code As c_code, oc.new_code As c_new_code, oc.quality, ocb.code as b_code, ocb.name, ocb.unit' +
                 '  FROM ' + this.tableName + ' scf ' +
                 '  LEFT JOIN ' + this.ctx.service.stage.tableName + ' s ON scf.sid = s.id' +
+                '  LEFT JOIN ' + this.ctx.service.change.tableName + ' oc ON scf.rela_cid = oc.cid ' +
+                '  LEFT JOIN ' + this.ctx.service.changeAuditList.tableName + ' ocb ON scf.rela_cbid = ocb.id ' +
                 '  WHERE scf.tid = ? And s.order <= ?';
-            const result = await this.db.query(sql, [stage.tid, stage.order]);
-            return result;
+            return await this.db.query(sql, [stage.tid, stage.order]);
+        }
+
+        async getLeafXmjStageImportData(stage, lid) {
+            const sql = 'SELECT scf.*, ' +
+                '    oc.p_code As c_code, oc.new_code As c_new_code, oc.quality, ocb.code as b_code, ocb.name, ocb.unit' +
+                '  FROM ' + this.tableName + ' scf ' +
+                '  LEFT JOIN ' + this.ctx.service.change.tableName + ' oc ON scf.rela_cid = oc.cid ' +
+                '  LEFT JOIN ' + this.ctx.service.changeAuditList.tableName + ' ocb ON scf.rela_cbid = ocb.id ' +
+                '  WHERE scf.sid = ? and import_lid = ?';
+            return await this.db.query(sql, [stage.id, lid]);
         }
 
         async getLeafXmjImportChange(sid, importLid) {
@@ -72,43 +96,44 @@ module.exports = app => {
                 : await this.getImportChange(stage.id);
             if (change.length === 0) return [];
 
-            const changeBills = await this.ctx.service.changeAuditList.getAllDataByCondition({
-                where: { cid: change.map(x => { return x.cid; }) }
-            });
-            const changeBillsIndex = {}, changeBillsPart = {};
-            for (const cb of changeBills) {
-                changeBillsIndex[cb.id] = cb;
-                if (!changeBillsPart[cb.cid]) changeBillsPart[cb.cid] = [];
-                changeBillsPart[cb.cid].push(cb);
-            }
-            const stageChangeBills = await this.getEndStageImportChange(stage);
-            for (const scb of stageChangeBills) {
-                if (!scb.rela_qty) continue;
-
-                const cb = changeBillsIndex[scb.rela_cbid];
-                if (cb) cb.used_qty = this.ctx.helper.add(cb.used_qty, scb.rela_qty);
-            }
-            for (const cid in changeBillsPart) {
-                const c = change.find(x => { return x.cid === cid });
-                if (!c) continue;
-
-                for (const cb of changeBillsPart[cid]) {
-                    cb.tp = this.ctx.helper.mul(cb.spamount, cb.unit_price, c.tp_decimal || this.ctx.tender.info.decimal.tp);
-                    cb.used_tp = this.ctx.helper.mul(cb.used_qty, cb.unit_price, this.ctx.tender.info.decimal.tp);
-
-                    c.used_tp = this.ctx.helper.add(c.used_tp, cb.used_tp);
-                    if (cb.spamount > 0) {
-                        c.p_tp = this.ctx.helper.add(c.p_tp, cb.tp);
-                        c.p_used_tp = this.ctx.helper.add(c.p_used_tp, cb.used_tp);
-                    } else if (cb.spamount < 0){
-                        c.n_tp = this.ctx.helper.add(c.n_tp, cb.tp);
-                        c.n_used_tp = this.ctx.helper.add(c.n_used_tp, cb.used_tp);
-                    }
-                }
-                c.used_pt = c.total_price ? this.ctx.helper.mul(this.ctx.helper.div(c.used_tp, c.total_price, 4), 100) : 0;
-                c.p_used_pt = c.p_tp ? this.ctx.helper.mul(this.ctx.helper.div(c.p_used_tp, c.p_tp, 4), 100) : 0;
-                c.n_used_pt = c.n_tp ? this.ctx.helper.mul(this.ctx.helper.div(c.n_used_tp, c.n_tp, 4), 100) : 0;
-            }
+            // 引入变更,不计算已执行等????
+            // const changeBills = await this.ctx.service.changeAuditList.getAllDataByCondition({
+            //     where: { cid: change.map(x => { return x.cid; }) }
+            // });
+            // const changeBillsIndex = {}, changeBillsPart = {};
+            // for (const cb of changeBills) {
+            //     changeBillsIndex[cb.id] = cb;
+            //     if (!changeBillsPart[cb.cid]) changeBillsPart[cb.cid] = [];
+            //     changeBillsPart[cb.cid].push(cb);
+            // }
+            // const stageChangeBills = await this.getEndStageImportChange(stage);
+            // for (const scb of stageChangeBills) {
+            //     if (!scb.rela_qty) continue;
+            //
+            //     const cb = changeBillsIndex[scb.rela_cbid];
+            //     if (cb) cb.used_qty = this.ctx.helper.add(cb.used_qty, scb.rela_qty);
+            // }
+            // for (const cid in changeBillsPart) {
+            //     const c = change.find(x => { return x.cid === cid });
+            //     if (!c) continue;
+            //
+            //     for (const cb of changeBillsPart[cid]) {
+            //         cb.tp = this.ctx.helper.mul(cb.spamount, cb.unit_price, c.tp_decimal || this.ctx.tender.info.decimal.tp);
+            //         cb.used_tp = this.ctx.helper.mul(cb.used_qty, cb.unit_price, this.ctx.tender.info.decimal.tp);
+            //
+            //         c.used_tp = this.ctx.helper.add(c.used_tp, cb.used_tp);
+            //         if (cb.spamount > 0) {
+            //             c.p_tp = this.ctx.helper.add(c.p_tp, cb.tp);
+            //             c.p_used_tp = this.ctx.helper.add(c.p_used_tp, cb.used_tp);
+            //         } else if (cb.spamount < 0){
+            //             c.n_tp = this.ctx.helper.add(c.n_tp, cb.tp);
+            //             c.n_used_tp = this.ctx.helper.add(c.n_used_tp, cb.used_tp);
+            //         }
+            //     }
+            //     c.used_pt = c.total_price ? this.ctx.helper.mul(this.ctx.helper.div(c.used_tp, c.total_price, 4), 100) : 0;
+            //     c.p_used_pt = c.p_tp ? this.ctx.helper.mul(this.ctx.helper.div(c.p_used_tp, c.p_tp, 4), 100) : 0;
+            //     c.n_used_pt = c.n_tp ? this.ctx.helper.mul(this.ctx.helper.div(c.n_used_tp, c.n_tp, 4), 100) : 0;
+            // }
             return change;
         }
 
@@ -152,6 +177,34 @@ module.exports = app => {
             const cur = await this.db.query(sql, [sid]);
             return this._.map(cur, 'rela_cid');
         }
+
+        // 分类汇总变更金额
+        async getSubtotal(stage) {
+            const helper = this.ctx.helper;
+            const tender = this.ctx.tender && this.ctx.tender.id === stage.tid ? this.ctx.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.rela_cid = c.cid' +
+                '  WHERE sid = ?';
+            const data = await this.db.query(sql, [stage.id]);
+            const bqData = [];
+            for (const d of data) {
+                if (!d.rela_qty) continue;
+                let bd = bqData.find(x => { return x.lid === d.lid && x.quality === d.quality; });
+                if (!bd) {
+                    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.rela_qty, bd.unit_price, tender.info.decimal.tp);
+                bd.tp = this.ctx.helper.add(bd.tp, tp);
+            }
+            const result = {};
+            result.common = helper.sum(helper._.map(bqData.filter(x => {return x.quality === changeConst.quality.common.value; }), 'tp'));
+            result.more = helper.sum(helper._.map(bqData.filter(x => {return x.quality === changeConst.quality.more.value; }), 'tp'));
+            result.great = helper.sum(helper._.map(bqData.filter(x => {return x.quality === changeConst.quality.great.value; }), 'tp'));
+            return result;
+        }
     }
 
     return StageImportChange;

+ 2 - 2
app/service/stage_rela.js

@@ -19,7 +19,7 @@ class srCache {
     }
 
     async _getCacheOrgTp() {
-        const bg = await this.ctx.service.stageChange.getQualityTotalPrice(this.stage);
+        const bg = await this.ctx.service.stageChange.getSubtotal(this.stage);
         const gcl100 = await this.ctx.service.stageBills.getSumTotalPriceGcl(this.stage, '^[^0-9]*1[0-9]{2}(-|$)');
         return {
             contract_tp: this.stage.contract_tp, qc_tp: this.stage.qc_tp,
@@ -290,7 +290,7 @@ module.exports = app => {
         }
 
         // async _getCacheOrgTp(stage) {
-        //     const bg = await this.ctx.service.stageChange.getQualityTotalPrice(stage);
+        //     const bg = await this.ctx.service.stageChange.getSubtotal(stage);
         //     const gcl100 = await this.ctx.service.stageBills.getSumTotalPriceGcl(stage, '^[^0-9]*1[0-9]{2}(-|$)');
         //     return {
         //         contract_tp: stage.contract_tp, qc_tp: stage.qc_tp,