uncheck_tender_check.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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
  24. && this.tender.advanceAuditorsId.indexOf(this.session.sessionUser.accountId) === -1) {
  25. throw '您无权查看该项目';
  26. } else if (this.tender.advanceAuditorsId.indexOf(this.session.sessionUser.accountId) !== -1) {
  27. throw '您无权查看该内容';
  28. }
  29. }
  30. yield next;
  31. } catch (err) {
  32. // 输出错误到日志
  33. if (err.stack) {
  34. this.logger.error(err);
  35. } else {
  36. this.session.message = {
  37. type: messageType.ERROR,
  38. icon: 'exclamation-circle',
  39. message: err,
  40. };
  41. this.getLogger('fail').info(JSON.stringify({
  42. error: err,
  43. project: this.session.sessionProject,
  44. user: this.session.sessionUser,
  45. body: this.session.body,
  46. }));
  47. }
  48. if (this.helper.isAjax(this.request)) {
  49. if (err.stack) {
  50. this.body = {err: 2, msg: '标段数据未知错误', data: null};
  51. } else {
  52. this.body = {err: 1, msg: err.toString(), data: null};
  53. }
  54. } else {
  55. if (this.helper.isWap(this.request)) {
  56. this.redirect('/wap/list');
  57. } else {
  58. err === '您无权查看该内容' ? this.redirect(this.request.headers.referer) : this.redirect('/list');
  59. }
  60. }
  61. }
  62. };
  63. };