MaiXinRong пре 5 година
родитељ
комит
f44e7a6a89
4 измењених фајлова са 114 додато и 31 уклоњено
  1. 15 26
      app/controller/stage_controller.js
  2. 58 3
      app/service/stage.js
  3. 37 1
      app/service/stage_audit.js
  4. 4 1
      sql/update.sql

+ 15 - 26
app/controller/stage_controller.js

@@ -411,7 +411,7 @@ module.exports = app => {
                         responseData.data = await ctx.service.stageBills.updateStageBillsCalcType(data.bills.calcType);
                     }
                 }
-                await ctx.service.stage.updateCheckCalcFlag(ctx.stage.id, true);
+                await ctx.service.stage.updateCheckCalcFlag(ctx.stage, true);
                 await ctx.service.stage.updateCacheTime(ctx.stage.id);
                 ctx.body = responseData;
             } catch (err) {
@@ -465,7 +465,7 @@ module.exports = app => {
                     result.change.data = await ctx.service.stageChange.getLastestStageData(ctx.tender.id,
                         ctx.stage.id, data.target.bills.id, '-1');
                 }
-                await ctx.service.stage.updateCheckCalcFlag(ctx.stage.id, true);
+                await ctx.service.stage.updateCheckCalcFlag(ctx.stage, true);
                 await ctx.service.stage.updateCacheTime(ctx.stage.id);
                 ctx.body = {err: 0, msg: '', data: result};
             } catch(err) {
@@ -678,6 +678,15 @@ module.exports = app => {
             }
         }
 
