financial_pay_check.js 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. const status = require('../const/audit').financial.status;
  13. module.exports = options => {
  14. /**
  15. * 标段校验 中间件
  16. * 1. 读取标段数据(包括属性)
  17. * 2. 检验用户是否可见标段(不校验具体权限)
  18. *
  19. * @param {function} next - 中间件继续执行的方法
  20. * @return {void}
  21. */
  22. return function* financialPayCheck(next) {
  23. try {
  24. if (!this.session.sessionProject.page_show.openFinancial) {
  25. throw '该功能已关闭或无法查看';
  26. }
  27. if (!this.subProject) throw '项目不存在';
  28. const fpid = this.params.fpid;
  29. if (!fpid) {
  30. throw '参数数据错误';
  31. }
  32. const financialPay = yield this.service.financialPay.getOnePay(fpid);
  33. yield this.service.financialPay.loadPayUser(financialPay);
  34. // 权限相关
  35. // todo 校验权限 (标段参与人、分享)
  36. const accountId = this.session.sessionUser.accountId,
  37. auditorIds = _.map(financialPay.auditors, 'aid');
  38. if (financialPay.permission.pay_show) {
  39. financialPay.filePermission = financialPay.permission.pay_file ||
  40. (financialPay.status === status.checking && auditorIds.indexOf(accountId) !== -1) ||
  41. ((financialPay.status === status.uncheck || financialPay.status === status.checkNo) && accountId === financialPay.uid);
  42. } else { // 其他不可见
  43. throw '您无权查看该数据';
  44. }
  45. financialPay.filePermission = financialPay.filePermission ? true : financialPay.permission.pay_file;
  46. // 调差的readOnly 指表格和页面只能看不能改,和审批无关
  47. // financialPay.readOnly = true;
  48. financialPay.readOnly = !((financialPay.status === status.uncheck || financialPay.status === status.checkNo) && accountId === financialPay.uid);
  49. financialPay.shenpiPower = financialPay.status === status.checking && financialPay.curAuditorIds.indexOf(accountId) !== -1;
  50. this.financialPay = financialPay;
  51. yield next;
  52. } catch (err) {
  53. // 输出错误到日志
  54. if (err.stack) {
  55. this.logger.error(err);
  56. } else {
  57. this.session.message = {
  58. type: messageType.ERROR,
  59. icon: 'exclamation-circle',
  60. message: err,
  61. };
  62. this.getLogger('fail').info(JSON.stringify({
  63. error: err,
  64. project: this.session.sessionProject,
  65. user: this.session.sessionUser,
  66. body: this.session.body,
  67. }));
  68. }
  69. if (this.helper.isAjax(this.request)) {
  70. if (err.stack) {
  71. this.body = { err: 4, msg: '标段数据未知错误', data: null };
  72. } else {
  73. this.body = { err: 3, msg: err.toString(), data: null };
  74. }
  75. } else {
  76. if (this.helper.isWap(this.request)) {
  77. this.redirect('/wap/list');
  78. } else {
  79. this.postError(err, '未知错误');
  80. err === '该功能已关闭或无法查看' ? this.redirect('/dashboard') : this.request.headers.referer ? this.redirect(this.request.headers.referer) : this.redirect('/financial');
  81. }
  82. }
  83. }
  84. };
  85. };