12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- 'use strict';
- /**
- *
- *
- * @author Mai
- * @date
- * @version
- */
- const messageType = require('../const/message_type');
- const paymentConst = require('../const/payment');
- const _ = require('lodash');
- module.exports = options => {
- /**
- * 标段校验 中间件
- * 1. 读取标段数据(包括属性)
- * 2. 检验用户是否可见标段(不校验具体权限)
- *
- * @param {function} next - 中间件继续执行的方法
- * @return {void}
- */
- return function* paymentTenderCheck(next) {
- try {
- if (!this.params.id) {
- throw '当前未打开标段';
- }
- const tender = yield this.service.paymentTender.getDataById(this.params.id);
- const projectInfo = yield this.service.project.getDataById(this.session.sessionProject.id);
- const modes = projectInfo.payment_setting ? JSON.parse(projectInfo.payment_setting) : _.cloneDeep(paymentConst.setting_modes);
- for (const m in paymentConst.setting_modes) {
- if (!modes[m]) modes[m] = _.cloneDeep(paymentConst.setting_modes[m]);
- }
- if (!tender) {
- throw '标段不存在';
- }
- this.tender = tender;
- this.project_setting = modes;
- yield next;
- } catch (err) {
- // 输出错误到日志
- if (err.stack) {
- this.logger.error(err);
- } else {
- this.session.message = {
- type: messageType.ERROR,
- icon: 'exclamation-circle',
- message: err,
- };
- this.getLogger('fail').info(JSON.stringify({
- error: err,
- project: this.session.sessionProject,
- user: this.session.sessionUser,
- body: this.session.body,
- }));
- }
- if (this.helper.isAjax(this.request)) {
- if (err.stack) {
- this.body = {err: 4, msg: '标段数据未知错误', data: null};
- } else {
- this.body = {err: 3, msg: err.toString(), data: null};
- }
- } else {
- if (this.helper.isWap(this.request)) {
- this.redirect('/wap/list');
- } else {
- err === '您无权查看该内容' ? this.redirect(this.request.headers.referer) : this.redirect('/payment');
- }
- }
- }
- };
- };
|