uncheck_tender_check.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const auditConst = require('../const/audit').ledger;
  10. const messageType = require('../const/message_type');
  11. module.exports = options => {
  12. /**
  13. * 标段校验 中间件
  14. * 1. 读取标段数据(包括属性)
  15. * 2. 检验用户是否可见标段(不校验具体权限)
  16. *
  17. * @param {function} next - 中间件继续执行的方法
  18. * @return {void}
  19. */
  20. return function* uncheckTenderCheck(next) {
  21. try {
  22. if (this.tender.data.ledger_status === auditConst.status.uncheck) {
  23. if (this.tender.data.user_id !== this.session.sessionUser.accountId && !this.session.sessionUser.is_admin && this.tender.advanceAuditorsId.indexOf(this.session.sessionUser.accountId) === -1 && !this.tender.isTourist) {
  24. throw '您无权查看该项目';
  25. } else if (this.tender.advanceAuditorsId.indexOf(this.session.sessionUser.accountId) !== -1 && !this.session.sessionUser.is_admin && !this.tender.isTourist) {
  26. throw '您无权查看该内容';
  27. }
  28. }
  29. yield next;
  30. } catch (err) {
  31. // 输出错误到日志
  32. if (err.stack) {
  33. this.logger.error(err);
  34. } else {
  35. this.session.message = {
  36. type: messageType.ERROR,
  37. icon: 'exclamation-circle',
  38. message: err,
  39. };
  40. this.getLogger('fail').info(JSON.stringify({
  41. error: err,
  42. project: this.session.sessionProject,
  43. user: this.session.sessionUser,
  44. body: this.session.body,
  45. }));
  46. }
  47. if (this.helper.isAjax(this.request)) {
  48. if (err.stack) {
  49. this.body = {err: 4, msg: '标段数据未知错误', data: null};
  50. } else {
  51. this.body = {err: 3, msg: err.toString(), data: null};
  52. }
  53. } else {
  54. if (this.helper.isWap(this.request)) {
  55. this.redirect('/wap/subproj');
  56. } else {
  57. err === '您无权查看该内容' ? this.redirect(this.request.headers.referer) : this.redirect(`/sp/${ctx.subProject.id}/list`);
  58. }
  59. }
  60. }
  61. };
  62. };