Browse Source

台账审批流程显示调整

MaiXinRong 11 months ago
parent
commit
ceaac43fa1
1 changed files with 15 additions and 3 deletions
  1. 15 3
      app/service/ledger_audit.js

+ 15 - 3
app/service/ledger_audit.js

@@ -198,13 +198,22 @@ module.exports = app => {
                     const auditors = await this.getAuditors(tenderId, i);
                     const group = this.ctx.helper.groupAuditors(auditors, 'audit_order');
                     const historyGroup = [];
-                    const max_order = group.length > 0 && group[group.length - 1].length > 0 ? group[group.length - 1][0].audit_order : -1;
+                    let max_order = 0;
                     for (const g of group) {
                         const his = {
                             beginYear: '', beginDate: '', beginTime: '', endYear: '', endDate: '', endTime: '', begin_time: null, end_time: null,
-                            audit_type: g[0].audit_type, audit_order: g[0].audit_order,
+                            audit_type: g[0].audit_type, order: g[0].audit_order,
                             auditors: g
                         };
+                        const curAuditId = g.map(x => { return x.audit_id; });
+                        const sameHis = historyGroup.find(x => {
+                            if (x.audit_type !== his.audit_type) return false;
+                            const auditId = x.auditors.map(xa => { return xa.audit_id; });
+                            this.ctx.helper._.remove(auditId, function(a) { return curAuditId.indexOf(a) >= 0; });
+                            return auditId.length === 0;
+                        });
+                        his.audit_order = sameHis ? sameHis.audit_order : his.order;
+                        if (!sameHis && his.audit_order > max_order) max_order = his.audit_order;
                         if (his.audit_type === auditType.key.common) {
                             his.name = g[0].name;
                         } else {
@@ -236,6 +245,9 @@ module.exports = app => {
                         }
                         historyGroup.push(his);
                     }
+                    historyGroup.forEach(hg => {
+                        hg.is_final = hg.audit_order === max_order;
+                    });
                     if (reverse) {
                         history.push(historyGroup.reverse());
                     } else {
@@ -442,7 +454,7 @@ module.exports = app => {
                 if (!auditor) {
                     throw '该审核人不存在';
                 }
-                await transaction.delete(this.tableName, { tid: tenderId, audit_order: auditor.audit_order, times});
+                await transaction.delete(this.tableName, { tender_id: 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();