소스 검색

资金支付权限调整

ellisran 3 주 전
부모
커밋
34f5735282

+ 33 - 17
app/controller/financial_controller.js

@@ -817,13 +817,13 @@ module.exports = app => {
             const tenders = hadTender ? await ctx.service.tender.getAllDataByCondition({ where: tenderCondition, columns: ['id', 'name', 'category'] }) : [];
             const filter = JSON.parse(JSON.stringify(auditConst.financial.filter));
             filter.count = [];
-            filter.count[filter.status.pending] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, payStage.id, filter.status.pending, filterTids, used);// await ctx.service.change.pendingDatas(tender.id, ctx.session.sessionUser.accountId);
-            filter.count[filter.status.uncheck] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, payStage.id, filter.status.uncheck, filterTids, used);// await ctx.service.change.checkingDatas(tender.id, ctx.session.sessionUser.accountId);
-            filter.count[filter.status.checking] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, payStage.id, filter.status.checking, filterTids, used);// await ctx.service.change.checkedDatas(tender.id, ctx.session.sessionUser.accountId);
-            filter.count[filter.status.checked] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, payStage.id, filter.status.checked, filterTids, used);// await ctx.service.change.pendingDatas(tender.id, ctx.session.sessionUser.accountId);
-            const payList = await ctx.service.financialPay.getListByStatus(ctx.subProject.id, payStage.id, status, filterTids, used, 1);
+            filter.count[filter.status.pending] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, null, payStage.id, filter.status.pending, filterTids, used);// await ctx.service.change.pendingDatas(tender.id, ctx.session.sessionUser.accountId);
+            filter.count[filter.status.uncheck] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, null, payStage.id, filter.status.uncheck, filterTids, used);// await ctx.service.change.checkingDatas(tender.id, ctx.session.sessionUser.accountId);
+            filter.count[filter.status.checking] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, null, payStage.id, filter.status.checking, filterTids, used);// await ctx.service.change.checkedDatas(tender.id, ctx.session.sessionUser.accountId);
+            filter.count[filter.status.checked] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, null, payStage.id, filter.status.checked, filterTids, used);// await ctx.service.change.pendingDatas(tender.id, ctx.session.sessionUser.accountId);
+            const payList = await ctx.service.financialPay.getListByStatus(ctx.subProject.id, null, payStage.id, status, filterTids, used, 1);
             const userTenderList = await ctx.service.financialPay.getUserTenderList(ctx.subProject.id, ctx.session.sessionUser.accountId, payStage.id);
-            const total = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, payStage.id, status, filterTids, used);
+            const total = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, null, payStage.id, status, filterTids, used);
             // 分页相关
             const page = ctx.page;
             const pageSize = ctx.pageSize;
@@ -1006,7 +1006,6 @@ module.exports = app => {
             const fptAuditTids = ctx.helper._.map(fptAudits, 'tid');
             const fptReportTids = ctx.helper._.map(ctx.helper._.filter(fptAudits, { is_report: 1 }), 'tid');
             const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: ctx.session.sessionProject.id } });
