| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 | 'use strict';/** * * * @author Ellisran * @date 2020/10/15 * @version */const status = require('../const/audit').changePlan.status;const _ = require('lodash');module.exports = options => {    /**     * 标段校验 中间件     * 1. 读取标段数据(包括属性)     * 2. 检验用户是否可见标段(不校验具体权限)     *     * @param {function} next - 中间件继续执行的方法     * @return {void}     */    return function* changePlanCheck(next) {        try {            // 获取revise            if (!this.session.sessionProject.page_show.openChangePlan) {                throw '该功能已关闭';            }            const cpid = this.params.cpid || this.request.body.cpid;            if (!cpid) {                throw '您访问的变更方案不存在';            }            const change = yield this.service.changePlan.getDataById(cpid);            if (!change) throw '变更方案数据有误';            // 读取原报、审核人数据            yield this.service.changePlan.loadChangeUser(change);            // decimal小数位设置            change.decimal = change.decimal ? JSON.parse(change.decimal) : { tp: this.tender.info.decimal.tp, up: this.tender.info.decimal.up, precision: this.tender.info.precision };            // 权限相关            // todo 校验权限 (标段参与人、分享)            const accountId = this.session.sessionUser.accountId,                shareIds = [];            const permission = this.session.sessionUser.permission;            if (accountId === change.uid) { // 原报                change.curTimes = change.times;                change.filePermission = true;            } else if (change.auditorIds.indexOf(accountId) !== -1) { // 审批人                if (change.status === status.uncheck) {                    throw '您无权查看该数据';                }                // change.readOnly = change.status !== status.checking || accountId !== change.curAuditor.aid;                change.curTimes = change.status === status.checkNo || change.status === status.revise ? change.times - 1 : change.times;                change.filePermission = true;            } else if ((change.status === status.checkNo || change.status === status.revise) && change.uid !== accountId) {                const preAuditors = yield this.service.changePlanAudit.getAuditors(change.id, change.times - 1);                const preAuditorIds = _.map(preAuditors, 'aid');                if (preAuditorIds.indexOf(accountId) === -1) {                    throw '您无权查看该数据';                }                change.filePermission = true;            } else if (this.tender.isTourist || this.session.sessionUser.is_admin) {                change.curTimes = change.times;                change.filePermission = this.tender.touristPermission.file || change.auditorIds.indexOf(accountId) !== -1;            } else if (shareIds.indexOf(accountId) !== -1 || (permission !== null && permission.tender !== undefined && permission.tender.indexOf('2') !== -1)) { // 分享人                if (change.status === status.uncheck) {                    throw '您无权查看该数据';                }                // change.readOnly = true;                change.curTimes = change.status === status.checkNo || change.status === status.revise ? change.times - 1 : change.times;                change.filePermission = false;            } else { // 其他不可见                throw '您无权查看该数据';            }            // 调差的readOnly 指表格和页面只能看不能改,和审批无关            change.readOnly = !((change.status === status.uncheck || change.status === status.checkNo || change.status === status.revise) && accountId === change.uid);            change.shenpiPower = change.status === status.checking && change.curAuditorIds.indexOf(accountId) !== -1;            this.change = change;            yield this.service.changePlan.doCheckChangeCanCancel(this.change);            yield next;        } catch (err) {            console.log(err);            // 输出错误到日志            if (err.stack) {                this.logger.error(err);            } else {                this.getLogger('fail').info(JSON.stringify({                    error: err,                    project: this.session.sessionProject,                    user: this.session.sessionUser,                    body: this.session.body,                }));            }            // 重定向值标段管理            this.redirect(this.request.headers.referer);        }    };};
 |