| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 | 
							- 'use strict';
 
- /**
 
-  * 预付款中间件
 
-  * @author lanjianrong
 
-  * @date 2020/8/10
 
-  * @version
 
-  */
 
- const status = require('../const/audit').advance.status;
 
- const shenpiConst = require('../const/shenpi');
 
- const _ = require('lodash');
 
- // const _ = require('lodash')
 
- module.exports = () => {
 
-     /**
 
-      * 预付款 中间件
 
-      * 1. 读取期数据
 
-      * 2. 检验用户是否参与期(不校验具体权限)
 
-      *
 
-      * 写入ctx.advance数据
 
-      * 其中:
 
-      * advance.auditors: 审批人列表(退回原报时,加载上一流程)
 
-      * advance.curAuditor: 当前审批人(未上报为空,审批通过 or 退回原报时,为空)
 
-      * advance.readonly: 登录人,是否可操作
 
-      * advance.curTimes: 当前登录人,操作、查阅数据times
 
-      * advance.curOrder: 当前登录人,操作、查阅数据order
 
-      *
 
-      * 该方法为通用方法,如需advance其他数据,请在controller中查询
 
-      *
 
-      * @param {function} next - 中间件继续执行的方法
 
-      * @return {void}
 
-      */
 
-     return function* advanceCheck(next) {
 
-         try {
 
-             // 读取预付款id
 
-             const id = parseInt(this.params.order);
 
-             if (!id || id <= 0) {
 
-                 throw '您访问的预付款期不存在';
 
-             }
 
-             const advance = yield this.service.advance.getDataById(id);
 
-             if (!advance) {
 
-                 throw '预付款数据错误';
 
-             }
 
-             advance.user = yield this.service.projectAccount.getAccountInfoById(advance.uid);
 
-             // 读取审核人列表数据
 
-             advance.auditors = yield this.service.advanceAudit.getAuditors(advance.id, advance.times);
 
-             advance.curAuditor = yield this.service.advanceAudit.getCurAuditor(advance.id, advance.times);
 
-             // 获取最新的期
 
-             // advance.highOrder = yield this.service.advance.getLastestAdvance(this.tender.id, type, true)
 
-             this.advance = advance;
 
-             // 根据状态判断是否需要更新审批人列表
 
-             if ((advance.status === status.uncheck || advance.status === status.checkNo) && this.tender.info.shenpi.advance !== shenpiConst.sp_status.sqspr) {
 
-                 const shenpi_status = this.tender.info.shenpi.advance;
 
-                 // 进一步比较审批流是否与审批流程设置的相同,不同则替换为固定审批流或固定的终审
 
-                 const auditList = yield this.service.advanceAudit.getAllDataByCondition({ where: { vid: advance.id, times: advance.times } });
 
-                 const auditIdList = _.map(auditList, 'audit_id');
 
-                 if (shenpi_status === shenpiConst.sp_status.gdspl) {
 
-                     const shenpiList = yield this.service.shenpiAudit.getAllDataByCondition({ where: { tid: advance.tid, sp_type: shenpiConst.sp_type.advance, sp_status: shenpi_status } });
 
-                     const shenpiIdList = _.map(shenpiList, 'audit_id');
 
-                     // 判断2个id数组是否相同,不同则删除原审批流,切换成固定的审批流
 
-                     if (!_.isEqual(auditIdList, shenpiIdList)) {
 
-                         yield this.service.advanceAudit.updateNewAuditList(advance, shenpiIdList);
 
-                     }
 
-                 } else if (shenpi_status === shenpiConst.sp_status.gdzs) {
 
-                     const shenpiInfo = yield this.service.shenpiAudit.getDataByCondition({ tid: advance.tid, sp_type: shenpiConst.sp_type.advance, sp_status: shenpi_status });
 
-                     // 判断最后一个id是否与固定终审id相同,不同则删除原审批流中如果存在的id和添加终审
 
-                     if (shenpiInfo && shenpiInfo.audit_id !== _.last(auditIdList)) {
 
-                         yield this.service.advanceAudit.updateLastAudit(advance, auditList, shenpiInfo.audit_id);
 
-                     } else if (!shenpiInfo) {
 
-                         // 不存在终审人的状态下这里恢复为授权审批人
 
-                         this.tender.info.shenpi.advance = shenpiConst.sp_status.sqspr;
 
-                     }
 
-                 }
 
-             }
 
-             yield next;
 
-         } catch (err) {
 
-             this.helper.log(err);
 
-             // 输出错误到日志
 
-             if (err.stack) {
 
-                 this.logger.error(err);
 
-             } else {
 
-                 this.getLogger('fail').info(
 
-                     JSON.stringify({
 
-                         error: err,
 
-                         project: this.session.sessionProject,
 
-                         user: this.session.sessionUser,
 
-                         body: this.session.body,
 
-                     })
 
-                 );
 
-             }
 
-             // 重定向值标段管理
 
-             this.redirect(this.request.headers.referer);
 
-         }
 
-     };
 
- };
 
 
  |