financial_check.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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.subProject) {
  24. throw '项目不存在';
  25. }
  26. if (!this.subProject.page_show.openFinancial) {
  27. throw '该功能已关闭或无法查看';
  28. }
  29. // const spid = this.params.spid;
  30. // if (!spid) {
  31. // throw '参数数据错误';
  32. // }
  33. // this.subProject = yield this.service.subProject.getDataById(spid);
  34. if (this.subProject.project_id !== this.session.sessionProject.id) throw '您无权查看该项目资金监管';
  35. const financialPermission = yield this.service.subProjPermission.getFinancailPermission(this.subProject.permission.fund_trans_permission, this.subProject.permission.fund_pay_permission);
  36. // const fAudit = yield this.service.financialAudit.getDataByCondition({ spid: this.subProject.id, uid: this.session.sessionUser.accountId });
  37. if (!financialPermission.transfer_show && !financialPermission.pay_show && !this.session.sessionUser.is_admin) throw '您无权查看该项目资金监管,请联系管理员添加';
  38. // if (!this.subProject) throw '项目不存在';
  39. yield next;
  40. } catch (err) {
  41. // 输出错误到日志
  42. if (err.stack) {
  43. this.logger.error(err);
  44. } else {
  45. this.session.message = {
  46. type: messageType.ERROR,
  47. icon: 'exclamation-circle',
  48. message: err,
  49. };
  50. this.getLogger('fail').info(JSON.stringify({
  51. error: err,
  52. project: this.session.sessionProject,
  53. user: this.session.sessionUser,
  54. body: this.session.body,
  55. }));
  56. }
  57. if (this.helper.isAjax(this.request)) {
  58. if (err.stack) {
  59. this.body = { err: 4, msg: '标段数据未知错误', data: null };
  60. } else {
  61. this.body = { err: 3, msg: err.toString(), data: null };
  62. }
  63. } else {
  64. if (this.helper.isWap(this.request)) {
  65. this.redirect('/wap/subproj');
  66. } else {
  67. this.postError(err, '未知错误');
  68. err === '该功能已关闭或无法查看' ? this.redirect('/dashboard') : this.request.headers.referer ? this.redirect(this.request.headers.referer) : this.redirect(`/sp/${this.subProject.id}/financial`);
  69. }
  70. }
  71. }
  72. };
  73. };