| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 | 'use strict';/** * * * @author Ellisran * @date 2020/10/15 * @version */const status = require('../const/audit').change.status;const shenpiConst = require('../const/shenpi');const _ = require('lodash');module.exports = options => {    /**     * 标段校验 中间件     * 1. 读取标段数据(包括属性)     * 2. 检验用户是否可见标段(不校验具体权限)     *     * @param {function} next - 中间件继续执行的方法     * @return {void}     */    return function* changeCheck(next) {        try {            // 获取revise            const cid = this.params.cid || this.request.body.cid;            if (!cid) {                throw '您访问的变更令不存在';            }            const change = yield this.service.change.getDataByCondition({ cid });            // 读取原报、审核人数据            // 读取原报、审核人数据            yield this.service.change.loadChangeUser(change);            // change.auditors = yield this.service.changeAudit.getListGroupByTimes(change.cid, change.times);            // change.curAuditor = yield this.service.changeAudit.getCurAuditor(change.cid, change.times);            if (!change) throw '变更令数据有误';            // 权限相关            // todo 校验权限 (变更参与人)            const accountId = this.session.sessionUser.accountId,                shareIds = [];            const permission = this.session.sessionUser.permission;            // if (change.status === status.uncheck || change.status === status.checkNo) {            //     change.readOnly = accountId !== change.uid;            // } else if (change.status === status.checked) {            //     change.readOnly = true;            // } else {            //     change.readOnly = change.flowAuditors.indexOf(accountId) < 0;            //     if (!change.readOnly) {            //         change.readOnly = !_.isEqual(change.flowAuditorIds, change.curAuditorIds);            //         change.canCheck = true;            //     }            // }            if (accountId === change.uid) { // 原报                change.curTimes = change.times;                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 (change.auditorIds.indexOf(accountId) !== -1) { // 审批人                if (change.status === status.uncheck) {                    throw '您无权查看该数据';                }                change.curTimes = change.status === status.checkNo || change.status === status.revise ? change.times - 1 : change.times;                change.filePermission = true;            } else if (shareIds.indexOf(accountId) !== -1 || (permission !== null && permission.tender !== undefined && permission.tender.indexOf('2') !== -1)) { // 分享人                if (change.status === status.uncheck) {                    throw '您无权查看该数据';                }                change.filePermission = true;            } else if ((change.status === status.checkNo || change.status === status.revise) && change.uid !== accountId) {                const preAuditors = yield this.service.changeAudit.getUniqAuditor(change.cid, change.times - 1);                const preAuditorIds = _.map(preAuditors, 'uid');                if (preAuditorIds.indexOf(accountId) === -1) {                    throw '您无权查看该数据';                }                change.filePermission = true;            } else { // 其他不可见                throw '您无权查看该数据';            }            change.readySettle = yield this.service.settle.getReadySettle(change.tid);            // 调差的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.status === status.checkNoPre) && change.curAuditorIds.indexOf(accountId) !== -1;            this.change = change;            if ((change.status === status.uncheck || change.status === status.checkNo || change.status === status.revise) && change.tp_decimal !== this.tender.info.decimal.tp) {                this.change.tp_decimal = this.tender.info.decimal.tp;                yield this.service.change.updateDecimalAndTp();            }            yield this.service.change.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);        }    };};
 |