revise_check.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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* reviseCheck(next) {
  20. try {
  21. // 获取revise
  22. const revise = this.params.rid
  23. ? yield this.service.ledgerRevise.getRevise(this.tender.id, this.params.rid)
  24. : yield this.service.ledgerRevise.getLastestRevise(this.tender.id);
  25. if (!revise) throw '台账修订数据有误';
  26. // 修订前后,历史台账
  27. revise.preHis = revise.pre_his_id ? yield this.service.ledgerHistory.getDataById(revise.pre_his_id) : null;
  28. revise.curHis = revise.his_id ? yield this.service.ledgerHistory.getDataById(revise.his_id) : null;
  29. revise.reviseUsers = [revise.uid];
  30. if (revise.status !== auditConst.status.uncheck) {
  31. const times = revise.status === auditConst.status.checkNo ? revise.times - 1 : revise.times;
  32. const auditors = yield this.service.reviseAudit.getAuditors(revise.id, times);
  33. const auditorsId = this.helper._.map(auditors, 'audit_id');
  34. revise.reviseUsers.push(...auditorsId);
  35. }
  36. revise.readOnly = revise.uid !== this.session.sessionUser.accountId ||
  37. revise.status === auditConst.status.checking || revise.status === auditConst.status.checked;
  38. this.revise = revise;
  39. yield next;
  40. } catch (err) {
  41. // 输出错误到日志
  42. if (err.stack) {
  43. this.logger.error(err);
  44. } else {
  45. this.getLogger('fail').info(JSON.stringify({
  46. error: err,
  47. project: this.session.sessionProject,
  48. user: this.session.sessionUser,
  49. body: this.session.body,
  50. }));
  51. }
  52. // 重定向值标段管理
  53. if (this.helper.isAjax(this.request)) {
  54. if (err.stack) {
  55. this.body = {err: 4, msg: '标段数据未知错误', data: null};
  56. } else {
  57. this.body = {err: 3, msg: err.toString(), data: null};
  58. }
  59. } else {
  60. if (this.helper.isWap(this.request)) {
  61. this.redirect('/wap/list');
  62. } else {
  63. err === '您无权查看该内容' ? this.redirect(this.request.headers.referer) : this.redirect('/list');
  64. }
  65. }
  66. }
  67. };
  68. };