Procházet zdrojové kódy

调差修改上下幅度设置功能

ellisran před 1 dnem
rodič
revize
c5be7c9863

+ 17 - 15
app/controller/material_controller.js

@@ -844,6 +844,8 @@ module.exports = app => {
                 }
                 // renderData.materialBillsData = await this._getMaterialBillsData(ctx);
                 renderData.materialExponentData = await this._getMaterialExponentData(ctx);
+                renderData.canAdminEditLatestRisk = ctx.session.sessionUser.is_admin && ctx.material.order === ctx.material.highOrder &&
+                    (ctx.material.status === auditConst.status.uncheck || ctx.material.status === auditConst.status.checkNo);
                 // 取对应期的截取上期的调差金额和应耗数量
                 if (ctx.material.highOrder !== ctx.material.order) {
                     for (const [mindex, me] of renderData.materialExponentData.entries()) {
@@ -1238,22 +1240,22 @@ module.exports = app => {
                 // 转换为整型,不然会无法获取
                 if (data.ms_id) data.ms_id = parseInt(data.ms_id);
                 if (data.mn_id) data.mn_id = parseInt(data.mn_id);
-                const isPastAdminRiskEdit = ctx.material.readOnly && ctx.session.sessionUser.is_admin && ctx.material.order < ctx.material.highOrder && (data.type === 'update' || data.type === 'paste');
-                if (isPastAdminRiskEdit) {
+                const canAdminEditLatestRisk = ctx.material.readOnly && ctx.session.sessionUser.is_admin && ctx.material.order === ctx.material.highOrder &&
+                    (ctx.material.status === auditConst.status.uncheck || ctx.material.status === auditConst.status.checkNo) &&
+                    (data.type === 'update' || data.type === 'paste');
+                if (canAdminEditLatestRisk) {
                     const updateList = data.type === 'paste' ? data.updateData : [data.updateData];
-                    const riskUpdates = updateList.map(item => ({
-                        id: ctx.material.showStageExponent || ctx.material.exponent_node ? item.me_id : item.id,
-                        m_up_risk: item.m_up_risk,
-                        m_down_risk: item.m_down_risk,
-                    }));
-                    if (riskUpdates.some(item => !item.id)) throw '往期指数工料参数有误';
-                    if (ctx.material.showStageExponent || ctx.material.exponent_node) {
-                        responseData.data = data.type === 'paste' ?
-                            await ctx.service.materialExponent.saveDatas(riskUpdates, data.ms_id, data.mn_id) :
-                            await ctx.service.materialExponent.save(riskUpdates[0], data.ms_id, data.mn_id);
-                    } else {
-                        responseData.data = await ctx.service.materialExponent.saveHistoryRisks(riskUpdates);
-                    }
+                    const riskUpdates = updateList.map(item => {
+                        const riskUpdate = { id: item.id };
+                        if (item.m_up_risk !== undefined) riskUpdate.m_up_risk = item.m_up_risk;
+                        if (item.m_down_risk !== undefined) riskUpdate.m_down_risk = item.m_down_risk;
+                        return riskUpdate;
+                    });
+                    if (riskUpdates.some(item => !item.id)) throw '指数工料参数有误';
+                    if (riskUpdates.some(item => Object.keys(item).length === 1)) throw '管理员只允许修改上涨、下跌幅度';
+                    responseData.data = data.type === 'paste' ?
+                        await ctx.service.materialExponent.saveDatas(riskUpdates, data.ms_id, data.mn_id) :
+                        await ctx.service.materialExponent.save(riskUpdates[0], data.ms_id, data.mn_id);
                     ctx.body = responseData;
                     return;
                 }

+ 5 - 6
app/public/js/material_exponent.js

@@ -14,7 +14,6 @@ function getPasteHint (str, row = '') {
 }
 $(document).ready(() => {
     autoFlashHeight();
-    const canAdminEditHistoryRisk = isAdmin && materialOrder < materialHighOrder;
     const materialExponentSpread = SpreadJsObj.createNewSpread($('#material-exponent-spread')[0]);
     const materialExponentSpreadSetting = {
         cols: [
@@ -39,7 +38,7 @@ $(document).ready(() => {
         defaultRowHeight: 21,
         headerFont: '12px 微软雅黑',
         font: '12px 微软雅黑',
-        readOnly: readOnly && !canAdminEditHistoryRisk,
+        readOnly: readOnly && !canAdminEditLatestRisk,
     };
     const materialExponentBase = {
         isUsed: function (data) {
@@ -94,7 +93,7 @@ $(document).ready(() => {
                 return !(!readOnly && data.type === 2);
             },
             risk: function (data) {
-                return !(data.type === 2 && (!readOnly || canAdminEditHistoryRisk));
+                return !(data.type === 2 && ((!readOnly && data.mid === materialID) || canAdminEditLatestRisk));
             },
             isConstant: function (data) {
                 // return !(!readOnly && materialExponentBase.isConstant(data));
@@ -125,7 +124,7 @@ $(document).ready(() => {
     };
     SpreadJsObj.initSheet(stageTjSpread.getActiveSheet(), stageTjSpreadSetting);
 
-    const needUpdateArray = ['weight_num', 'm_up_risk', 'm_down_risk', 'm_price', 'effective_price', 'remark'];
+    const needUpdateArray = ['weight_num', 'm_price', 'effective_price', 'remark'];
 
     const materialExponentSpreadObj = {
         getMaterialExponentData: function (msid = null, mnid = null) {
@@ -443,7 +442,7 @@ $(document).ready(() => {
             }
         },
         deletePress: function (sheet) {
-            if (!sheet.zh_setting || (readOnly && !canAdminEditHistoryRisk) || sheet.zh_setting.readOnly) return;
+            if (!sheet.zh_setting || (readOnly && !canAdminEditLatestRisk) || sheet.zh_setting.readOnly) return;
             // materialExponentBase.isUsed(select)
             if (sheet.zh_setting && sheet.zh_data) {
                 const sel = sheet.getSelections()[0];
@@ -836,7 +835,7 @@ $(document).ready(() => {
         $('#calc_basic_select').html(html);
     }
 
-    if (!readOnly || canAdminEditHistoryRisk) {
+    if (!readOnly || canAdminEditLatestRisk) {
         materialExponentSpread.bind(spreadNS.Events.EditEnded, materialExponentSpreadObj.editEnded);
         materialExponentSpread.bind(spreadNS.Events.ClipboardPasted, materialExponentSpreadObj.clipboardPasted);
         if (!editForAudit) SpreadJsObj.addDeleteBind(materialExponentSpread, materialExponentSpreadObj.deletePress);

+ 41 - 118
app/service/material_exponent.js

@@ -232,6 +232,7 @@ module.exports = app => {
                     case materialConst.exponent_status.shared_noNode: {
                         const exponentInfo = await transaction.get(this.tableName, { id: data.id, tid: this.ctx.tender.id });
                         if (!exponentInfo) throw '指数工料数据不存在';
+                        this._checkRiskEditPermission(data, exponentInfo);
                         this._setEffectivePrice(exponentInfo, data);
                         await transaction.update(this.tableName, data);
                         [result.ex_tp, result.ex_tax_tp, result.ex_expr] = await this.calcMaterialExTp(transaction);
@@ -248,7 +249,9 @@ module.exports = app => {
                         if (info.needUp) {
                             result.exponentData = await transaction.select(this.tableName, { where: { id: data.id } });
                         }
-                        result.exponentShardData = await transaction.select(this.ctx.service.materialExponentShard.tableName, { where: { mid: this.ctx.material.id, mn_id, me_id: data.id } });
+                        result.exponentShardData = await transaction.select(this.ctx.service.materialExponentShard.tableName, {
+                            where: info.needCalc ? { mid: this.ctx.material.id } : { mid: this.ctx.material.id, mn_id, me_id: data.id },
+                        });
                         result.nodeData = info.needCalc ? await transaction.select(this.ctx.service.materialExponentNode.tableName, { where: { mid: this.ctx.material.id } }) :
                             await transaction.select(this.ctx.service.materialExponentNode.tableName, { where: { mid: this.ctx.material.id, id: mn_id } });
                         break;
@@ -262,7 +265,9 @@ module.exports = app => {
                         if (info.needUp) {
                             result.exponentData = await transaction.select(this.tableName, { where: { id: data.id } });
                         }
-                        result.exponentShardData = await transaction.select(this.ctx.service.materialExponentShard.tableName, { where: { mid: this.ctx.material.id, ms_id, me_id: data.id } });
+                        result.exponentShardData = await transaction.select(this.ctx.service.materialExponentShard.tableName, {
+                            where: info.needCalc ? { mid: this.ctx.material.id } : { mid: this.ctx.material.id, ms_id, me_id: data.id },
+                        });
                         result.stageData = info.needCalc ? await transaction.select(this.ctx.service.materialStage.tableName, { where: { mid: this.ctx.material.id } }) :
                             await transaction.select(this.ctx.service.materialStage.tableName, { where: { mid: this.ctx.material.id, id: ms_id } });
                         break;
@@ -276,7 +281,9 @@ module.exports = app => {
                         if (info.needUp) {
                             result.exponentData = await transaction.select(this.tableName, { where: { id: data.id } });
                         }
-                        result.exponentShardData = await transaction.select(this.ctx.service.materialExponentShard.tableName, { where: { mid: this.ctx.material.id, ms_id, mn_id, me_id: data.id } });
+                        result.exponentShardData = await transaction.select(this.ctx.service.materialExponentShard.tableName, {
+                            where: info.needCalc ? { mid: this.ctx.material.id } : { mid: this.ctx.material.id, ms_id, mn_id, me_id: data.id },
+                        });
                         result.stageData = info.needCalc ? await transaction.select(this.ctx.service.materialStage.tableName, { where: { mid: this.ctx.material.id } }) :
                             await transaction.select(this.ctx.service.materialStage.tableName, { where: { mid: this.ctx.material.id, id: ms_id } });
                         result.nodeData = info.needCalc ? await transaction.select(this.ctx.service.materialExponentNode.tableName, { where: { mid: this.ctx.material.id } }) :
@@ -284,9 +291,6 @@ module.exports = app => {
                         break;
                     default: break;
                 }
-                if (this.ctx.material.order < this.ctx.material.highOrder && this.ctx.session.sessionUser.is_admin) {
-                    await this._syncHistoricalTotals(transaction);
-                }
                 await transaction.commit();
                 return result;
             } catch (err) {
@@ -297,14 +301,15 @@ module.exports = app => {
 
         async _updateOneExponentData(transaction, data, ms_id = null, mn_id = null) {
             // 当以下值和exponent值不相同时,需要同步更新最新的计算表达式和金额到stage表里,无需更新到exponentShard表
-            const updateColsArray = ['symbol', 'symbol_desc', 'code', 'basic_price', 'is_summary', 'basic_times'];
-            const updateCalcArray = ['weight_num', 'basic_price', 'is_summary'];
+            const updateColsArray = ['symbol', 'symbol_desc', 'code', 'basic_price', 'm_up_risk', 'm_down_risk', 'is_summary', 'basic_times'];
+            const updateCalcArray = ['weight_num', 'basic_price', 'm_up_risk', 'm_down_risk', 'is_summary'];
             let needCalc = false;
             let needUp = false;
             const meInfo = await this.getDataById(data.id);
             if (!meInfo) {
                 throw '指数工料数据不存在';
             }
+            this._checkRiskEditPermission(data, meInfo);
             const updateData = {};
             for (const uc of updateColsArray) {
                 if (data[uc] !== undefined && data[uc] !== meInfo[uc]) {
@@ -320,7 +325,7 @@ module.exports = app => {
                 updateData.id = data.id;
                 await transaction.update(this.tableName, updateData);
             }
-            if (updateData.basic_price !== undefined) {
+            if (updateData.basic_price !== undefined || updateData.m_up_risk !== undefined || updateData.m_down_risk !== undefined) {
                 await this.ctx.service.materialExponentShard.resetEffectivePrice(transaction, [data.id]);
             }
             if (needCalc) {
@@ -358,6 +363,7 @@ module.exports = app => {
                         for (const data of datas) {
                             const exponentInfo = this._.find(exponentList, { id: data.id });
                             if (!exponentInfo) throw '指数工料数据不存在';
+                            this._checkRiskEditPermission(data, exponentInfo);
                             this._setEffectivePrice(exponentInfo, data);
                         }
                         await transaction.updateRows(this.tableName, datas);
@@ -399,9 +405,6 @@ module.exports = app => {
                         break;
                     default: break;
                 }
-                if (this.ctx.material.order < this.ctx.material.highOrder && this.ctx.session.sessionUser.is_admin) {
-                    await this._syncHistoricalTotals(transaction);
-                }
                 await transaction.commit();
                 return result;
             } catch (err) {
@@ -410,113 +413,14 @@ module.exports = app => {
             }
         }
 
-        async saveHistoryRisks(datas) {
-            if (!this.ctx.session.sessionUser.is_admin || this.ctx.material.order >= this.ctx.material.highOrder) {
-                throw '无权修改往期指数幅度';
-            }
-            const updateList = datas instanceof Array ? datas : [datas];
-            const transaction = await this.db.beginTransaction();
-            try {
-                const historyIds = this._.map(updateList, 'id');
-                const historyList = await transaction.select(this.ctx.service.materialExponentHistory.tableName, {
-                    where: { id: historyIds, mid: this.ctx.material.id, order: this.ctx.material.order },
-                });
-                const updates = [];
-                for (const data of updateList) {
-                    const historyInfo = this._.find(historyList, { id: data.id });
-                    if (!historyInfo || historyInfo.type !== materialConst.ex_type[1].value) throw '往期指数工料数据不存在';
-                    const updateData = { id: historyInfo.id };
-                    if (data.m_up_risk !== undefined) updateData.m_up_risk = this._normalizeRisk(data.m_up_risk);
-                    if (data.m_down_risk !== undefined) updateData.m_down_risk = this._normalizeRisk(data.m_down_risk);
-                    if (Object.keys(updateData).length === 1) continue;
-                    updateData.effective_price = this.getEffectivePrice(Object.assign({}, historyInfo, updateData));
-                    const calcNum = historyInfo.basic_price > 0 ? this.ctx.helper.mul(historyInfo.weight_num, this.ctx.helper.div(updateData.effective_price, historyInfo.basic_price)) : 0;
-                    updateData.calc_num = calcNum ? this.ctx.helper.round(calcNum, this.ctx.material.exponent_decimal.qty) : calcNum;
-                    updates.push(updateData);
-                }
-                if (updates.length === 0) throw '上涨、下跌幅度未发生变化';
-                await transaction.updateRows(this.ctx.service.materialExponentHistory.tableName, updates);
-                const [ex_tp, ex_tax_tp, ex_expr] = await this._calcHistoryExTp(transaction);
-                await this._syncHistoricalTotals(transaction);
-                const historyData = await transaction.select(this.ctx.service.materialExponentHistory.tableName, { where: { id: this._.map(updates, 'id') } });
-                await transaction.commit();
-                return { ex_tp, ex_tax_tp, ex_expr, historyData };
-            } catch (err) {
-                await transaction.rollback();
-                throw err;
-            }
-        }
-
-        async _calcHistoryExTp(transaction) {
-            let basicCalc = 0;
-            const exCalc = this.ctx.material.ex_calc ? JSON.parse(this.ctx.material.ex_calc) : null;
-            if (exCalc) {
-                for (const calc of exCalc) {
-                    if (!calc.select) continue;
-                    basicCalc = this.ctx.helper.add(basicCalc, calc.code === 'zdy' && calc.result ? calc.result : calc.value);
-                }
-            }
-            const exponentList = await transaction.select(this.ctx.service.materialExponentHistory.tableName, {
-                where: { mid: this.ctx.material.id, order: this.ctx.material.order, is_summary: materialConst.is_summary.yes },
-            });
-            let expr = basicCalc + '*[';
-            let sumByChange = 0;
-            let constant = 0;
-            for (const ex of exponentList) {
-                if (ex.type === materialConst.ex_type[0].value) {
-                    constant = ex.weight_num || 0;
-                    expr += constant.toString();
-                } else if (ex.type === materialConst.ex_type[1].value) {
-                    const effectivePrice = ex.effective_price !== null && ex.effective_price !== undefined ? ex.effective_price : ex.m_price;
-                    const calcNum = ex.basic_price > 0 ? this.ctx.helper.mul(ex.weight_num, this.ctx.helper.div(effectivePrice, ex.basic_price)) : 0;
-                    const change = calcNum ? this.ctx.helper.round(calcNum, this.ctx.material.exponent_decimal.qty) : 0;
-                    expr += change !== 0 ? '+' + ex.weight_num.toString() + '*(' + effectivePrice.toString() + '/' + ex.basic_price.toString() + ')' : '';
-                    sumByChange = this.ctx.helper.add(sumByChange, change);
-                }
-            }
-            expr += '-1]';
-            expr = constant !== 0 ? expr : null;
-            const exTp = constant !== 0 ? this.ctx.helper.round(this.ctx.helper.mul(basicCalc, this.ctx.helper.sub(this.ctx.helper.add(constant, sumByChange), 1)), this.ctx.material.exponent_decimal.tp) : null;
-            const exTaxTp = exTp !== null ? this.ctx.helper.round(this.ctx.helper.mul(exTp, 1 + this.ctx.material.exponent_rate / 100), this.ctx.material.exponent_decimal.tp) : null;
-            await transaction.update(this.ctx.service.material.tableName, {
-                id: this.ctx.material.id,
-                ex_tp: exTp,
-                ex_tax_tp: exTaxTp,
-                ex_expr: expr,
-            });
-            return [exTp, exTaxTp, expr];
-        }
-
-        async _syncHistoricalTotals(transaction) {
-            const materialList = await transaction.select(this.ctx.service.material.tableName, {
-                where: { tid: this.ctx.tender.id },
-                orders: [['order', 'asc']],
-            });
-            let exponentPreTp = 0;
-            let exponentTaxPreTp = 0;
-            const updates = [];
-            for (const material of materialList) {
-                updates.push({
-                    id: material.id,
-                    ex_pre_tp: exponentPreTp,
-                    ex_tax_pre_tp: exponentTaxPreTp,
-                });
-                exponentPreTp = this.ctx.helper.add(exponentPreTp, material.ex_tp || 0);
-                exponentTaxPreTp = this.ctx.helper.add(exponentTaxPreTp, material.ex_tax_tp || 0);
-            }
-            if (updates.length > 0) await transaction.updateRows(this.ctx.service.material.tableName, updates);
-            const tpData = await this.ctx.service.materialAudit.getTpData(transaction, this.ctx.material.id, this.ctx.material.decimal, this.ctx.material.exponent_decimal);
-            await transaction.update(this.ctx.service.material.tableName, { id: this.ctx.material.id, tp_data: JSON.stringify(tpData) });
-        }
-
         async _updateMoreExponentData(transaction, datas, result, meList, ms_id = null, mn_id = null) {
             // 判断data值是否需要更新materialExponent和materialExponentShard
             const mesCondition = { me_id: this._.map(datas, 'id') };
             if (ms_id !== null) mesCondition.ms_id = ms_id;
             if (mn_id !== null) mesCondition.mn_id = mn_id;
             const mesList = await transaction.select(this.ctx.service.materialExponentShard.tableName, { where: mesCondition });
-            const materialExponentColArray = ['symbol', 'symbol_desc', 'code', 'basic_price', 'is_summary', 'basic_times'];
-            const materialExponentShardColArray = ['weight_num', 'm_up_risk', 'm_down_risk', 'm_price', 'remark'];
+            const materialExponentColArray = ['symbol', 'symbol_desc', 'code', 'basic_price', 'm_up_risk', 'm_down_risk', 'is_summary', 'basic_times'];
+            const materialExponentShardColArray = ['weight_num', 'm_price', 'remark'];
             const updateCalcArray = ['weight_num', 'basic_price', 'm_up_risk', 'm_down_risk', 'm_price', 'is_summary'];
             const updateMeArray = [];
             const udpateMseArray = [];
@@ -524,6 +428,8 @@ module.exports = app => {
             for (const data of datas) {
                 const meInfo = this._.find(meList, { id: data.id });
                 const mseInfo = this._.find(mesList, { me_id: data.id });
+                if (!meInfo || !mseInfo) throw '指数工料数据不存在';
+                this._checkRiskEditPermission(data, meInfo);
                 for (const uc of materialExponentColArray) {
                     if (data[uc] !== undefined && data[uc] !== meInfo[uc]) {
                         const updateMe = this._.find(updateMeArray, { id: meInfo.id });
@@ -566,10 +472,10 @@ module.exports = app => {
                 // const condition = mn_id ? { mid: this.ctx.material.id, mn_id } : { mid: this.ctx.material.id, ms_id };
                 result.exponentShardData = await transaction.select(this.ctx.service.materialExponentShard.tableName, { where: { id: this._.map(udpateMseArray, 'id') } });
             }
-            const basicPriceMeIds = this._.map(this._.filter(updateMeArray, data => data.basic_price !== undefined), 'id');
-            if (basicPriceMeIds.length > 0) {
-                await this.ctx.service.materialExponentShard.resetEffectivePrice(transaction, basicPriceMeIds);
-                result.exponentShardData = await transaction.select(this.ctx.service.materialExponentShard.tableName, { where: { mid: this.ctx.material.id, me_id: basicPriceMeIds } });
+            const sharedPriceMeIds = this._.map(this._.filter(updateMeArray, data => data.basic_price !== undefined || data.m_up_risk !== undefined || data.m_down_risk !== undefined), 'id');
+            if (sharedPriceMeIds.length > 0) {
+                await this.ctx.service.materialExponentShard.resetEffectivePrice(transaction, sharedPriceMeIds);
+                result.exponentShardData = await transaction.select(this.ctx.service.materialExponentShard.tableName, { where: { mid: this.ctx.material.id } });
             }
             return needCalc;
         }
@@ -817,12 +723,29 @@ module.exports = app => {
                 if (!materialExponent) continue;
                 const updateEx = { id: ex.id };
                 if (ex.m_price !== null && ex.m_price !== undefined) updateEx.m_price = this.ctx.helper.round(ex.m_price, decimal.up);
-                updateEx.effective_price = this.getEffectivePrice(Object.assign({}, materialExponent, ex, updateEx), decimal.up);
+                updateEx.effective_price = this.getEffectivePrice(Object.assign({}, materialExponent, ex, updateEx, {
+                    m_up_risk: materialExponent.m_up_risk,
+                    m_down_risk: materialExponent.m_down_risk,
+                }), decimal.up);
                 if (updateEx.m_price !== ex.m_price || updateEx.effective_price !== ex.effective_price) updateStageArray.push(updateEx);
             }
             if (updateArray.length > 0) await transaction.updateRows(this.tableName, updateArray);
             if (updateStageArray.length > 0) await transaction.updateRows(this.ctx.service.materialExponentShard.tableName, updateStageArray);
         }
+
+        _checkRiskEditPermission(data, exponentInfo) {
+            const riskChanged = ['m_up_risk', 'm_down_risk'].some(col => data[col] !== undefined && data[col] !== exponentInfo[col]);
+            if (!riskChanged) return;
+            if (this.ctx.material.order < this.ctx.material.highOrder) {
+                throw '历史期上涨、下跌幅度不能修改';
+            }
+            if (exponentInfo.type !== materialConst.ex_type[1].value) {
+                throw '定值不能设置上涨、下跌幅度';
+            }
+            if (exponentInfo.mid !== this.ctx.material.id && !this.ctx.session.sessionUser.is_admin) {
+                throw '往期添加的指数工料仅管理员可修改上涨、下跌幅度';
+            }
+        }
     }
 
     return MaterialExponent;

+ 0 - 6
app/service/material_exponent_node.js

@@ -95,8 +95,6 @@ module.exports = app => {
                                         mn_id: node.id,
                                         me_id: ex.id,
                                         type: ex.type,
-                                        m_up_risk: sourceData.m_up_risk || 0,
-                                        m_down_risk: sourceData.m_down_risk || 0,
                                         m_price: sourceData.m_price || 0,
                                         effective_price: sourceData.effective_price !== null && sourceData.effective_price !== undefined ? sourceData.effective_price : (sourceData.m_price || 0),
                                         remark: ex.remark,
@@ -114,8 +112,6 @@ module.exports = app => {
                                         mn_id: node.id,
                                         me_id: ex.id,
                                         type: ex.type,
-                                        m_up_risk: sourceData.m_up_risk || 0,
-                                        m_down_risk: sourceData.m_down_risk || 0,
                                         m_price: sourceData.m_price || 0,
                                         effective_price: sourceData.effective_price !== null && sourceData.effective_price !== undefined ? sourceData.effective_price : (sourceData.m_price || 0),
                                         remark: ex.remark,
@@ -157,8 +153,6 @@ module.exports = app => {
                                     mn_id: null,
                                     me_id: ex.id,
                                     type: ex.type,
-                                    m_up_risk: 0,
-                                    m_down_risk: 0,
                                     m_price: 0,
                                     effective_price: 0,
                                     remark: ex.remark,

+ 11 - 9
app/service/material_exponent_shard.js

@@ -12,7 +12,7 @@ const auditConst = require('../const/audit').material;
 const materialConst = require('../const/material');
 const MaterialCalculator = require('../lib/material_calc');
 
-const needUpdateArray = ['weight_num', 'm_up_risk', 'm_down_risk', 'm_price', 'remark'];
+const needUpdateArray = ['weight_num', 'm_price', 'remark'];
 
 module.exports = app => {
     class MaterialExponentShard extends app.BaseService {
@@ -77,14 +77,17 @@ module.exports = app => {
             for (const nu of needUpdateArray) {
                 if (data[nu] !== undefined && mesInfo[nu] !== data[nu]) updateData[nu] = data[nu];
             }
-            if (updateData.m_price !== undefined || updateData.m_up_risk !== undefined || updateData.m_down_risk !== undefined || needCalc) {
+            if (updateData.m_price !== undefined || needCalc) {
                 const exponentInfo = await this._getExponentInfo(transaction, data.id);
                 if (!exponentInfo) throw '指数工料数据不存在';
-                updateData.effective_price = this.ctx.service.materialExponent.getEffectivePrice(Object.assign({}, exponentInfo, mesInfo, updateData));
+                updateData.effective_price = this.ctx.service.materialExponent.getEffectivePrice(Object.assign({}, exponentInfo, mesInfo, updateData, {
+                    m_up_risk: exponentInfo.m_up_risk,
+                    m_down_risk: exponentInfo.m_down_risk,
+                }));
             }
             // 如果只有id,则不更新
             if (Object.keys(updateData).length > 1) await transaction.update(this.tableName, updateData);
-            if (updateData.m_price !== undefined || updateData.m_up_risk !== undefined || updateData.m_down_risk !== undefined || updateData.weight_num !== undefined || needCalc) {
+            if (updateData.m_price !== undefined || updateData.weight_num !== undefined || needCalc) {
                 const mnInfo = mn_id ? await transaction.get(this.ctx.service.materialExponentNode.tableName, { mid: this.ctx.material.id, id: mn_id }) : null;
                 const msInfo = ms_id && !mn_id ? await transaction.get(this.ctx.service.materialStage.tableName, { mid: this.ctx.material.id, id: ms_id }) : null;
                 const ex_calc = mnInfo ? JSON.parse(mnInfo.ex_calc) : msInfo ? JSON.parse(msInfo.ex_calc) : materialConst.ex_calc;
@@ -127,7 +130,10 @@ module.exports = app => {
             for (const shard of shardList) {
                 const exponentInfo = await this._getExponentInfo(transaction, shard.me_id);
                 if (!exponentInfo) continue;
-                const effectivePrice = this.ctx.service.materialExponent.getEffectivePrice(Object.assign({}, exponentInfo, shard));
+                const effectivePrice = this.ctx.service.materialExponent.getEffectivePrice(Object.assign({}, exponentInfo, shard, {
+                    m_up_risk: exponentInfo.m_up_risk,
+                    m_down_risk: exponentInfo.m_down_risk,
+                }));
                 if (effectivePrice !== shard.effective_price) updates.push({ id: shard.id, effective_price: effectivePrice });
             }
             if (updates.length > 0) await transaction.updateRows(this.tableName, updates);
@@ -322,8 +328,6 @@ module.exports = app => {
                         me_id: me.id,
                         type: me.type,
                         weight_num: me.weight_num,
-                        m_up_risk: me.m_up_risk,
-                        m_down_risk: me.m_down_risk,
                         m_price: me.m_price,
                         effective_price: me.effective_price !== null ? me.effective_price : me.m_price,
                         remark: me.remark,
@@ -354,8 +358,6 @@ module.exports = app => {
                         ms_id: ms.id,
                         type: e.type,
                         weight_num: e.weight_num,
-                        m_up_risk: e.m_up_risk,
-                        m_down_risk: e.m_down_risk,
                         m_price: e.m_price,
                         effective_price: e.effective_price !== null ? e.effective_price : e.m_price,
                     };

+ 1 - 2
app/view/material/exponent.ejs

@@ -197,11 +197,10 @@
 </div>
 <script>
     const readOnly = <%- material.readOnly %>;
-    const isAdmin = <%- ctx.session.sessionUser.is_admin %>;
     const materialID = <%- material.id %>;
     const materialTax = <%- material.material_tax %>;
     const materialOrder = <%- material.order %>;
-    const materialHighOrder = <%- material.highOrder %>;
+    const canAdminEditLatestRisk = <%- canAdminEditLatestRisk %>;
     const isStageSelf = parseInt('<%- material.is_stage_self %>');
     const showStageExponent = <%- material.showStageExponent %>;
     const exponent_nodes = JSON.parse(unescape('<%- escape(JSON.stringify(ctx.material.exponent_node)) %>'));

+ 0 - 17
sql/update.sql

@@ -53,23 +53,6 @@ ADD COLUMN `m_down_risk` tinyint(3) NOT NULL DEFAULT 0 COMMENT '本期下跌幅
 ADD COLUMN `effective_price` decimal(30,8) DEFAULT NULL COMMENT '本期有效价格指数(Ft)' AFTER `m_price`;
 
 ALTER TABLE `zh_material_exponent_shard`
-ADD COLUMN `m_up_risk` tinyint(3) NOT NULL DEFAULT 0 COMMENT '上涨幅度(%)' AFTER `weight_num`,
-ADD COLUMN `m_down_risk` tinyint(3) NOT NULL DEFAULT 0 COMMENT '下跌幅度(%)' AFTER `m_up_risk`,
-ADD COLUMN `effective_price` decimal(30,8) DEFAULT NULL COMMENT '有效价格指数(Ft)' AFTER `m_price`;
-
-ALTER TABLE `zh_material_exponent`
-ADD COLUMN `m_up_risk` tinyint(3) NOT NULL DEFAULT 0 COMMENT '上涨幅度(%)' AFTER `basic_times`,
-ADD COLUMN `m_down_risk` tinyint(3) NOT NULL DEFAULT 0 COMMENT '下跌幅度(%)' AFTER `m_up_risk`,
-ADD COLUMN `effective_price` decimal(30,8) DEFAULT NULL COMMENT '有效价格指数(Ft)' AFTER `m_price`;
-
-ALTER TABLE `zh_material_exponent_history`
-ADD COLUMN `m_up_risk` tinyint(3) NOT NULL DEFAULT 0 COMMENT '本期上涨幅度(%)' AFTER `basic_times`,
-ADD COLUMN `m_down_risk` tinyint(3) NOT NULL DEFAULT 0 COMMENT '本期下跌幅度(%)' AFTER `m_up_risk`,
-ADD COLUMN `effective_price` decimal(30,8) DEFAULT NULL COMMENT '本期有效价格指数(Ft)' AFTER `m_price`;
-
-ALTER TABLE `zh_material_exponent_shard`
-ADD COLUMN `m_up_risk` tinyint(3) NOT NULL DEFAULT 0 COMMENT '上涨幅度(%)' AFTER `weight_num`,
-ADD COLUMN `m_down_risk` tinyint(3) NOT NULL DEFAULT 0 COMMENT '下跌幅度(%)' AFTER `m_up_risk`,
 ADD COLUMN `effective_price` decimal(30,8) DEFAULT NULL COMMENT '有效价格指数(Ft)' AFTER `m_price`;
 
 ALTER TABLE `zh_filing`