budget_check.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. module.exports = options => {
  10. /**
  11. * 标段校验 中间件
  12. * 1. 读取标段数据(包括属性)
  13. * 2. 检验用户是否可见标段(不校验具体权限)
  14. *
  15. * @param {function} next - 中间件继续执行的方法
  16. * @return {void}
  17. */
  18. return function* budgetCheck(next) {
  19. try {
  20. if (!this.subProject.page_show.openBudget) {
  21. throw '该功能已关闭或无法查看';
  22. }
  23. // 读取标段数据
  24. this.budget = yield this.service.budget.getCurBudget(this.subProject.budget_id);
  25. this.budget.name = this.subProject.name || '';
  26. if (!this.budget) throw '未设置概预算标准';
  27. if (this.budget.pid !== this.session.sessionProject.id) throw '您无权查看该项目';
  28. this.budget.readOnly = this.subProject.permission.budget_permission.indexOf(this.service.subProjPermission.PermissionConst.budget.edit.value) < 0;
  29. yield next;
  30. } catch (err) {
  31. this.log(err);
  32. if (this.helper.isAjax(this.request)) {
  33. this.ajaxErrorBody(err, '概算投资项目未知错误');
  34. } else {
  35. this.postError(err, '概算投资项目未知错误');
  36. err === '该功能已关闭或无法查看' ? this.redirect(`/sp/${this.subProject.id}/dashboard`) : this.redirect(this.request.headers.referer);
  37. }
  38. }
  39. };
  40. };