financial_pay_check.js 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.subProject) throw '项目不存在';
  25. if (!this.subProject.page_show.openFinancial) {
  26. throw '该功能已关闭或无法查看';
  27. }
  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. const fptAudits = yield this.service.financialPayTenderAudit.getDataByCondition({ spid: financialPay.spid, tid: financialPay.tid, uid: accountId });
  40. if (!this.session.sessionUser.is_admin && !fptAudits) {
  41. throw '您无权查看该数据';
  42. }
  43. financialPay.filePermission = financialPay.permission.pay_file ||
  44. (financialPay.status === status.checking && auditorIds.indexOf(accountId) !== -1) ||
  45. ((financialPay.status === status.uncheck || financialPay.status === status.checkNo) && accountId === financialPay.uid);
  46. } else { // 其他不可见
  47. throw '您无权查看该数据';
  48. }
  49. financialPay.filePermission = financialPay.filePermission ? true : financialPay.permission.pay_file;
  50. // 调差的readOnly 指表格和页面只能看不能改,和审批无关
  51. // financialPay.readOnly = true;
  52. financialPay.readOnly = !((financialPay.status === status.uncheck || financialPay.status === status.checkNo) && accountId === financialPay.uid);
  53. financialPay.shenpiPower = financialPay.status === status.checking && financialPay.curAuditorIds.indexOf(accountId) !== -1;
  54. this.financialPay = financialPay;
  55. yield next;
  56. } catch (err) {
  57. // 输出错误到日志
  58. if (err.stack) {
  59. this.logger.error(err);
  60. } else {
  61. this.session.message = {
  62. type: messageType.ERROR,
  63. icon: 'exclamation-circle',
  64. message: err,
  65. };
  66. this.getLogger('fail').info(JSON.stringify({
  67. error: err,
  68. project: this.session.sessionProject,
  69. user: this.session.sessionUser,
  70. body: this.session.body,
  71. }));
  72. }
  73. if (this.helper.isAjax(this.request)) {
  74. if (err.stack) {
  75. this.body = { err: 4, msg: '标段数据未知错误', data: null };
  76. } else {
  77. this.body = { err: 3, msg: err.toString(), data: null };
  78. }
  79. } else {
  80. if (this.helper.isWap(this.request)) {
  81. this.redirect('/wap/subproj');
  82. } else {
  83. this.postError(err, '未知错误');
  84. err === '该功能已关闭或无法查看' ? this.redirect('/dashboard') : this.request.headers.referer ? this.redirect(this.request.headers.referer) : this.redirect(`/sp/${this.subProject.id}/financial`);
  85. }
  86. }
  87. }
  88. };
  89. };