tender_build_check.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. * @param {function} next - 中间件继续执行的方法
  16. * @return {void}
  17. */
  18. return function* tenderBuildCheck(next) {
  19. try {
  20. if (this.tender.readOnly) throw '当前标段已完工,不可进行该操作';
  21. yield next;
  22. } catch (err) {
  23. // 输出错误到日志
  24. this.log(err);
  25. if (this.helper.isAjax(this.request)) {
  26. if (err.stack) {
  27. this.body = {err: 4, msg: '标段数据未知错误', data: null};
  28. } else {
  29. this.body = {err: 3, msg: err.toString(), data: null};
  30. }
  31. } else {
  32. if (this.helper.isWap(this.request)) {
  33. this.redirect('/wap/subproj');
  34. } else {
  35. this.postError(err, '操作失败');
  36. this.redirect(this.request.headers.referer);
  37. }
  38. }
  39. }
  40. };
  41. };