revise_check.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. if (revise.reviseUsers.indexOf(this.session.sessionUser.accountId) < 0) throw '您无权查看该数据';
  37. revise.readOnly = revise.uid !== this.session.sessionUser.accountId ||
  38. revise.status === auditConst.status.checking || revise.status === auditConst.status.checked;
  39. revise.priceCount = yield this.service.revisePrice.count({ rid: revise.id });
  40. revise.readySettle = yield this.service.settle.getReadySettle(revise.tid);
  41. this.revise = revise;
  42. yield next;
  43. } catch (err) {
  44. // 输出错误到日志
  45. this.log(err);
  46. // 重定向值标段管理
  47. if (this.helper.isAjax(this.request)) {
  48. this.ajaxErrorBody(err, '标段数据未知错误');
  49. } else {
  50. this.postError(err, '标段数据未知错误');
  51. if (this.helper.isWap(this.request)) {
  52. this.redirect('/wap/subproj');
  53. } else {
  54. this.redirect(this.request.headers.referer);
  55. }
  56. }
  57. }
  58. };
  59. };