瀏覽代碼

限制单位工程数量

vian 5 年之前
父節點
當前提交
bbb401a8d6

+ 1 - 1
modules/import/controllers/import_controller.js

@@ -33,7 +33,7 @@ let controller = {
         const result = {
             error: 0
         };
-        result.data = await pm_facade.importInterface(req.body.key, req.body.session.sessionUser.id, req.body.session.sessionCompilation._id);
+        result.data = await pm_facade.importInterface(req.body.key, req.body.session);
         return result;
     },
     async getDataForInterface (req) {

+ 26 - 1
modules/main/middleware/system_setting.js

@@ -3,11 +3,20 @@
  */
 
 module.exports={
-    rationNumberChecking:rationNumberChecking
+    getSystemSetting,
+    rationNumberChecking:rationNumberChecking,
+    tenderNumberChecking
 };
 
 let mongoose = require("mongoose");
 let rationModel = mongoose.model("ration");
+const systemSettingModel = mongoose.model('system_setting');
+const pmFacade = require('../../pm/facade/pm_facade');
+
+// 获取系统设置,这个系统设置正常情况下有存在session中
+async function getSystemSetting() {
+    return await systemSettingModel.findOne({}).lean();
+}
 
 async function rationNumberChecking(req, res, next) {
     if(req.session.systemSetting){
@@ -25,4 +34,20 @@ async function rationNumberChecking(req, res, next) {
         }
     }
     next();
+}
+
+async function tenderNumberChecking(req, res, next) {
+    const data = JSON.parse(req.body.data);
+    const tenderCount = data.tenderCount;
+    if (tenderCount) {
+        const tenderOverrun = await pmFacade.isTenderOverrun(tenderCount, req.session);
+        if (tenderOverrun) {
+            return res.json({
+                error: 1,
+                message: '您创建的项目个数超限,请联系我们的客服人员,或者导出建设项目保存到本地备份,删除云上数据。'
+            });
+        }
+    }
+    next();
+
 }

+ 39 - 1
modules/pm/facade/pm_facade.js

@@ -37,6 +37,7 @@ module.exports={
     downLoadProjectFile:downLoadProjectFile,
     importProcessChecking:importProcessChecking,
     importInterface,
+    isTenderOverrun
 };
 
 
@@ -109,6 +110,7 @@ let qiniu = require("qiniu");
 let fs = require("fs");
 let path = require("path");
 let request = require("request");
+const systemSettingMiddleware = require('../../main/middleware/system_setting');
 
 let qiniu_config = {
     "AccessKey": "_gR1ed4vi1vT2G2YITGSf4_H0fJu_nRS9Tzk3T4z",
@@ -1839,7 +1841,7 @@ async function downloadFileSync(key) {
 }
 
 // 导入接口
-async function importInterface(key, userID, compilationID) {
+async function importInterface(key, session) {
     // 源文件内容文本
     let downloadFilePath = '';
     try {
@@ -1848,7 +1850,18 @@ async function importInterface(key, userID, compilationID) {
         if (!srcData) {
             throw '无有效数据';
         }
+        const userID = session.sessionUser.id;
+        const compilationID = session.sessionCompilation._id;
         const importData = JSON.parse(srcData);
+        let  tenderCount = 0;
+        importData.engs.forEach(eng => {
+            eng.tenders.forEach(tender => {
+                tenderCount += 1;
+            });
+        });
+        if (await isTenderOverrun(tenderCount, session)) {
+            throw '您创建的项目个数超限,请联系我们的客服人员,或者导出建设项目保存到本地备份,删除云上数据。';
+        }
         const projectData = await importProject(importData, userID, compilationID);
         return projectData;
     } catch (err) {
@@ -1877,6 +1890,12 @@ async function importProjects(data,req,updateData) {
             result.error = 1;
             result.msg = `导入失败:您要导入的文件是由“${fileCompilationName}”导出,当前软件是“${curCompilationName}”,请选择正确的费用定额再进行操作!`;
         }else {
+            const tenders = mainData.projects.filter(item => item.projType === projectType.tender);
+            const tenderOverrun = await isTenderOverrun(tenders.length, req.session);
+            if (tenderOverrun) {
+                result.error = 1;
+                result.msg = `您创建的项目个数超限,请联系我们的客服人员,或者导出建设项目保存到本地备份,删除云上数据。`;
+            }
             let [projectIDMap,labourCoeFileIDMap,calcProgramFileIDMap] = await handleMainProjectDatas(mainData,updateData,req.session.sessionUser.id);
             if(datas.length > 1 ){
                 for(let i = 1;i<datas.length;i++){
@@ -2147,4 +2166,23 @@ function uploadToken() {
         domain: qiniu_config.Domain
     }
     return result
+}
+
+// 有些方法无法通过中间件就检查单位工程数量是否超限
+// 需要到具体的业务代码中进行判断
+// 这个方法就是具体业务代码中,需要检查单位工程数量是否超限用
+async function isTenderOverrun(tenderCount, session) {
+    const userID = session.sessionUser.id;
+    const compilation = session.sessionCompilation._id;
+    const compilationVersion = session.compilationVersion || '免费';
+    let systemSetting = session.systemSetting;
+    // 这种情况只有在刚上线此功能时会出现,不考虑时间差
+    if (!systemSetting) {
+        systemSetting = await systemSettingMiddleware.getSystemSetting();
+        session.systemSetting = systemSetting;
+    }
+    const type = compilationVersion.includes('免费') ? 'normal' : 'professional';
+    const limit = systemSetting[type].project;
+    const curTenderCount = await projectModel.count({userID, compilation, projType: 'Tender', '$or':[{deleteInfo: null}, {'deleteInfo.completeDeleted': false}]});
+    return tenderCount + curTenderCount > limit;
 }

+ 3 - 2
modules/pm/routes/pm_route.js

@@ -6,6 +6,7 @@ import BaseController from "../../common/base/base_controller";
 let express = require('express');
 let pmController = require('./../controllers/pm_controller');
 const baseController = new BaseController();
+const systemMiddleware = require('../../main/middleware/system_setting');
 
 module.exports = function (app) {
 
@@ -34,7 +35,7 @@ module.exports = function (app) {
      req.body = {data: '{user_id: user_id, updateData: [{updateType, updateData}]}'}
      data.updateData.updateType: 1 of ['new', 'update', 'delete']
      */
-    pmRouter.post('/updateProjects', pmController.updateProjects);
+    pmRouter.post('/updateProjects', systemMiddleware.tenderNumberChecking, pmController.updateProjects);
     pmRouter.post('/updateMixDatas', pmController.updateMixDatas);
     pmRouter.post('/moveProject', pmController.moveProject);
 
@@ -43,7 +44,7 @@ module.exports = function (app) {
      data.updateData.updateType: 1 of ['update', 'copy']
      */
     pmRouter.post('/getProjectsByQuery', pmController.getProjectsByQuery);
-    pmRouter.post('/copyProjects', pmController.copyProjects);
+    pmRouter.post('/copyProjects', systemMiddleware.tenderNumberChecking, pmController.copyProjects);
     pmRouter.post('/renameProject', pmController.rename);
     pmRouter.post('/beforeOpenProject', pmController.beforeOpenProject);
     pmRouter.post('/getProject', pmController.getProject);

+ 2 - 2
public/web/common_ajax.js

@@ -6,14 +6,14 @@ var CommonAjax = {
     get:function (url,data,cb,dataType) {
         $.get(url,data,cb,dataType)
     },
-    post: function (url, data, successCallback, errorCallback) {
+    post: function (url, data, successCallback, errorCallback, timeout = 50000) {
         $.ajax({
             type:"POST",
             url: url,
             data: {'data': JSON.stringify(data)},
             dataType: 'json',
             cache: false,
-            timeout: 50000,
+            timeout: timeout,
             success: function(result){
                 if (result.error === 0) {
                     if (successCallback) {

+ 4 - 1
web/building_saas/css/custom.css

@@ -374,6 +374,9 @@ input.text-right{
     color:#ECE0F5 !important;
     -webkit-text-stroke:.5px #ced4da;
 }
+.z-index-3000 {
+    z-index: 3000;
+}
 .progress-bar {
     position: relative;
     width: 100%;
@@ -452,7 +455,7 @@ input.text-right{
     height: 500px;
 }
 
-@media screen and (max-width: 1366px) {
+@media screen and (max-width: 1366px), (max-height: 768px) {
     .middle-modal-width {
         max-width: 500px;
     }

+ 1 - 1
web/building_saas/pm/html/project-management.html

@@ -491,7 +491,7 @@
             <div class="modal-footer">
                 <a href="javascript:void(0);" class="btn btn-primary" id="add-tender-prev" style="display: none">上一步</a>
                 <a href="javascript:void(0);" class="btn btn-primary" id="add-tender-next">下一步</a>
-                <a href="javascript:void(0);" class="btn btn-primary" style="display: none" id="add-tender-confirm">确定</a>
+                <a href="javascript:void(0);" class="btn btn-primary" data-dismiss="modal" style="display: none" id="add-tender-confirm">确定</a>
                 <button type="button" class="btn btn-secondary" data-dismiss="modal" id="add-tender-cancel" style="display: none;">取消</button>
             </div>
         </div>

+ 3 - 2
web/building_saas/pm/js/pm_ajax.js

@@ -25,10 +25,11 @@ var GetAllProjectData = function (callback) {
 }
 // 更新数据到服务器
 var UpdateProjectData = function (updateData, callback, errCB) {
+    const tenderCount = updateData.filter(item => item.updateType === 'new' && item.updateData.projType === projectType.tender).length;
     $.ajax({
         type:"POST",
         url: '/pm/api/updateProjects',
-        data: {'data': JSON.stringify({"user_id": userID, "updateData": updateData})},
+        data: {'data': JSON.stringify({"user_id": userID, "updateData": updateData, tenderCount})},
         dataType: 'json',
         cache: false,
         timeout: 50000,
@@ -39,7 +40,7 @@ var UpdateProjectData = function (updateData, callback, errCB) {
                 if (errCB) {
                     errCB();
                 }
-                alert('error: ' + result.message);
+                alert(result.message);
             }
         },
         error: function(jqXHR, textStatus, errorThrown){

+ 9 - 2
web/building_saas/pm/js/pm_newMain.js

@@ -1699,6 +1699,13 @@ function setupRequiredWarn(compilation) {
     }
 }
 $(document).ready(function() {
+    // 单位工程超限提示后,弹出客服列表
+    $('#hintBox_form').on('hide.bs.modal', function () {
+        const text = $('#hintBox_caption').text();
+        if (text === '您创建的项目个数超限,请联系我们的客服人员,或者导出建设项目保存到本地备份,删除云上数据。') {
+            $('#customerService').click();
+        } 
+    });
     setupRequiredWarn(compilationData);
     $('#add-project-dialog').find('.modal-body').append();
     //绑定项目管理的升降级、上下移按钮事件
@@ -2621,12 +2628,12 @@ $(document).ready(function() {
         projectMap['copy'] = {document:projectData};
         $("#copy-to-dialog").modal('hide');
         $.bootstrapLoading.start();
-        CommonAjax.post('/pm/api/copyProjects',{projectMap:projectMap,user_id: userID},function (result) {
+        CommonAjax.post('/pm/api/copyProjects',{projectMap:projectMap,user_id: userID, tenderCount: 1},function (result) {
             let newNode = projTreeObj.insert(result['copy'].document,parent,next);
             let refreshNodes = projTreeObj.calEngineeringCost(newNode);
             projTreeObj.refreshNodeData(refreshNodes);
             $.bootstrapLoading.end();
-        })
+        }, null, 1000 * 60 * 5);
 
     });
     $('#selectSameTypeProject').click(function(){

+ 2 - 2
web/building_saas/pm/js/pm_share.js

@@ -946,11 +946,11 @@ const pmShare = (function () {
             copyMap.copy = {document: copyData};
             $('#copyShare').modal('hide');
             $.bootstrapLoading.start();
-            CommonAjax.post('/pm/api/copyProjects', {projectMap: copyMap, user_id: userID}, function (rstData) {
+            CommonAjax.post('/pm/api/copyProjects', {projectMap: copyMap, user_id: userID, tenderCount: 1}, function (rstData) {
                 $.bootstrapLoading.end();
             }, function () {
                 $.bootstrapLoading.end();
-            });
+            }, 1000 * 60 * 5);
         });
 
     }

+ 1 - 1
web/common/html/header.html

@@ -183,7 +183,7 @@
 </div>
 <!--激活产品 & 售后服务 & 联系客服-->
 <!--办事处客服列表-->
-<div class="modal fade" id="activ" data-backdrop="static" style="display: none;" aria-hidden="true">
+<div class="modal fade z-index-3000" id="activ" data-backdrop="static" style="display: none;" aria-hidden="true">
     <div class="modal-dialog modal-lg" role="document">
         <div class="modal-content">
             <div class="modal-header">