Просмотр исходного кода

判断是否是累进基数的方法

vian 5 лет назад
Родитель
Сommit
8b2e8843d7
3 измененных файлов с 76 добавлено и 50 удалено
  1. 12 8
      modules/pm/controllers/pm_controller.js
  2. 37 42
      modules/pm/models/project_model.js
  3. 27 0
      public/calculate_util.js

+ 12 - 8
modules/pm/controllers/pm_controller.js

@@ -83,14 +83,18 @@ module.exports = {
         });
         });
     },
     },
     updateProjects: async function (req, res) {
     updateProjects: async function (req, res) {
-        let data = JSON.parse(req.body.data);
-        await ProjectsData.updateUserProjects(req.session.sessionUser.id, req.session.sessionCompilation._id, req.session.sessionCompilation, data.updateData, function (err, message, data) {
-            if (err === 0) {
-                callback(req, res, err, message, data);
-            } else {
-                callback(req, res, err, message, null);
-            }
-        });
+        try {
+            let data = JSON.parse(req.body.data);
+            await ProjectsData.updateUserProjects(req.session.sessionUser.id, req.session.sessionCompilation._id, req.session.sessionCompilation, data.updateData, function (err, message, data) {
+                if (err === 0) {
+                    callback(req, res, err, message, data);
+                } else {
+                    callback(req, res, err, message, null);
+                }
+            });
+        } catch (err) {
+            callback(req, res, 1, String(err), null);
+        }
     },
     },
     // CSL, 2017-12-14 该方法用于项目属性:提交保存混合型数据,这些数据来自不同的表,包括projects.property、ration、bills、labour_coes.
     // CSL, 2017-12-14 该方法用于项目属性:提交保存混合型数据,这些数据来自不同的表,包括projects.property、ration、bills、labour_coes.
     updateMixDatas: async function(req, res){
     updateMixDatas: async function(req, res){

+ 37 - 42
modules/pm/models/project_model.js

@@ -255,51 +255,46 @@ ProjectsDAO.prototype.updateUserProjects = async function (userId, compilationId
                 data.updateData['deleteInfo'] = deleteInfo;
                 data.updateData['deleteInfo'] = deleteInfo;
                 //Projects.update({userID: userId, ID: data.updateData.ID}, data.updateData, updateAll);
                 //Projects.update({userID: userId, ID: data.updateData.ID}, data.updateData, updateAll);
                 //update
                 //update
-                try {
-                    if (data.updateData.projType === projectType.project) {
-                        let tenders = await Projects.find({userID: userId, ParentID: data.updateData.ID});
-                        if (tenders.length > 0) {
-                            await UnitPriceFiles.update({
-                                user_id: userId,
-                                root_project_id: data.updateData.ID
-                            }, {$set: {deleteInfo: deleteInfo}}, {multi: true});
-                            await FeeRateFiles.update({
-                                userID: userId,
-                                rootProjectID: data.updateData.ID
-                            }, {$set: {deleteInfo: deleteInfo}}, {multi: true});
-                            await Projects.update({userID: userId, ID: data.updateData.ID}, data.updateData, updateAll);
-                        } else {//true
-                            await UnitPriceFiles.remove({user_id: userId, root_project_id: data.updateData.ID});
-                            await FeeRateFiles.remove({userID: userId, rootProjectID: data.updateData.ID});
-                            //await Projects.update({userID: userId, NextSiblingID: data.updateData.ID, deleteInfo: null}, {$set: {NextSiblingID: data.NextSiblingID}});
-                            await Projects.remove({userID: userId, ID: data.updateData.ID}, updateAll);
+                if (data.updateData.projType === projectType.project) {
+                    let tenders = await Projects.find({ userID: userId, ParentID: data.updateData.ID });
+                    if (tenders.length > 0) {
+                        await UnitPriceFiles.update({
+                            user_id: userId,
+                            root_project_id: data.updateData.ID
+                        }, { $set: { deleteInfo: deleteInfo } }, { multi: true });
+                        await FeeRateFiles.update({
+                            userID: userId,
+                            rootProjectID: data.updateData.ID
+                        }, { $set: { deleteInfo: deleteInfo } }, { multi: true });
+                        await Projects.update({ userID: userId, ID: data.updateData.ID }, data.updateData, updateAll);
+                    } else {//true
+                        await UnitPriceFiles.remove({ user_id: userId, root_project_id: data.updateData.ID });
+                        await FeeRateFiles.remove({ userID: userId, rootProjectID: data.updateData.ID });
+                        //await Projects.update({userID: userId, NextSiblingID: data.updateData.ID, deleteInfo: null}, {$set: {NextSiblingID: data.NextSiblingID}});
+                        await Projects.remove({ userID: userId, ID: data.updateData.ID }, updateAll);
+                    }
+                } else if (data.updateData.projType === projectType.tender) {//fake
+                    let delTender = await Projects.findOne({ userID: userId, ID: data.updateData.ID });
+                    //如果这个单位工程用到的费率文件、单价文件,没有被其他的单位工程使用,则应该一起跟随删除
+                    if (delTender) {
+                        let unitPriceFile = delTender.property.unitPriceFile;
+                        let feeRateFile = delTender.property.feeFile;
+                        let usedUFTenders = await Projects.find(
+                            { userID: userId, $or: [{ deleteInfo: null }, { 'deleteInfo.deleted': false }], 'property.unitPriceFile.id': unitPriceFile.id });
+                        if (usedUFTenders.length === 1) {
+                            await UnitPriceFiles.update({ id: unitPriceFile.id }, { $set: { deleteInfo: deleteInfo } });
                         }
                         }
-                    } else if (data.updateData.projType === projectType.tender) {//fake
-                        let delTender = await Projects.findOne({userID: userId, ID: data.updateData.ID});
-                        //如果这个单位工程用到的费率文件、单价文件,没有被其他的单位工程使用,则应该一起跟随删除
-                        if(delTender){
-                            let unitPriceFile = delTender.property.unitPriceFile;
-                            let feeRateFile = delTender.property.feeFile;
-                            let usedUFTenders = await Projects.find(
-                                {userID: userId, $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}], 'property.unitPriceFile.id': unitPriceFile.id});
-                            if(usedUFTenders.length === 1){
-                                await UnitPriceFiles.update({id: unitPriceFile.id}, {$set: {deleteInfo: deleteInfo}});
-                            }
-                            let usedFRTenders = await Projects.find(
-                                {userID: userId, $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}], 'property.feeFile.id': feeRateFile.id});
-                            if(usedFRTenders.length === 1){
-                                await FeeRateFiles.update({ID: feeRateFile.id}, {$set: {deleteInfo: deleteInfo}});
-                            }
-                            await Projects.update({userID: userId, ID: data.updateData.ID}, data.updateData, updateAll);
+                        let usedFRTenders = await Projects.find(
+                            { userID: userId, $or: [{ deleteInfo: null }, { 'deleteInfo.deleted': false }], 'property.feeFile.id': feeRateFile.id });
+                        if (usedFRTenders.length === 1) {
+                            await FeeRateFiles.update({ ID: feeRateFile.id }, { $set: { deleteInfo: deleteInfo } });
                         }
                         }
+                        await Projects.update({ userID: userId, ID: data.updateData.ID }, data.updateData, updateAll);
+                    }
 
 
-                    } else if (data.updateData.projType === projectType.folder) {//true
-                        await Projects.remove({userID: userId, ID: data.updateData.ID}, updateAll);
-                    } else throw '未知文件类型,删除失败!';
-                }
-                catch (error) {
-                    callback(1, error, null);
-                }
+                } else if (data.updateData.projType === projectType.folder) {//true
+                    await Projects.remove({ userID: userId, ID: data.updateData.ID }, updateAll);
+                } else throw '未知文件类型,删除失败!';
             }
             }
             else {
             else {
                 hasError = true;
                 hasError = true;

+ 27 - 0
public/calculate_util.js

@@ -104,8 +104,35 @@
         fee += (baseFee - withinData.min) * withinData.feeRate * 0.01;
         fee += (baseFee - withinData.min) * withinData.feeRate * 0.01;
         return scMathUtil.roundForObj(fee, decimal);
         return scMathUtil.roundForObj(fee, decimal);
     }
     }