-            const filterTids = tid === null ? (ctx.session.sessionUser.is_admin ? null : fptAuditTids) : [tid];
             const tenderCondition = { spid: ctx.subProject.id, filter_fund: 0 };
             let hadTender = false;
             if (ctx.session.sessionUser.is_admin) {
@@ -1030,20 +1029,23 @@ module.exports = app => {
             const userCompanyList = await ctx.service.financialPayStage.getUserCompanyList(ctx.subProject.id, userCompany ? userCompany.id : 0, unitList, qi);
             const userOrderList = await ctx.service.financialPayStage.getUserOrderList(ctx.subProject.id, userCompany ? userCompany.id : 0, companyInfo ? companyInfo.id : null);
             const userTenderList = await ctx.service.financialPay.getUserTenderList(ctx.subProject.id, ctx.session.sessionUser.accountId);
+            const filterTids = tid === null ? (ctx.session.sessionUser.is_admin ? null : userTenderList.length > 0 ? ctx.helper._.map(userTenderList, 'tid') : []) : [tid];
             let fpsidList = null;
             if (company || qi) {
                 const fpstageList = await ctx.service.financialPayStage.getListByStatus(ctx.subProject.id, companyInfo ? companyInfo.id : null, userCompany ? userCompany.id : 0, qi, 0);
                 fpsidList = fpstageList.length > 0 ? ctx.helper._.map(fpstageList, 'id') : 0;
             }
+            const allPayStages = !ctx.session.sessionUser.is_admin ? await ctx.service.financialPayStage.getListByStatus(ctx.subProject.id, null, userCompany ? userCompany.id : 0, null, 0) : null;
+            const allFpsidList = !ctx.session.sessionUser.is_admin ? ctx.helper._.map(allPayStages, 'id') : null;
             // const payList = await ctx.service.financialPayStage.getListByStatus(ctx.subProject.id, companyInfo ? companyInfo.id : null, userCompany ? userCompany.id : 0, qi);
             const filter = JSON.parse(JSON.stringify(auditConst.financial.filter));
             filter.count = [];
-            filter.count[filter.status.pending] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, fpsidList !== null ? fpsidList : null, filter.status.pending, filterTids, used);
-            filter.count[filter.status.uncheck] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, fpsidList !== null ? fpsidList : null, filter.status.uncheck, filterTids, used);
-            filter.count[filter.status.checking] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, fpsidList !== null ? fpsidList : null, filter.status.checking, filterTids, used);
-            filter.count[filter.status.checked] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, fpsidList !== null ? fpsidList : null, filter.status.checked, filterTids, used);
-            const payList = await ctx.service.financialPay.getListByStatus(ctx.subProject.id, fpsidList !== null ? fpsidList : null, status, filterTids, used, 1);
-            const total = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, fpsidList !== null ? fpsidList : null, status, filterTids, used);
+            filter.count[filter.status.pending] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, allFpsidList, fpsidList !== null ? fpsidList : null, filter.status.pending, filterTids, used);
+            filter.count[filter.status.uncheck] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, allFpsidList, fpsidList !== null ? fpsidList : null, filter.status.uncheck, filterTids, used);
+            filter.count[filter.status.checking] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, allFpsidList, fpsidList !== null ? fpsidList : null, filter.status.checking, filterTids, used);
+            filter.count[filter.status.checked] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, allFpsidList, fpsidList !== null ? fpsidList : null, filter.status.checked, filterTids, used);
+            const payList = await ctx.service.financialPay.getListByStatus(ctx.subProject.id, allFpsidList, fpsidList !== null ? fpsidList : null, status, filterTids, used, 1);
+            const total = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, allFpsidList, fpsidList !== null ? fpsidList : null, status, filterTids, used);
             // 分页相关
             const page = ctx.page;
             const pageSize = ctx.pageSize;
@@ -1055,8 +1057,9 @@ module.exports = app => {
                 total: Math.ceil(total / pageSize),
                 queryData: JSON.stringify(ctx.urlInfo.query),
             };
+            const allTenders = await ctx.service.tender.getAllDataByCondition({ where: { spid: ctx.subProject.id, filter_fund: 0 }, columns: ['id', 'name', 'category'] });
             for (const pay of payList) {
-                const t = ctx.helper._.find(tenders, { id: pay.tid });
+                const t = ctx.helper._.find(allTenders, { id: pay.tid });
                 pay.tenderName = t ? t.name : '';
                 const userInfo = ctx.helper._.find(accountList, { id: pay.uid });
                 pay.username = userInfo ? userInfo.name : '';
@@ -1159,7 +1162,9 @@ module.exports = app => {
             const fptAuditTids = ctx.helper._.map(fptAudits, 'tid');
             const fptReportTids = ctx.helper._.map(ctx.helper._.filter(fptAudits, { is_report: 1 }), 'tid');
             const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: ctx.session.sessionProject.id } });
