12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- 'use strict';
- /**
- * 预付款中间件
- * @author lanjianrong
- * @date 2020/8/10
- * @version
- */
- const status = require('../const/audit').advance.status;
- // 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;
- 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);
- }
- };
- };
|