Browse Source

子项目待办页调整

ellisran 2 months ago
parent
commit
a3dd115664

+ 32 - 32
app/controller/dashboard_controller.js

@@ -28,18 +28,18 @@ module.exports = app => {
          * @return {void}
          */
         async index(ctx) {
-            const auditTenders = await ctx.service.ledgerAudit.getAuditTender(ctx.session.sessionUser.accountId);
-            const auditStages = await ctx.service.stageAudit.getAuditStage(ctx.session.sessionUser.accountId);
-            const auditChanges = await ctx.service.changeAudit.getAuditChange(ctx.session.sessionUser.accountId);
-            const auditRevise = await ctx.service.reviseAudit.getAuditRevise(ctx.session.sessionUser.accountId);
-            const auditMaterial = ctx.subProject.page_show.openMaterial ? await ctx.service.materialAudit.getAuditMaterial(ctx.session.sessionUser.accountId) : [];
-            const auditAdvance = await ctx.service.advanceAudit.getAuditAdvance(ctx.session.sessionUser.accountId);
-            const auditChangeProject = ctx.subProject.page_show.openChangeProject ? await ctx.service.changeProjectAudit.getAuditChangeProject(ctx.session.sessionUser.accountId) : [];
-            const auditChangeApply = ctx.subProject.page_show.openChangeApply ? await ctx.service.changeApplyAudit.getAuditChangeApply(ctx.session.sessionUser.accountId) : [];
-            const auditChangePlan = ctx.subProject.page_show.openChangePlan ? await ctx.service.changePlanAudit.getAuditChangePlan(ctx.session.sessionUser.accountId) : [];
-            const auditPayments = ctx.subProject.page_show.openPayment ? await ctx.service.paymentDetailAudit.getAuditPayment(ctx.session.sessionUser.accountId) : [];
-            const auditStageAss = await ctx.service.stageAuditAss.getAuditStageAss(ctx.session.sessionUser.accountId);
-            const auditFinancials = ctx.subProject.page_show.openFinancial ? await ctx.service.financialPayAudit.getAuditFinancial(ctx.session.sessionUser.accountId) : [];
+            const auditTenders = await ctx.service.ledgerAudit.getAuditTender(ctx.session.sessionUser.accountId, ctx.subProject.id);
+            const auditStages = await ctx.service.stageAudit.getAuditStage(ctx.session.sessionUser.accountId, ctx.subProject.id);
+            const auditChanges = await ctx.service.changeAudit.getAuditChange(ctx.session.sessionUser.accountId, ctx.subProject.id);
+            const auditRevise = await ctx.service.reviseAudit.getAuditRevise(ctx.session.sessionUser.accountId, ctx.subProject.id);
+            const auditMaterial = ctx.subProject.page_show.openMaterial ? await ctx.service.materialAudit.getAuditMaterial(ctx.session.sessionUser.accountId, ctx.subProject.id) : [];
+            const auditAdvance = await ctx.service.advanceAudit.getAuditAdvance(ctx.session.sessionUser.accountId, ctx.subProject.id);
+            const auditChangeProject = ctx.subProject.page_show.openChangeProject ? await ctx.service.changeProjectAudit.getAuditChangeProject(ctx.session.sessionUser.accountId, ctx.subProject.id) : [];
+            const auditChangeApply = ctx.subProject.page_show.openChangeApply ? await ctx.service.changeApplyAudit.getAuditChangeApply(ctx.session.sessionUser.accountId, ctx.subProject.id) : [];
+            const auditChangePlan = ctx.subProject.page_show.openChangePlan ? await ctx.service.changePlanAudit.getAuditChangePlan(ctx.session.sessionUser.accountId, ctx.subProject.id) : [];
+            const auditPayments = ctx.subProject.page_show.openPayment ? await ctx.service.paymentDetailAudit.getAuditPayment(ctx.session.sessionUser.accountId, ctx.subProject.id) : [];
+            const auditStageAss = await ctx.service.stageAuditAss.getAuditStageAss(ctx.session.sessionUser.accountId, ctx.subProject.id);
+            const auditFinancials = ctx.subProject.page_show.openFinancial ? await ctx.service.financialPayAudit.getAuditFinancial(ctx.session.sessionUser.accountId, ctx.subProject.id) : [];
             const pa = await ctx.service.projectAccount.getDataById(ctx.session.sessionUser.accountId);
             const noticeList = await ctx.service.noticePush.getNotice(ctx.session.sessionProject.id, pa.id);
             const projectData = await ctx.service.project.getDataById(ctx.session.sessionProject.id);
@@ -58,30 +58,30 @@ module.exports = app => {
             const maintainData = await ctx.service.maintain.getDataById(1);
             // 获取各个审批的次数及最后的审批时间
             const shenpi_count = [
-                { count: await ctx.service.advanceAudit.getCountByChecked(ctx.session.sessionUser.accountId), name: '预付款' },
-                { count: await ctx.service.ledgerAudit.getCountByChecked(ctx.session.sessionUser.accountId), name: '台账审批' },
-                { count: await ctx.service.reviseAudit.getCountByChecked(ctx.session.sessionUser.accountId), name: '台账修订' },
-                { count: await ctx.service.stageAudit.getCountByChecked(ctx.session.sessionUser.accountId), name: '计量审批' },
-                { count: await ctx.service.changeAudit.getCountByChecked(ctx.session.sessionUser.accountId), name: '变更审批' },
+                { count: await ctx.service.advanceAudit.getCountByChecked(ctx.session.sessionUser.accountId, ctx.subProject.id), name: '预付款' },
+                { count: await ctx.service.ledgerAudit.getCountByChecked(ctx.session.sessionUser.accountId, ctx.subProject.id), name: '台账审批' },
+                { count: await ctx.service.reviseAudit.getCountByChecked(ctx.session.sessionUser.accountId, ctx.subProject.id), name: '台账修订' },
+                { count: await ctx.service.stageAudit.getCountByChecked(ctx.session.sessionUser.accountId, ctx.subProject.id), name: '计量审批' },
+                { count: await ctx.service.changeAudit.getCountByChecked(ctx.session.sessionUser.accountId, ctx.subProject.id), name: '变更审批' },
             ];
-            if (ctx.subProject.page_show.openChangeProject) shenpi_count.push({ count: await ctx.service.changeProjectAudit.getCountByChecked(ctx.session.sessionUser.accountId), name: '变更立项' });
-            if (ctx.subProject.page_show.openChangeApply) shenpi_count.push({ count: await ctx.service.changeApplyAudit.getCountByChecked(ctx.session.sessionUser.accountId), name: '变更申请' });
-            if (ctx.subProject.page_show.openChangePlan) shenpi_count.push({ count: await ctx.service.changePlanAudit.getCountByChecked(ctx.session.sessionUser.accountId), name: '变更方案' });
-            if (ctx.subProject.page_show.openMaterial) shenpi_count.push({ count: await ctx.service.materialAudit.getCountByChecked(ctx.session.sessionUser.accountId), name: '材料调差' });
-            if (ctx.subProject.page_show.openFinancial) shenpi_count.push({ count: await ctx.service.financialPayAudit.getCountByChecked(ctx.session.sessionUser.accountId), name: '资金支付' });
+            if (ctx.subProject.page_show.openChangeProject) shenpi_count.push({ count: await ctx.service.changeProjectAudit.getCountByChecked(ctx.session.sessionUser.accountId, ctx.subProject.id), name: '变更立项' });
+            if (ctx.subProject.page_show.openChangeApply) shenpi_count.push({ count: await ctx.service.changeApplyAudit.getCountByChecked(ctx.session.sessionUser.accountId, ctx.subProject.id), name: '变更申请' });
+            if (ctx.subProject.page_show.openChangePlan) shenpi_count.push({ count: await ctx.service.changePlanAudit.getCountByChecked(ctx.session.sessionUser.accountId, ctx.subProject.id), name: '变更方案' });
+            if (ctx.subProject.page_show.openMaterial) shenpi_count.push({ count: await ctx.service.materialAudit.getCountByChecked(ctx.session.sessionUser.accountId, ctx.subProject.id), name: '材料调差' });
+            if (ctx.subProject.page_show.openFinancial) shenpi_count.push({ count: await ctx.service.financialPayAudit.getCountByChecked(ctx.session.sessionUser.accountId, ctx.subProject.id), name: '资金支付' });
             // shenpi_count.push({ count: await ctx.service.advanceAudit.getCountByChecked(ctx.session.sessionUser.accountId), name: '预付款' });
             const total_count = ctx.app._.sumBy(shenpi_count, 'count');
             const shenpi_lastime = [
-                await ctx.service.advanceAudit.getLastEndTimeByChecked(ctx.session.sessionUser.accountId),
-                await ctx.service.ledgerAudit.getLastEndTimeByChecked(ctx.session.sessionUser.accountId),
-                await ctx.service.reviseAudit.getLastEndTimeByChecked(ctx.session.sessionUser.accountId),
-                await ctx.service.stageAudit.getLastEndTimeByChecked(ctx.session.sessionUser.accountId),
-                await ctx.service.changeAudit.getLastEndTimeByChecked(ctx.session.sessionUser.accountId),
-                ctx.subProject.page_show.openChangeProject ? await ctx.service.changeProjectAudit.getLastEndTimeByChecked(ctx.session.sessionUser.accountId) : null,
-                ctx.subProject.page_show.openChangeApply ? await ctx.service.changeApplyAudit.getLastEndTimeByChecked(ctx.session.sessionUser.accountId) : null,
-                ctx.subProject.page_show.openChangePlan ? await ctx.service.changePlanAudit.getLastEndTimeByChecked(ctx.session.sessionUser.accountId) : null,
-                ctx.subProject.page_show.openMaterial ? await ctx.service.materialAudit.getLastEndTimeByChecked(ctx.session.sessionUser.accountId) : null,
-                ctx.subProject.page_show.openFinancial ? await ctx.service.financialPayAudit.getLastEndTimeByChecked(ctx.session.sessionUser.accountId) : null,
+                await ctx.service.advanceAudit.getLastEndTimeByChecked(ctx.session.sessionUser.accountId, ctx.subProject.id),
+                await ctx.service.ledgerAudit.getLastEndTimeByChecked(ctx.session.sessionUser.accountId, ctx.subProject.id),
+                await ctx.service.reviseAudit.getLastEndTimeByChecked(ctx.session.sessionUser.accountId, ctx.subProject.id),
+                await ctx.service.stageAudit.getLastEndTimeByChecked(ctx.session.sessionUser.accountId, ctx.subProject.id),
+                await ctx.service.changeAudit.getLastEndTimeByChecked(ctx.session.sessionUser.accountId, ctx.subProject.id),
+                ctx.subProject.page_show.openChangeProject ? await ctx.service.changeProjectAudit.getLastEndTimeByChecked(ctx.session.sessionUser.accountId, ctx.subProject.id) : null,
+                ctx.subProject.page_show.openChangeApply ? await ctx.service.changeApplyAudit.getLastEndTimeByChecked(ctx.session.sessionUser.accountId, ctx.subProject.id) : null,
+                ctx.subProject.page_show.openChangePlan ? await ctx.service.changePlanAudit.getLastEndTimeByChecked(ctx.session.sessionUser.accountId, ctx.subProject.id) : null,
+                ctx.subProject.page_show.openMaterial ? await ctx.service.materialAudit.getLastEndTimeByChecked(ctx.session.sessionUser.accountId, ctx.subProject.id) : null,
+                ctx.subProject.page_show.openFinancial ? await ctx.service.financialPayAudit.getLastEndTimeByChecked(ctx.session.sessionUser.accountId, ctx.subProject.id) : null,
             ];
             const last_time = ctx.app._.max(shenpi_lastime);
             // console.log(ctx.app._.max(shenpi_lastime), ctx.helper.calcDayNum(last_time));

+ 20 - 9
app/service/advance_audit.js

@@ -675,13 +675,16 @@ module.exports = app => {
          * 获取待处理审核列表
          * @param {Number} auditorId 审核人id
          */
-        async getAuditAdvance(auditorId) {
+        async getAuditAdvance(auditorId, spid = '') {
+            const spSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
             const sql = 'SELECT ma.`audit_id`, ma.`times`, ma.`order`, ma.`create_time`, ma.`end_time`, ma.`tid`, ma.`vid`,' +
                         '    m.`order` As `morder`, m.`status` As `mstatus`, m.`type` As `mtype`,' +
                         '    t.`name`, t.`project_id`, t.`type`, t.`user_id` ' +
-                        '  FROM ?? AS ma, ?? AS m, ?? As t ' +
-                        '  WHERE ((ma.`audit_id` = ? and ma.`status` = ?) OR (m.`uid` = ? and ma.`status` = ? and m.`status` = ? and ma.`times` = (m.`times`-1)))' +
-                        '    and ma.`vid` = m.`id` and ma.`tid` = t.`id` ORDER BY ma.`create_time` DESC';
+                        '  FROM ?? AS ma' +
+                        '  LEFT JOIN ?? AS m On ma.vid = m.id' +
+                        '  LEFT JOIN ?? As t On m.tid = t.id' +
+                        '  WHERE ((ma.`audit_id` = ? and ma.`status` = ?) OR (m.`uid` = ? and ma.`status` = ? and m.`status` = ? and ma.`times` = (m.`times`-1)))' + spSql +
+                        '  ORDER BY ma.`create_time` DESC';
             const sqlParam = [this.tableName, this.ctx.service.advance.tableName, this.ctx.service.tender.tableName, auditorId, auditConst.status.checking, auditorId, auditConst.status.checkNo, auditConst.status.checkNo];
             return await this.db.query(sql, sqlParam);
         }
@@ -704,7 +707,13 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getCountByChecked(auditorId) {
+        async getCountByChecked(auditorId, spid = '') {
+            if (spid) {
+                const sql = 'SELECT count(*) AS count FROM ?? AS a LEFT JOIN ?? AS t ON a.tid = t.id WHERE a.`audit_id` = ? AND a.`status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo, auditConst.status.checkNoPre]) + ') AND t.`spid` = ?';
+                const sqlParam = [this.tableName, this.ctx.service.tender.tableName, auditorId, spid];
+                const result = await this.db.queryOne(sql, sqlParam);
+                return result.count ? result.count : 0;
+            }
             return await this.db.count(this.tableName, { audit_id: auditorId, status: [auditConst.status.checked, auditConst.status.checkNo, auditConst.status.checkNoPre] });
         }
 
@@ -714,10 +723,12 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getLastEndTimeByChecked(auditorId) {
-            const sql = 'SELECT `end_time` FROM ?? WHERE `audit_id` = ? ' +
-                'AND `status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo]) + ') ORDER BY `end_time` DESC';
-            const sqlParam = [this.tableName, auditorId];
+        async getLastEndTimeByChecked(auditorId, spid = '') {
+            const sqSql = spid ? ' AND t.`spid` = "' + spid + '"' : '';
+            const sql = 'SELECT a.`end_time` FROM ?? AS a LEFT JOIN ?? AS t ON a.`tid` = t.`id` WHERE a.`audit_id` = ? ' +
+                'AND a.`status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo]) + ')' + sqSql +
+                ' ORDER BY a.`end_time` DESC';
+            const sqlParam = [this.tableName, this.ctx.service.tender.tableName, auditorId];
             const result = await this.db.queryOne(sql, sqlParam);
             return result ? result.end_time : null;
         }

+ 16 - 7
app/service/change_apply_audit.js

@@ -390,12 +390,13 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getAuditChangeApply(auditorId) {
+        async getAuditChangeApply(auditorId, spid = '') {
+            const spSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
             const sql = 'SELECT ma.`aid`, ma.`times`, ma.`order`, ma.`begin_time`, ma.`end_time`, ma.`tid`, ma.`caid`,' +
                 '    m.`status` As `mstatus`, m.`code` As `mcode`,' +
                 '    t.`name`, t.`project_id`, t.`type`, t.`user_id` ' +
                 '  FROM ?? AS ma LEFT JOIN ?? AS m ON  ma.`caid` = m.`id` LEFT JOIN ?? As t ON ma.`tid` = t.`id`' +
-                '  WHERE ((ma.`aid` = ? and ma.`status` = ?) OR (m.`uid` = ? and ma.`status` = ? and m.`status` = ? and ma.`times` = (m.`times`-1)))' +
+                '  WHERE ((ma.`aid` = ? and ma.`status` = ?) OR (m.`uid` = ? and ma.`status` = ? and m.`status` = ? and ma.`times` = (m.`times`-1)))' + spSql +
                 '  ORDER BY ma.`begin_time` DESC';
             const sqlParam = [this.tableName, this.ctx.service.changeApply.tableName, this.ctx.service.tender.tableName, auditorId, auditConst.status.checking, auditorId, auditConst.status.checkNo, auditConst.status.checkNo];
             const result = await this.db.query(sql, sqlParam);
@@ -417,7 +418,13 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getCountByChecked(auditorId) {
+        async getCountByChecked(auditorId, spid = '') {
+            if (spid) {
+                const sql = 'SELECT count(*) AS count FROM ?? AS a LEFT JOIN ?? AS t ON a.tid = t.id WHERE a.`aid` = ? AND a.`status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo]) + ') AND t.`spid` = ?';
+                const sqlParam = [this.tableName, this.ctx.service.tender.tableName, auditorId, spid];
+                const result = await this.db.queryOne(sql, sqlParam);
+                return result.count ? result.count : 0;
+            }
             return await this.db.count(this.tableName, { aid: auditorId, status: [auditConst.status.checked, auditConst.status.checkNo] });
         }
 
@@ -427,10 +434,12 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getLastEndTimeByChecked(auditorId) {
-            const sql = 'SELECT `end_time` FROM ?? WHERE `aid` = ? ' +
-                'AND `status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo]) + ') ORDER BY `end_time` DESC';
-            const sqlParam = [this.tableName, auditorId];
+        async getLastEndTimeByChecked(auditorId, spid = '') {
+            const sqSql = spid ? ' AND t.`spid` = "' + spid + '"' : '';
+            const sql = 'SELECT a.`end_time` FROM ?? AS a LEFT JOIN ?? AS t ON a.`tid` = t.`id` WHERE a.`aid` = ? ' +
+                'AND a.`status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo]) + ')' + sqSql +
+                ' ORDER BY a.`end_time` DESC';
+            const sqlParam = [this.tableName, this.ctx.service.tender.tableName, auditorId];
             const result = await this.db.queryOne(sql, sqlParam);
             return result ? result.end_time : null;
         }

+ 13 - 9
app/service/change_audit.js

@@ -217,19 +217,20 @@ module.exports = app => {
          * @param uid
          * @return {Promise<void>}
          */
-        async getAuditChange(uid) {
+        async getAuditChange(uid, spid = '') {
             // const sql = 'SELECT ca.`uid`, ca.`times`, ca.`usite`, ca.`usort`, ca.`tid`, ca.`cid`, ca.`begin_time`, ca.`end_time`, ca.`sin_time`, ca.`name` As `caname`, ' +
             //     '    c.`code` As `ccode`, c.`name` As `cname`, c.`status` As `cstatus`, c.`cin_time`, ' +
             //     '    t.`name`, t.`type`, t.`user_id` ' +
             //     '  FROM ?? AS ca, ?? AS c, ?? As t ' +
             //     '  WHERE ca.`uid` = ? and ca.`status` = ? and c.`status` != ?' +
             //     '    and ca.`cid` = c.`cid` and ca.`tid` = t.`id` ORDER BY ca.`sin_time` DESC';
+            const spSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
             const sql = 'SELECT ca.`uid`, ca.`times`, ca.`usite`, ca.`usort`, ca.`tid`, ca.`cid`, ca.`begin_time`, ca.`end_time`, ca.`sin_time`, ca.`name` As `caname`, ' +
                 '    c.`code` As `ccode`, c.`name` As `cname`, c.`status` As `cstatus`, c.`cin_time`, ' +
                 '    t.`name`, t.`type`, t.`user_id` ' +
                 '  FROM ?? AS ca LEFT JOIN ?? AS c ON ca.`cid` = c.`cid` ' +
                 '    LEFT JOIN ?? As t ON ca.`tid` = t.`id` ' +
-                '  WHERE ca.`uid` = ? and ca.`status` = ? and c.`status` != ?' +
+                '  WHERE ca.`uid` = ? and ca.`status` = ? and c.`status` != ?' + spSql +
                 '  ORDER BY ca.`begin_time` DESC';
             const sqlParam = [this.tableName, this.ctx.service.change.tableName, this.ctx.service.tender.tableName, uid, auditConst.status.checking, auditConst.status.uncheck];
             const changes = await this.db.query(sql, sqlParam);
@@ -255,9 +256,10 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getCountByChecked(auditorId) {
-            const sql = 'Select count(*) as count FROM ?? WHERE uid = ? AND usite != 0 AND status in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo, auditConst.status.checkNoPre]) +')';
-            const sqlParam = [this.tableName, auditorId];
+        async getCountByChecked(auditorId, spid = '') {
+            const sqSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
+            const sql = 'Select count(*) as count FROM ?? AS ca LEFT JOIN ?? AS t ON ca.`tid` = t.`id` WHERE ca.`uid` = ? AND ca.`usite` != 0 AND ca.`status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo, auditConst.status.checkNoPre]) +')' + sqSql;
+            const sqlParam = [this.tableName, this.ctx.service.tender.tableName, auditorId];
             const result = await this.db.queryOne(sql, sqlParam);
             return result.count ? result.count : 0;
             // return await this.db.count(this.tableName, { aid: auditorId, status: [auditConst.status.checked, auditConst.status.checkNo] });
@@ -269,10 +271,12 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getLastEndTimeByChecked(auditorId) {
-            const sql = 'SELECT `sin_time` FROM ?? WHERE `uid` = ? AND usite != 0 ' +
-                'AND `status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo, auditConst.status.checkNoPre]) + ') ORDER BY `sin_time` DESC';
-            const sqlParam = [this.tableName, auditorId];
+        async getLastEndTimeByChecked(auditorId, spid = '') {
+            const sqSql = spid ? ' AND t.`spid` = "' + spid + '"' : '';
+            const sql = 'SELECT a.`sin_time` FROM ?? AS a LEFT JOIN ?? AS t ON a.`tid` = t.`id` WHERE a.`uid` = ? ' +
+                'AND a.`status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo, auditConst.status.checkNoPre]) + ')' + sqSql +
+                ' ORDER BY a.`sin_time` DESC';
+            const sqlParam = [this.tableName, this.ctx.service.tender.tableName, auditorId];
             const result = await this.db.queryOne(sql, sqlParam);
             return result ? result.sin_time : null;
         }

+ 16 - 7
app/service/change_plan_audit.js

@@ -388,12 +388,13 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getAuditChangePlan(auditorId) {
+        async getAuditChangePlan(auditorId, spid = '') {
+            const spSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
             const sql = 'SELECT ma.`aid`, ma.`times`, ma.`order`, ma.`begin_time`, ma.`end_time`, ma.`tid`, ma.`cpid`,' +
                 '    m.`status` As `mstatus`, m.`code` As `mcode`,' +
                 '    t.`name`, t.`project_id`, t.`type`, t.`user_id` ' +
                 '  FROM ?? AS ma LEFT JOIN ?? AS m ON  ma.`cpid` = m.`id` LEFT JOIN ?? As t ON ma.`tid` = t.`id`' +
-                '  WHERE ((ma.`aid` = ? and ma.`status` = ?) OR (m.`uid` = ? and ma.`status` = ? and m.`status` = ? and ma.`times` = (m.`times`-1)))' +
+                '  WHERE ((ma.`aid` = ? and ma.`status` = ?) OR (m.`uid` = ? and ma.`status` = ? and m.`status` = ? and ma.`times` = (m.`times`-1)))' + spSql +
                 '  ORDER BY ma.`begin_time` DESC';
             const sqlParam = [this.tableName, this.ctx.service.changePlan.tableName, this.ctx.service.tender.tableName, auditorId, auditConst.status.checking, auditorId, auditConst.status.checkNo, auditConst.status.checkNo];
             const result = await this.db.query(sql, sqlParam);
@@ -415,7 +416,13 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getCountByChecked(auditorId) {
+        async getCountByChecked(auditorId, spid = '') {
+            if (spid) {
+                const sql = 'SELECT count(*) AS count FROM ?? AS a LEFT JOIN ?? AS t ON a.tid = t.id WHERE a.`aid` = ? AND a.`status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo]) + ') AND t.`spid` = ?';
+                const sqlParam = [this.tableName, this.ctx.service.tender.tableName, auditorId, spid];
+                const result = await this.db.queryOne(sql, sqlParam);
+                return result.count ? result.count : 0;
+            }
             return await this.db.count(this.tableName, { aid: auditorId, status: [auditConst.status.checked, auditConst.status.checkNo] });
         }
 
@@ -425,10 +432,12 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getLastEndTimeByChecked(auditorId) {
-            const sql = 'SELECT `end_time` FROM ?? WHERE `aid` = ? ' +
-                'AND `status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo]) + ') ORDER BY `end_time` DESC';
-            const sqlParam = [this.tableName, auditorId];
+        async getLastEndTimeByChecked(auditorId, spid = '') {
+            const sqSql = spid ? ' AND t.`spid` = "' + spid + '"' : '';
+            const sql = 'SELECT a.`end_time` FROM ?? AS a LEFT JOIN ?? AS t ON a.`tid` = t.`id` WHERE a.`aid` = ? ' +
+                'AND a.`status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo]) + ')' + sqSql +
+                ' ORDER BY a.`end_time` DESC';
+            const sqlParam = [this.tableName, this.ctx.service.tender.tableName, auditorId];
             const result = await this.db.queryOne(sql, sqlParam);
             return result ? result.end_time : null;
         }

+ 16 - 7
app/service/change_project_audit.js

@@ -397,12 +397,13 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getAuditChangeProject(auditorId) {
+        async getAuditChangeProject(auditorId, spid = '') {
+            const spSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
             const sql = 'SELECT ma.`aid`, ma.`times`, ma.`order`, ma.`begin_time`, ma.`end_time`, ma.`tid`, ma.`cpid`,' +
                 '    m.`status` As `mstatus`, m.`code` As `mcode`,' +
                 '    t.`name`, t.`project_id`, t.`type`, t.`user_id` ' +
                 '  FROM ?? AS ma LEFT JOIN ?? AS m ON  ma.`cpid` = m.`id` LEFT JOIN ?? As t ON ma.`tid` = t.`id`' +
-                '  WHERE ((ma.`aid` = ? and ma.`status` = ?) OR (m.`uid` = ? and ma.`status` = ? and m.`status` = ? and ma.`times` = (m.`times`-1)))' +
+                '  WHERE ((ma.`aid` = ? and ma.`status` = ?) OR (m.`uid` = ? and ma.`status` = ? and m.`status` = ? and ma.`times` = (m.`times`-1)))' + spSql +
                 '  ORDER BY ma.`begin_time` DESC';
             const sqlParam = [this.tableName, this.ctx.service.changeProject.tableName, this.ctx.service.tender.tableName, auditorId, auditConst.status.checking, auditorId, auditConst.status.back, auditConst.status.back];
             const result = await this.db.query(sql, sqlParam);
@@ -424,7 +425,13 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getCountByChecked(auditorId) {
+        async getCountByChecked(auditorId, spid = '') {
+            if (spid) {
+                const sql = 'SELECT count(*) AS count FROM ?? AS a LEFT JOIN ?? AS t ON a.tid = t.id WHERE a.`aid` = ? AND a.`status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.back, auditConst.status.checkNo]) + ') AND t.`spid` = ?';
+                const sqlParam = [this.tableName, this.ctx.service.tender.tableName, auditorId, spid];
+                const result = await this.db.queryOne(sql, sqlParam);
+                return result.count ? result.count : 0;
+            }
             return await this.db.count(this.tableName, { aid: auditorId, status: [auditConst.status.checked, auditConst.status.back, auditConst.status.checkNo] });
         }
 
@@ -434,10 +441,12 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getLastEndTimeByChecked(auditorId) {
-            const sql = 'SELECT `end_time` FROM ?? WHERE `aid` = ? ' +
-                'AND `status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.back, auditConst.status.checkNo]) + ') ORDER BY `end_time` DESC';
-            const sqlParam = [this.tableName, auditorId];
+        async getLastEndTimeByChecked(auditorId, spid = '') {
+            const sqSql = spid ? ' AND t.`spid` = "' + spid + '"' : '';
+            const sql = 'SELECT a.`end_time` FROM ?? AS a LEFT JOIN ?? AS t ON a.`tid` = t.`id` WHERE a.`aid` = ? ' +
+                'AND a.`status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.back, auditConst.status.checkNo]) + ')' + sqSql +
+                ' ORDER BY a.`end_time` DESC';
+            const sqlParam = [this.tableName, this.ctx.service.tender.tableName, auditorId];
             const result = await this.db.queryOne(sql, sqlParam);
             return result ? result.end_time : null;
         }

+ 11 - 5
app/service/financial_pay_audit.js

@@ -463,12 +463,13 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getAuditFinancial(auditorId) {
+        async getAuditFinancial(auditorId, spid = '') {
+            const spSql = spid ? ' and ma.`spid` = "' + spid + '"' : '';
             const sql = 'SELECT ma.`aid`, ma.`times`, ma.`order`, ma.`begin_time`, ma.`end_time`, ma.`spid`, ma.`fpid`,' +
                 '    m.`status` As `fpstatus`, m.`code` As `fpcode`,' +
                 '    sp.`name`, sp.`project_id` ' +
                 '  FROM ?? AS ma LEFT JOIN ?? AS m ON  ma.`fpid` = m.`id` LEFT JOIN ?? As sp ON ma.`spid` = sp.`id`' +
-                '  WHERE ((ma.`aid` = ? and ma.`status` = ?) OR (m.`uid` = ? and ma.`status` = ? and m.`status` = ? and ma.`times` = (m.`times`-1)))' +
+                '  WHERE ((ma.`aid` = ? and ma.`status` = ?) OR (m.`uid` = ? and ma.`status` = ? and m.`status` = ? and ma.`times` = (m.`times`-1)))' + spSql +
                 '  ORDER BY ma.`begin_time` DESC';
             const sqlParam = [this.tableName, this.ctx.service.financialPay.tableName, this.ctx.service.subProject.tableName, auditorId, auditConst.status.checking, auditorId, auditConst.status.checkNo, auditConst.status.checkNo];
             const result = await this.db.query(sql, sqlParam);
@@ -490,7 +491,10 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getCountByChecked(auditorId) {
+        async getCountByChecked(auditorId, spid = '') {
+            if (spid) {
+                return await this.db.count(this.tableName, { spid, aid: auditorId, status: [auditConst.status.checked, auditConst.status.checkNo] });
+            }
             return await this.db.count(this.tableName, { aid: auditorId, status: [auditConst.status.checked, auditConst.status.checkNo] });
         }
 
@@ -500,9 +504,11 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getLastEndTimeByChecked(auditorId) {
+        async getLastEndTimeByChecked(auditorId, spid = '') {
+            const spSql = spid ? ' and `spid` = "' + spid + '"' : '';
             const sql = 'SELECT `end_time` FROM ?? WHERE `aid` = ? ' +
-                'AND `status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo]) + ') ORDER BY `end_time` DESC';
+                'AND `status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo]) + ')' + spSql +
+                ' ORDER BY `end_time` DESC';
             const sqlParam = [this.tableName, auditorId];
             const result = await this.db.queryOne(sql, sqlParam);
             return result ? result.end_time : null;

+ 16 - 7
app/service/ledger_audit.js

@@ -840,11 +840,12 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getAuditTender(auditorId) {
+        async getAuditTender(auditorId, spid = '') {
+            const spSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
             const sql =
                 'SELECT la.`audit_id`, la.`times`, la.`audit_order`, la.`begin_time`, la.`end_time`, t.`id`, t.`name`, t.`project_id`, t.`type`, t.`user_id`, t.`ledger_status` ' +
                 '  FROM ?? AS la Left Join ?? AS t ON la.`tender_id` = t.`id` ' +
-                '  WHERE ((la.`audit_id` = ? and la.`status` = ?) OR (t.`user_id` = ? and t.`ledger_status` = ? and la.`status` = ? and la.`times` = (t.`ledger_times`-1)))' +
+                '  WHERE ((la.`audit_id` = ? and la.`status` = ?) OR (t.`user_id` = ? and t.`ledger_status` = ? and la.`status` = ? and la.`times` = (t.`ledger_times`-1)))' + spSql +
                 '    ORDER BY la.`begin_time` DESC';
             const sqlParam = [
                 this.tableName,
@@ -864,7 +865,13 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getCountByChecked(auditorId) {
+        async getCountByChecked(auditorId, spid = '') {
+            if (spid) {
+                const sql = 'SELECT count(*) as count FROM ?? AS la Left Join ?? AS t ON la.`tender_id` = t.`id` WHERE la.`audit_id` = ? AND la.`status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo]) + ') AND t.`spid` = ?';
+                const sqlParam = [this.tableName, this.ctx.service.tender.tableName, auditorId, spid];
+                const result = await this.db.queryOne(sql, sqlParam);
+                return result ? result.count : 0;
+            }
             return await this.db.count(this.tableName, { audit_id: auditorId, status: [auditConst.status.checked, auditConst.status.checkNo] });
         }
 
@@ -874,10 +881,12 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getLastEndTimeByChecked(auditorId) {
-            const sql = 'SELECT `end_time` FROM ?? WHERE `audit_id` = ? ' +
-                'AND `status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo]) + ') ORDER BY `end_time` DESC';
-            const sqlParam = [this.tableName, auditorId];
+        async getLastEndTimeByChecked(auditorId, spid = '') {
+            const sqSql = spid ? ' AND t.`spid` = "' + spid + '"' : '';
+            const sql = 'SELECT a.`end_time` FROM ?? AS a LEFT JOIN ?? AS t ON a.`tender_id` = t.`id` WHERE a.`audit_id` = ? ' +
+                'AND a.`status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo]) + ')' + sqSql +
+                ' ORDER BY a.`end_time` DESC';
+            const sqlParam = [this.tableName, this.ctx.service.tender.tableName, auditorId];
             const result = await this.db.queryOne(sql, sqlParam);
             return result ? result.end_time : null;
         }

+ 20 - 9
app/service/material_audit.js

@@ -857,13 +857,16 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getAuditMaterial(auditorId) {
+        async getAuditMaterial(auditorId, spid = '') {
+            const spSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
             const sql = 'SELECT ma.`aid`, ma.`times`, ma.`order`, ma.`begin_time`, ma.`end_time`, ma.`tid`, ma.`mid`,' +
                 '    m.`order` As `morder`, m.`status` As `mstatus`,' +
                 '    t.`name`, t.`project_id`, t.`type`, t.`user_id` ' +
-                '  FROM ?? AS ma, ?? AS m, ?? As t ' +
-                '  WHERE ((ma.`aid` = ? and ma.`status` = ?) OR (m.`user_id` = ? and ma.`status` = ? and m.`status` = ? and ma.`times` = (m.`times`-1)))' +
-                '    and ma.`mid` = m.`id` and ma.`tid` = t.`id` ORDER BY ma.`begin_time` DESC';
+                '  FROM ?? AS ma' +
+                '  LEFT JOIN ?? AS m On ma.mid = m.id' +
+                '  LEFT JOIN ?? As t On m.tid = t.id' +
+                '  WHERE ((ma.`aid` = ? and ma.`status` = ?) OR (m.`user_id` = ? and ma.`status` = ? and m.`status` = ? and ma.`times` = (m.`times`-1)))' + spSql +
+                '  ORDER BY ma.`begin_time` DESC';
             const sqlParam = [this.tableName, this.ctx.service.material.tableName, this.ctx.service.tender.tableName, auditorId, auditConst.status.checking, auditorId, auditConst.status.checkNo, auditConst.status.checkNo];
             const result = await this.db.query(sql, sqlParam);
             // 过滤result中存在重复sid的值, 保留最新的一条
@@ -884,7 +887,13 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getCountByChecked(auditorId) {
+        async getCountByChecked(auditorId, spid = '') {
+            if (spid) {
+                const sql = 'SELECT count(*) AS count FROM ?? AS a LEFT JOIN ?? AS t ON a.tid = t.id WHERE a.`aid` = ? AND a.`status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo, auditConst.status.checkNoPre]) + ') AND t.`spid` = ?';
+                const sqlParam = [this.tableName, this.ctx.service.tender.tableName, auditorId, spid];
+                const result = await this.db.queryOne(sql, sqlParam);
+                return result.count ? result.count : 0;
+            }
             return await this.db.count(this.tableName, { aid: auditorId, status: [auditConst.status.checked, auditConst.status.checkNo, auditConst.status.checkNoPre] });
         }
 
@@ -894,10 +903,12 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getLastEndTimeByChecked(auditorId) {
-            const sql = 'SELECT `end_time` FROM ?? WHERE `aid` = ? ' +
-                'AND `status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo]) + ') ORDER BY `end_time` DESC';
-            const sqlParam = [this.tableName, auditorId];
+        async getLastEndTimeByChecked(auditorId, spid = '') {
+            const sqSql = spid ? ' AND t.`spid` = "' + spid + '"' : '';
+            const sql = 'SELECT a.`end_time` FROM ?? AS a LEFT JOIN ?? AS t ON a.`tid` = t.`id` WHERE a.`aid` = ? ' +
+                'AND a.`status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo]) + ')' + sqSql +
+                ' ORDER BY a.`end_time` DESC';
+            const sqlParam = [this.tableName, this.ctx.service.tender.tableName, auditorId];
             const result = await this.db.queryOne(sql, sqlParam);
             return result ? result.end_time : null;
         }

+ 3 - 2
app/service/payment_detail_audit.js

@@ -657,7 +657,8 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getAuditPayment(auditorId) {
+        async getAuditPayment(auditorId, spid = '') {
+            const spSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
             const sql =
                 'SELECT pda.`aid`, pda.`times`, pda.`order`, pda.`begin_time`, pda.`end_time`, pda.`tender_id`, pda.`tr_id`, pda.`td_id`,' +
                 '    pd.`code` As `scode`, pd.`order` As `sorder`, pd.`status` As `sstatus`, pd.type,' +
@@ -667,7 +668,7 @@ module.exports = app => {
                 '    Left Join ?? AS pd On pda.`td_id` = pd.`id` ' +
                 '    Left Join ?? AS pr On pda.`tr_id` = pr.`id` ' +
                 '    Left Join ?? As t ON pda.`tender_id` = t.`id`' +
-                '  WHERE ((pda.`aid` = ? and pda.`status` = ?) OR (pd.`uid` = ? and pda.`status` = ? and pd.`status` = ? and pda.`times` = (pd.`times`-1)))' +
+                '  WHERE ((pda.`aid` = ? and pda.`status` = ?) OR (pd.`uid` = ? and pda.`status` = ? and pd.`status` = ? and pda.`times` = (pd.`times`-1)))' + spSql +
                 '  ORDER BY pda.`begin_time` DESC';
             const sqlParam = [
                 this.tableName,

+ 17 - 7
app/service/revise_audit.js

@@ -841,7 +841,8 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getAuditRevise(auditorId) {
+        async getAuditRevise(auditorId, spid = '') {
+            const spSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
             const sql =
                 'SELECT ra.`audit_id`, ra.`times`, ra.`audit_order`, ra.`begin_time`, ra.`end_time`,' +
                 '    r.id, r.corder, r.uid, r.status, r.content,' +
@@ -852,7 +853,8 @@ module.exports = app => {
                 '  Left Join ' + this.ctx.service.tender.tableName + ' AS t On r.tid = t.id' +
                 '  Left Join ' + this.ctx.service.projectAccount.tableName + ' As p On ra.audit_id = p.id' +
                 '  WHERE r.`valid` != 0 and ((ra.`audit_id` = ? and ra.`status` = ?) OR' +
-                '    (r.`uid` = ? and r.`status` = ? and ra.`status` = ? and ra.`times` = (r.`times`-1))) ORDER BY ra.`begin_time` DESC';
+                '    (r.`uid` = ? and r.`status` = ? and ra.`status` = ? and ra.`times` = (r.`times`-1)))' + spSql +
+                ' ORDER BY ra.`begin_time` DESC';
             const sqlParam = [auditorId, auditConst.status.checking, auditorId, auditConst.status.checkNo, auditConst.status.checkNo];
             return await this.db.query(sql, sqlParam);
         }
@@ -863,7 +865,13 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getCountByChecked(auditorId) {
+        async getCountByChecked(auditorId, spid = '') {
+            if (spid) {
+                const sql = 'SELECT count(*) as count FROM ?? AS ra Left Join ?? AS t ON ra.`tender_id` = t.`id` WHERE ra.`audit_id` = ? AND ra.`status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo]) + ') AND t.`spid` = ?';
+                const sqlParam = [this.tableName, this.ctx.service.tender.tableName, auditorId, spid];
+                const result = await this.db.queryOne(sql, sqlParam);
+                return result ? result.count : 0;
+            }
             return await this.db.count(this.tableName, { audit_id: auditorId, status: [auditConst.status.checked, auditConst.status.checkNo] });
         }
 
@@ -873,10 +881,12 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getLastEndTimeByChecked(auditorId) {
-            const sql = 'SELECT `end_time` FROM ?? WHERE `audit_id` = ? ' +
-                'AND `status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo]) + ') ORDER BY `end_time` DESC';
-            const sqlParam = [this.tableName, auditorId];
+        async getLastEndTimeByChecked(auditorId, spid = '') {
+            const sqSql = spid ? ' AND t.`spid` = "' + spid + '"' : '';
+            const sql = 'SELECT a.`end_time` FROM ?? AS a LEFT JOIN ?? AS t ON a.`tender_id` = t.`id` WHERE a.`audit_id` = ? ' +
+                'AND a.`status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo]) + ')' + sqSql +
+                ' ORDER BY a.`end_time` DESC';
+            const sqlParam = [this.tableName, this.ctx.service.tender.tableName, auditorId];
             const result = await this.db.queryOne(sql, sqlParam);
             return result ? result.end_time : null;
         }

+ 17 - 8
app/service/stage_audit.js

@@ -1562,7 +1562,8 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getAuditStage(auditorId) {
+        async getAuditStage(auditorId, spid = '') {
+            const spSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
             const sql =
                 'SELECT sa.`aid`, sa.`times`, sa.`order`, sa.`begin_time`, sa.`end_time`, sa.`tid`, sa.`sid`,' +
                 '    s.`order` As `sorder`, s.`status` As `sstatus`, s.`in_time`,' +
@@ -1570,7 +1571,7 @@ module.exports = app => {
                 '  FROM ?? AS sa ' +
                 '    Left Join ?? AS s On sa.`sid` = s.`id` ' +
                 '    Left Join ?? As t ON sa.`tid` = t.`id`' +
-                '  WHERE (sa.`aid` = ? and sa.`status` = ?) OR (s.`user_id` = ? and sa.`status` = ? and s.`status` = ? and sa.`times` = (s.`times`-1))' +
+                '  WHERE ((sa.`aid` = ? and sa.`status` = ?) OR (s.`user_id` = ? and sa.`status` = ? and s.`status` = ? and sa.`times` = (s.`times`-1)))' + spSql +
                 '  ORDER BY sa.`begin_time` DESC';
             const sqlParam = [
                 this.tableName,
@@ -1588,7 +1589,7 @@ module.exports = app => {
                 ' t.`id` AS `tid`, t.`name`, t.`project_id`, t.`type`, t.`user_id`' +
                 ' FROM ?? AS s' +
                 ' Left Join ?? As t ON s.`tid` = t.`id`' +
-                ' WHERE s.`user_id` = ? and s.`status` != ?' +
+                ' WHERE s.`user_id` = ? and s.`status` != ?' + spSql +
                 ' ORDER BY s.`in_time` ASC';
             const sqlParam1 = [this.ctx.service.stage.tableName, this.ctx.service.tender.tableName, auditorId, auditConst.status.checked];
             const result1 = await this.db.query(sql1, sqlParam1);
@@ -1626,7 +1627,13 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getCountByChecked(auditorId) {
+        async getCountByChecked(auditorId, spid = '') {
+            if (spid) {
+                const sql = 'SELECT count(*) AS count FROM ?? AS a LEFT JOIN ?? AS t ON a.tid = t.id WHERE a.`aid` = ? AND a.`status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo, auditConst.status.checkNoPre]) + ') AND t.`spid` = ?';
+                const sqlParam = [this.tableName, this.ctx.service.tender.tableName, auditorId, spid];
+                const result = await this.db.queryOne(sql, sqlParam);
+                return result.count ? result.count : 0;
+            }
             return await this.db.count(this.tableName, { aid: auditorId, status: [auditConst.status.checked, auditConst.status.checkNo, auditConst.status.checkNoPre] });
         }
 
@@ -1636,10 +1643,12 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getLastEndTimeByChecked(auditorId) {
-            const sql = 'SELECT `end_time` FROM ?? WHERE `aid` = ? ' +
-                'AND `status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo, auditConst.status.checkNoPre]) + ') ORDER BY `end_time` DESC';
-            const sqlParam = [this.tableName, auditorId];
+        async getLastEndTimeByChecked(auditorId, spid = '') {
+            const sqSql = spid ? ' AND t.`spid` = "' + spid + '"' : '';
+            const sql = 'SELECT a.`end_time` FROM ?? AS a LEFT JOIN ?? AS t ON a.`tid` = t.`id` WHERE a.`aid` = ? ' +
+                'AND a.`status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo, auditConst.status.checkNoPre]) + ')' + sqSql +
+                ' ORDER BY a.`end_time` DESC';
+            const sqlParam = [this.tableName, this.ctx.service.tender.tableName, auditorId];
             const result = await this.db.queryOne(sql, sqlParam);
             return result ? result.end_time : null;
         }

+ 17 - 3
app/service/stage_audit_ass.js

@@ -40,9 +40,16 @@ module.exports = app => {
             return result;
         }
 
-        async getAuditStageAss(ass_user_id) {
+        async getAuditStageAss(ass_user_id, spid = '') {
             // 找出待上报或待审批的协同字段
-            const accountStageAssData = await this.getAllDataByCondition({ where: { ass_user_id } });
+            let accountStageAssData = [];
+            if (spid) {
+                const sql = 'SELECT * FROM ?? AS a LEFT JOIN ?? AS t ON a.`tid` = t.`id` WHERE t.`spid` = "' + spid + '" AND a.`ass_user_id` = ?';
+                const params = [this.tableName, this.ctx.service.tender.tableName, ass_user_id];
+                accountStageAssData = await this.db.query(sql, params);
+            } else {
+                accountStageAssData = await this.getAllDataByCondition({ where: { ass_user_id } });
+            }
             const lastStageList = [];
             const tidList = this._.map(accountStageAssData, 'tid');
             for (const t of tidList) {
@@ -61,7 +68,14 @@ module.exports = app => {
                 }
             }
             const result = [];
-            const accountAssData = await this.ctx.service.auditAss.getAllDataByCondition({ where: { ass_user_id } });
+            let accountAssData = [];
+            if (spid) {
+                const sql = 'SELECT * FROM ?? AS a LEFT JOIN ?? AS t ON a.`tid` = t.`id` WHERE t.`spid` = "' + spid + '" AND a.`ass_user_id` = ?';
+                const params = [this.ctx.service.auditAss.tableName, this.ctx.service.tender.tableName, ass_user_id];
+                accountAssData = await this.db.query(sql, params);
+            } else {
+                accountAssData = await this.ctx.service.auditAss.getAllDataByCondition({ where: { ass_user_id } });
+            }
             for (const as of accountStageAssDatas) {
                 const index = accountAssData.findIndex(x => { return x.tid === as.tid && x.user_id === as.user_id; });
                 if (index >= 0) {