-            const filterTids = ctx.session.sessionUser.is_admin ? null : fptAuditTids;
+            const userTenderList = await ctx.service.financialPay.getUserTenderList(ctx.subProject.id, ctx.session.sessionUser.accountId);
+            const filterTids = ctx.session.sessionUser.is_admin ? null : userTenderList.length > 0 ? ctx.helper._.map(userTenderList, 'tid') : [];
+            // const filterTids = ctx.session.sessionUser.is_admin ? null : fptAuditTids;
             const tenderCondition = { spid: ctx.subProject.id, filter_fund: 0 };
             let hadTender = false;
             if (ctx.session.sessionUser.is_admin) {
@@ -1173,7 +1178,6 @@ module.exports = app => {
             }
             const categoryData = await this.ctx.service.category.getAllCategory(ctx.subProject);
             const tenders = hadTender ? await ctx.service.tender.getAllDataByCondition({ where: tenderCondition, columns: ['id', 'name', 'category'] }) : [];
-            const allPays = await ctx.service.financialPay.getListByStatus(ctx.subProject.id, null, 0, filterTids);
             const transfersCondition = { spid: ctx.subProject.id };
             if (filterTids) {
                 transfersCondition.tid = filterTids;
@@ -1186,6 +1190,9 @@ module.exports = app => {
                 throw '请联系管理员添加用户所在单位信息';
             }
             const allPayStages = await ctx.service.financialPayStage.getListByStatus(ctx.subProject.id, null, userCompany ? userCompany.id : 0, null, 0);
+            // const allPayStages = !ctx.session.sessionUser.is_admin ? await ctx.service.financialPayStage.getListByStatus(ctx.subProject.id, null, userCompany ? userCompany.id : 0, null, 0) : null;
+            const allFpsidList = !ctx.session.sessionUser.is_admin ? ctx.helper._.map(allPayStages, 'id') : null;
+            const allPays = await ctx.service.financialPay.getListByStatus(ctx.subProject.id, allFpsidList, null, 0, filterTids);
             for (const t of tenders) {
                 t.category = t.category && t.category !== '' ? JSON.parse(t.category) : null;
                 const tenderPays = ctx.helper._.filter(allPays, { tid: t.id });
@@ -1709,7 +1716,16 @@ module.exports = app => {
                 responseData.data.tenders = hadTender ? await ctx.service.tender.getAllDataByCondition({ where: tenderCondition, columns: ['id', 'name'] }) : [];
                 responseData.data.transferList = tid === null ? await ctx.service.financialTransfer.getAllDataByCondition({ where: { spid: ctx.subProject.id } }) : [];
                 responseData.data.transferTenderList = tid === null ? await ctx.service.financialTransferTender.getAllDataByCondition({ where: { spid: ctx.subProject.id } }) : [];
-                responseData.data.payList = await ctx.service.financialPay.getListByStatus(ctx.subProject.id, null, 0, filterTids);
+                const accountList = await ctx.service.projectAccount.getAllSubProjectAccount(ctx.subProject, ['id', 'account', 'name', 'company', 'company_id', 'role', 'enable', 'is_admin', 'account_group', 'mobile']);
+                const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: ctx.session.sessionProject.id } });
+                const user = accountList.find(item => item.id === ctx.session.sessionUser.accountId) || null;
+                const userCompany = user ? ctx.helper._.find(unitList, { name: user.company }) : null;
+                if (!userCompany) {
+                    throw '请联系管理员添加用户所在单位信息';
+                }
+                const allPayStages = !ctx.session.sessionUser.is_admin ? await ctx.service.financialPayStage.getListByStatus(ctx.subProject.id, null, userCompany ? userCompany.id : 0, null, 0) : null;
+                const allFpsidList = !ctx.session.sessionUser.is_admin ? ctx.helper._.map(allPayStages, 'id') : null;
+                responseData.data.payList = await ctx.service.financialPay.getListByStatus(ctx.subProject.id, allFpsidList, null, 0, filterTids);
                 ctx.body = responseData;
             } catch (err) {
                 this.log(err);

+ 17 - 3
app/service/financial_pay.js

@@ -40,11 +40,18 @@ module.exports = app => {
          * @param {int} hadlimit - 分页
          * @return {object} list - 列表
          */
-        async getListByStatus(spid, fpsid = null, status = 0, tid = null, used = null, hadlimit = 0, sortBy = '', orderBy = '') {
+        async getListByStatus(spid, allfpsid = null, fpsid = null, status = 0, tid = null, used = null, hadlimit = 0, sortBy = '', orderBy = '') {
             let addSql = '';
             if (fpsid !== null) {
                 fpsid = fpsid instanceof Array ? fpsid : [fpsid];
                 addSql += ' AND a.fpsid in (' + this.ctx.helper.getInArrStrSqlFilter(fpsid) + ')';
+            } else if (!this.ctx.session.sessionUser.is_admin && this._.includes([0, 5, 3], status)) {
+                addSql += ` AND (a.id in(SELECT b.fpid FROM ${this.ctx.service.financialPayAudit.tableName} as b WHERE b.spid = '${spid}' AND b.aid = ${this.ctx.session.sessionUser.accountId}) OR a.uid = ${this.ctx.session.sessionUser.accountId}`;
+                if (allfpsid !== null) {
+                    allfpsid = fpsid instanceof Array ? allfpsid : [allfpsid];
+                    addSql += ' OR a.fpsid in (' + this.ctx.helper.getInArrStrSqlFilter(allfpsid) + ')';
+                }
+                addSql += ')';
             }
             if (tid !== null) {
                 if (tid.length === 0) {
@@ -116,11 +123,18 @@ module.exports = app => {
          * @param {int} status - 状态
          * @return {void}
          */
-        async getCountByStatus(spid, fpsid = null, status = 0, tid = null, used = null, company_id = null, user_company_id, qi = null) {
+        async getCountByStatus(spid, allfpsid = null, fpsid = null, status = 0, tid = null, used = null) {
             let addSql = '';
             if (fpsid !== null) {
                 fpsid = fpsid instanceof Array ? fpsid : [fpsid];
                 addSql += ' AND a.fpsid in (' + this.ctx.helper.getInArrStrSqlFilter(fpsid) + ')';
+            } else if (!this.ctx.session.sessionUser.is_admin && this._.includes([0, 5, 3], status)) {
+                addSql += ` AND (a.id in(SELECT b.fpid FROM ${this.ctx.service.financialPayAudit.tableName} as b WHERE b.spid = '${spid}' AND b.aid = ${this.ctx.session.sessionUser.accountId}) OR a.uid = ${this.ctx.session.sessionUser.accountId}`;
+                if (allfpsid !== null) {
+                    allfpsid = fpsid instanceof Array ? allfpsid : [allfpsid];
+                    addSql += ' OR a.fpsid in (' + this.ctx.helper.getInArrStrSqlFilter(allfpsid) + ')';
+                }
+                addSql += ')';
             }
             if (tid !== null) {
                 if (tid.length === 0) {
@@ -179,7 +193,7 @@ module.exports = app => {
                 addSql += ' AND a.fpsid = ' + fpsid;
             }
             if (!this.ctx.session.sessionUser.is_admin) {
-                notAdminSql += 'a.tid in (SELECT tid FROM ' + this.ctx.service.financialPayAudit.tableName + ' WHERE aid = ' + this.ctx.session.sessionUser.accountId + (fpsid ? ' AND fpsid = ' + fpsid : '') + ' GROUP BY tid)';
+                notAdminSql += 'a.tid in (SELECT tid FROM ' + this.ctx.service.financialPayAudit.tableName + ' WHERE spid = "' + spid + '" AND aid = ' + this.ctx.session.sessionUser.accountId + (fpsid ? ' AND fpsid = ' + fpsid : '') + ' GROUP BY tid)';
                 addSql += ' AND (a.uid = ' + uid + ' OR ' + notAdminSql + ')';
             }
             const sql = 'SELECT a.tid, t.name FROM ?? As a LEFT JOIN ?? As t ON a.tid = t.id' +

+ 5 - 4
app/service/shenpi_audit.js

@@ -28,7 +28,7 @@ module.exports = app => {
         async getShenpi(tid, info) {
             const spConst = this._.cloneDeep(shenpiConst);
             for (const sp of spConst.sp_lc) {
-                sp.status = info.shenpi ? info.shenpi[sp.code] : shenpiConst.sp_status.sqspr;
+                sp.status = info.shenpi && info.shenpi[sp.code] ? info.shenpi[sp.code] : shenpiConst.sp_status.sqspr;
                 if (sp.status === shenpiConst.sp_status.gdspl) {
                     sp.groupList = await this.ctx.service.shenpiGroup.getGroupList(tid, sp.type) || [];
                     if (sp.groupList && sp.groupList.length > 0) {
@@ -477,12 +477,13 @@ module.exports = app => {
 
         async getRemoveTenders(tenders) {
             const removeTenders = [];
+            const shenpiInfos = await this.ctx.service.tenderInfo.getAllTenderShenpiInfo(this._.map(tenders, 'id'));
             for (const tender of tenders) {
-                const shenpiInfo = await this.ctx.service.tenderInfo.getTenderShenpiInfo(tender.id);
-                if (!shenpiInfo) {
+                const tenderInfo = this._.find(shenpiInfos, { tid: tender.id });
+                if (!tenderInfo) {
                     removeTenders.push(tender.id);
                 } else {
-                    tender.shenpiInfo = shenpiInfo;
+                    tender.shenpiInfo = tenderInfo.shenpiInfo;
                     // 获取所有的固定审批流或固定终审
                     const shenpiauditList = {};
                     for (const shenpi in tender.shenpiInfo) {

+ 30 - 2
app/service/tender_info.js

@@ -11,6 +11,7 @@
 const infoConst = require('../const/tender_info');
 const parseInfo = infoConst.parseInfo;
 const arrayInfo = infoConst.arrayInfo;
+const spDefaultInfo = infoConst.defaultInfo.shenpi;
 const advanceConst = require('../const/audit').advance;
 const auditConst = require('../const/audit');
 const measureType = require('../const/tender').measureType;
@@ -494,13 +495,13 @@ module.exports = app => {
          * @return {Promise<void>}
          */
         async getTenderShenpiInfo(tenderId) {
-            const defaultInfo = await this.getDefaultInfo(tenderId);
+            // const defaultInfo = await this.getDefaultInfo(tenderId);
             const info = await this.getDataByCondition({ tid: tenderId });
             // 还没选择模式的标段不应该可以选择审批流程设置
             if (!info) {
                 return false;
             }
-            const defaultShenpiInfo = JSON.parse(JSON.stringify(defaultInfo.shenpi));
+            const defaultShenpiInfo = JSON.parse(JSON.stringify(spDefaultInfo));
             const shenpiInfo = !info.shenpi || info.shenpi === null || info.shenpi === '' ? defaultShenpiInfo : JSON.parse(info.shenpi);
             // 查漏补缺
             for (const sp in defaultShenpiInfo) {
@@ -512,6 +513,33 @@ module.exports = app => {
         }
 
         /**
+         * 获取标段审批相关信息 (审批设置用)
+         * @param tenderId
+         * @return {Promise<void>}
+         */
+        async getAllTenderShenpiInfo(tenderIds) {
+            // const defaultInfo = await this.getDefaultInfo(tenderId);
+            const infos = await this.getAllDataByCondition({ columns: ['tid', 'shenpi'], where: { tid: tenderIds } });
+            const shenpiInfos = [];
+            if (!infos || infos.length === 0) return shenpiInfos;
+            for (const info of infos) {
+                const defaultShenpiInfo = JSON.parse(JSON.stringify(spDefaultInfo));
+                const shenpiInfo = !info.shenpi || info.shenpi === null || info.shenpi === '' ? defaultShenpiInfo : JSON.parse(info.shenpi);
+                // 查漏补缺
+                for (const sp in defaultShenpiInfo) {
+                    if (!shenpiInfo[sp]) {
+                        shenpiInfo[sp] = defaultShenpiInfo[sp];
+                    }
+                }
+                shenpiInfos.push({
+                    tid: info.tid,
+                    shenpiInfo,
+                });
+            }
+            return shenpiInfos;
+        }
+
+        /**
          * 拷贝标段数据至当前标段
          * @param {number} id - 当前标段id
          * @param {number} copy_id - 被拷贝的标段id

+ 2 - 2
app/view/dashboard/index.ejs

@@ -297,7 +297,7 @@
                                         <% for (const af of auditFinancials) { %>
                                             <tr data-type="11">
                                                 <td><span class="bg-new-financial text-new-financial badge text-width">资金支付</span></td>
-                                                <td><a href="/sp/<%- af.spid %>/financial/pay"><%- af.name %></a> <a href="/sp/<%- af.spid %>/financial/pay/<%- af.fpid %>/detail"><%- af.fpcode %></a></td>
+                                                <td><a href="/sp/<%- af.spid %>/financial/pay/stage" class="account-page-size"><%- af.name %></a> <a href="/sp/<%- af.spid %>/financial/pay/<%- af.fpid %>/detail"><%- af.fpcode %></a></td>
                                                 <td>支付</td>
                                                 <td><%- (
                                                             af.fpcstatus !== acFinancial.status.checkNo
@@ -526,7 +526,7 @@
                                             <% } else if(notice.type === pushType.financial && ctx.subProject.page_show.openFinancial) { %>
                                                 <tr data-type="11">
                                                     <td><span class="bg-new-financial text-new-financial badge text-width">资金支付</span></td>
-                                                    <td><a href="/sp/<%- notice.spid %>/financial/pay"><%- notice.name %></a> <a href="/sp/<%- notice.spid %>/financial/pay/<%- notice.fpid %>/detail"><%- notice.code %></a></td>
+                                                    <td><a href="/sp/<%- notice.spid %>/financial/pay/stage" class="account-page-size"><%- notice.name %></a> <a href="/sp/<%- notice.spid %>/financial/pay/<%- notice.fpid %>/detail"><%- notice.code %></a></td>
                                                     <td><%- notice.su_name %><%- (notice.su_role ? '-' + notice.su_role : '') %></td>
                                                     <td><%- ctx.helper.dateTran(notice.create_time, 'YYYY/MM/DD HH:mm') %></td>
                                                     <td>支付</td>

+ 1 - 1
app/view/financial/pay_tender.ejs

@@ -6,7 +6,7 @@
             <div class="col-11 pl-0">
                 <div class="btn-group group-tab">
                     <a class="btn btn-sm btn-light account-page-size" href="/sp/<%- ctx.subProject.id %>/financial/pay/stage">支付列表</a>
-                    <a class="btn btn-sm btn-light" href="/sp/<%- ctx.subProject.id %>/financial/pay/list">汇总列表</a>
+                    <a class="btn btn-sm btn-light account-page-size" href="/sp/<%- ctx.subProject.id %>/financial/pay/list">汇总列表</a>
                     <a class="btn btn-sm btn-light active" href="javascript:void(0);">标段统计</a>
                 </div>
             </div>