+    
+    // 所有编办的累进基数(如果以后编办基数有冲突,则此判断方法不可用了。如在编办A、B均有计算x,且A中x为累进基数,B中x为非累进基数)
+    const progression = [
+        '施工场地建设费', '养护单位(业主)管理费', '信息化费', '路线工程监理费', '独立桥梁隧道工程监理费', // 重庆2018
+        '设计文件审查费', '路线勘察设计费', '独立桥梁隧道维修加固勘察设计费', '招标代理及标底(最高投标限价)编制费',
+        '养护单位管理费', '养护项目信息化费', '工程监理费', '前期工作费', // 安徽2019
+        '养护单位项目管理费', // 内蒙2019
+        '养护工程管理费' // 浙江2005
+    ];
+
+    /**
+     * 判断该基数是否包含累进基数
+     * @param {String} calcBase - 计算基数
+     * @return {Boolean}
+     */
+    function isProgressive(calcBase) {
+        if (typeof calcBase !== 'string') {
+            return false;
+        }
+        const reg = /{[^}]+}/g;
+        const matched = calcBase.match(reg);
+        if (!matched) {
+            return false;
+        }
+        return matched.some(mStr => progression.some(pStr => `{${pStr}}` === mStr));
+    }
 
 
     return {
     return {
         getProgressiveFee,
         getProgressiveFee,
+        isProgressive,
     };
     };
 });
 });