revise_check.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const auditConst = require('../const/audit').revise;
  10. module.exports = options => {
  11. /**
  12. * 标段校验 中间件
  13. * 1. 读取标段数据(包括属性)
  14. * 2. 检验用户是否可见标段(不校验具体权限)
  15. *
  16. * @param {function} next - 中间件继续执行的方法
  17. * @return {void}
  18. */
  19. return function* reviseAuditCheck(next) {
  20. try {
  21. // 获取revise
  22. const revise = yield this.service.ledgerRevise.getLastestRevise(this.tender.id);
  23. if (!revise) throw '台账修订数据有误';
  24. revise.reviseUsers = [revise.uid];
  25. if (revise.status !== auditConst.status.uncheck) {
  26. const times = revise.status === auditConst.status.checkNo ? revise.times - 1 : revise.times;
  27. const auditors = yield this.service.reviseAudit.getAuditors(revise.id, times);
  28. const auditorsId = this.helper._.map(auditors, 'audit_id');
  29. revise.reviseUsers.push(...auditorsId);
  30. }
  31. this.revise = revise;
  32. yield next;
  33. } catch (err) {
  34. // 输出错误到日志
  35. if (err.stack) {
  36. this.logger.error(err);
  37. } else {
  38. this.getLogger('fail').info(JSON.stringify({
  39. error: err,
  40. project: this.session.sessionProject,
  41. user: this.session.sessionUser,
  42. body: this.session.body,
  43. }));
  44. }
  45. // 重定向值标段管理
  46. if (this.helper.isAjax(this.request)) {
  47. if (err.stack) {
  48. this.body = {err: 4, msg: '标段数据未知错误', data: null};
  49. } else {
  50. this.body = {err: 3, msg: err.toString(), data: null};
  51. }
  52. } else {
  53. if (this.helper.isWap(this.request)) {
  54. this.redirect('/wap/list');
  55. } else {
  56. err === '您无权查看该内容' ? this.redirect(this.request.headers.referer) : this.redirect('/list');
  57. }
  58. }
  59. }
  60. };
  61. };