Browse Source

小数位数计算相关

MaiXinRong 1 năm trước cách đây
mục cha
commit
4fa74cf68c
3 tập tin đã thay đổi với 72 bổ sung66 xóa
  1. 3 1
      app/service/stage.js
  2. 6 5
      app/service/tender_cache.js
  3. 63 60
      app/service/tender_info.js

+ 3 - 1
app/service/stage.js

@@ -327,9 +327,11 @@ module.exports = app => {
                     stage = firstFlowStage.status === auditConst.stage.status.uncheck ? stages[flowStages.length] : firstFlowStage;
                 }
             }
-            if (stage) stage.tp_history = stage.tp_history ? JSON.parse(stage.tp_history) : [];
             return stage;
         }
+        async getUnCompleteStages(tenderId) {
+            return this.db.query(`SELECT * From ${this.tableName} WHERE tid = ? and status <> ?`, [tenderId, auditConst.stage.status.checked]);
+        }
 
         /**
          * 获取 最新一期 审批完成的 期计量

+ 6 - 5
app/service/tender_cache.js

@@ -57,7 +57,7 @@ module.exports = app => {
                 tender.pre_flow = cache.stage_flow_pre_info ? JSON.parse(cache.stage_flow_pre_info) : null;
                 tender.stage_tp = JSON.parse(cache.stage_flow_cur_tp || cache.stage_flow_pre_tp);
                 tender.progress = {
-                    title: `第${tender.cur_flow.order}期`,
+                    title: `第${tender.cur_flow.order === undefined ? tender.cur_flow[0].order : tender.cur_flow.order}期`,
                     status: auditConst.stage.tiStatusString[cache.stage_status],
                     status_class: auditConst.stage.tiStatusStringClass[cache.stage_status],
                 };
@@ -70,7 +70,7 @@ module.exports = app => {
                 tender.pre_flow = cache.stage_flow_pre_info ? JSON.parse(cache.stage_flow_pre_info) : null;
                 tender.stage_tp = cache.stage_flow_pre_tp ? JSON.parse(cache.stage_flow_pre_tp) : {};
                 tender.progress = {
-                    title: `第${tender.pre_flow.order}期`,
+                    title: `第${tender.pre_flow.order === undefined ? tender.pre_flow[0].order : tender.pre_flow.order}期`,
                     status: auditConst.stage.tiStatusString[auditConst.stage.status.checked],
                     status_class: auditConst.stage.tiStatusStringClass[auditConst.stage.status.checked],
                 };
@@ -390,10 +390,11 @@ module.exports = app => {
 
         async _refreshStageRela(tender, data) {
             if (tender.ledger_status === auditConst.ledger.status.checked) {
+                const endLastStage = await this.ctx.service.stage.getLastestStage(tender.id, true);
                 const lastStage = await this.ctx.service.stage.getFlowLatestStage(tender.id, true);
-                if (!lastStage) return;
+                if (!lastStage || !endLastStage) return;
 
-                data.stage_count = lastStage.order;
+                data.stage_count = endLastStage.order;
                 data.stage_complete_count = lastStage.status === auditConst.stage.status.checked ? lastStage.order : lastStage.order - 1;
                 data.stage_status = lastStage.status;
                 const tp = {
@@ -411,7 +412,7 @@ module.exports = app => {
                         const preAuditorIds = preAuditors.map(x => { return x.aid; });
                         data.stage_flow_pre_uid = preAuditorIds.join(',');
                         data.stage_flow_pre_info = preAuditors.length > 0 ? JSON.stringify(preAuditors.map(preAuditor => { return {
-                            order: preAuditor.order, audit_type: preAuditor.audit_type, audit_order: preAuditor.order, status: preAuditor.status, time: preAuditor.end_time,
+                            order: preStage.order, audit_type: preAuditor.audit_type, audit_order: preAuditor.order, status: preAuditor.status, time: preAuditor.end_time,
                             name: preAuditor.name, company: preAuditor.company, role: preAuditor.role, mobile: preAuditor.mobile, telephone: preAuditor.telephone,
                         }})) : '';
                         data.stage_flow_pre_tp = JSON.stringify({

+ 63 - 60
app/service/tender_info.js

@@ -249,78 +249,81 @@ module.exports = app => {
         }
 
         async _reCalcStageBills(tenderId, newDecimal, oldDecimal) {
-            let updateStageBills = [], insertStageBills = [];
-            const stage = await this.ctx.service.stage.getLastestStage(tenderId, true);
-            if (!stage || stage.status === auditConst.stage.status.checking ||
-                stage.status === auditConst.stage.status.checked || newDecimal.tp === oldDecimal.tp)
-                return [updateStageBills, insertStageBills];
-
-            const stageBills = await this.ctx.service.stageBills.getLastestStageData2(stage.tid, stage.id);
-            const bills = await this.ctx.service.ledger.getAllDataByCondition({
-                columns: ['id', 'unit_price'],
-                where: { tender_id: tenderId, is_leaf: true },
-            });
-            for (const sb of stageBills) {
-                const b = bills.find(x => {return x.id === sb.lid});
-                const contract_tp = this.ctx.helper.mul(b.unit_price, sb.contract_qty, newDecimal.tp);
-                const qc_tp = this.ctx.helper.mul(b.unit_price, sb.qc_qty, newDecimal.tp);
-                if (contract_tp == sb.contract_tp && qc_tp === sb.qc_tp) continue;
-
-                //if (sb.)
-                if (sb.times === stage.times && sb.order === 0) {
-                    updateStageBills.push({
-                        id: sb.id, contract_tp, qc_tp
-                    });
-                } else {
-                    insertStageBills.push({
-                        tid: stage.tid, lid: sb.lid, sid: stage.id, said: this.ctx.session.sessionUser.accountId,
-                        times: stage.times, order: 0,
-                        contract_qty: sb.contract_qty, contract_expr: sb.contract_expr, contract_tp,
-                        qc_qty: sb.qc_qty, qc_tp,
-                        postil: sb.postil,
-                    });
+            const updateStageBills = [], insertStageBills = [];
+            const stages = await this.ctx.service.stage.getUnCompleteStages(tenderId);
+            if (stages.length === 0 || newDecimal.tp === oldDecimal.tp) return [updateStageBills, insertStageBills];
+
+            for (const stage of stages) {
+                const stageBills = await this.ctx.service.stageBills.getLastestStageData2(stage.tid, stage.id);
+                const bills = await this.ctx.service.ledger.getAllDataByCondition({
+                    columns: ['id', 'unit_price'],
+                    where: { tender_id: tenderId, is_leaf: true },
+                });
+                for (const sb of stageBills) {
+                    const b = bills.find(x => {return x.id === sb.lid});
+                    const contract_tp = this.ctx.helper.mul(b.unit_price, sb.contract_qty, newDecimal.tp);
+                    const qc_tp = this.ctx.helper.mul(b.unit_price, sb.qc_qty, newDecimal.tp);
+                    if (contract_tp == sb.contract_tp && qc_tp === sb.qc_tp) continue;
+
+                    if (sb.times === stage.times && sb.order === 0) {
+                        updateStageBills.push({
+                            id: sb.id, contract_tp, qc_tp
+                        });
+                    } else {
+                        insertStageBills.push({
+                            tid: stage.tid, lid: sb.lid, sid: stage.id, said: this.ctx.session.sessionUser.accountId,
+                            times: stage.times, order: 0,
+                            contract_qty: sb.contract_qty, contract_expr: sb.contract_expr, contract_tp,
+                            qc_qty: sb.qc_qty, qc_tp,
+                            postil: sb.postil,
+                        });
+                    }
                 }
             }
             return [updateStageBills, insertStageBills];
         }
 
         async _reCalcStageExtra(tenderId, newDecimal, oldDecimal) {
-            let changeSj = [], changeSb = [], changeSo = [];
-            const stage = await this.ctx.service.stage.getLastestStage(tenderId, true);
-            if (!stage) return [changeSj, changeSb, changeSo];
+            const changeSj = [], changeSb = [], changeSo = [];
+            const stages = await this.ctx.service.stage.getUnCompleteStages(tenderId);
+            if (stages.length === 0) return [changeSj, changeSb, changeSo];
 
             const upDecimal = newDecimal.up, tpDecimal = newDecimal.extra ? newDecimal.extraTp : newDecimal.tp;
             const calcUp = upDecimal < oldDecimal.up,
                 calcTp = tpDecimal < (oldDecimal.extra ? oldDecimal.extraTp : oldDecimal.tp);
 
-            if (calcUp || calcTp) {
-                const stageJgcl = await this.ctx.service.stageJgcl.getAllDataByCondition({
-                    columns: ['id', 'unit_price', 'arrive_qty', 'deduct_qty'],
-                    where: { sid: stage.id }
-                });
-                for (const sj of stageJgcl) {
-                    const cj = { id: sj.id };
-                    cj.unit_price = calcUp ? this.ctx.helper.round(sj.unit_price, upDecimal) : sj.unit_price;
-                    cj.arrive_tp = this.ctx.helper.mul(sj.arrive_qty, sj.unit_price, tpDecimal);
-                    cj.deduct_tp = this.ctx.helper.mul(sj.deduct_qty, sj.unit_price, tpDecimal);
-                    changeSj.push(cj);
-                }
-            }
-            if (calcTp) {
-                changeSb = await this.ctx.service.stageBonus.getAllDataByCondition({
-                    columns: ['id', 'tp'],
-                    where: { sid: stage.id }
-                });
-                for (const cb of changeSb) {
-                    cb.tp = this.ctx.helper.round(cb.tp, tpDecimal);
+            for (const stage of stages) {
+                if (calcUp || calcTp) {
+                    const stageJgcl = await this.ctx.service.stageJgcl.getAllDataByCondition({
+                        columns: ['id', 'unit_price', 'arrive_qty', 'deduct_qty'],
+                        where: { sid: stage.id }
+                    });
+                    for (const sj of stageJgcl) {
+                        const cj = { id: sj.id };
+                        cj.unit_price = calcUp ? this.ctx.helper.round(sj.unit_price, upDecimal) : sj.unit_price;
+                        cj.arrive_tp = this.ctx.helper.mul(sj.arrive_qty, sj.unit_price, tpDecimal);
+                        cj.deduct_tp = this.ctx.helper.mul(sj.deduct_qty, sj.unit_price, tpDecimal);
+                        changeSj.push(cj);
+                    }
                 }
-                changeSo = await this.ctx.service.stageOther.getAllDataByCondition({
-                    columns: ['id', 'total_price', 'tp'],
-                    where: { sid: stage.id }
-                });
-                for (const co of changeSo) {
-                    if (stage.order === 1) co.total_price = this.ctx.helper.round(co.total_price, tpDecimal);
-                    co.tp = this.ctx.helper.round(co.tp, tpDecimal);
+                if (calcTp) {
+                    const stageChangeSb = await this.ctx.service.stageBonus.getAllDataByCondition({
+                        columns: ['id', 'tp'],
+                        where: { sid: stage.id }
+                    });
+                    for (const cb of stageChangeSb) {
+                        cb.tp = this.ctx.helper.round(cb.tp, tpDecimal);
+                    }
+                    changeSb.push(...stageChangeSb);
+                    const stageChangeSo = await this.ctx.service.stageOther.getAllDataByCondition({
+                        columns: ['id', 'total_price', 'tp'],
+                        where: { sid: stage.id }
+                    });
+                    for (const co of stageChangeSo) {
+                        if (stage.order === 1) co.total_price = this.ctx.helper.round(co.total_price, tpDecimal);
+                        co.tp = this.ctx.helper.round(co.tp, tpDecimal);
+                    }
+                    changeSo.push(...stageChangeSo);
                 }
             }
             return [changeSj, changeSb, changeSo];