change_check.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Ellisran
  6. * @date 2020/10/15
  7. * @version
  8. */
  9. const status = require('../const/audit').change.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* changeCheck(next) {
  22. try {
  23. // 获取revise
  24. const cid = this.params.cid || this.request.body.cid;
  25. if (!cid) {
  26. throw '您访问的变更令不存在';
  27. }
  28. const change = yield this.service.change.getDataByCondition({ cid });
  29. // 读取原报、审核人数据
  30. // 读取原报、审核人数据
  31. yield this.service.change.loadChangeUser(change);
  32. // change.auditors = yield this.service.changeAudit.getListGroupByTimes(change.cid, change.times);
  33. // change.curAuditor = yield this.service.changeAudit.getCurAuditor(change.cid, change.times);
  34. if (!change) throw '变更令数据有误';
  35. // 权限相关
  36. // todo 校验权限 (变更参与人)
  37. const accountId = this.session.sessionUser.accountId,
  38. shareIds = [];
  39. const permission = this.session.sessionUser.permission;
  40. // if (change.status === status.uncheck || change.status === status.checkNo) {
  41. // change.readOnly = accountId !== change.uid;
  42. // } else if (change.status === status.checked) {
  43. // change.readOnly = true;
  44. // } else {
  45. // change.readOnly = change.flowAuditors.indexOf(accountId) < 0;
  46. // if (!change.readOnly) {
  47. // change.readOnly = !_.isEqual(change.flowAuditorIds, change.curAuditorIds);
  48. // change.canCheck = true;
  49. // }
  50. // }
  51. if (accountId === change.uid) { // 原报
  52. change.curTimes = change.times;
  53. change.filePermission = true;
  54. } else if (this.tender.isTourist || this.session.sessionUser.is_admin) {
  55. change.curTimes = change.times;
  56. change.filePermission = this.tender.touristPermission.file || change.auditorIds.indexOf(accountId) !== -1;
  57. } else if (change.auditorIds.indexOf(accountId) !== -1) { // 审批人
  58. if (change.status === status.uncheck) {
  59. throw '您无权查看该数据';
  60. }
  61. change.curTimes = change.status === status.checkNo || change.status === status.revise ? change.times - 1 : change.times;
  62. change.filePermission = true;
  63. } else if (shareIds.indexOf(accountId) !== -1 || (permission !== null && permission.tender !== undefined && permission.tender.indexOf('2') !== -1)) { // 分享人
  64. if (change.status === status.uncheck) {
  65. throw '您无权查看该数据';
  66. }
  67. change.filePermission = true;
  68. } else if ((change.status === status.checkNo || change.status === status.revise) && change.uid !== accountId) {
  69. const preAuditors = yield this.service.changeAudit.getUniqAuditor(change.cid, change.times - 1);
  70. const preAuditorIds = _.map(preAuditors, 'uid');
  71. if (preAuditorIds.indexOf(accountId) === -1) {
  72. throw '您无权查看该数据';
  73. }
  74. change.filePermission = true;
  75. } else { // 其他不可见
  76. throw '您无权查看该数据';
  77. }
  78. change.readySettle = yield this.service.settle.getReadySettle(change.tid);
  79. // 调差的readOnly 指表格和页面只能看不能改,和审批无关
  80. change.readOnly = !((change.status === status.uncheck || change.status === status.checkNo || change.status === status.revise) && accountId === change.uid);
  81. change.shenpiPower = (change.status === status.checking || change.status === status.checkNoPre) && change.curAuditorIds.indexOf(accountId) !== -1;
  82. this.change = change;
  83. if ((change.status === status.uncheck || change.status === status.checkNo || change.status === status.revise) && change.tp_decimal !== this.tender.info.decimal.tp) {
  84. this.change.tp_decimal = this.tender.info.decimal.tp;
  85. yield this.service.change.updateDecimalAndTp();
  86. }
  87. yield this.service.change.doCheckChangeCanCancel(this.change);
  88. yield next;
  89. } catch (err) {
  90. console.log(err);
  91. // 输出错误到日志
  92. if (err.stack) {
  93. this.logger.error(err);
  94. } else {
  95. this.getLogger('fail').info(JSON.stringify({
  96. error: err,
  97. project: this.session.sessionProject,
  98. user: this.session.sessionUser,
  99. body: this.session.body,
  100. }));
  101. }
  102. // 重定向值标段管理
  103. this.redirect(this.request.headers.referer);
  104. }
  105. };
  106. };