1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- 'use strict';
- /**
- *
- *
- * @author Mai
- * @date
- * @version
- */
- const messageType = require('../const/message_type');
- const _ = require('lodash');
- const financialConst = require('../const/financial');
- const status = require('../const/audit').financial.status;
- module.exports = options => {
- /**
- * 标段校验 中间件
- * 1. 读取标段数据(包括属性)
- * 2. 检验用户是否可见标段(不校验具体权限)
- *
- * @param {function} next - 中间件继续执行的方法
- * @return {void}
- */
- return function* financialPayCheck(next) {
- try {
- if (!this.subProject) throw '项目不存在';
- if (!this.subProject.page_show.openFinancial) {
- throw '该功能已关闭或无法查看';
- }
- const fpid = this.params.fpid;
- if (!fpid) {
- throw '参数数据错误';
- }
- const financialPay = yield this.service.financialPay.getOnePay(fpid);
- yield this.service.financialPay.loadPayUser(financialPay);
- // 权限相关
- // todo 校验权限 (标段参与人、分享)
- const accountId = this.session.sessionUser.accountId,
- auditorIds = _.map(financialPay.auditors, 'aid');
- if (financialPay.permission.pay_show) {
- const fptAudits = yield this.service.financialPayTenderAudit.getDataByCondition({ spid: financialPay.spid, tid: financialPay.tid, uid: accountId });
- if (!this.session.sessionUser.is_admin && !fptAudits) {
- throw '您无权查看该数据';
- }
- financialPay.filePermission = financialPay.permission.pay_file ||
- (financialPay.status === status.checking && auditorIds.indexOf(accountId) !== -1) ||
- ((financialPay.status === status.uncheck || financialPay.status === status.checkNo) && accountId === financialPay.uid);
- } else { // 其他不可见
- throw '您无权查看该数据';
- }
- financialPay.filePermission = financialPay.filePermission ? true : financialPay.permission.pay_file;
- // 调差的readOnly 指表格和页面只能看不能改,和审批无关
- // financialPay.readOnly = true;
- financialPay.readOnly = !((financialPay.status === status.uncheck || financialPay.status === status.checkNo) && accountId === financialPay.uid);
- financialPay.shenpiPower = financialPay.status === status.checking && financialPay.curAuditorIds.indexOf(accountId) !== -1;
- this.financialPay = financialPay;
- 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/subproj');
- } else {
- this.postError(err, '未知错误');
- err === '该功能已关闭或无法查看' ? this.redirect('/dashboard') : this.request.headers.referer ? this.redirect(this.request.headers.referer) : this.redirect(`/sp/${this.subProject.id}/financial`);
- }
- }
- }
- };
- };
|