phase_pay_check.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. module.exports = options => {
  10. /**
  11. * 期校验 中间件
  12. * 1. 读取期数据
  13. * 2. 检验用户是否参与期(不校验具体权限)
  14. *
  15. * 写入ctx.phasePay数据
  16. * 其中:
  17. * phasePay.user: 创建人
  18. * phasePay.auditors: 审批人列表(退回原报时,加载上一流程)
  19. * phasePay.curAuditors: 当前审批人(未上报为空,审批通过 or 退回原报时,为空)
  20. *
  21. * phasePay.readOnly: 登录人,是否可操作
  22. * phasePay.curTimes: 当前登录人,操作、查阅数据times
  23. * phasePay.curOrder: 当前登录人,操作、查阅数据order
  24. *
  25. * 该方法为通用方法,如需phasePay其他数据,请在controller中查询
  26. *
  27. * @param {function} next - 中间件继续执行的方法
  28. * @return {void}
  29. */
  30. return function* phasePayCheck(next) {
  31. try {
  32. // 读取标段数据
  33. const phaseOrder = parseInt(this.params.order);
  34. if (phaseOrder <= 0) throw '您访问的合同支付不存在';
  35. const phasePay = yield this.service.phasePay.getPhasePayByOrder(this.tender.id, phaseOrder);
  36. if (!phasePay) throw '合同支付数据错误';
  37. // 读取原报、审核人数据
  38. yield this.service.phasePay.doCheckPhase(phasePay);
  39. phasePay.latestOrder = yield this.service.phasePay.count({ tid: this.tender.id });
  40. phasePay.isLatest = phasePay.latestOrder === phasePay.phase_order;
  41. yield this.service.phasePay.checkShenpi(phasePay);
  42. this.phasePay = phasePay;
  43. yield next;
  44. } catch (err) {
  45. this.log(err);
  46. if (this.helper.isAjax(this.request)) {
  47. this.ajaxErrorBody(err, '读取合同支付错误');
  48. } else {
  49. this.postError(err, '读取合同支付错误');
  50. this.redirect(this.request.headers.referer);
  51. }
  52. }
  53. };
  54. };