financial_pay_audit_check.js 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Ellisran
  6. * @date 2020/10/15
  7. * @version
  8. */
  9. const status = require('../const/audit').financial.status;
  10. const shenpiConst = require('../const/shenpi');
  11. const _ = require('lodash');
  12. module.exports = options => {
  13. /**
  14. * 标段校验 中间件
  15. * 1. 读取标段数据(包括属性)
  16. * 2. 检验用户是否可见标段(不校验具体权限)
  17. *
  18. * @param {function} next - 中间件继续执行的方法
  19. * @return {void}
  20. */
  21. return function* financailPayAuditCheck(next) {
  22. try {
  23. // 获取revise
  24. const id = this.params.fpid || this.request.body.fpid;
  25. if (!id) {
  26. throw '您访问的资金支付不存在';
  27. }
  28. // const change = yield this.service.change.getDataByCondition({ cid });
  29. if (!this.financialPay) {
  30. const financialPay = yield this.service.financialPay.getDataById(id);
  31. if (!financialPay) throw '资金支付数据有误';
  32. yield this.service.financialPay.loadChangeUser(financialPay);
  33. this.financialPay = financialPay;
  34. }
  35. const financialPay = this.financialPay;
  36. if (financialPay.status === status.uncheck || financialPay.status === status.checkNo) {
  37. // 进一步比较审批流是否与审批流程设置的相同,不同则替换为固定审批流或固定的终审
  38. const auditList = yield this.service.financialPayAudit.getAllDataByCondition({ where: { fpid: financialPay.id, times: financialPay.times }, orders: [['order', 'asc']] });
  39. const condition = { tid: financialPay.tid, sp_type: shenpiConst.sp_other_type.financial, sp_status: shenpiConst.sp_status.gdspl };
  40. const shenpiList = yield this.service.shenpiAudit.getAllDataByCondition({ where: condition, orders: [['audit_order', 'asc']] });
  41. yield this.service.shenpiAudit.noYbShenpiList(financialPay.uid, shenpiList);
  42. // 判断2个id数组是否相同,不同则删除原审批流,切换成固定的审批流
  43. let sameAudit = auditList.length === shenpiList.length;
  44. if (sameAudit) {
  45. for (const audit of auditList) {
  46. const shenpi = shenpiList.find(x => { return x.audit_id === audit.aid; });
  47. if (!shenpi || shenpi.audit_order !== audit.audit_order || shenpi.audit_type !== audit.audit_type) {
  48. sameAudit = false;
  49. break;
  50. }
  51. }
  52. }
  53. if (!sameAudit) {
  54. yield this.service.financialPayAudit.updateNewAuditList(financialPay, shenpiList);
  55. yield this.service.financialPay.loadPayUser(financialPay);
  56. }
  57. }
  58. yield next;
  59. } catch (err) {
  60. console.log(err);
  61. // 输出错误到日志
  62. if (err.stack) {
  63. this.logger.error(err);
  64. } else {
  65. this.getLogger('fail').info(JSON.stringify({
  66. error: err,
  67. project: this.session.sessionProject,
  68. user: this.session.sessionUser,
  69. body: this.session.body,
  70. }));
  71. }
  72. // 重定向值标段管理
  73. this.redirect(this.request.headers.referer);
  74. }
  75. };
  76. };