Forráskód Böngészése

部分设置读取调整

MaiXinRong 3 hónapja
szülő
commit
4198d2f81c

+ 5 - 0
.gitignore

@@ -15,3 +15,8 @@ app/public/archive
 .vscode/
 /report_temp
 /file
+temp
+/app/public/deal_bills/downloads
+/app/public/deal_bills/uploads
+/app/public/js/webCache
+views

+ 1 - 1
app/controller/budget_controller.js

@@ -180,7 +180,7 @@ module.exports = app => {
         }
         async _getNeedGcl() {
             if (!this.ctx.params.btype) throw '参数错误';
-            const funRela = await this.ctx.service.project.getFunRela(this.ctx.session.sessionProject.id);
+            const funRela = this.ctx.subProject.fun_rela;
             return ['yu', 'zb'].indexOf(this.ctx.params.btype) >= 0 && !!funRela.needGcl;
         }
 

+ 7 - 14
app/controller/change_controller.js

@@ -170,8 +170,7 @@ module.exports = app => {
 
             if (ctx.session.sessionProject.page_show.openChangeState) {
                 // 工程变更类别读取
-                const projectData = await ctx.service.project.getDataById(ctx.session.sessionProject.id);
-                const fun_set = await ctx.service.project.getFunSet(projectData.fun_set);
+                const fun_set = this.ctx.subProject.fun_set;
                 const changeState = fun_set.change_state;
                 for (const cs of changeState) {
                     cs.count = await ctx.service.change.getCountByStatus(tender.id, status, cs.order);
@@ -302,8 +301,7 @@ module.exports = app => {
                 if (!data.code || data.code === '') {
                     throw '变更令号不能为空';
                 }
-                const projectData = await ctx.service.project.getDataById(ctx.session.sessionProject.id);
-                const fun_set = await ctx.service.project.getFunSet(projectData.fun_set);
+                const fun_set = this.ctx.subProject.fun_set;
                 const stateInfo = ctx.helper._.find(fun_set.change_state, { order: 3 });
                 // 在生成新变更令后,需要copy前一个变更令报表的签名信息
                 const lastChange = await ctx.service.change.getLastChange(tenderId);
@@ -442,8 +440,7 @@ module.exports = app => {
                 }
 
                 // 工程变更类别读取
-                const projectData = await ctx.service.project.getDataById(ctx.session.sessionProject.id);
-                const fun_set = await ctx.service.project.getFunSet(projectData.fun_set);
+                const fun_set = this.ctx.subProject.fun_set;
 
                 // 获取用户人验证手机号
                 const pa = await ctx.service.projectAccount.getDataById(ctx.session.sessionUser.accountId);
@@ -627,8 +624,7 @@ module.exports = app => {
                         if (!ctx.session.sessionProject.page_show.openChangeWhiteList) {
                             throw '空白清单添加功能未开启。';
                         }
-                        const projectData = await ctx.service.project.getDataById(ctx.session.sessionProject.id);
-                        const fun_set = await ctx.service.project.getFunSet(projectData.fun_set);
+                        const fun_set = this.ctx.subProject.fun_set;
                         const stateInfo = ctx.helper._.find(fun_set.change_state, { order: ctx.change.state });
                         if (data.type === 'add') {
                             responseData.data = await ctx.service.changeAuditList.add(data.postData, stateInfo.value);
@@ -666,8 +662,7 @@ module.exports = app => {
                     case 'info':
                         let value = 100;
                         if (data.updateData.state && parseInt(data.updateData.state) !== ctx.change.state) {
-                            const projectData = await ctx.service.project.getDataById(ctx.session.sessionProject.id);
-                            const fun_set = await ctx.service.project.getFunSet(projectData.fun_set);
+                            const fun_set = this.ctx.subProject.fun_set;
                             const stateInfo = ctx.helper._.find(fun_set.change_state, { order: parseInt(data.updateData.state) });
                             value = stateInfo.value;
                         }
@@ -729,8 +724,7 @@ module.exports = app => {
                         if (ctx.change.status !== audit.change.status.uncheck && ctx.change.status !== audit.change.status.checkNo && ctx.change.status !== audit.change.status.revise) {
                             throw '该变更令正在审批中或已完成,无法操作清单数据';
                         }
-                        const projectData2 = await ctx.service.project.getDataById(ctx.session.sessionProject.id);
-                        const fun_set2 = await ctx.service.project.getFunSet(projectData2.fun_set);
+                        const fun_set2 = this.ctx.subProject.fun_set;
                         const stateInfo2 = ctx.helper._.find(fun_set2.change_state, { order: ctx.change.state });
                         await ctx.service.changeAuditList.adds(data.postData, stateInfo2.value);
                         responseData.data = { changeList: await ctx.service.changeAuditList.getList(ctx.change.cid) };
@@ -2214,8 +2208,7 @@ module.exports = app => {
         // 变更类别获取及更新
         async _getOrUpdateClass(ctx, serviceName) {
             // 工程变更类别读取
-            const projectData = await ctx.service.project.getDataById(ctx.session.sessionProject.id);
-            const fun_set = await ctx.service.project.getFunSet(projectData.fun_set);
+            const fun_set = this.ctx.subProject.fun_set;
             if (ctx.change.status === audit[serviceName].status.uncheck ||
                 (serviceName === 'changeProject' && ctx.change.status === audit[serviceName].status.back) ||
                 (serviceName !== 'changeProject' && ctx.change.status === audit[serviceName].status.checkNo)) {

+ 1 - 1
app/controller/pay_controller.js

@@ -153,7 +153,7 @@ module.exports = app => {
                 await this.ctx.service.phasePay.loadAuditViewData(ctx.phasePay);
                 const pays = await this.ctx.service.phasePayDetail.getDetailData(ctx.phasePay);
                 const calcBase = this.ctx.service.phasePay.getPhasePayCalcBase(ctx.phasePay, ctx.tender.info);
-                const projectFunInfo = await this.ctx.service.project.getFunRela(ctx.session.sessionProject.id);
+                const projectFunInfo = this.ctx.subProject.fun_rela;
                 const lastStage = await this.ctx.service.stage.getLastestCompleteStage(ctx.tender.id);
                 const accountList = await ctx.service.projectAccount.getAllDataByCondition({
                     where: { project_id: ctx.session.sessionProject.id, enable: 1 },

+ 0 - 103
app/controller/setting_controller.js

@@ -945,109 +945,6 @@ module.exports = app => {
             }
         }
 
-        async logs(ctx) {
-            try {
-                // 获取项目数据
-                const projectId = ctx.session.sessionProject.id;
-                await this._checkMenu(projectId);
-                const projectData = await ctx.service.project.getDataById(projectId);
-                if (projectData === null) {
-                    throw '没有对应的项目数据';
-                }
-                if (ctx.session.sessionUser.is_admin === 0) {
-                    throw '没有访问权限';
-                }
-                const settingType = ctx.params.type ? parseInt(ctx.params.type) : 0;
-                const logs = await ctx.service.projectLog.getLogs(projectId, settingType);
-                const renderData = {
-                    projectData,
-                    officeList,
-                    projectLog,
-                    settingType,
-                    logs,
-                };
-                await this.layout('setting/logs.ejs', renderData);
-            } catch (error) {
-                console.log(error);
-                ctx.redirect('/dashboard');
-            }
-        }
-
-        async fun(ctx) {
-            try {
-                const projectId = ctx.session.sessionProject.id;
-                await this._checkMenu(projectId);
-                const projectData = await ctx.service.project.getDataById(projectId);
-                const funRela = await ctx.service.project.getFunRela(projectId);
-                if (projectData === null) {
-                    throw '没有对应的项目数据';
-                }
-                if (ctx.session.sessionUser.is_admin === 0) {
-                    throw '没有访问权限';
-                }
-                const fun_set = await ctx.service.project.getFunSet(projectData.fun_set);
-                await this.layout('setting/fun.ejs', {
-                    projectData,
-                    funRela,
-                    imType,
-                    endMonth: funSet.endMonth,
-                    funSet: fun_set,
-                }, 'setting/fun_modal.ejs');
-            } catch (error) {
-                ctx.helper.log(error);
-                ctx.redirect('/dashboard');
-            }
-        }
-
-        /**
-         * 保存功能设置相关
-         * @param ctx
-         * @returns {Promise<void>}
-         */
-        async updateFun(ctx) {
-            try {
-                const projectId = ctx.session.sessionProject.id;
-                const projectData = await ctx.service.project.getDataById(projectId);
-                if (projectData === null) {
-                    throw '没有对应的项目数据';
-                }
-                if (ctx.session.sessionUser.is_admin === 0) {
-                    throw '没有访问权限';
-                }
-
-                const data = JSON.parse(ctx.request.body.data);
-                if (data) ctx.request.body = data;
-                const rule = ctx.service.project.rule('fun');
-                ctx.validate(rule);
-
-                const result = await ctx.service.project.updateFunRela(projectId, ctx.request.body);
-                if (!result) throw '保存数据失败';
-                this.ctx.session.sessionProject.page_show.openChangeProject = data.openChangeProject ? 1 : 0;
-                this.ctx.session.sessionProject.page_show.openChangeApply = data.openChangeApply ? 1 : 0;
-                this.ctx.session.sessionProject.page_show.openChangePlan = data.openChangePlan ? 1 : 0;
-                this.ctx.session.sessionProject.page_show.openChangeWhiteList = data.openChangeWhiteList ? 1 : 0;
-                this.ctx.session.sessionProject.page_show.openChangeState = data.openChangeState ? 1 : 0;
-                this.ctx.session.sessionProject.page_show.openMaterialTax = data.openMaterialTax ? 1 : 0;
-                this.ctx.session.sessionProject.page_show.openMaterialChecklist = data.openMaterialChecklist ? 1 : 0;
-                this.ctx.session.sessionProject.page_show.openMaterialSelf = data.openMaterialSelf ? 1 : 0;
-                this.ctx.session.sessionProject.page_show.openMaterialEditForAudit = data.openMaterialEditForAudit ? 1 : 0;
-                this.ctx.session.sessionProject.page_show.openStageStart = data.openStageStart ? 1 : 0;
-                const result2 = await ctx.service.project.updatePageshow(projectId);
-                if (!result2) throw '保存数据失败';
-                if (data.addFunSet) {
-                    const funSet = projectData.fun_set ? JSON.parse(projectData.fun_set) : {};
-                    ctx.helper._.defaultsDeep(data.addFunSet, funSet);
-                    const result3 = await ctx.service.project.updateFunSet(projectId, data.addFunSet);
-                    if (!result3) throw '保存数据失败';
-                }
-
-                ctx.body = {err: 0, msg: '', data: null};
-            } catch (error) {
-                ctx.helper.log(error);
-                this.ajaxErrorBody(error, '保存数据失败');
-            }
-        }
-
         async s2b(ctx) {
             try {
                 const projectId = ctx.session.sessionProject.id;

+ 0 - 2
app/controller/settle_controller.js

@@ -199,7 +199,6 @@ module.exports = app => {
                 const renderData = await this._getDefaultRenderData(ctx);
                 renderData.jsFiles = this.app.jsFiles.common.concat(this.app.jsFiles.settle.select);
 
-                const projectFunInfo = await this.ctx.service.project.getFunRela(ctx.session.sessionProject.id);
                 renderData.whiteList = this.ctx.app.config.multipart.whitelist;
                 await this.layout('settle/select.ejs', renderData, 'settle/select_modal.ejs');
             } catch(err) {
@@ -213,7 +212,6 @@ module.exports = app => {
                 const renderData = await this._getDefaultRenderData(ctx);
                 renderData.jsFiles = this.app.jsFiles.common.concat(this.app.jsFiles.settle.ledger);
 
-                const projectFunInfo = await this.ctx.service.project.getFunRela(ctx.session.sessionProject.id);
                 renderData.whiteList = this.ctx.app.config.multipart.whitelist;
                 await this.layout('settle/index.ejs', renderData, 'settle/modal.ejs');
             } catch(err) {

+ 4 - 6
app/controller/stage_controller.js

@@ -161,7 +161,7 @@ module.exports = app => {
             try {
                 await this._getStageAuditViewData(ctx);
                 const renderData = await this._getDefaultRenderData(ctx);
-                const projectFunInfo = await this.ctx.service.project.getFunRela(ctx.session.sessionProject.id);
+                const projectFunInfo = this.ctx.subProject.fun_rela;
                 renderData.minusNoValue = projectFunInfo.minusNoValue && ctx.tender.info.fun_rela.stage_change.minusNoValue;
                 [renderData.ledgerSpread, renderData.posSpread] = await spreadSetting.getStageSpreadSetting(ctx, ctx.tender.id,
                     this.ctx.stage.readOnly || this.ctx.stage.revising, {minusNoValue: renderData.minusNoValue});
@@ -468,7 +468,7 @@ module.exports = app => {
                     x.final_1_qty = helper.add(x.quantity, x.end_qc_minus_qty);
                 });
 
-                const projRela = await this.ctx.service.project.getFunRela(this.ctx.session.sessionProject.id);
+                const projRela = this.ctx.subProject.fun_rela;
                 const checkDataModel = require('../lib/ledger').checkData;
                 const checkData = new checkDataModel(ctx, measureType);
                 checkData.loadData(ledgerData, posData);
@@ -625,8 +625,6 @@ module.exports = app => {
                 }
                 const bills = data.bills ? data.bills : await ctx.service.ledger.getDataById(data.pos.lid);
                 const pos = data.pos;
-                const projectFunInfo = await this.ctx.service.project.getFunRela(ctx.session.sessionProject.id);
-                // const changes = await ctx.service.change.getValidChanges(ctx.tender, ctx.stage, data, projectFunInfo.minusNoValue && ctx.tender.info.fun_rela.stage_change.minusNoValue);
                 const changes = await ctx.service.change.getValidChanges(ctx.tender, ctx.stage, data, true);
                 const useChanges = ctx.stage.readOnly
                     ? await ctx.service.stageChange.getAuditorStageData(ctx.tender.id, ctx.stage.id, ctx.stage.curTimes, ctx.stage.curOrder, bills.id, pos ? pos.id : -1)
@@ -1043,7 +1041,7 @@ module.exports = app => {
                 // 用户有无权限上传和删除附件
                 renderData.uploadPermission = !ctx.tender.isTourist || ctx.tender.touristPermission.file;
 
-                const projectFunInfo = await this.ctx.service.project.getFunRela(ctx.session.sessionProject.id);
+                const projectFunInfo = this.ctx.subProject.fun_rela;
                 renderData.lockPayExpr = projectFunInfo.lockPayExpr;
                 renderData.showMinusCol = projectFunInfo.showMinusCol;
                 renderData.deleteFilePermission = PermissionCheck.delFile(this.ctx.session.sessionUser.permission);
@@ -1505,7 +1503,7 @@ module.exports = app => {
                 await this._getStageAuditViewData(ctx);
                 const renderData = await this._getDefaultRenderData(ctx);
                 [renderData.gclSpread, renderData.leafXmjSpread, renderData.gatherLeafXmjSpread] = await spreadSetting.getStageGatherSpreadSetting(ctx);
-                const projectFunInfo = await this.ctx.service.project.getFunRela(ctx.session.sessionProject.id);
+                const projectFunInfo = this.ctx.subProject.fun_rela;
                 renderData.hintOver = projectFunInfo.hintOver && ctx.tender.info.fun_rela.hintOver;
 
                 renderData.jsFiles = this.app.jsFiles.common.concat(this.app.jsFiles.stage.gather);

+ 1 - 1
app/controller/stage_rela_controller.js

@@ -97,7 +97,7 @@ module.exports = app => {
                 const renderData = await this._getDefaultRenderData(ctx);
                 renderData.jsFiles = this.app.jsFiles.common.concat(this.app.jsFiles.stageRela.detail);
                 const relaTenderInfo = await this.ctx.service.tenderInfo.getTenderInfo(relaStage.rela_tid);
-                const projectFunInfo = await this.ctx.service.project.getFunRela(ctx.session.sessionProject.id);
+                const projectFunInfo = this.ctx.subProject.fun_rela;
                 renderData.minusNoValue = projectFunInfo.minusNoValue && relaTenderInfo.fun_rela.stage_change.minusNoValue;
                 [renderData.ledgerSpread, renderData.posSpread] = await spreadSetting.getStageSpreadSetting(ctx, null, true, {minusNoValue: renderData.minusNoValue});
                 renderData.measureType = measureType;

+ 2 - 2
app/controller/sub_proj_setting_controller.js

@@ -236,8 +236,8 @@ module.exports = app => {
         async fun(ctx) {
             try {
                 this.defaultCheck(ctx);
-                const funRela = await ctx.service.subProject.getFunRela(ctx.subProject);
-                const fun_set = await ctx.service.subProject.getFunSet(ctx.subProject.fun_set);
+                const funRela = this.ctx.subProject.fun_rela;
+                const fun_set = this.ctx.subProject.fun_set;
                 await this.layout('sp_setting/fun.ejs', {
                     funRela,
                     imType,

+ 4 - 0
app/middleware/sub_project_check.js

@@ -27,6 +27,10 @@ module.exports = options => {
             if (this.subProject.project_id !== this.session.sessionProject.id) throw '您无权查看该项目';
 
             if (!this.subProject) throw '项目不存在';
+            // 解析属性并加载默认值
+            this.subProject.page_show = this.service.subProject.getPageShow(this.subProject.page_show);
+            this.subProject.fun_set = this.service.subProject.getFunSet(this.subProject.fun_set);
+            this.subProject.fun_rela = this.service.subProject.getFunRela(this.subProject.fun_rela);
 
             if (this.session.sessionUser.is_admin) {
                 this.subProject.readOnly = false;

+ 1 - 2
app/service/change.js

@@ -168,8 +168,7 @@ module.exports = app => {
                         change.new_code = planInfo.c_new_code;
                         change.new_name = planInfo.design_name;
                         // 工程变更类别读取
-                        const projectData = await this.ctx.service.project.getDataById(this.ctx.session.sessionProject.id);
-                        const fun_set = await this.ctx.service.project.getFunSet(projectData.fun_set);
+                        const fun_set = this.ctx.subProject.fun_set;
                         const classInfo = this._.find(fun_set.change_class, function(item) {
                             return item.name === planInfo.class || (item.checked && item.new_name === planInfo.class);
                         });

+ 1 - 2
app/service/change_project.js

@@ -87,8 +87,7 @@ module.exports = app => {
             }
 
             // 工程变更类别读取
-            const projectData = await this.ctx.service.project.getDataById(this.ctx.session.sessionProject.id);
-            const fun_set = await this.ctx.service.project.getFunSet(projectData.fun_set);
+            const fun_set = this.ctx.subProject.fun_set;
             const classInfo = this._.find(fun_set.change_class, { checked: true });
             // 初始化事务
             this.transaction = await this.db.beginTransaction();

+ 0 - 36
app/service/project.js

@@ -160,29 +160,6 @@ module.exports = app => {
             return result;
         }
 
-        /**
-         * 功能设置
-         * @param id
-         * @returns {Promise<null>}
-         */
-        async getFunRela(id) {
-            const projectData = await this.db.get(this.tableName, { id });
-            const result = projectData.fun_rela ? JSON.parse(projectData.fun_rela) : {};
-            this.ctx.helper._.defaults(result, defaultFunRela);
-            return result;
-        }
-
-        async updateFunRela(id, data) {
-            const result = await this.db.update(this.tableName, {
-                id: id, fun_rela: JSON.stringify({
-                    banOver: data.banOver, hintOver: data.hintOver, banMinusChangeBills: data.banMinusChangeBills,
-                    imType: data.imType, needGcl: data.needGcl, minusNoValue: data.minusNoValue,
-                    lockPayExpr: data.lockPayExpr, showMinusCol: data.showMinusCol,
-                }),
-            });
-            return result.affectedRows === 1;
-        }
-
         async getSjsRela(id) {
             const projectData = await this.db.get(this.tableName, { id });
             const result = projectData.sjs_rela ? JSON.parse(projectData.sjs_rela) : {};
@@ -277,19 +254,6 @@ module.exports = app => {
             return result ? result.split(',') : [];
         }
 
-        async getFunSet(fun_set = null) {
-            const result = fun_set ? JSON.parse(fun_set) : {};
-            this.ctx.helper._.defaults(result, defaultFunSet);
-            return result;
-        }
-
-        async updateFunSet(id, funSet) {
-            const result = await this.db.update(this.tableName, {
-                id, fun_set: JSON.stringify(funSet),
-            });
-            return result.affectedRows === 1;
-        }
-
         async updateProjectSet(id, field, datas) {
             const updateData = {
                 id,

+ 1 - 1
app/service/stage.js

@@ -541,7 +541,7 @@ module.exports = app => {
                     }
                 }
             } else {
-                const projFunRela = await this.ctx.service.project.getFunRela(this.ctx.session.sessionProject.id);
+                const projFunRela = this.ctx.subProject.fun_rela;
                 newStage.im_type = projFunRela.imType;
             }
             const transaction = await this.db.beginTransaction();

+ 2 - 2
app/service/stage_change.js

@@ -813,7 +813,7 @@ module.exports = app => {
             const stageChange = await this.ctx.service.stageChange.getAllDataByCondition({ where: { sid: stage.id, lid }});
 
             const useModal = new autoUseChange(this.ctx.helper, tender.info);
-            const projectFunInfo = await this.ctx.service.project.getFunRela(this.ctx.session.sessionProject.id);
+            const projectFunInfo = this.ctx.subProject.fun_rela;
             const minusNoValue = projectFunInfo.minusNoValue && tender.info.fun_rela.stage_change.minusNoValue;
             useModal.use({ledgerData, posData, stageBills, stagePos, stageChange, default: { tid: stage.tid, sid: stage.id, said: this.ctx.session.sessionUser.accountId } }, validChangeBills, minusNoValue);
 
@@ -862,7 +862,7 @@ module.exports = app => {
             const stageBills = await this.ctx.service.stageBills.getAllDataByCondition({ where: { sid: stage.id } });
             const stagePos = await this.ctx.service.stagePos.getAllDataByCondition({ where: { sid: stage.id } });
             const useModal = new autoUseChange(this.ctx.helper, tender.info, this.ctx.service.settle.settleStatus);
-            const projectFunInfo = await this.ctx.service.project.getFunRela(this.ctx.session.sessionProject.id);
+            const projectFunInfo = this.ctx.subProject.fun_rela;
             const minusNoValue = projectFunInfo.minusNoValue && tender.info.fun_rela.stage_change.minusNoValue;
             useModal.use({ledgerData, posData, stageBills, stagePos, default: { tid: stage.tid, sid: stage.id, said: this.ctx.session.sessionUser.accountId } }, validChangeBills, minusNoValue);
 

+ 12 - 2
app/service/sub_project.js

@@ -21,6 +21,7 @@ const defaultFunRela = {
 };
 const funSet = require('../const/fun_set');
 const defaultFunSet = funSet.defaultInfo;
+const pageShowConst = require('../const/page_show').defaultSetting;
 
 module.exports = app => {
     class SubProject extends app.BaseService {
@@ -523,12 +524,21 @@ module.exports = app => {
             return await this.db.query(`SELECT id, name FROM zh_file_reference_list`);
         };
 
+        getPageShow(page_show) {
+            const info = page_show ? JSON.parse(page_show) : {};
+            for (const pi in pageShowConst) {
+                info[pi] = info[pi] === undefined ? pageShowConst[pi] : parseInt(info[pi]);
+                this.ctx.helper._.defaults(info[pi], pageShowConst[pi]);
+            }
+            return info;
+        }
+
         /**
          * 功能设置
          * @param id
          * @returns {Promise<null>}
          */
-        async getFunRela(subProject) {
+        getFunRela(subProject) {
             const result = subProject.fun_rela ? JSON.parse(subProject.fun_rela) : {};
             this.ctx.helper._.defaults(result, defaultFunRela);
             return result;
@@ -545,7 +555,7 @@ module.exports = app => {
             return result.affectedRows === 1;
         }
 
-        async getFunSet(fun_set = null) {
+        getFunSet(fun_set = null) {
             const result = fun_set ? JSON.parse(fun_set) : {};
             this.ctx.helper._.defaults(result, defaultFunSet);
             return result;