Ver código fonte

修复资金监管bug

ellisran 2 semanas atrás
pai
commit
a26c3ac551
2 arquivos alterados com 30 adições e 27 exclusões
  1. 24 23
      app/controller/financial_controller.js
  2. 6 4
      app/service/financial_pay.js

+ 24 - 23
app/controller/financial_controller.js

@@ -822,7 +822,7 @@ module.exports = app => {
             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 userTenderList = await ctx.service.financialPay.getUserTenderList(ctx.subProject.id, ctx.session.sessionUser.accountId, null, payStage.id);
             const total = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, null, payStage.id, status, filterTids, used);
             // 分页相关
             const page = ctx.page;
@@ -1028,8 +1028,6 @@ module.exports = app => {
             const companyInfo = company ? ctx.helper._.find(unitList, { name: company }) : null;
             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);
@@ -1037,6 +1035,8 @@ module.exports = app => {
             }
             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 userTenderList = await ctx.service.financialPay.getUserTenderList(ctx.subProject.id, ctx.session.sessionUser.accountId, allFpsidList);
+            const filterTids = tid === null ? (ctx.session.sessionUser.is_admin ? null : userTenderList.length > 0 ? ctx.helper._.map(userTenderList, 'tid') : []) : [tid];
             // 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 = [];
@@ -1162,7 +1162,15 @@ 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 userTenderList = await ctx.service.financialPay.getUserTenderList(ctx.subProject.id, ctx.session.sessionUser.accountId);
+            const accountList = await ctx.service.projectAccount.getAllSubProjectAccount(ctx.subProject, ['id', 'account', 'name', 'company', 'company_id', 'role', 'enable', 'is_admin', 'account_group', 'mobile']);
+            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 = await ctx.service.financialPayStage.getListByStatus(ctx.subProject.id, null, userCompany ? userCompany.id : 0, null, 0);
+            const allFpsidList = !ctx.session.sessionUser.is_admin ? ctx.helper._.map(allPayStages, 'id') : null;
+            const userTenderList = await ctx.service.financialPay.getUserTenderList(ctx.subProject.id, ctx.session.sessionUser.accountId, allFpsidList);
             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 };
@@ -1187,15 +1195,6 @@ module.exports = app => {
                 transfersCondition.tid = filterTids;
             }
             const allTransfers = !notTids ? await ctx.service.financialTransferTender.getAllDataByCondition({ where: transfersCondition }) : [];
-            const accountList = await ctx.service.projectAccount.getAllSubProjectAccount(ctx.subProject, ['id', 'account', 'name', 'company', 'company_id', 'role', 'enable', 'is_admin', 'account_group', 'mobile']);
-            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 = 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;
@@ -1705,7 +1704,18 @@ module.exports = app => {
                 const tid = parseInt(ctx.query.tid) || null;
                 const fptAudits = await ctx.service.financialPayTenderAudit.getAllDataByCondition({ where: { spid: ctx.subProject.id, uid: ctx.session.sessionUser.accountId } });
                 const fptAuditTids = ctx.helper._.map(fptAudits, 'tid');
-                const filterTids = tid === null ? (ctx.session.sessionUser.is_admin ? null : fptAuditTids) : [tid];
+                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;
+                const userTenderList = await ctx.service.financialPay.getUserTenderList(ctx.subProject.id, ctx.session.sessionUser.accountId, allFpsidList);
+                const filterTids = tid === null ? (ctx.session.sessionUser.is_admin ? null : userTenderList.length > 0 ? ctx.helper._.map(userTenderList, 'tid') : []) : [tid];
+                // const filterTids = tid === null ? (ctx.session.sessionUser.is_admin ? null : fptAuditTids) : [tid];
                 const tenderCondition = { spid: ctx.subProject.id };
                 let hadTender = false;
                 if (ctx.session.sessionUser.is_admin) {
@@ -1720,15 +1730,6 @@ 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 } }) : [];
-                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) {

+ 6 - 4
app/service/financial_pay.js

@@ -49,13 +49,11 @@ module.exports = app => {
                 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 = allfpsid instanceof Array ? allfpsid : [allfpsid];
-                    console.log('allfpsid', allfpsid);
                     addSql += allfpsid.length > 0 ? ' OR a.fpsid in (' + this.ctx.helper.getInArrStrSqlFilter(allfpsid) + ')' : '';
                 }
                 addSql += ')';
             }
             if (tid !== null) {
-                console.log(tid);
                 if (tid.length === 0) {
                     return [];
                 }
@@ -188,14 +186,18 @@ module.exports = app => {
             }
         }
 
-        async getUserTenderList(spid, uid, fpsid = null) {
+        async getUserTenderList(spid, uid, allFpsidList, fpsid = null) {
             let addSql = '';
             let notAdminSql = '';
             if (fpsid) {
                 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 spid = "' + spid + '" AND 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)';
+                if (!fpsid && allFpsidList && allFpsidList.length > 0) {
+                    notAdminSql += ' OR a.tid in (SELECT tid FROM ' + this.tableName + ' WHERE spid = "' + spid + '" AND fpsid in (' + this.ctx.helper.getInArrStrSqlFilter(allFpsidList) + ') GROUP BY tid)';
+                }
+                notAdminSql += ')';
                 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' +