| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 | 
							- '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.subProject) {
 
-                 throw '项目不存在';
 
-             }
 
-             if (!this.subProject.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 financialPermission = yield this.service.subProjPermission.getFinancailPermission(this.subProject.permission.fund_trans_permission, this.subProject.permission.fund_pay_permission);
 
-             // const fAudit = yield this.service.financialAudit.getDataByCondition({ spid: this.subProject.id, uid: this.session.sessionUser.accountId });
 
-             if (!financialPermission.transfer_show && !financialPermission.pay_show && !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/subproj');
 
-                 } else {
 
-                     this.postError(err, '未知错误');
 
-                     err === '该功能已关闭或无法查看' ? this.redirect('/dashboard') : this.request.headers.referer ? this.redirect(this.request.headers.referer) : this.redirect(`/sp/${this.subProject.id}/financial`);
 
-                 }
 
-             }
 
-         }
 
-     };
 
- };
 
 
  |