Quellcode durchsuchen

Merge branch 'dev' of http://192.168.1.41:3000/maixinrong/Calculation into dev

Tony Kang vor 3 Monaten
Ursprung
Commit
d39342c46d

+ 33 - 33
app/controller/dashboard_controller.js

@@ -28,20 +28,20 @@ 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 noticeList = await ctx.service.noticePush.getNotice(ctx.session.sessionProject.id, pa.id, ctx.subProject.id);
             const projectData = await ctx.service.project.getDataById(ctx.session.sessionProject.id);
             // 获取销售人员数据
             const salesmanData = await ctx.service.manager.getDataById(projectData.manager_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));

+ 16 - 7
app/public/js/path_tree.js

@@ -325,13 +325,18 @@ const createNewPathTree = function (type, setting) {
         /**
          * 树结构根据显示排序
          */
-        sortTreeNode(isResort) {
+        sortTreeNode(isResort, isReturn) {
+            const resorts = [];
             const self = this;
+            if (isReturn) this.nodes.forEach((x, i) => { x.__org_tree_index = i });
             const addSortNodes = function (nodes) {
                 if (!nodes) { return }
                 for (let i = 0; i < nodes.length; i++) {
                     self.nodes.push(nodes[i]);
                     nodes[i].index = self.nodes.length - 1;
+                    if (isReturn && nodes[i].__org_tree_index !== undefined && nodes[i].__org_tree_index !== nodes[i].index) {
+                        resorts.push(nodes[i]);
+                    }
                     if (!isResort) {
                         nodes[i].children = self.getChildren(nodes[i]);
                     } else {
@@ -347,6 +352,7 @@ const createNewPathTree = function (type, setting) {
                 this.sortByOrder(this.children);
             }
             addSortNodes(this.children);
+            return resorts;
         }
         sortByOrder(datas) {
             const setting = this.setting;
@@ -790,9 +796,9 @@ const createNewPathTree = function (type, setting) {
                                 loadedData.push(this.getItems(node[this.setting.pid]));
                                 loadedData.push(this.getItems(data[this.setting.pid]));
                             }
-                            if (prop === this.setting.order) {
-                                loadedData = loadedData.concat(this.getPosterity(node));
-                            }
+                            // if (prop === this.setting.order) {
+                            //     loadedData = loadedData.concat(this.getPosterity(node));
+                            // }
                             node[prop] = data[prop];
                         }
                     }
@@ -808,7 +814,9 @@ const createNewPathTree = function (type, setting) {
                     this.children = this.getChildren(null);
                 }
             }
-            this.sortTreeNode(true);
+            const resortTreeNodes = this.sortTreeNode(true, true);
+            loadedData.push(...resortTreeNodes);
+            loadedData = _.uniq(loadedData);
             return loadedData;
         };
         /**
@@ -845,8 +853,8 @@ const createNewPathTree = function (type, setting) {
                         resortData.push(node);
                     }
                     const parent = this.getItems(node[this.setting.pid]);
-                    if (parent && resortData.indexOf(parent) === -1) {
-                        resortData.push(parent);
+                    if (parent) {
+                        if (resortData.indexOf(parent) === -1) resortData.push(parent);
                     } else {
                         resortData.push(this.setting.rootId);
                     }
@@ -899,6 +907,7 @@ const createNewPathTree = function (type, setting) {
             for (const node of freeDatas) {
                 removeArrayData(this.nodes, node);
             }
+            this.sortTreeNode(true);
             return freeDatas;
         };
         /**

+ 7 - 6
app/public/js/payment_index.js

@@ -39,7 +39,7 @@ $(function () {
 
     function recursiveGetTenderNodeHtml (node, arr, pid) {
         const html = [];
-        html.push('<tr fid="' + (node.parent_id !== undefined ? node.id: 0) + '" pid="' + pid + '">');
+        html.push('<tr fid="' + (node.parent_id !== undefined ? node.folder_id: 0) + '" pid="' + pid + '">');
         // 名称
         html.push('<td style="width: 40%" class="in-' + node.level + '">');
         if (node.parent_id !== undefined) {
@@ -84,13 +84,13 @@ $(function () {
                     html.push('<a class="dropdown-item show_del_btn" data-type="'+ (node.parent_id === undefined ? 'tender' : 'folder') +'" data-id="'+ node.id +'" href="javascript:void(0);"><i class="fa fa-remove mr-2"></i>删除</a>\n');
                 }
             }
-            if (auditPermission.admin && (node.uid === uid || is_admin) && (node.is_leaf || (node.parent_id !== undefined && !node.is_tender))) {
+            if (auditPermission.admin && (node.uid === uid || is_admin) && (node.is_leaf || (node.parent_id !== undefined && !node.is_tender)) && noSpTenderList.length === 0) {
                 html.push('<div class="dropdown-divider"></div>\n');
             }
-            if (auditPermission.admin && node.parent_id !== undefined && !node.is_tender) {
+            if (auditPermission.admin && node.parent_id !== undefined && !node.is_tender && noSpTenderList.length === 0) {
                 html.push('<a class="dropdown-item show_new_folder_btn" href="#add-folder" data-toggle="modal" data-target="#add-folder" data-parentName="'+ node.name +'" data-parentId="'+ node.folder_id +'"><i class="fa fa-folder-o mr-2"></i>新建子文件夹</a>\n');
             }
-            if (auditPermission.admin && node.is_leaf) {
+            if (auditPermission.admin && node.is_leaf && noSpTenderList.length === 0) {
                 html.push('<a class="dropdown-item show_new_tender_btn" href="javascript:void(0);"><i class="fa fa-folder-o mr-2"></i>新建标段</a>\n');
             }
             html.push('                        </div>\n' +
@@ -227,7 +227,7 @@ $(function () {
         $('.c-body table tr').removeClass('table-warning');
         $(this).addClass('table-warning');
         const fid = parseInt($(this).attr('fid'));
-        const folderInfo = _.find(allFolders, { id: fid });
+        const folderInfo = _.find(allFolders, { folder_id: fid });
         if (auditPermission.admin && folderInfo && folderInfo.is_leaf) {
             $('#show_new_tender_btn').show();
             $('#add_tender_folder_id').val(fid);
@@ -245,7 +245,8 @@ $(function () {
             toastr.error('请选中文件夹');
             return;
         }
-        const folderInfo = _.find(allFolders, { id: parseInt(fid) });
+        const folderInfo = _.find(allFolders, { folder_id: parseInt(fid) });
+        console.log(folderInfo);
         if (!folderInfo || folderInfo.is_leaf === 0) {
             toastr.error('文件夹不存在或存在子文件夹不能新建标段');
             return;

+ 3 - 0
app/public/js/sub_project.js

@@ -46,8 +46,11 @@ $(document).ready(function() {
                 if (node.is_folder) {
                     html.push(`<td class="text-center"></td>`);
                     html.push(`<td class="text-center"></td>`);
+                    html.push(`<td class="text-center"></td>`);
                 } else {
                     html.push(`<td class="text-center">${moment(node.create_time).format('YYYY-MM-DD')}</td>`);
+                    // 标段个数
+                    html.push(`<td class="text-center">${node.tender_count}</td>`);
                     if (canEdit) {
                         html.push(`<td class="text-center">${node.management || ''}<a class="ml-2" href="javascript: void(0)" name="set-management"><i class="fa fa-pencil-square-o "></i></a>${node.management ? '<a class="ml-2" href="javascript: void(0)" name="refresh-management"><i class="fa fa-refresh "></i></a>': ''}</td>`);
                     } else {

+ 26 - 15
app/service/advance_audit.js

@@ -285,9 +285,9 @@ module.exports = app => {
                 // 获取推送必要信息
                 const noticeContent = await this.getNoticeContent(pid, audit.tid, advanceId, audit.audit_id, checkData.opinion);
                 // 添加推送
-                const records = [{ pid, type: pushType.advance, uid: this.ctx.advance.uid, status: auditConst.status.checked, content: noticeContent }];
+                const records = [{ pid, tid: audit.tid, type: pushType.advance, uid: this.ctx.advance.uid, status: auditConst.status.checked, content: noticeContent }];
                 auditors.forEach(audit => {
-                    records.push({ pid, type: pushType.advance, uid: audit.audit_id, status: auditConst.status.checked, content: noticeContent });
+                    records.push({ pid, tid: audit.tid, type: pushType.advance, uid: audit.audit_id, status: auditConst.status.checked, content: noticeContent });
                 });
                 await transaction.insert(this.ctx.service.noticePush.tableName, records);
                 // 无下一审核人表示,审核结束
@@ -381,9 +381,9 @@ module.exports = app => {
                 await this.ctx.service.noticeAgain.stopNoticeAgain(transaction, this.tableName, audit.id);
                 // 添加到消息推送表
                 const noticeContent = await this.getNoticeContent(pid, audit.tid, advanceId, audit.audit_id, checkData.opinion);
-                const records = [{ pid, type: pushType.advance, uid: this.ctx.advance.uid, status: auditConst.status.checkNo, content: noticeContent }];
+                const records = [{ pid, tid: audit.tid, type: pushType.advance, uid: this.ctx.advance.uid, status: auditConst.status.checkNo, content: noticeContent }];
                 auditors.forEach(audit => {
-                    records.push({ pid, type: pushType.advance, uid: audit.audit_id, status: auditConst.status.checkNo, content: noticeContent });
+                    records.push({ pid, tid: audit.tid, type: pushType.advance, uid: audit.audit_id, status: auditConst.status.checkNo, content: noticeContent });
                 });
                 await transaction.insert(this.ctx.service.noticePush.tableName, records);
 
@@ -436,9 +436,9 @@ module.exports = app => {
             const transaction = await this.db.beginTransaction();
             try {
                 // 添加到消息推送表
-                const records = [{ pid, type: pushType.advance, uid: this.ctx.advance.uid, status: auditConst.status.checkNoPre, content: noticeContent }];
+                const records = [{ pid, tid: audit.tid, type: pushType.advance, uid: this.ctx.advance.uid, status: auditConst.status.checkNoPre, content: noticeContent }];
                 auditors2.forEach(audit => {
-                    records.push({ pid, type: pushType.advance, uid: audit.audit_id, status: auditConst.status.checkNoPre, content: noticeContent });
+                    records.push({ pid, tid: audit.tid, type: pushType.advance, uid: audit.audit_id, status: auditConst.status.checkNoPre, content: noticeContent });
                 });
                 await transaction.insert(this.ctx.service.noticePush.tableName, records);
                 await transaction.update(this.tableName, { id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time });
@@ -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;
         }

+ 5 - 0
app/service/change.js

@@ -955,6 +955,7 @@ module.exports = app => {
                 auditors.forEach(auditor => {
                     records.push({
                         pid,
+                        tid: changeData.tid,
                         type: pushType.change,
                         uid: auditor.uid,
                         status: audit.change.status.checked,
@@ -1192,6 +1193,7 @@ module.exports = app => {
                 auditors.forEach(auditor => {
                     records.push({
                         pid,
+                        tid: changeData.tid,
                         type: pushType.change,
                         uid: auditor.uid,
                         status: audit.change.status.checkNo,
@@ -1301,6 +1303,7 @@ module.exports = app => {
                 auditors.forEach(auditor => {
                     records.push({
                         pid,
+                        tid: changeData.tid,
                         type: pushType.change,
                         uid: auditor.uid,
                         status: audit.change.status.checkNoPre,
@@ -1617,6 +1620,7 @@ module.exports = app => {
                 auditors.forEach(auditor => {
                     records.push({
                         pid,
+                        tid: change.tid,
                         type: pushType.change,
                         uid: auditor.uid,
                         status: audit.change.status.revise,
@@ -1730,6 +1734,7 @@ module.exports = app => {
                 auditors.forEach(auditor => {
                     records.push({
                         pid,
+                        tid: changeData.tid,
                         type: pushType.change,
                         uid: auditor.uid,
                         status: audit.change.status.checked,

+ 23 - 12
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;
         }
@@ -510,7 +519,7 @@ module.exports = app => {
                 const records = [];
                 const auditors = await this.getAuditorsWithOwner(caId, times);
                 auditors.forEach(audit => {
-                    records.push({ pid, type: pushType.changeApply, uid: audit.aid, status: auditConst.status.checked, content: noticeContent });
+                    records.push({ pid, tid: selfAudit.tid, type: pushType.changeApply, uid: audit.aid, status: auditConst.status.checked, content: noticeContent });
                 });
                 await transaction.insert('zh_notice', records);
                 if (audits.length === 1 || selfAudit.audit_type !== auditType.key.and) {
@@ -641,9 +650,9 @@ module.exports = app => {
                 await this.ctx.service.noticeAgain.stopNoticeAgain(transaction, this.tableName, this._.map(updateData, 'id'));
                 // 添加到消息推送表
                 const noticeContent = await this.getNoticeContent(pid, selfAudit.tid, caId, selfAudit.aid, checkData.opinion);
-                const records = [{ pid, type: pushType.changeApply, uid: this.ctx.change.uid, status: auditConst.status.checkNo, content: noticeContent }];
+                const records = [{ pid, tid: selfAudit.tid, type: pushType.changeApply, uid: this.ctx.change.uid, status: auditConst.status.checkNo, content: noticeContent }];
                 auditors.forEach(audit => {
-                    records.push({ pid, type: pushType.changeApply, uid: audit.aid, status: auditConst.status.checkNo, content: noticeContent });
+                    records.push({ pid, tid: selfAudit.tid, type: pushType.changeApply, uid: audit.aid, status: auditConst.status.checkNo, content: noticeContent });
                 });
                 await transaction.insert(this.ctx.service.noticePush.tableName, records);
                 // 同步期信息
@@ -941,10 +950,11 @@ module.exports = app => {
                 const auditors = await this.getUniqAuditor(change.id, change.times); // 全部参与的审批人
                 // 添加到消息推送表
                 const noticeContent = await this.getNoticeContent(pid, change.tid, change.id, this.ctx.session.sessionUser.accountId, '发起修订');
-                const records = [{ pid, type: pushType.changeProject, uid: change.uid, status: auditConst.status.revise, content: noticeContent }];
+                const records = [{ pid, tid: change.tid, type: pushType.changeProject, uid: change.uid, status: auditConst.status.revise, content: noticeContent }];
                 auditors.forEach(auditor => {
                     records.push({
                         pid,
+                        tid: change.tid,
                         type: pushType.changeApply,
                         uid: auditor.aid,
                         status: auditConst.status.revise,
@@ -1011,10 +1021,11 @@ module.exports = app => {
                 const auditors = await this.getUniqAuditor(change.id, change.times - 1); // 全部参与的审批人
                 // 添加到消息推送表
                 const noticeContent = await this.getNoticeContent(pid, change.tid, change.id, this.ctx.session.sessionUser.accountId, '撤销修订');
-                const records = [{ pid, type: pushType.changeProject, uid: change.uid, status: auditConst.status.cancelRevise, content: noticeContent }];
+                const records = [{ pid, tid: change.tid, type: pushType.changeProject, uid: change.uid, status: auditConst.status.cancelRevise, content: noticeContent }];
                 auditors.forEach(auditor => {
                     records.push({
                         pid,
+                        tid: change.tid,
                         type: pushType.changeApply,
                         uid: auditor.aid,
                         status: auditConst.status.cancelRevise,

+ 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;
         }

+ 23 - 12
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;
         }
@@ -508,7 +517,7 @@ module.exports = app => {
                 const records = [];
                 const auditors = await this.getAuditorsWithOwner(cpId, times);
                 auditors.forEach(audit => {
-                    records.push({ pid, type: pushType.changePlan, uid: audit.aid, status: auditConst.status.checked, content: noticeContent });
+                    records.push({ pid, tid: selfAudit.tid, type: pushType.changePlan, uid: audit.aid, status: auditConst.status.checked, content: noticeContent });
                 });
                 await transaction.insert('zh_notice', records);
                 if (audits.length === 1 || selfAudit.audit_type !== auditType.key.and) {
@@ -639,9 +648,9 @@ module.exports = app => {
                 await this.ctx.service.noticeAgain.stopNoticeAgain(transaction, this.tableName, this._.map(updateData, 'id'));
                 // 添加到消息推送表
                 const noticeContent = await this.getNoticeContent(pid, selfAudit.tid, cpId, selfAudit.aid, checkData.opinion);
-                const records = [{ pid, type: pushType.changePlan, uid: this.ctx.change.uid, status: auditConst.status.checkNo, content: noticeContent }];
+                const records = [{ pid, tid: selfAudit.tid, type: pushType.changePlan, uid: this.ctx.change.uid, status: auditConst.status.checkNo, content: noticeContent }];
                 auditors.forEach(audit => {
-                    records.push({ pid, type: pushType.changePlan, uid: audit.aid, status: auditConst.status.checkNo, content: noticeContent });
+                    records.push({ pid, tid: selfAudit.tid, type: pushType.changePlan, uid: audit.aid, status: auditConst.status.checkNo, content: noticeContent });
                 });
                 await transaction.insert(this.ctx.service.noticePush.tableName, records);
                 // 同步期信息
@@ -996,10 +1005,11 @@ module.exports = app => {
                 // const auditors = await this.db.query(sql, sqlParam);
                 // 添加到消息推送表
                 const noticeContent = await this.getNoticeContent(pid, change.tid, change.id, this.ctx.session.sessionUser.accountId, '发起修订');
-                const records = [{ pid, type: pushType.changePlan, uid: change.uid, status: auditConst.status.revise, content: noticeContent }];
+                const records = [{ pid, tid: change.tid, type: pushType.changePlan, uid: change.uid, status: auditConst.status.revise, content: noticeContent }];
                 auditors.forEach(auditor => {
                     records.push({
                         pid,
+                        tid: change.tid,
                         type: pushType.changePlan,
                         uid: auditor.aid,
                         status: auditConst.status.revise,
@@ -1069,10 +1079,11 @@ module.exports = app => {
                 const auditors = await this.getUniqAuditor(change.id, change.times - 1); // 全部参与的审批人
                 // 添加到消息推送表
                 const noticeContent = await this.getNoticeContent(pid, change.tid, change.id, this.ctx.session.sessionUser.accountId, '撤销修订');
-                const records = [{ pid, type: pushType.changePlan, uid: change.uid, status: auditConst.status.cancelRevise, content: noticeContent }];
+                const records = [{ pid, tid: change.tid, type: pushType.changePlan, uid: change.uid, status: auditConst.status.cancelRevise, content: noticeContent }];
                 auditors.forEach(auditor => {
                     records.push({
                         pid,
+                        tid: change.tid,
                         type: pushType.changePlan,
                         uid: auditor.aid,
                         status: auditConst.status.cancelRevise,

+ 25 - 14
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;
         }
@@ -530,7 +539,7 @@ module.exports = app => {
                 const records = [];
                 const auditors = await this.getAuditorsWithOwner(cpId, times);
                 auditors.forEach(audit => {
-                    records.push({ pid, type: pushType.changeProject, uid: audit.aid, status: auditConst.status.checked, content: noticeContent });
+                    records.push({ pid, tid: selfAudit.tid, type: pushType.changeProject, uid: audit.aid, status: auditConst.status.checked, content: noticeContent });
                 });
                 await transaction.insert('zh_notice', records);
                 if (audits.length === 1 || selfAudit.audit_type !== auditType.key.and) {
@@ -660,9 +669,9 @@ module.exports = app => {
                 await this.ctx.service.noticeAgain.stopNoticeAgain(transaction, this.tableName, this._.map(updateData, 'id'));
                 // 添加到消息推送表
                 const noticeContent = await this.getNoticeContent(pid, selfAudit.tid, cpId, selfAudit.aid, checkData.opinion);
-                const records = [{ pid, type: pushType.changeProject, uid: this.ctx.change.uid, status: auditConst.status.back, content: noticeContent }];
+                const records = [{ pid, tid: selfAudit.tid, type: pushType.changeProject, uid: this.ctx.change.uid, status: auditConst.status.back, content: noticeContent }];
                 auditors.forEach(audit => {
-                    records.push({ pid, type: pushType.changeProject, uid: audit.aid, status: auditConst.status.back, content: noticeContent });
+                    records.push({ pid, tid: selfAudit.tid, type: pushType.changeProject, uid: audit.aid, status: auditConst.status.back, content: noticeContent });
                 });
                 await transaction.insert(this.ctx.service.noticePush.tableName, records);
                 // 同步期信息
@@ -728,9 +737,9 @@ module.exports = app => {
                 // 获取推送必要信息
                 const noticeContent = await this.getNoticeContent(pid, selfAudit.tid, cpId, selfAudit.aid, checkData.opinion);
                 // 添加推送
-                const records = [{ pid, type: pushType.changeProject, uid: this.ctx.change.uid, status: auditConst.status.checkNo, content: noticeContent }];
+                const records = [{ pid, tid: selfAudit.tid, type: pushType.changeProject, uid: this.ctx.change.uid, status: auditConst.status.checkNo, content: noticeContent }];
                 auditors.forEach(audit => {
-                    records.push({ pid, type: pushType.changeProject, uid: audit.aid, status: auditConst.status.checkNo, content: noticeContent });
+                    records.push({ pid, tid: selfAudit.tid, type: pushType.changeProject, uid: audit.aid, status: auditConst.status.checkNo, content: noticeContent });
                 });
                 await transaction.insert('zh_notice', records);
                 // 本期结束
@@ -1083,10 +1092,11 @@ module.exports = app => {
                 // const auditors = await this.db.query(sql, sqlParam);
                 // 添加到消息推送表
                 const noticeContent = await this.getNoticeContent(pid, change.tid, change.id, this.ctx.session.sessionUser.accountId, '发起修订');
-                const records = [{ pid, type: pushType.changeProject, uid: change.uid, status: auditConst.status.revise, content: noticeContent }];
+                const records = [{ pid, tid: change.tid, type: pushType.changeProject, uid: change.uid, status: auditConst.status.revise, content: noticeContent }];
                 auditors.forEach(auditor => {
                     records.push({
                         pid,
+                        tid: change.tid,
                         type: pushType.changeProject,
                         uid: auditor.aid,
                         status: auditConst.status.revise,
@@ -1150,10 +1160,11 @@ module.exports = app => {
                 const auditors = await this.getUniqAuditor(change.id, change.times - 1); // 全部参与的审批人
                 // 添加到消息推送表
                 const noticeContent = await this.getNoticeContent(pid, change.tid, change.id, this.ctx.session.sessionUser.accountId, '撤销修订');
-                const records = [{ pid, type: pushType.changeProject, uid: change.uid, status: auditConst.status.cancelRevise, content: noticeContent }];
+                const records = [{ pid, tid: change.tid, type: pushType.changeProject, uid: change.uid, status: auditConst.status.cancelRevise, content: noticeContent }];
                 auditors.forEach(auditor => {
                     records.push({
                         pid,
+                        tid: change.tid,
                         type: pushType.changeProject,
                         uid: auditor.aid,
                         status: auditConst.status.cancelRevise,

+ 14 - 8
app/service/financial_pay_audit.js

@@ -356,7 +356,7 @@ module.exports = app => {
                 const records = [];
                 const auditors = await this.getAuditorsWithOwner(fp.id, fp.times);
                 auditors.forEach(audit => {
-                    records.push({ pid, type: pushType.financial, uid: audit.aid, status: auditConst.status.checked, content: noticeContent });
+                    records.push({ pid, spid: fp.spid, type: pushType.financial, uid: audit.aid, status: auditConst.status.checked, content: noticeContent });
                 });
                 await transaction.insert('zh_notice', records);
                 if (audits.length === 1 || selfAudit.audit_type !== auditType.key.and) {
@@ -437,9 +437,9 @@ module.exports = app => {
                 await transaction.updateRows(this.tableName, updateData);
                 // 添加到消息推送表
                 const noticeContent = await this.getNoticeContent(pid, fp.spid, fp.id, selfAudit.aid, checkData.opinion);
-                const records = [{ pid, type: pushType.financial, uid: fp.uid, status: auditConst.status.checkNo, content: noticeContent }];
+                const records = [{ pid, spid: fp.spid, type: pushType.financial, uid: fp.uid, status: auditConst.status.checkNo, content: noticeContent }];
                 auditors.forEach(audit => {
-                    records.push({ pid, type: pushType.financial, uid: audit.aid, status: auditConst.status.checkNo, content: noticeContent });
+                    records.push({ pid, spid: fp.spid, type: pushType.financial, uid: audit.aid, status: auditConst.status.checkNo, content: noticeContent });
                 });
                 await transaction.insert(this.ctx.service.noticePush.tableName, records);
                 // 同步期信息
@@ -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;

+ 18 - 9
app/service/ledger_audit.js

@@ -577,7 +577,7 @@ module.exports = app => {
             const time = new Date();
 
             const noticeContent = await this.getNoticeContent(selfAuditor.tender_id, pid, accountId, opinion);
-            const defaultNoticeRecord = { pid, type: pushType.ledger, status: auditConst.status.checkNo, content: noticeContent };
+            const defaultNoticeRecord = { pid, tid: selfAuditor.tender_id, type: pushType.ledger, status: auditConst.status.checkNo, content: noticeContent };
 
             const transaction = await this.db.beginTransaction();
             try {
@@ -651,7 +651,7 @@ module.exports = app => {
             const time = new Date();
 
             const noticeContent = await this.getNoticeContent(selfAuditor.tender_id, pid, accountId, opinion);
-            const defaultNoticeRecord = { pid, type: pushType.ledger, status: auditConst.status.checked, content: noticeContent };
+            const defaultNoticeRecord = { pid, tid: selfAuditor.tender_id, type: pushType.ledger, status: auditConst.status.checked, content: noticeContent };
 
             const transaction = await this.db.beginTransaction();
             try {
@@ -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;
         }

+ 25 - 14
app/service/material_audit.js

@@ -364,7 +364,7 @@ module.exports = app => {
                 const records = [];
                 // const records = [{ pid, type: pushType.material, uid: this.ctx.material.user_id, status: auditConst.status.checked, content: noticeContent }];
                 auditors.forEach(audit => {
-                    records.push({ pid, type: pushType.material, uid: audit.aid, status: auditConst.status.checked, content: noticeContent });
+                    records.push({ pid, tid: selfAudit.tid, type: pushType.material, uid: audit.aid, status: auditConst.status.checked, content: noticeContent });
                 });
                 await transaction.insert('zh_notice', records);
                 const materialInfo = await this.ctx.service.material.getDataById(materialId);
@@ -568,9 +568,9 @@ module.exports = app => {
                 await this.ctx.service.noticeAgain.stopNoticeAgain(transaction, this.tableName, this._.map(updateData, 'id'));
                 // 添加到消息推送表
                 const noticeContent = await this.getNoticeContent(pid, selfAudit.tid, materialId, selfAudit.aid, checkData.opinion);
-                const records = [{ pid, type: pushType.material, uid: this.ctx.material.user_id, status: auditConst.status.checkNo, content: noticeContent }];
+                const records = [{ pid, tid: selfAudit.tid, type: pushType.material, uid: this.ctx.material.user_id, status: auditConst.status.checkNo, content: noticeContent }];
                 auditors.forEach(audit => {
-                    records.push({ pid, type: pushType.material, uid: audit.aid, status: auditConst.status.checkNo, content: noticeContent });
+                    records.push({ pid, tid: selfAudit.tid, type: pushType.material, uid: audit.aid, status: auditConst.status.checkNo, content: noticeContent });
                 });
                 await transaction.insert(this.ctx.service.noticePush.tableName, records);
                 // 同步期信息
@@ -626,9 +626,9 @@ module.exports = app => {
                 const tp_data = await this.getTpData(transaction, materialId);
                 // 添加到消息推送表
                 const noticeContent = await this.getNoticeContent(pid, selfAudit.tid, materialId, selfAudit.aid, checkData.opinion);
-                const records = [{ pid, type: pushType.material, uid: this.ctx.material.user_id, status: auditConst.status.checkNoPre, content: noticeContent }];
+                const records = [{ pid, tid: selfAudit.tid, type: pushType.material, uid: this.ctx.material.user_id, status: auditConst.status.checkNoPre, content: noticeContent }];
                 auditors2.forEach(audit => {
-                    records.push({ pid, type: pushType.material, uid: audit.aid, status: auditConst.status.checkNoPre, content: noticeContent });
+                    records.push({ pid, tid: selfAudit.tid, type: pushType.material, uid: audit.aid, status: auditConst.status.checkNoPre, content: noticeContent });
                 });
                 await transaction.insert('zh_notice', records);
                 const updateData = [];
@@ -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;
         }

+ 16 - 11
app/service/notice_push.js

@@ -34,7 +34,7 @@ module.exports = app => {
          * @param {Integer} pid - 项目id
          * @param {Integer} uid - 查询人id
          */
-        async getNotice(pid, uid = 0) {
+        async getNotice(pid, uid = 0, spid = '') {
             // const noticeList = [];
             // for (const type in auditConst.pushType) {
             //     const wheres = { pid, type: auditConst.pushType[type] };
@@ -55,16 +55,21 @@ module.exports = app => {
             //     noticeList.push(...notice);
             // }
             // return this._.orderBy(noticeList, ['create_time'], ['desc']);
-            const wheres = { pid };
-            if (uid !== 0) {
-                wheres.uid = uid;
-            }
-            let notice = await this.db.select(this.tableName, {
-                where: wheres,
-                orders: [['create_time', 'desc']],
-                limit: 30,
-                offset: 0
-            });
+            // const wheres = { pid };
+            // if (uid !== 0) {
+            //     wheres.uid = uid;
+            // }
+            // let notice = await this.db.select(this.tableName, {
+            //     where: wheres,
+            //     orders: [['create_time', 'desc']],
+            //     limit: 30,
+            //     offset: 0
+            // });
+            const uidSql = uid ? ' AND a.`uid` = ' + uid : '';
+            const spidSql = spid ? ' AND (a.`spid` = "' + spid + '" OR t.`spid` = "' + spid + '")': '';
+            const sql = 'SELECT a.* FROM ?? AS a LEFT JOIN ?? AS t ON a.`tid` = t.`id` WHERE a.`pid` = ?' + uidSql + spidSql + ' ORDER BY a.`create_time` DESC LIMIT 0,30';
+            const params = [this.tableName, this.ctx.service.tender.tableName, pid];
+            let notice = await this.db.query(sql, params);
             notice = notice.map(v => {
                 const extra = JSON.parse(v.content);
                 delete v.content;

+ 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,

+ 3 - 2
app/service/phase_pay_audit.js

@@ -391,6 +391,7 @@ module.exports = app => {
                 const noticeContent = await this._getNoticeContent(this.ctx.session.sessionProject.id, phasePay.tid, phasePay.id, accountId, opinion);
                 const defaultNoticeRecord = {
                     pid: this.ctx.session.sessionProject.id,
+                    tid: phasePay.tid,
                     type: pushType.phasePay,
                     status: auditConst.phasePay.status.checked,
                     content: noticeContent,
@@ -517,7 +518,7 @@ module.exports = app => {
             try {
                 // 添加提醒
                 const noticeContent = await this._getNoticeContent(pid, selfAudit.tid, phasePay.id, selfAudit.audit_id, opinion);
-                const defaultNoticeRecord = { pid, type: pushType.phasePay, status: auditConst.phasePay.status.checkNo, content: noticeContent };
+                const defaultNoticeRecord = { pid, tid: selfAudit.tid, type: pushType.phasePay, status: auditConst.phasePay.status.checkNo, content: noticeContent };
                 const records = phasePay.userIds.map(x => {
                     return { uid: x, ...defaultNoticeRecord };
                 });
@@ -578,7 +579,7 @@ module.exports = app => {
                 // 添加通知
                 const noticeContent = await this._getNoticeContent(pid, phasePay.tid, phasePay.id, selfAudit.audit_id, opinion);
                 const defaultNoticeRecord = {
-                    pid, type: pushType.phasePay, status: auditConst.phasePay.status.checkNoPre, content: noticeContent,
+                    pid, tid: phasePay.tid, type: pushType.phasePay, status: auditConst.phasePay.status.checkNoPre, content: noticeContent,
                 };
                 const records = phasePay.userIds.map(x => {
                     return { uid: x, ...defaultNoticeRecord };

+ 19 - 9
app/service/revise_audit.js

@@ -574,7 +574,7 @@ module.exports = app => {
             const time = new Date();
 
             const noticeContent = await this.getNoticeContent(pid, selfAuditor.tender_id, revise.id, selfAuditor.audit_id, opinion);
-            const defaultNoticeRecord = { pid, type: pushType.revise, status: auditConst.status.checked, content: noticeContent};
+            const defaultNoticeRecord = { pid, tid: selfAuditor.tender_id, type: pushType.revise, status: auditConst.status.checked, content: noticeContent};
 
             const transaction = await this.db.beginTransaction();
             try {
@@ -719,7 +719,7 @@ module.exports = app => {
             const time = new Date();
 
             const noticeContent = await this.getNoticeContent(pid, revise.tid, revise.id, accountId, opinion);
-            const defaultNoticeRecord = { pid, type: pushType.revise, status: auditConst.status.checkNo, content: noticeContent };
+            const defaultNoticeRecord = { pid, tid: selfAuditor.tender_id, type: pushType.revise, status: auditConst.status.checkNo, content: noticeContent };
 
             // 整理当前流程审核人状态更新 warning(在try catch中写,会报auditors未初始化)
             const updateAuditData = audits.map(x => {
@@ -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;
         }

+ 3 - 2
app/service/settle_audit.js

@@ -422,6 +422,7 @@ module.exports = app => {
                 const noticeContent = await this._getNoticeContent(this.ctx.session.sessionProject.id, settle.tid, settle.id, accountId, opinion);
                 const defaultNoticeRecord = {
                     pid: this.ctx.session.sessionProject.id,
+                    tid: settle.tid,
                     type: pushType.settle,
                     status: auditConst.settle.status.checked,
                     content: noticeContent,
@@ -549,7 +550,7 @@ module.exports = app => {
             try {
                 // 添加提醒
                 const noticeContent = await this._getNoticeContent(pid, selfAudit.tid, settle.id, selfAudit.audit_id, opinion);
-                const defaultNoticeRecord = { pid, type: pushType.settle, status: auditConst.settle.status.checkNo, content: noticeContent };
+                const defaultNoticeRecord = { pid, tid: selfAudit.tid, type: pushType.settle, status: auditConst.settle.status.checkNo, content: noticeContent };
                 const records = settle.userIds.map(x => {
                     return { uid: x, ...defaultNoticeRecord };
                 });
@@ -612,7 +613,7 @@ module.exports = app => {
                 // 添加通知
                 const noticeContent = await this._getNoticeContent(pid, settle.tid, settle.id, selfAudit.audit_id, opinion);
                 const defaultNoticeRecord = {
-                    pid, type: pushType.settle, status: auditConst.settle.status.checkNoPre, content: noticeContent,
+                    pid, tid: settle.tid, type: pushType.settle, status: auditConst.settle.status.checkNoPre, content: noticeContent,
                 };
                 const records = settle.userIds.map(x => {
                     return { uid: x, ...defaultNoticeRecord };

+ 20 - 8
app/service/stage_audit.js

@@ -442,6 +442,7 @@ module.exports = app => {
                 const auditors = await this.getAuditGroupByListWithOwner(stageId, times);
                 const defaultNoticeRecord = {
                     pid,
+                    tid: stageInfo.tid,
                     type: pushType.stage,
                     status: auditConst.status.checked,
                     content: noticeContent,
@@ -664,6 +665,7 @@ module.exports = app => {
                 const noticeContent = await this.getNoticeContent(pid, selfAudit.tid, stageId, selfAudit.aid, checkData.opinion);
                 const defaultNoticeRecord = {
                     pid,
+                    tid: selfAudit.tid,
                     type: pushType.stage,
                     status: auditConst.status.checkNo,
                     content: noticeContent,
@@ -791,6 +793,7 @@ module.exports = app => {
                 const noticeContent = await this.getNoticeContent(pid, selfAudit.tid, stageId, selfAudit.aid, checkData.opinion);
                 const defaultNoticeRecord = {
                     pid,
+                    tid: selfAudit.tid,
                     type: pushType.stage,
                     status: auditConst.status.checkNoPre,
                     content: noticeContent,
@@ -1562,7 +1565,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 +1574,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 +1592,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 +1630,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 +1646,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) {

+ 1 - 0
app/view/payment/index.ejs

@@ -32,4 +32,5 @@
     const uid = <%- ctx.session.sessionUser.accountId %>;
     const is_admin = <%- ctx.session.sessionUser.is_admin %>;
     const auditPermission = JSON.parse(unescape('<%- escape(JSON.stringify(auditPermission)) %>'));
+    const noSpTenderList = JSON.parse(unescape('<%- escape(JSON.stringify(noSpTenderList)) %>'));
 </script>

+ 0 - 1
app/view/payment/modal.ejs

@@ -239,7 +239,6 @@
     <!--<script src="/public/js/bootstrap/bootstrap-table-fixed-columns.min.js"></script>-->
 <script>
     <% if (noSpTenderList.length > 0) { %>
-    const noSpTenderList = JSON.parse(unescape('<%- escape(JSON.stringify(noSpTenderList)) %>'));
     const noSpFolderList = JSON.parse(unescape('<%- escape(JSON.stringify(noSpFolderList)) %>'));
     <% } %>
     $(function () {

+ 1 - 1
app/view/sub_proj/index.ejs

@@ -21,7 +21,7 @@
                 </div>
                 <% } else { %>
                 <table class="table table-bordered">
-                    <tr class="text-center"><th style="min-width: 200px">项目名称</th><th>概预算标准</th><th>创建时间</th><th>管理单位</th><th>操作</th></tr>
+                    <tr class="text-center"><th style="min-width: 200px">项目名称</th><th>概预算标准</th><th>创建时间</th><th>标段个数</th><th>管理单位</th><th>操作</th></tr>
                     <tbody id="projectList">
                     </tbody>
                 </table>

+ 2 - 0
app/view/tender/list_sub_menu_list.ejs

@@ -5,6 +5,7 @@
         </li>
     </ul>
 </div>
+<% if (ctx.subProject.page_show.openTenderContract) { %>
 <div class="nav-box">
     <ul class="nav-list list-unstyled">
         <li class="<% if (ctx.url === '/sp/' + ctx.subProject.id + '/contract/tender') { %>active<% } %>">
@@ -12,6 +13,7 @@
         </li>
     </ul>
 </div>
+<% } %>
 <% if (ctx.subProject.page_show.openConstruction) { %>
 <div class="nav-box">
     <ul class="nav-list list-unstyled">

+ 2 - 2
config/menu.js

@@ -22,7 +22,7 @@ const projectMenu = {
     dataview: {
         name: '数据大屏',
         icon: 'fa-th-large',
-        display: true,
+        display: false,
         url: '/dataview',
         children: null,
         caption: '数据大屏',
@@ -40,7 +40,7 @@ const projectMenu = {
     spgather: {
         name: '项目汇总',
         icon: 'fa-sitemap',
-        display: true,
+        display: false,
         url: '/spgather',
         children: null,
         caption: '项目汇总',

+ 8 - 0
sql/update.sql

@@ -71,6 +71,10 @@ ALTER TABLE `zh_tender`
 ADD COLUMN `filter_budget` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '动态投资-是否过滤' AFTER `spid`,
 ADD COLUMN `filter_fund` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '资金监管-是否过滤' AFTER `filter_budget`;
 
+ALTER TABLE `zh_notice`
+ADD COLUMN `spid` varchar(36) NULL DEFAULT '' COMMENT '子项目id' AFTER `pid`,
+ADD COLUMN `tid` int(11) NULL DEFAULT NULL COMMENT '标段id' AFTER `spid`;
+
 ------------------------------------
 -- 表数据
 ------------------------------------
@@ -82,3 +86,7 @@ Update zh_project_col_set SET pid = id;
 Update zh_payment_folder SET folder_id = id;
 
 INSERT INTO `zh_permission` (`id`, `name`, `controller`, `action`, `pid`, `icon_class`, `create_time`, `isshow`) VALUES (77, '项目设置', 'project', 'sp-pageshow', 38, 'sp-pageshow', NULL, 1);
+
+UPDATE zh_notice SET tid = JSON_UNQUOTE(JSON_EXTRACT(content, '$.tid')) WHERE tid IS NULL;
+
+UPDATE zh_notice SET spid = JSON_UNQUOTE(JSON_EXTRACT(content, '$.spid')) WHERE spid = '';