| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 | 
							- 'use strict';
 
- /**
 
-  *
 
-  *
 
-  * @author Ellisran
 
-  * @date 2020/10/15
 
-  * @version
 
-  */
 
- const status = require('../const/audit').flow.status;
 
- const shenpiConst = require('../const/shenpi');
 
- const _ = require('lodash');
 
- module.exports = options => {
 
-     /**
 
-      * 标段校验 中间件
 
-      * 1. 读取标段数据(包括属性)
 
-      * 2. 检验用户是否可见标段(不校验具体权限)
 
-      *
 
-      * @param {function} next - 中间件继续执行的方法
 
-      * @return {void}
 
-      */
 
-     return function* changeAuditCheck(next) {
 
-         try {
 
-             // 获取revise
 
-             const cid = this.params.cid || this.request.body.cid;
 
-             if (!cid) {
 
-                 throw '您访问的变更令不存在';
 
-             }
 
-             const change = yield this.service.change.getDataByCondition({ cid });
 
-             if (!change) throw '变更令数据有误';
 
-             if ((change.status === status.uncheck || change.status === status.back || change.status === status.revise) && this.tender.info.shenpi.change !== shenpiConst.sp_status.sqspr) {
 
-                 const shenpi_status = this.tender.info.shenpi.change;
 
-                 // 进一步比较审批流是否与审批流程设置的相同,不同则替换为固定审批流或固定的终审
 
-                 const auditList = yield this.service.changeAudit.getAllDataByCondition({ where: { cid: change.cid, times: change.times }, orders: [['usort', 'asc']] });
 
-                 auditList.shift();
 
-                 const auditIdList = _.map(auditList, 'uid');
 
-                 if (shenpi_status === shenpiConst.sp_status.gdspl) {
 
-                     const shenpiList = yield this.service.shenpiAudit.getAllDataByCondition({ where: { tid: this.tender.id, sp_type: shenpiConst.sp_type.change, sp_status: shenpi_status } });
 
-                     const shenpiIdList = _.map(shenpiList, 'audit_id');
 
-                     // 判断2个id数组是否相同,不同则删除原审批流,切换成固定的审批流
 
-                     if (!_.isEqual(auditIdList, shenpiIdList)) {
 
-                         yield this.service.changeAudit.updateNewAuditList(change, shenpiIdList);
 
-                     }
 
-                 } else if (shenpi_status === shenpiConst.sp_status.gdzs) {
 
-                     const shenpiInfo = yield this.service.shenpiAudit.getDataByCondition({ tid: this.tender.id, sp_type: shenpiConst.sp_type.change, sp_status: shenpi_status });
 
-                     // 判断最后一个id是否与固定终审id相同,不同则删除原审批流中如果存在的id和添加终审
 
-                     if (shenpiInfo && shenpiInfo.audit_id !== _.last(auditIdList)) {
 
-                         yield this.service.changeAudit.updateLastAudit(change, auditList, shenpiInfo.audit_id);
 
-                     } else if (!shenpiInfo) {
 
-                         // 不存在终审人的状态下这里恢复为授权审批人
 
-                         this.tender.info.shenpi.change = shenpiConst.sp_status.sqspr;
 
-                     }
 
-                 }
 
-             }
 
-             yield next;
 
-         } catch (err) {
 
-             console.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);
 
-         }
 
-     };
 
- };
 
 
  |