financial_check.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const messageType = require('../const/message_type');
  10. const _ = require('lodash');
  11. const financialConst = require('../const/financial');
  12. module.exports = options => {
  13. /**
  14. * 标段校验 中间件
  15. * 1. 读取标段数据(包括属性)
  16. * 2. 检验用户是否可见标段(不校验具体权限)
  17. *
  18. * @param {function} next - 中间件继续执行的方法
  19. * @return {void}
  20. */
  21. return function* financialCheck(next) {
  22. try {
  23. if (!this.session.sessionProject.page_show.openFinancial) {
  24. throw '该功能已关闭或无法查看';
  25. }
  26. const spid = this.params.spid;
  27. if (!spid) {
  28. throw '参数数据错误';
  29. }
  30. this.subProject = yield this.service.subProject.getDataById(spid);
  31. if (this.subProject.project_id !== this.session.sessionProject.id) throw '您无权查看该项目资金监管';
  32. const fAudit = yield this.service.financialAudit.getDataByCondition({ spid: this.subProject.id, uid: this.session.sessionUser.accountId });
  33. if (!fAudit && !this.session.sessionUser.is_admin) throw '您无权查看该项目资金监管,请联系管理员添加';
  34. if (!this.subProject) throw '项目不存在';
  35. yield next;
  36. } catch (err) {
  37. // 输出错误到日志
  38. if (err.stack) {
  39. this.logger.error(err);
  40. } else {
  41. this.session.message = {
  42. type: messageType.ERROR,
  43. icon: 'exclamation-circle',
  44. message: err,
  45. };
  46. this.getLogger('fail').info(JSON.stringify({
  47. error: err,
  48. project: this.session.sessionProject,
  49. user: this.session.sessionUser,
  50. body: this.session.body,
  51. }));
  52. }
  53. if (this.helper.isAjax(this.request)) {
  54. if (err.stack) {
  55. this.body = { err: 4, msg: '标段数据未知错误', data: null };
  56. } else {
  57. this.body = { err: 3, msg: err.toString(), data: null };
  58. }
  59. } else {
  60. if (this.helper.isWap(this.request)) {
  61. this.redirect('/wap/list');
  62. } else {
  63. this.postError(err, '未知错误');
  64. err === '该功能已关闭或无法查看' ? this.redirect('/dashboard') : this.request.headers.referer ? this.redirect(this.request.headers.referer) : this.redirect('/financial');
  65. }
  66. }
  67. }
  68. };
  69. };