advance_check.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. 'use strict';
  2. /**
  3. * 预付款中间件
  4. * @author lanjianrong
  5. * @date 2020/8/10
  6. * @version
  7. */
  8. const status = require('../const/audit').advance.status;
  9. // const _ = require('lodash')
  10. module.exports = () => {
  11. /**
  12. * 预付款 中间件
  13. * 1. 读取期数据
  14. * 2. 检验用户是否参与期(不校验具体权限)
  15. *
  16. * 写入ctx.advance数据
  17. * 其中:
  18. * advance.auditors: 审批人列表(退回原报时,加载上一流程)
  19. * advance.curAuditor: 当前审批人(未上报为空,审批通过 or 退回原报时,为空)
  20. * advance.readonly: 登录人,是否可操作
  21. * advance.curTimes: 当前登录人,操作、查阅数据times
  22. * advance.curOrder: 当前登录人,操作、查阅数据order
  23. *
  24. * 该方法为通用方法,如需advance其他数据,请在controller中查询
  25. *
  26. * @param {function} next - 中间件继续执行的方法
  27. * @return {void}
  28. */
  29. return function* advanceCheck(next) {
  30. try {
  31. // 读取预付款id
  32. const id = parseInt(this.params.order);
  33. if (!id || id <= 0) {
  34. throw '您访问的预付款期不存在';
  35. }
  36. const advance = yield this.service.advance.getDataById(id);
  37. if (!advance) {
  38. throw '预付款数据错误';
  39. }
  40. advance.user = yield this.service.projectAccount.getAccountInfoById(advance.uid);
  41. // 读取审核人列表数据
  42. advance.auditors = yield this.service.advanceAudit.getAuditors(advance.id, advance.times);
  43. advance.curAuditor = yield this.service.advanceAudit.getCurAuditor(advance.id, advance.times);
  44. // 获取最新的期
  45. // advance.highOrder = yield this.service.advance.getLastestAdvance(this.tender.id, type, true)
  46. this.advance = advance;
  47. yield next;
  48. } catch (err) {
  49. this.helper.log(err);
  50. // 输出错误到日志
  51. if (err.stack) {
  52. this.logger.error(err);
  53. } else {
  54. this.getLogger('fail').info(
  55. JSON.stringify({
  56. error: err,
  57. project: this.session.sessionProject,
  58. user: this.session.sessionUser,
  59. body: this.session.body,
  60. })
  61. );
  62. }
  63. // 重定向值标段管理
  64. this.redirect(this.request.headers.referer);
  65. }
  66. };
  67. };