Browse Source

审批流程加载相关

MaiXinRong 7 months ago
parent
commit
8fc7a88718
1 changed files with 14 additions and 10 deletions
  1. 14 10
      app/service/phase_pay_audit.js

+ 14 - 10
app/service/phase_pay_audit.js

@@ -230,7 +230,9 @@ module.exports = app => {
         }
         // 固定审批流-更新
         async updateNewAuditList(phasePay, newList) {
-            const newAuditsInfo = await this.ctx.service.projectAccount.getAllDataByCondition({ where: { id: newList.map(x => { return x.audit_id; })} });
+            const newAuditsInfo = newList && newList.length > 0
+                ? await this.ctx.service.projectAccount.getAllDataByCondition({ where: { id: newList.map(x => { return x.audit_id; })} })
+                : [];
             const transaction = await this.db.beginTransaction();
             try {
                 // 先删除旧的审批流,再添加新的
@@ -255,11 +257,11 @@ module.exports = app => {
         }
         // 固定终审-更新
         async updateLastAudit(phasePay, auditList, lastId) {
-            const lastUser = await this.ctx.service.projectAccount.getDataById(lastId);
+            const lastUser = lastId ? await this.ctx.service.projectAccount.getDataById(lastId) : null;
             const transaction = await this.db.beginTransaction();
             try {
                 // 先判断auditList里的aid是否与lastId相同,相同则删除并重新更新order
-                const existAudit = auditList.find(x => { return x.audit_id === lastId });
+                const existAudit = lastId ? auditList.find(x => { return x.audit_id === lastId }) : null;
                 let auditOrder = auditList.length > 0 ? auditList.reduce((rst, a) => { return Math.max(rst, a.active_order)}, 0) + 1 : 1; // 最大值 + 1
                 if (existAudit) {
                     await transaction.delete(this.tableName, { phase_id: phasePay.id, audit_times: phasePay.audit_times, audit_id: lastId });
@@ -277,13 +279,15 @@ module.exports = app => {
                     }
                 }
                 // 添加终审
-                const newAuditor = {
-                    tid: phasePay.tid, phase_id: phasePay.id, audit_id: lastId,
-                    name: lastUser.name, company: lastUser.company, role: lastUser.role, mobile: lastUser.mobile,
-                    audit_times: phasePay.audit_times, active_order: auditOrder, audit_status: auditConst.phasePay.status.uncheck,
-                    audit_type: auditType.key.common, audit_order: auditOrder,
-                };
-                await transaction.insert(this.tableName, newAuditor);
+                if (lastUser) {
+                    const newAuditor = {
+                        tid: phasePay.tid, phase_id: phasePay.id, audit_id: lastId,
+                        name: lastUser.name, company: lastUser.company, role: lastUser.role, mobile: lastUser.mobile,
+                        audit_times: phasePay.audit_times, active_order: auditOrder, audit_status: auditConst.phasePay.status.uncheck,
+                        audit_type: auditType.key.common, audit_order: auditOrder,
+                    };
+                    await transaction.insert(this.tableName, newAuditor);
+                }
                 await transaction.commit();
             } catch (err) {
                 await transaction.rollback();