12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- 'use strict';
- /**
- *
- *
- * @author Ellisran
- * @date 2020/10/15
- * @version
- */
- const status = require('../const/audit').financial.status;
- const shenpiConst = require('../const/shenpi');
- const _ = require('lodash');
- module.exports = options => {
- /**
- * 标段校验 中间件
- * 1. 读取标段数据(包括属性)
- * 2. 检验用户是否可见标段(不校验具体权限)
- *
- * @param {function} next - 中间件继续执行的方法
- * @return {void}
- */
- return function* financailPayAuditCheck(next) {
- try {
- // 获取revise
- const id = this.params.fpid || this.request.body.fpid;
- if (!id) {
- throw '您访问的资金支付不存在';
- }
- // const change = yield this.service.change.getDataByCondition({ cid });
- if (!this.financialPay) {
- const financialPay = yield this.service.financialPay.getDataById(id);
- if (!financialPay) throw '资金支付数据有误';
- yield this.service.financialPay.loadChangeUser(financialPay);
- this.financialPay = financialPay;
- }
- const financialPay = this.financialPay;
- if (financialPay.status === status.uncheck || financialPay.status === status.checkNo) {
- // 进一步比较审批流是否与审批流程设置的相同,不同则替换为固定审批流或固定的终审
- const auditList = yield this.service.financialPayAudit.getAllDataByCondition({ where: { fpid: financialPay.id, times: financialPay.times }, orders: [['order', 'asc']] });
- const condition = { tid: financialPay.tid, sp_type: shenpiConst.sp_other_type.financial, sp_status: shenpiConst.sp_status.gdspl };
- const shenpiList = yield this.service.shenpiAudit.getAllDataByCondition({ where: condition, orders: [['audit_order', 'asc']] });
- yield this.service.shenpiAudit.noYbShenpiList(financialPay.uid, shenpiList);
- // 判断2个id数组是否相同,不同则删除原审批流,切换成固定的审批流
- let sameAudit = auditList.length === shenpiList.length;
- if (sameAudit) {
- for (const audit of auditList) {
- const shenpi = shenpiList.find(x => { return x.audit_id === audit.aid; });
- if (!shenpi || shenpi.audit_order !== audit.audit_order || shenpi.audit_type !== audit.audit_type) {
- sameAudit = false;
- break;
- }
- }
- }
- if (!sameAudit) {
- yield this.service.financialPayAudit.updateNewAuditList(financialPay, shenpiList);
- yield this.service.financialPay.loadPayUser(financialPay);
- }
- }
- 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);
- }
- };
- };
|