| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 | 'use strict';/** * * * @author Mai * @date * @version */const messageType = require('../const/message_type');const _ = require('lodash');const financialConst = require('../const/financial');module.exports = options => {    /**     * 标段校验 中间件     * 1. 读取标段数据(包括属性)     * 2. 检验用户是否可见标段(不校验具体权限)     *     * @param {function} next - 中间件继续执行的方法     * @return {void}     */    return function* financialCheck(next) {        try {            if (!this.session.sessionProject.page_show.openFinancial) {                throw '该功能已关闭或无法查看';            }            const spid = this.params.spid;            if (!spid) {                throw '参数数据错误';            }            this.subProject = yield this.service.subProject.getDataById(spid);            if (this.subProject.project_id !== this.session.sessionProject.id) throw '您无权查看该项目资金监管';            const fAudit = yield this.service.financialAudit.getDataByCondition({ spid: this.subProject.id, uid: this.session.sessionUser.accountId });            if (!fAudit && !this.session.sessionUser.is_admin) throw '您无权查看该项目资金监管,请联系管理员添加';            if (!this.subProject) throw '项目不存在';            yield next;        } catch (err) {            // 输出错误到日志            if (err.stack) {                this.logger.error(err);            } else {                this.session.message = {                    type: messageType.ERROR,                    icon: 'exclamation-circle',                    message: err,                };                this.getLogger('fail').info(JSON.stringify({                    error: err,                    project: this.session.sessionProject,                    user: this.session.sessionUser,                    body: this.session.body,                }));            }            if (this.helper.isAjax(this.request)) {                if (err.stack) {                    this.body = { err: 4, msg: '标段数据未知错误', data: null };                } else {                    this.body = { err: 3, msg: err.toString(), data: null };                }            } else {                if (this.helper.isWap(this.request)) {                    this.redirect('/wap/list');                } else {                    this.postError(err, '未知错误');                    err === '该功能已关闭或无法查看' ? this.redirect('/dashboard') : this.request.headers.referer ? this.redirect(this.request.headers.referer) : this.redirect('/financial');                }            }        }    };};
 |