schedule_check.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author EllisRan
  6. * @date
  7. * @version
  8. */
  9. const scPermission = require('../const/schedule').permission;
  10. module.exports = options => {
  11. /**
  12. * 投资进度校验 中间件
  13. *
  14. * @param {function} next - 中间件继续执行的方法
  15. * @return {void}
  16. */
  17. return function* scheduleCheck(next) {
  18. try {
  19. if (!this.subProject.page_show.xxjd) {
  20. throw '该功能已关闭';
  21. }
  22. if (!this.tender.user_permission.schedule.view) {
  23. throw '您无权查看该内容';
  24. }
  25. yield next;
  26. } catch (err) {
  27. // 输出错误到日志
  28. if (err.stack) {
  29. this.logger.error(err);
  30. } else {
  31. this.getLogger('fail').info(JSON.stringify({
  32. error: err,
  33. project: this.session.sessionProject,
  34. user: this.session.sessionUser,
  35. body: this.session.body,
  36. }));
  37. }
  38. if (this.helper.isWap(this.request)) {
  39. this.redirect('/wap/subproj');
  40. } else {
  41. err === '您无权查看该内容' ? this.redirect(this.request.headers.referer) : this.redirect(`/sp/${ctx.subProject.id}/schedule/tender`);
  42. }
  43. }
  44. };
  45. };