+        async _updateStageCache(ctx, payCalculator) {
+            await ctx.service.stage.update({
+                check_calc: false,
+                contract_tp: payCalculator.cur.contract_tp, qc_tp: payCalculator.cur.qc_tp,
+                yf_tp: payCalculator.yf.tp,
+                sf_tp: payCalculator.sf.tp
+            }, {id: ctx.stage.id});
+        }
+
         /**
          * 合同支付 (Get)
          * @param ctx
@@ -719,12 +728,7 @@ module.exports = app => {
                     // 计算 本期金额
                     const payCalculator = new PayCalculator(ctx, ctx.stage, ctx.tender.info);
                     await payCalculator.calculateAll(renderData.dealPay);
-                    await this.ctx.service.stage.update({
-                        check_calc: false,
-                        contract_tp: payCalculator.cur.contract_tp, qc_tp: payCalculator.cur.qc_tp,
-                        yf_tp: payCalculator.yf.tp,
-                        sf_tp: payCalculator.sf.tp
-                    }, {id: this.ctx.stage.id});
+                    await this._updateStageCache(ctx, payCalculator);
                 }
                 await this.layout('stage/pay.ejs', renderData, 'stage/pay_modal.ejs');
             } catch (err) {
@@ -759,12 +763,7 @@ module.exports = app => {
                         await ctx.service.pay.del(data.id);
                         responseData.data = await ctx.service.stagePay.getStagePays(ctx.stage);
                         await payCalculator.calculateAll(responseData.data);
-                        // await this.ctx.service.stage.update({
-                        //     check_calc: false,
-                        //     contract_tp: payCalculator.cur.contract_tp, qc_tp: payCalculator.cur.qc_tp,
-                        //     yf_tp: payCalculator.yf.tp,
-                        //     sf_tp: payCalculator.sf.tp
-                        // }, {id: this.ctx.stage.id});
+                        await this._updateStageCache(ctx, payCalculator);
                         break;
                     case 'changeOrder':
                         responseData.data = await ctx.service.pay.changeOrder(data.id1, data.id2);
@@ -775,12 +774,7 @@ module.exports = app => {
                         if (bReCalc) {
                             responseData.data = await ctx.service.stagePay.getStagePays(ctx.stage);
                             await payCalculator.calculateAll(responseData.data);
-                            // await this.ctx.service.stage.update({
-                            //     check_calc: false,
-                            //     contract_tp: payCalculator.cur.contract_tp, qc_tp: payCalculator.cur.qc_tp,
-                            //     yf_tp: payCalculator.yf.tp,
-                            //     sf_tp: payCalculator.sf.tp
-                            // }, {id: this.ctx.stage.id});
+                            await this._updateStageCache(ctx, payCalculator);
                         } else {
                             if (data.updateData instanceof Array) {
                                 responseData.data = await ctx.service.stagePay.getStagePay(ctx.stage, this.app._.map(responseData.data, 'id'));
@@ -793,12 +787,7 @@ module.exports = app => {
                         await ctx.service.stagePay.save(data.updateData);
                         responseData.data = await ctx.service.stagePay.getStagePays(ctx.stage);
                         await payCalculator.calculateAll(responseData.data);
-                        // await this.ctx.service.stage.update({
-                        //     check_calc: false,
-                        //     contract_tp: payCalculator.cur.contract_tp, qc_tp: payCalculator.cur.qc_tp,
-                        //     yf_tp: payCalculator.yf.tp,
-                        //     sf_tp: payCalculator.sf.tp
-                        // }, {id: this.ctx.stage.id});
+                        await this._updateStageCache(ctx, payCalculator);
                         break;
                 }
 

+ 58 - 3
app/service/stage.js

@@ -28,6 +28,46 @@ module.exports = app => {
             this.tableName = 'stage';
         }
 
+        /**
+         * 根据id查找数据
+         *
+         * @param {Number} id - 数据库中的id
+         * @return {Object} - 返回单条数据
+         */
+        async getDataById(id) {
+            const result = await this.db.get(this.tableName, { id });
+            if (result)
+                result.tp_history = result.tp_history ? JSON.parse(result.tp_history) : [];
+            return result;
+        }
+
+        /**
+         * 根据条件查找单条数据
+         *
+         * @param {Object} condition - 筛选条件
+         * @return {Object} - 返回单条数据
+         */
+        async getDataByCondition(condition) {
+            const result = await this.db.get(this.tableName, condition);
+            if (result)
+                result.tp_history = result.tp_history ? JSON.parse(result.tp_history) : [];
+            return result;
+        }
+
+        /**
+         * 根据条件查找列表数据
+         *
+         * @param {Object} condition - 筛选条件
+         * @return {Array} - 返回数据
+         */
+        async getAllDataByCondition(condition) {
+            const result = await this.db.select(this.tableName, condition);
+            for (const r of result) {
+                r.tp_history = r.tp_history ? JSON.parse(r.tp_history) : [];
+            }
+            return result;
+        }
+
         async doCheckStage(stage) {
             const status = auditConst.status;
             stage.auditors = await this.ctx.service.stageAudit.getAuditors(stage.id, stage.times);
@@ -119,6 +159,7 @@ module.exports = app => {
             this.sqlBuilder.orderBy = [['order', 'desc']];
             const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
             const stage = await this.db.queryOne(sql, sqlParam);
+            stage.tp_history = stage.tp_history ? JSON.parse(stage.tp_history) : [];
             return stage;
         }
 
@@ -140,6 +181,7 @@ module.exports = app => {
             this.sqlBuilder.orderBy = [['order', 'desc']];
             const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
             const stage = await this.db.queryOne(sql, sqlParam);
+            if (stage) stage.tp_history = stage.tp_history ? JSON.parse(stage.tp_history) : [];
             return stage;
         }
 
@@ -197,6 +239,7 @@ module.exports = app => {
                 s.tp = this.ctx.helper.add(s.contract_tp, s.qc_tp);
                 s.pre_tp = this.ctx.helper.add(s.pre_contract_tp, s.pre_qc_tp);
                 s.end_tp = this.ctx.helper.add(s.pre_tp, s.tp);
+                s.tp_history = s.tp_history ? JSON.parse(s.tp_history) : [];
             }
             if (stages.length !== 0) {
                 const lastStage = stages[stages.length - 1];
@@ -205,7 +248,9 @@ module.exports = app => {
                 }
             }
             // 最新一期计量(未审批完成),当前操作人的期详细数据,应实时计算
-            if (stages.length > 0 && stages[0].status !== auditConst.status.checked) {
+            if (stages.length === 0) return stages;
+
+            if (stages[0].status !== auditConst.status.checked) {
                 const stage = stages[0];
                 await this.doCheckStage(stage);
                 if (!stage.readOnly) {
@@ -217,6 +262,16 @@ module.exports = app => {
                     stage.sf_tp = tp.sf;
                     stage.tp = this.ctx.helper.add(stage.contract_tp, stage.qc_tp);
                     stage.end_tp = this.ctx.helper.add(stage.pre_tp, stage.tp);
+                } else {
+                    const his = this.ctx.helper._.find(stage.tp_history, {times: stage.curTimes, order: stage.curOrder});
+                    if (his) {
+                        stage.contract_tp = his.contract_tp;
+                        stage.qc_tp = his.qc_tp;
+                        stage.yf_tp = his.yf_tp;
+                        stage.sf_tp = his.sf_tp;
+                        stage.tp = this.ctx.helper.add(stage.contract_tp, stage.qc_tp);
+                        stage.end_tp = this.ctx.helper.add(stage.pre_tp, stage.tp);
+                    }
                 }
             }
             for (const s of stages) {
@@ -393,8 +448,8 @@ module.exports = app => {
             return calcBase;
         }
 
-        async updateCheckCalcFlag(sid, check) {
-            const result = await this.db.update(this.tableName, {id: sid, check_calc: check});
+        async updateCheckCalcFlag(stage, check) {
+            const result = await this.db.update(this.tableName, {id: stage.id, check_calc: check});
             return result.affectedRows === 1;
         }
 

+ 37 - 1
app/service/stage_audit.js

@@ -216,7 +216,6 @@ module.exports = app => {
 
             const transaction = await this.db.beginTransaction();
             try {
-                await transaction.update(this.tableName, {id: audit.id, status: auditConst.status.checking, begin_time: new Date()});
                 // 计算原报最终数据
                 const [yfPay, sfPay] = await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
                 // 复制一份下一审核人数据
@@ -226,12 +225,21 @@ module.exports = app => {
                 await this.ctx.service.stageOther.updateHistory(this.ctx.stage, transaction);
                 // 更新期数据
                 const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
+                const tpHistory = this.ctx.stage.tp_history ? JSON.parse(this.ctx.stage.tp_history) : [];
+                tpHistory.push({
+                    times: this.ctx.stage.curTimes, order: 0,
+                    contract_tp: tpData.contract_tp,
+                    qc_tp: tpData.qc_tp,
+                    yf_tp: yfPay.tp,
+                    sf_tp: sfPay.tp,
+                });
                 await transaction.update(this.ctx.service.stage.tableName, {
                     id: stageId, status: auditConst.status.checking,
                     contract_tp: tpData.contract_tp,
                     qc_tp: tpData.qc_tp,
                     yf_tp: yfPay.tp,
                     sf_tp: sfPay.tp,
+                    tp_history: JSON.stringify(tpHistory),
                     cache_time_r: this.ctx.stage.cache_time_l,
                 });
 
@@ -276,6 +284,14 @@ module.exports = app => {
                 await transaction.update(this.tableName, {id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time});
                 // 计算并合同支付最终数据
                 const [yfPay, sfPay] = await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
+                const tpHistory = this.ctx.stage.tp_history ? JSON.parse(this.ctx.stage.tp_history) : [];
+                tpHistory.push({
+                    times: times, order: audit.order,
+                    contract_tp: tpData.contract_tp,
+                    qc_tp: tpData.qc_tp,
+                    yf_tp: yfPay.tp,
+                    sf_tp: sfPay.tp,
+                });
                 // 无下一审核人表示,审核结束
                 if (nextAudit) {
                     // 复制一份下一审核人数据
@@ -292,6 +308,7 @@ module.exports = app => {
                         qc_tp: tpData.qc_tp,
                         yf_tp: yfPay.tp,
                         sf_tp: sfPay.tp,
+                        tp_history: JSON.stringify(tpHistory),
                         cache_time_r: this.ctx.stage.cache_time_l,
                     });
 
@@ -326,6 +343,7 @@ module.exports = app => {
                         qc_tp: tpData.qc_tp,
                         yf_tp: yfPay.tp,
                         sf_tp: sfPay.tp,
+                        tp_history: JSON.stringify(tpHistory),
                         cache_time_r: this.ctx.stage.cache_time_l,
                     });
 
@@ -389,6 +407,14 @@ module.exports = app => {
             try {
                 // 计算并合同支付最终数据
                 const [yfPay, sfPay] = await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
+                const tpHistory = this.ctx.stage.tp_history ? JSON.parse(this.ctx.stage.tp_history) : [];
+                tpHistory.push({
+                    times: times + 1, order: 0,
+                    contract_tp: tpData.contract_tp,
+                    qc_tp: tpData.qc_tp,
+                    yf_tp: yfPay.tp,
+                    sf_tp: sfPay.tp,
+                });
                 await transaction.update(this.tableName, {id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time});
                 // 同步 期信息
                 await transaction.update(this.ctx.service.stage.tableName, {
@@ -398,6 +424,7 @@ module.exports = app => {
                     times: times + 1,
                     yf_tp: yfPay.tp,
                     sf_tp: sfPay.tp,
+                    tp_history: JSON.stringify(tpHistory),
                     cache_time_r: this.ctx.stage.cache_time_l,
                 });
                 // 拷贝新一次审核流程列表
@@ -466,6 +493,14 @@ module.exports = app => {
             try {
                 // 计算并合同支付最终数据
                 const [yfPay, sfPay] = await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
+                const tpHistory = this.ctx.stage.tp_history ? JSON.parse(this.ctx.stage.tp_history) : [];
+                tpHistory.push({
+                    times: times, order: audit.order,
+                    contract_tp: tpData.contract_tp,
+                    qc_tp: tpData.qc_tp,
+                    yf_tp: yfPay.tp,
+                    sf_tp: sfPay.tp,
+                });
                 // 同步 期信息
                 await transaction.update(this.ctx.service.stage.tableName, {
                     id: stageId,
@@ -474,6 +509,7 @@ module.exports = app => {
                     times: times,
                     yf_tp: yfPay.tp,
                     sf_tp: sfPay.tp,
+                    tp_history: JSON.stringify(tpHistory),
                     cache_time_r: this.ctx.stage.cache_time_l,
                 });
                 await transaction.update(this.tableName, {id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time});

+ 4 - 1
sql/update.sql

@@ -68,4 +68,7 @@ ALTER TABLE `zh_project` ADD `page_show` VARCHAR(5000) CHARACTER SET utf8 COLLAT
 
 ALTER TABLE `zh_project` CHANGE `creator` `creator` INT(11) NOT NULL COMMENT '创建者';
 
-INSERT INTO `zh_permission`(`id`, `name`, `controller`, `action`, `pid`, `icon_class`, `create_time`, `isshow`) VALUES (71,'页面显示','project','pageshow',38,'',NULL,1)
+INSERT INTO `zh_permission`(`id`, `name`, `controller`, `action`, `pid`, `icon_class`, `create_time`, `isshow`) VALUES (71,'页面显示','project','pageshow',38,'',NULL,1);
+
+ALTER TABLE `zh_stage`
+ADD COLUMN `tp_history`  text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '金额类的历史记录' AFTER `cache_time_l`;