فهرست منبع

计量台账,计量单元计算相关

MaiXinRong 5 سال پیش
والد
کامیت
6ad327ebd0

+ 6 - 6
app/controller/report_controller.js

@@ -360,19 +360,19 @@ async function getReportData(ctx, params, filters, memFieldKeys) {
                     break;
                 case 'mem_stage_im_zl':
                     // memFieldKeys[filter]
-                    runnableRst.push(ctx.service.reportMemory.getStageImZlData(params.tender_id, params.stage_id));
+                    runnableRst.push(ctx.service.reportMemory.getStageImZlData(params.tender_id, params.stage_id, memFieldKeys[filter]));
                     runnableKey.push('mem_stage_im_zl');
                     break;
                 case 'mem_month_progress':
-                    runnableRst.push(ctx.service.reportMemory.getMonthProgress(params.tender_id));
+                    runnableRst.push(ctx.service.reportMemory.getMonthProgress(params.tender_id, memFieldKeys[filter]));
                     runnableKey.push('mem_month_progress');
                     break;
                 case 'mem_stage_bills':
-                    runnableRst.push(ctx.service.reportMemory.getStageBillsData(params.tender_id, params.stage_id));
+                    runnableRst.push(ctx.service.reportMemory.getStageBillsData(params.tender_id, params.stage_id, memFieldKeys[filter]));
                     runnableKey.push('mem_stage_pos');
                     break;
                 case 'mem_stage_pos':
-                    runnableRst.push(ctx.service.reportMemory.getStagePosData(params.tender_id, params.stage_id));
+                    runnableRst.push(ctx.service.reportMemory.getStagePosData(params.tender_id, params.stage_id, memFieldKeys[filter]));
                     runnableKey.push('mem_stage_pos');
                     break;
                 case 'change':
@@ -395,10 +395,10 @@ async function getReportData(ctx, params, filters, memFieldKeys) {
     for (const filter of filters) {
         switch (filter) {
             case 'mem_stage_im_tz':
-                rst[filter] = await ctx.service.reportMemory.getStageImTzData(params.tender_id, params.stage_id);
+                rst[filter] = await ctx.service.reportMemory.getStageImTzData(params.tender_id, params.stage_id, memFieldKeys[filter]);
                 break;
             case 'mem_stage_im_tz_bills':
-                rst[filter] = await ctx.service.reportMemory.getStageImTzBillsData(params.tender_id, params.stage_id);
+                rst[filter] = await ctx.service.reportMemory.getStageImTzBillsData(params.tender_id, params.stage_id, memFieldKeys[filter]);
                 break;
             default:
                 break;

+ 0 - 6
app/public/js/spreadjs_rela/spreadjs_zh.js

@@ -1806,15 +1806,10 @@ const SpreadJsObj = {
             const proto = ActiveComboCellType.prototype;
             proto.paintValue = function (ctx, value, x, y, w, h, style, options) {
                 const sheet = options.sheet;
-                console.log('paint');
-                console.log('row: ' + options.row + ' ' + sheet.getActiveRowIndex());
-                console.log('col: ' + options.col + ' ' + sheet.getActiveColumnIndex());
                 if (options.row === sheet.getActiveRowIndex() && options.col === sheet.getActiveColumnIndex()
                     && !sheet.getCell(options.row, options.col).locked()) {
-                    console.log('comboBox');
                     spreadNS.CellTypes.ComboBox.prototype.paintValue.apply(this, arguments);
                 } else {
-                    console.log('base');
                     spreadNS.CellTypes.Base.prototype.paintValue.apply(this, arguments);
                 }
             };
@@ -1822,7 +1817,6 @@ const SpreadJsObj = {
                 hitinfo.sheet.repaint(hitinfo.cellRect);
             };
             proto.getHitInfo = function (x, y, cellStyle, cellRect, options) {
-                console.log('getHitInfo');
                 const sheet = options.sheet;
                 if (options.row === sheet.getActiveRowIndex() && options.col === sheet.getActiveColumnIndex()
                     && !sheet.getCell(options.row, options.col).locked()) {

+ 1 - 1
app/public/js/stage.js

@@ -1118,7 +1118,7 @@ $(document).ready(() => {
                 const range = info.cellRange;
                 const validField = ['contract_qty', 'qc_qty', 'postil'];
                 if (!checkTzMeasureType()) {
-                    validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty');
+                    validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'position');
                 }
                 for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
                     const col = info.sheet.zh_setting.cols[iCol];

+ 4 - 4
app/service/report_memory.js

@@ -165,7 +165,7 @@ module.exports = app => {
             return rst;
         }
 
-        async getStageImTzData(tid, sid) {
+        async getStageImTzData(tid, sid, fields) {
             await this.ctx.service.tender.checkTender(tid);
             await this.ctx.service.stage.checkStage(sid);
             const cache = await this._getReportMemoryCache('mem_stage_im_tz', tid, sid, this.ctx.stage.cacheTime, stageImVersion);
@@ -190,7 +190,7 @@ module.exports = app => {
             return this.stageImData.main;
         }
 
-        async getStageImTzBillsData(tid, sid) {
+        async getStageImTzBillsData(tid, sid, fields) {
             await this.ctx.service.tender.checkTender(tid);
             await this.ctx.service.stage.checkStage(sid);
             const cache = await this._getReportMemoryCache('mem_stage_im_tz_bills', tid, sid, this.ctx.stage.cacheTime, stageImVersion);
@@ -211,7 +211,7 @@ module.exports = app => {
             return this.stageImData.bills;
         }
 
-        async getStageImZlData(tid, sid) {
+        async getStageImZlData(tid, sid, fields) {
             await this.ctx.service.tender.checkTender(tid);
             await this.ctx.service.stage.checkStage(sid);
             const cache = await this._getReportMemoryCache('mem_stage_im_zl', tid, sid, this.ctx.stage.cacheTime, stageImVersion);
@@ -229,7 +229,7 @@ module.exports = app => {
             return this.stageImData.main;
         }
 
-        async getMonthProgress(tid) {
+        async getMonthProgress(tid, fields) {
             const helper = this.ctx.helper;
             await this.ctx.service.tender.checkTender(tid);
             const tender = this.ctx.tender;

+ 0 - 1
app/service/stage_bills.js

@@ -316,7 +316,6 @@ module.exports = app => {
                 if (stageBills.contract_qty === posGather.contract_qty && stageBills.qc_qty === posGather.qc_qty) {
                     return;
                 } else {
-                    const curOrder = this.ctx.stage.curAuditor ? this.ctx.stage.curAuditor.order : 0;
                     if (stageBills.times === this.ctx.stage.curTimes && stageBills.order === this.ctx.stage.curOrder) {
                         posGather.id = stageBills.id;
                         await transaction.update(this.tableName, posGather);

+ 189 - 130
app/service/stage_pos.js

@@ -146,61 +146,86 @@ module.exports = app => {
          * @private
          */
         async _addStagePosData(data) {
-            let bills , precision;
+            let bills , precision, updateBills = null;
             const  result = {pos: [], ledger: []};
-            const datas = data instanceof Array ? data : [data], calcBills = [], calcStageBills = [];
+            const datas = data instanceof Array ? data : [data], calcStageBills = [];
+            if (datas[0].sgfh_qty !== undefined || datas[0].sjcl_qty !== undefined || datas[0].qtcl_qty !== undefined
+                || datas[0].contract_qty !== undefined || datas[0].qc_qty !== undefined) {
+                bills = await this.ctx.service.ledger.getDataById(datas[0].lid);
+                precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
+                result.ledger.push(bills.id);
+            }
+            if (datas[0].contract_qty !== undefined || datas[0].qc_qty !== undefined || datas[0].postil !== undefined) {
+                result.stageUpdate = true;
+            }
 
-            const transaction = await this.db.beginTransaction();
-            try {
-                for (const d of datas) {
-                    if (d.sgfh_qty !== undefined || d.sjcl_qty !== undefined || d.qtcl_qty !== undefined) {
-                        if (!bills || bills.id !== data.lid) {
-                            bills = await this.ctx.service.ledger.getDataById(d.lid);
-                            precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
-                        }
-                    }
-                    // 在主表pos中新增数据
-                    const p = {
-                        id: this.uuid.v4(), tid: this.ctx.tender.id, lid: d.lid, name: d.name, porder: d.porder, position: d.position,
-                        add_stage: this.ctx.stage.id,
-                        add_times: this.ctx.stage.curTimes,
-                        add_user: this.ctx.session.sessionUser.accountId,
-                    };
-                    if (d.sgfh_qty) p.sgfh_qty = this.round(d.sgfh_qty, precision.value);
-                    if (d.sjcl_qty) p.sjcl_qty = this.round(d.sjcl_qty, precision.value);
-                    if (d.qtcl_qty) p.qtcl_qty = this.round(d.qtcl_qty, precision.value);
+            const insertPos = [], insertPosStage = [];
+            for (const d of datas) {
+                const p = {
+                    id: this.uuid.v4(), tid: this.ctx.tender.id, lid: d.lid, name: d.name, porder: d.porder, position: d.position,
+                    add_stage: this.ctx.stage.id,
+                    add_times: this.ctx.stage.curTimes,
+                    add_user: this.ctx.session.sessionUser.accountId,
+                };
+                if (d.sgfh_qty !== undefined || d.sjcl_qty !== undefined || d.qtcl_qty !== undefined) {
+                    if (d.sgfh_qty!== undefined) p.sgfh_qty = this.round(d.sgfh_qty, precision.value);
+                    if (d.sjcl_qty!== undefined) p.sjcl_qty = this.round(d.sjcl_qty, precision.value);
+                    if (d.qtcl_qty!== undefined) p.qtcl_qty = this.round(d.qtcl_qty, precision.value);
                     p.quantity = this.ctx.helper.sum([p.sgfh_qty, p.sjcl_qty, p.qtcl_qty]);
-                    const addRst = await transaction.insert(this.ctx.service.pos.tableName, p);
-                    result.pos.push(p.id);
-                    // 如果存在复核数据,更新计算主表清单
-                    if (p.sgfh_qty || p.sjcl_qty || p.qtcl_qty) {
-                        calcBills.push(p.lid);
-                        result.ledger.push(p.lid);
-                    }
-                    // 如果存在本期计算数据,更新计算清单本期计量数据
-                    if (d.contract_qty || d.qc_qty || d.postil) {
-                        const ps = {
-                            pid: p.id,
-                            lid: d.lid,
-                            tid: this.ctx.tender.id,
-                            sid: this.ctx.stage.id,
-                            said: this.ctx.session.sessionUser.accountId,
-                            times: this.ctx.stage.curTimes,
-                            order: this.ctx.stage.curOrder,
-                        };
-                        if (d.contract_qty) ps.contract_qty = this.round(d.contract_qty, precision.value);
-                        if (d.qc_qty) ps.qc_qty = this.round(d.qc_qty, precision.value);
-                        if (d.postil) ps.postil = d.postil;
-                        await transaction.insert(this.tableName, ps);
-                        if ((d.contract_qty || d.qc_qty) && calcStageBills.indexOf(ps.lid) === -1) {
-                            calcStageBills.push(ps.lid);
-                        }
-                        result.stageUpdate = true;
+                    if (!updateBills) updateBills = {id: bills.id, sgfh_qty: bills.sgfh_qty, sjcl_qty: bills.sjcl_qty, qtcl_qty: bills.qtcl_qty};
+                }
+                insertPos.push(p);
+                result.pos.push(p.id);
+
+                if (d.contract_qty!== undefined || d.qc_qty!== undefined || d.postil!== undefined) {
+                    const ps = {
+                        pid: p.id,
+                        lid: d.lid,
+                        tid: this.ctx.tender.id,
+                        sid: this.ctx.stage.id,
+                        said: this.ctx.session.sessionUser.accountId,
+                        times: this.ctx.stage.curTimes,
+                        order: this.ctx.stage.curOrder,
+                    };
+                    if (d.contract_qty !== undefined) ps.contract_qty = this.round(d.contract_qty, precision.value);
+                    if (d.qc_qty!== undefined) ps.qc_qty = this.round(d.qc_qty, precision.value);
+                    if (d.postil!== undefined) ps.postil = d.postil;
+                    insertPosStage.push(ps);
+                    if ((d.contract_qty || d.qc_qty) && calcStageBills.indexOf(ps.lid) === -1) {
+                        calcStageBills.push(ps.lid);
                     }
                 }
-                for (const lid of calcBills) {
-                    await this.ctx.service.ledger.calc(this.ctx.tender.id, lid, transaction);
+            }
+            if (updateBills) {
+                for (const d of insertPos) {
+                    if (d.sgfh_qty) {
+                        d.sgfh_qty = this.ctx.helper.round(d.sgfh_qty, precision.value);
+                        updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, d.sgfh_qty);
+                    }
+                    if (d.sjcl_qty) {
+                        d.sjcl_qty = this.ctx.helper.round(d.sjcl_qty, precision.value);
+                        updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, d.sjcl_qty);
+                    }
+                    if (d.qtcl_qty) {
+                        d.qtcl_qty = this.ctx.helper.round(d.qtcl_qty, precision.value);
+                        updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, d.qtcl_qty);
+                    }
+                    d.quantity = this.ctx.helper.sum([d.sgfh_qty, d.qtcl_qty, d.sjcl_qty]);
                 }
+                updateBills.quantity = this.ctx.helper.sum([updateBills.sgfh_qty, updateBills.qtcl_qty, updateBills.sjcl_qty]);
+                const info = this.ctx.tender.info;
+                updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
+                updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
+                updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
+                updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
+            }
+
+            const transaction = await this.db.beginTransaction();
+            try {
+                if (insertPos.length > 0) await transaction.insert(this.ctx.service.pos.tableName, insertPos);
+                if (updateBills) await transaction.update(this.ctx.service.ledger.tableName, updateBills);
+                if (insertPosStage.length > 0) await transaction.insert(this.tableName, insertPosStage);
+
                 for (const lid of calcStageBills) {
                     await this.ctx.service.stageBills.calc(this.ctx.tender.id, this.ctx.stage.id, lid, transaction);
                 }
@@ -221,89 +246,110 @@ module.exports = app => {
          * @private
          */
         async _updateStagePosData(data) {
-            let bills, precision;
-            const result = {ledger: [], pos: [], stageUpdate: true}, ledgerCalc = [];
+            let bills, precision, updateBills = null;
             const datas = data instanceof Array ? data : [data];
             const orgPos = await this.ctx.service.pos.getPosDataByIds(this._.map(datas, 'pid'));
+            const result = {ledger: [], pos: [], stageUpdate: true};
             const orgStagePos = await this.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id,
                 {pid: this._.map(datas, 'pid')});
 
-            const transaction = await this.db.beginTransaction();
-            try {
-                for (const d of datas) {
-                    if (d.sgfh_qty !== undefined || d.qtcl_qty !== undefined || d.sjcl_qty !== undefined
-                        || d.contract_qty !== undefined || d.qc_qty !== undefined) {
-                        if (!bills || bills.id !== data.lid) {
-                            bills = await this.ctx.service.ledger.getDataById(d.lid);
-                            precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
-                        }
-                    }
-                    if (d.name !== undefined || d.drawing_code !== undefined || d.position !== undefined
-                        || d.sgfh_qty !== undefined || d.qtcl_qty !== undefined || d.sjcl_qty !== undefined) {
-                        const op = this._.find(orgPos, {id: d.pid});
-                        if (op.add_stage !== this.ctx.stage.id) throw '不可修改数据';
-                        const p = {id: d.pid};
-                        if (d.name !== undefined) p.name = d.name;
-                        if (d.position !== undefined) p.position = d.position;
-                        if (d.sgfh_qty !== undefined || d.qtcl_qty !== undefined || d.sjcl_qty !== undefined) {
-                            p.sgfh_qty = d.sgfh_qty !== undefined ? d.sgfh_qty : op.sgfh_qty;
-                            p.sjcl_qty = d.sjcl_qty !== undefined ? d.sjcl_qty : op.sjcl_qty;
-                            p.qtcl_qty = d.qtcl_qty !== undefined ? d.qtcl_qty : op.qtcl_qty;
-                            p.quantity = this.ctx.helper.sum([p.sgfh_qty, p.sjcl_qty, p.qtcl_qty]);
-                            if (ledgerCalc.indexOf(op.lid) === -1) {
-                                ledgerCalc.push(op.lid);
-                            }
-                        }
-                        if (d.drawing_code !== undefined) p.drawing_code = d.drawing_code;
-                        await transaction.update(this.ctx.service.pos.tableName, p);
+            if (datas[0].sgfh_qty !== undefined || datas[0].qtcl_qty !== undefined || datas[0].sjcl_qty !== undefined
+                || datas[0].contract_qty !== undefined || datas[0].qc_qty !== undefined) {
+                bills = await this.ctx.service.ledger.getDataById(datas[0].lid);
+                precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
+                result.ledger.push(bills.id);
+            }
+            const updatePos = [], updatePosStage = [], insertPosStage = [];
+            for (const d of datas) {
+                if (d.name !== undefined || d.drawing_code !== undefined || d.position !== undefined
+                    || d.sgfh_qty !== undefined || d.qtcl_qty !== undefined || d.sjcl_qty !== undefined) {
+
+                    const op = this._.find(orgPos, {id: d.pid});
+                    if (op.add_stage !== this.ctx.stage.id) throw '不可修改数据';
+
+                    const p = {id: op.id};
+                    if (d.name !== undefined) p.name = d.name;
+                    if (d.position !== undefined) p.position = d.position;
+                    if (d.sgfh_qty !== undefined || d.qtcl_qty !== undefined || d.sjcl_qty !== undefined) {
+                        p.sgfh_qty = d.sgfh_qty !== undefined ? d.sgfh_qty : op.sgfh_qty;
+                        p.sjcl_qty = d.sjcl_qty !== undefined ? d.sjcl_qty : op.sjcl_qty;
+                        p.qtcl_qty = d.qtcl_qty !== undefined ? d.qtcl_qty : op.qtcl_qty;
+                        p.quantity = this.ctx.helper.sum([p.sgfh_qty, p.sjcl_qty, p.qtcl_qty]);
+                        if (!updateBills) updateBills = {id: bills.id};
                     }
+                    if (d.drawing_code !== undefined) p.drawing_code = d.drawing_code;
+                    updatePos.push(p);
+                }
 
-                    if (d.contract_qty !== undefined || d.qc_qty !== undefined || d.postil !== undefined) {
-                        const osp = this._.find(orgStagePos, function (p) { return p.pid === d.pid; });
-                        if (osp && osp.times === this.ctx.stage.curTimes && osp.order === this.ctx.stage.curOrder) {
-                            const sp = {};
-                            if (d.contract_qty !== undefined) {
-                                sp.contract_qty = this.ctx.helper.round(d.contract_qty, precision.value);
-                            }
-                            if (d.qc_qty !== undefined) {
-                                sp.qc_qty = this.ctx.helper.round(d.qc_qty, precision.value);
-                            }
-                            if (d.postil !== undefined) {
-                                sp.postil = d.postil;
-                            }
-                            await transaction.update(this.tableName, sp, {where: {id: osp.id}});
-                        } else {
-                            const sp = {
-                                pid: d.pid, lid: d.lid,
-                                tid: this.ctx.tender.id, sid: this.ctx.stage.id,
-                                said: this.ctx.session.sessionUser.accountId,
-                                times: this.ctx.stage.curTimes, order: this.ctx.stage.curOrder
-                            };
-                            if (d.contract_qty !== undefined || osp) {
-                                sp.contract_qty = d.contract_qty === undefined && osp
-                                    ? osp.contract_qty
-                                    : this.ctx.helper.round(d.contract_qty, precision.value);
-                            }
-                            if (d.qc_qty || osp) {
-                                sp.qc_qty = d.qc_qty === undefined && osp
-                                    ? osp.qc_qty
-                                    : this.ctx.helper.round(d.qc_qty, precision.value);
-                            }
-                            if (d.postil || osp) {
-                                sp.postil = d.postil === undefined && osp ? osp.postil : d.postil;
-                            }
-                            await transaction.insert(this.tableName, sp);
+                if (d.contract_qty !== undefined || d.qc_qty !== undefined || d.postil !== undefined) {
+                    const osp = this._.find(orgStagePos, function (p) { return p.pid === d.pid; });
+                    if (osp && osp.times === this.ctx.stage.curTimes && osp.order === this.ctx.stage.curOrder) {
+                        const sp = {id: osp.id};
+                        if (d.contract_qty !== undefined) {
+                            sp.contract_qty = this.ctx.helper.round(d.contract_qty, precision.value);
                         }
-                    }
-                    result.pos.push(d.pid);
-                    if ((d.sgfh_qty !== undefined || d.qtcl_qty !== undefined || d.sjcl_qty !== undefined ||
-                            d.contract_qty === undefined || d.qc_qty === undefined)
-                         && (result.ledger.indexOf(d.lid) === -1)) {
-                        result.ledger.push(d.lid);
+                        if (d.qc_qty !== undefined) {
+                            sp.qc_qty = this.ctx.helper.round(d.qc_qty, precision.value);
+                        }
+                        if (d.postil !== undefined) {
+                            sp.postil = d.postil;
+                        }
+                        updatePosStage.push(sp);
+                    } else {
+                        const sp = {
+                            pid: d.pid, lid: d.lid,
+                            tid: this.ctx.tender.id, sid: this.ctx.stage.id,
+                            said: this.ctx.session.sessionUser.accountId,
+                            times: this.ctx.stage.curTimes, order: this.ctx.stage.curOrder
+                        };
+                        if (d.contract_qty !== undefined || osp) {
+                            sp.contract_qty = d.contract_qty === undefined && osp
+                                ? osp.contract_qty
+                                : this.ctx.helper.round(d.contract_qty, precision.value);
+                        }
+                        if (d.qc_qty || osp) {
+                            sp.qc_qty = d.qc_qty === undefined && osp
+                                ? osp.qc_qty
+                                : this.ctx.helper.round(d.qc_qty, precision.value);
+                        }
+                        if (d.postil || osp) {
+                            sp.postil = d.postil === undefined && osp ? osp.postil : d.postil;
+                        }
+                        insertPosStage.push(sp);
                     }
                 }
-                for (const lid of ledgerCalc) {
-                    await this.ctx.service.ledger.calc(this.ctx.tender.id, lid, transaction);
+                result.pos.push(d.pid);
+            }
+            if (updateBills) {
+                const billsPos = await this.ctx.service.pos.getAllDataByCondition({where: {tid: bills.tender_id, lid: bills.id} });
+                for (const bp of billsPos) {
+                    const newPos = updatePos.find(function (x) { return x.id === bp.id });
+                    const calcData = newPos ? newPos : bp;
+                    updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, calcData.sgfh_qty);
+                    updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, calcData.sjcl_qty);
+                    updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, calcData.qtcl_qty);
+                    updateBills.quantity = this.ctx.helper.add(updateBills.quantity, calcData.quantity);
+                }
+                const info = this.ctx.tender.info;
+                updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
+                updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
+                updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
+                updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
+            }
+
+            const transaction = await this.db.beginTransaction();
+            try {
+                if (updatePos.length > 0) {
+                    await transaction.updateRows(this.ctx.service.pos.tableName, updatePos);
+                }
+                if (updateBills) {
+                    await transaction.update(this.ctx.service.ledger.tableName, updateBills);
+                }
+                if (updatePosStage.length > 0) {
+                    await transaction.updateRows(this.tableName, updatePosStage);
+                }
+                if (insertPosStage.length > 0) {
+                    await transaction.insert(this.tableName, insertPosStage);
                 }
                 for (const lid of result.ledger) {
                     await this.ctx.service.stageBills.calc(this.ctx.tender.id, this.ctx.stage.id, lid, transaction);
@@ -332,27 +378,40 @@ module.exports = app => {
                     if (p.add_stage !== this.ctx.stage.id /*|| p.add_times !== this.ctx.stage.curTimes || p.add_user !== this.ctx.session.sessionUser.accountId*/) {
                         throw '不可删除该数据';
                     }
+                    if (p.lid !== pos[0].lid) {
+                        throw '提交数据错误';
+                    }
                 }
             } else if (pos.add_stage !== this.ctx.stage.id /*|| pos.add_times !== this.ctx.stage.curTimes || pos.add_user !== this.ctx.session.sessionUser.accountId*/) {
                 throw '不可删除该数据';
             }
-            const ledgerIds = this._.map(pos, 'lid');
+            const bills = await this.ctx.service.ledger.getDataById(pos[0].lid);
+            const billsPos = await this.ctx.service.pos.getAllDataByCondition({ where: {tid: bills.tender_id, lid: bills.id} });
+            const updateBills = {id: bills.id, sgfh_qty: null, sjcl_qty: null, qtcl_qty: null, quantity: null};
+            for (const bp of billsPos) {
+                if (data.indexOf(bp.id) >= 0) continue;
+                updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, bp.sgfh_qty);
+                updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, bp.sjcl_qty);
+                updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, bp.qtcl_qty);
+                updateBills.quantity = this.ctx.helper.add(updateBills.quantity, bp.quantity);
+            }
+            const info = this.ctx.tender.info;
+            updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
+            updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
+            updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
+            updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
 
             const transaction = await this.db.beginTransaction();
             try {
                 // 删除部位明细
                 await transaction.delete(this.ctx.service.pos.tableName, {tid: this.ctx.tender.id, id: data});
-                for (const lid of ledgerIds) {
-                    await this.ctx.service.ledger.calc(this.ctx.tender.id, lid, transaction);
-                }
+                await transaction.update(this.ctx.service.ledger.tableName, updateBills);
                 // 删除部位明细计量数据
                 await transaction.delete(this.tableName, {tid: this.ctx.tender.id, lid: data});
-                for (const lid of ledgerIds) {
-                    await this.ctx.service.stageBills.calc(this.ctx.tender.id, this.ctx.stage.id, lid, transaction);
-                }
+                await this.ctx.service.stageBills.calc(this.ctx.tender.id, this.ctx.stage.id, bills.id, transaction);
                 await transaction.commit();
                 // 获取需要更新的数据
-                result.ledger = ledgerIds;
+                result.ledger = [bills.id];
                 result.stageUpdate = true;
                 return result;
             } catch (err) {