revise_check.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. revise.priceCount = yield this.service.revisePrice.count({ rid: revise.id });
  39. this.revise = revise;
  40. yield next;
  41. } catch (err) {
  42. // 输出错误到日志
  43. if (err.stack) {
  44. this.logger.error(err);
  45. } else {
  46. this.getLogger('fail').info(JSON.stringify({
  47. error: err,
  48. project: this.session.sessionProject,
  49. user: this.session.sessionUser,
  50. body: this.session.body,
  51. }));
  52. }
  53. // 重定向值标段管理
  54. if (this.helper.isAjax(this.request)) {
  55. if (err.stack) {
  56. this.body = {err: 4, msg: '标段数据未知错误', data: null};
  57. } else {
  58. this.body = {err: 3, msg: err.toString(), data: null};
  59. }
  60. } else {
  61. if (this.helper.isWap(this.request)) {
  62. this.redirect('/wap/list');
  63. } else {
  64. err === '您无权查看该内容' ? this.redirect(this.request.headers.referer) : this.redirect('/list');
  65. }
  66. }
  67. }
  68. };
  69. };