Просмотр исходного кода

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

Tony Kang 9 месяцев назад
Родитель
Сommit
5af780bef2

+ 2 - 2
app/middleware/ledger_audit_check.js

@@ -20,7 +20,7 @@ const checkAuditFlow = async function(ctx) {
 
     const shenpi_status = info.shenpi.ledger;
     // 进一步比较审批流是否与审批流程设置的相同,不同则替换为固定审批流或固定的终审
-    const auditList = await ctx.service.ledgerAudit.getAuditors(tender.id, tender.times);
+    const auditList = await ctx.service.ledgerAudit.getAuditors(tender.id, tender.ledger_times);
     if (shenpi_status === shenpiConst.sp_status.gdspl) {
         const shenpiList = await ctx.service.shenpiAudit.getAllDataByCondition({ where: { tid: tender.id, sp_type: shenpiConst.sp_type.ledger, sp_status: shenpi_status } });
         // 判断2个id数组是否相同,不同则删除原审批流,切换成固定的审批流
@@ -38,7 +38,7 @@ const checkAuditFlow = async function(ctx) {
     } else if (shenpi_status === shenpiConst.sp_status.gdzs) {
         const shenpiInfo = await ctx.service.shenpiAudit.getDataByCondition({ tid: tender.id, sp_type: shenpiConst.sp_type.ledger, sp_status: shenpi_status });
         // 判断最后一个id是否与固定终审id相同,不同则删除原审批流中如果存在的id和添加终审
-        const lastAuditors = auditList.filter(x => { x.order === auditList[auditList.length - 1].order; });
+        const lastAuditors = auditList.filter(x => { x.audit_order === auditList[auditList.length - 1].audit_order; });
         if (shenpiInfo && (lastAuditors.length === 0 || (lastAuditors.length > 1 || shenpiInfo.audit_id !== lastAuditors[0].audit_id))) {
             await ctx.service.ledgerAudit.updateLastAudit(tender, auditList, shenpiInfo.audit_id);
         } else if (!shenpiInfo) {

+ 1 - 1
app/middleware/revise_audit_check.js

@@ -40,7 +40,7 @@ const checkAuditFlow = async function(ctx) {
     } else if (shenpi_status === shenpiConst.sp_status.gdzs) {
         const shenpiInfo = await ctx.service.shenpiAudit.getDataByCondition({ tid: revise.tid, sp_type: shenpiConst.sp_type.revise, sp_status: shenpi_status });
         // 判断最后一个id是否与固定终审id相同,不同则删除原审批流中如果存在的id和添加终审
-        const lastAuditors = auditList.filter(x => { x.order === auditList[auditList.length - 1].order; });
+        const lastAuditors = auditList.filter(x => { x.audit_order === auditList[auditList.length - 1].audit_order; });
         if (shenpiInfo && (lastAuditors.length === 0 || (lastAuditors.length > 1 || shenpiInfo.audit_id !== lastAuditors[0].audit_id))) {
             await ctx.service.reviseAudit.updateLastAudit(revise, auditList, shenpiInfo.audit_id);
         } else if (!shenpiInfo) {

+ 2 - 2
app/public/js/ledger.js

@@ -4188,8 +4188,8 @@ $(document).ready(function() {
             });
         }
     });
-    $('body').on('click', '#auditors li>a', function () {
-        const li = $(this).parent();
+    $('body').on('click', '#auditors li>div>a', function () {
+        const li = $(this).parent().parent();
         const data = {
             auditorId: parseInt(li.attr('auditorId')),
         };

+ 46 - 19
app/service/ledger_audit.js

@@ -160,6 +160,23 @@ module.exports = app => {
             return group;
         }
 
+        groupAuditorsUniq(group) {
+            const helper = this.ctx.helper;
+            const uniqGroup = [];
+            for (const g of group) {
+                const curAuditId = g.map(x => { return x.audit_id; });
+                const sameGroup = uniqGroup.find(x => {
+                    if (!x) return false;
+                    if (x[0].audit_type !== g[0].audit_type) return false;
+                    const auditId = x.map(xa => { return xa.audit_id; });
+                    helper._.remove(auditId, function(a) { return curAuditId.indexOf(a) >= 0; });
+                    return auditId.length === 0;
+                });
+                if (!sameGroup) uniqGroup[g[0].audit_order] = g;
+            }
+            return uniqGroup.filter(x => { return !!x });
+        }
+
         async getUniqUserGroup(tenderId, times) {
             const group = await this.getAuditorGroup(tenderId, times);
             const sql =
@@ -171,7 +188,7 @@ module.exports = app => {
             const sqlParam = [times, tenderId, tenderId];
             const user = await this.db.queryOne(sql, sqlParam);
             group.unshift([ user ]);
-            return this.ctx.helper.groupAuditorsUniq(group, 'audit_order');
+            return this.groupAuditorsUniq(group);
         }
 
         async getAuditorHistory(tenderId, times, reverse = false) {
@@ -254,13 +271,13 @@ module.exports = app => {
             tender.nextAuditors = tender.curAuditors.length > 0 ? tender.auditors.filter(x => { return x.audit_order === tender.curAuditors[0].audit_order + 1; }) : [];
             tender.nextAuditorIds = this._.map(tender.nextAuditors, 'audit_id');
             tender.auditorGroups = this.ctx.helper.groupAuditors(tender.auditors, 'audit_order');
-            tender.userGroups = this.ctx.helper.groupAuditorsUniq(tender.auditorGroups);
+            tender.userGroups = this.groupAuditorsUniq(tender.auditorGroups);
             tender.userGroups.unshift([{
-                aid: tender.user.id, order: 0, times: tender.ledger_times, audit_order: 0, audit_type: auditType.key.common,
+                audit_id: tender.user.id, order: 0, times: tender.ledger_times, audit_order: 0, audit_type: auditType.key.common,
                 name: tender.user.name, role: tender.user.role, company: tender.user.company
             }]);
-            tender.finalAuditorIds = tender.userGroups[tender.userGroups.length - 1].map(x => { return x.aid; });
-            tender.relaAuditor = tender.auditors.find(x => { return x.aid === accountId });
+            tender.finalAuditorIds = tender.userGroups[tender.userGroups.length - 1].map(x => { return x.audit_id; });
+            tender.relaAuditor = tender.auditors.find(x => { return x.audit_id === accountId });
 
             tender.assists = [];// await this.service.ledgerAuditAss.getData(tender); // 全部协同人
             tender.assists = tender.assists.filter(x => {
@@ -285,9 +302,9 @@ module.exports = app => {
             if (tender.status === auditConst.status.checkNo && tender.user_id !== this.ctx.session.sessionUser.accountId) {
                 const auditors = await this.getAuditors(tender.id, times); // 全部参与的审批人
                 const auditorGroups = this.ctx.helper.groupAuditors(auditors, 'audit_order');
-                tender.auditors2 = this.ctx.helper.groupAuditorsUniq(auditorGroups, 'audit_order');
+                tender.auditors2 = this.groupAuditorsUniq(auditorGroups);
                 tender.auditors2.unshift([{
-                    aid: tender.user.id, order: 0, times: tender.ledger_times - 1, audit_order: 0, audit_type: auditType.key.common,
+                    audit_id: tender.user.id, order: 0, times: tender.ledger_times - 1, audit_order: 0, audit_type: auditType.key.common,
                     name: tender.user.name, role: tender.user.role, company: tender.user.company
                 }]);
             } else {
@@ -425,6 +442,7 @@ module.exports = app => {
                 if (!auditor) {
                     throw '该审核人不存在';
                 }
+                await transaction.delete(this.tableName, { tid: tenderId, audit_order: auditor.audit_order, times});
                 await this._syncOrderByDelete(transaction, tenderId, auditor.audit_order, times);
                 await transaction.delete(this.tableName, condition);
                 await transaction.commit();
@@ -696,28 +714,37 @@ module.exports = app => {
          */
         async checkAgain(tenderId, times = 1) {
             const time = new Date();
+            const accountId = this.ctx.session.sessionUser.accountId;
             // 整理当前流程审核人状态更新
             const auditors = await this.getAllDataByCondition({
                 where: { tender_id: tenderId, times },
                 orders: [['audit_order', 'desc']],
             });
             if (auditors.length <= 0) throw '台账审核数据错误';
-            const selfAudit = auditors[0];
-            if (selfAudit.audit_id !== this.ctx.session.sessionUser.accountId) throw '当前台账您无权重审';
+            const flowAuditors = auditors.filter(x => { return x.audit_order === auditors[0].audit_order; });
+            const selfAudit = flowAuditors.find(x => { return x.audit_id === accountId; });
+            if (!selfAudit) throw '当前台账您无权重审';
             const tender = this.ctx.service.tender.getDataById(tenderId);
             if (!tender) throw '标段数据错误';
 
             let otherAuditIds = [tender.user_id, ...auditors.map(x => { return x.audit_id })];
             otherAuditIds = this._.uniq(otherAuditIds).filter(x => { return x !== selfAudit.audit_id; });
 
-            const checkAgainAuditor = {
-                tender_id: tenderId, times, audit_order: selfAudit.audit_order + 1, audit_id: selfAudit.audit_id,
-                begin_time: time, end_time: time, opinion: '', status: auditConst.status.checkAgain,
-            };
-            const checkingAuditor = {
-                tender_id: tenderId, times, audit_order: selfAudit.audit_order + 2, audit_id: selfAudit.audit_id,
-                begin_time: time, end_time: null, opinion: '', status: auditConst.status.checking,
-            };
+            const checkAgainAuditor = flowAuditors.map(x => {
+                return {
+                    tender_id: tenderId, times, audit_order: x.audit_order + 1, audit_id: x.audit_id,
+                    audit_type: x.audit_type, audit_ledger_id: x.audit_ledger_id,
+                    begin_time: time, end_time: time, opinion: '',
+                    status: x.audit_id === accountId ? auditConst.status.checkAgain : auditConst.status.checkSkip,
+                }
+            });
+            const checkingAuditor = flowAuditors.map(x => {
+                return {
+                    tender_id: tenderId, times, audit_order: x.audit_order + 2, audit_id: x.audit_id,
+                    audit_type: x.audit_type, audit_ledger_id: x.audit_ledger_id,
+                    begin_time: time, end_time: null, opinion: '', status: auditConst.status.checking,
+                };
+            });
             const transaction = await this.db.beginTransaction();
             try {
                 // 当前审批人2次添加至流程中
@@ -898,8 +925,8 @@ module.exports = app => {
         async updateLastAudit(tender, auditList, lastId) {
             const transaction = await this.db.beginTransaction();
             try {
-                // 先判断auditList里的aid是否与lastId相同,相同则删除并重新更新order
-                const existAudit = auditList.find(x => { return x.aid === lastId });
+                // 先判断auditList里的audit_id是否与lastId相同,相同则删除并重新更新order
+                const existAudit = auditList.find(x => { return x.audit_id === lastId });
                 let order = auditList.length > 0 ? auditList.reduce((rst, a) => { return Math.max(rst, a.audit_order)}, 0) + 1 : 1; // 最大值 + 1
                 if (existAudit) {
                     await transaction.delete(this.tableName, { sid: stage.id, times: stage.times, audit_id: lastId });

+ 9 - 8
app/service/revise_audit.js

@@ -279,11 +279,11 @@ module.exports = app => {
             revise.auditorGroups = this.ctx.helper.groupAuditors(revise.auditors, 'audit_order');
             revise.userGroups = this.ctx.helper.groupAuditorsUniq(revise.auditorGroups);
             revise.userGroups.unshift([{
-                aid: revise.user.id, order: 0, times: revise.times, audit_order: 0, audit_type: auditType.key.common,
+                audit_id: revise.user.id, order: 0, times: revise.times, audit_order: 0, audit_type: auditType.key.common,
                 name: revise.user.name, role: revise.user.role, company: revise.user.company
             }]);
-            revise.finalAuditorIds = revise.userGroups[revise.userGroups.length - 1].map(x => { return x.aid; });
-            revise.relaAuditor = revise.auditors.find(x => { return x.aid === accountId });
+            revise.finalAuditorIds = revise.userGroups[revise.userGroups.length - 1].map(x => { return x.audit_id; });
+            revise.relaAuditor = revise.auditors.find(x => { return x.audit_id === accountId });
 
             revise.assists = [];// await this.service.ledgerAuditAss.getData(tender); // 全部协同人
             revise.assists = revise.assists.filter(x => {
@@ -310,7 +310,7 @@ module.exports = app => {
                 const auditorGroups = this.ctx.helper.groupAuditors(auditors, 'audit_order');
                 revise.auditors2 = this.ctx.helper.groupAuditorsUniq(auditorGroups, 'audit_order');
                 revise.auditors2.unshift([{
-                    aid: revise.user.id, order: 0, times: revise.times - 1, audit_order: 0, audit_type: auditType.key.common,
+                    audit_id: revise.user.id, order: 0, times: revise.times - 1, audit_order: 0, audit_type: auditType.key.common,
                     name: revise.user.name, role: revise.user.role, company: revise.user.company
                 }]);
             } else {
@@ -420,6 +420,7 @@ module.exports = app => {
                 if (!auditor) {
                     throw '该审核人不存在';
                 }
+                await transaction.delete(this.tableName, { rid: revise.id, audit_order: auditor.audit_order, times });
                 await this._syncOrderByDelete(transaction, revise.id, auditor.audit_order, times);
                 await transaction.delete(this.tableName, condition);
                 await transaction.commit();
@@ -723,8 +724,8 @@ module.exports = app => {
                 return {
                     id: x.id,
                     status: x.audit_id === selfAuditor.audit_id ? auditConst.status.checkNo : auditConst.status.checkSkip,
-                    opinion: x.audit_id === selfAuditor.aid ? opinion : '',
-                    end_time: x.audit_id === selfAuditor.aid ? time : null,
+                    opinion: x.audit_id === selfAuditor.audit_id ? opinion : '',
+                    end_time: x.audit_id === selfAuditor.audit_id ? time : null,
                 };
             });
 
@@ -1051,8 +1052,8 @@ module.exports = app => {
         async updateLastAudit(revise, auditList, lastId) {
             const transaction = await this.db.beginTransaction();
             try {
-                // 先判断auditList里的aid是否与lastId相同,相同则删除并重新更新order
-                const existAudit = auditList.find(x => { return x.aid === lastId });
+                // 先判断auditList里的audit_id是否与lastId相同,相同则删除并重新更新order
+                const existAudit = auditList.find(x => { return x.audit_id === lastId });
                 let order = auditList.length > 0 ? auditList.reduce((rst, a) => { return Math.max(rst, a.audit_order)}, 0) + 1 : 1; // 最大值 + 1
                 if (existAudit) {
                     await transaction.delete(this.tableName, { sid: stage.id, times: stage.times, audit_id: lastId });

+ 23 - 2
app/service/tender_cache.js

@@ -33,9 +33,24 @@ module.exports = app => {
             tender.ledger_tp = cache.ledger_tp ? JSON.parse(cache.ledger_tp) : {};
 
             uid = uid + '';
+            cache.ledger_flow_cur_uid = cache.ledger_flow_cur_uid ? cache.ledger_flow_cur_uid.split(',') : [];
+            cache.ledger_flow_pre_uid = cache.ledger_flow_pre_uid ? cache.ledger_flow_pre_uid.split(',') : [];
             cache.stage_flow_cur_uid = cache.stage_flow_cur_uid ? cache.stage_flow_cur_uid.split(',') : [];
             cache.stage_flow_pre_uid = cache.stage_flow_pre_uid ? cache.stage_flow_pre_uid.split(',') : [];
-            if (!cache.stage_count || (cache.stage_count === 1 && cache.stage_status === auditConst.stage.status.uncheck && cache.stage_flow_cur_uid.indexOf(uid) < 0)) {
+            if (!cache.stage_count) {
+                tender.cur_flow = (cache.ledger_status === auditConst.ledger.status.checkNo)
+                    ? JSON.parse(cache.ledger_flow_pre_info) : JSON.parse(cache.ledger_flow_cur_info || cache.ledger_flow_pre_info);
+                tender.cur_flow.title = '台账';
+                tender.pre_flow = cache.ledger_flow_pre_info ? JSON.parse(cache.ledger_flow_pre_info) : null;
+                tender.stage_tp = {};
+                tender.stage_count = 0;
+                tender.stage_status = cache.stage_status;
+                tender.progress = {
+                    title: '台账',
+                    status: auditConst.ledger.tiStatusString[cache.ledger_status],
+                    status_class: auditConst.ledger.tiStatusStringClass[cache.ledger_status],
+                };
+            } else if (cache.stage_count === 1 && cache.stage_status === auditConst.stage.status.uncheck && cache.stage_flow_cur_uid.indexOf(uid) < 0) {
                 tender.cur_flow = JSON.parse(cache.ledger_flow_cur_info || cache.ledger_flow_pre_info);
                 tender.cur_flow.title = '台账';
                 tender.pre_flow = cache.ledger_flow_pre_info ? JSON.parse(cache.ledger_flow_pre_info) : null;
@@ -98,7 +113,13 @@ module.exports = app => {
 
         async loadTenderCache(tender, uid) {
             const cache = await this.getDataById(tender.id);
-            if (cache) this._analysisTenderCache(tender, cache, uid);
+            if (cache) {
+                try {
+                    this._analysisTenderCache(tender, cache, uid);
+                } catch(err) {
+                    console.log(tender);
+                }
+            }
         }
 
         async insertTenderCache(transaction, tid, uid) {

+ 1 - 1
app/view/ledger/audit_modal.ejs

@@ -499,7 +499,7 @@
         </div>
     </div>
 <% } %>
-<% if (tender.ledger_status === auditConst.status.checked && auditors[auditors.length - 1].audit_id === ctx.session.sessionUser.accountId && !tender.hasStage && !tender.hasRevise) { %>
+<% if (tender.ledger_status === auditConst.status.checked && tender.finalAuditorIds.indexOf(ctx.session.sessionUser.accountId) >= 0 && !tender.hasStage && !tender.hasRevise) { %>
 <% if (!authMobile && ctx.session.sessionUser.loginStatus === 0) { %>
 <!--终审重新审批-->
 <div class="modal fade" id="sp-down-back" data-backdrop="static">

+ 1 - 2
app/view/ledger/explode_modal.ejs

@@ -175,10 +175,9 @@
                                 <% } %>
                                 <% if (ctx.tender.info.shenpi.ledger === shenpiConst.sp_status.sqspr ||
                                         (ctx.tender.info.shenpi.ledger === shenpiConst.sp_status.gdzs && i+1 !== iLen)) { %>
-                                <a href="javascript: void(0)" class="text-danger pull-right">移除</a>
+                                <a href="javascript: void(0)" class="text-danger pull-right ml-1">移除</a>
                                 <% } %>
                             </div>
-
                         </li>
                         <% } %>
                     </ul>