|
@@ -109,24 +109,13 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取期数据
|
|
|
+ * 获取审批界面所需的 原报、审批人数据等
|
|
|
* @param ctx
|
|
|
* @returns {Promise<void>}
|
|
|
* @private
|
|
|
*/
|
|
|
- async _getStage(ctx) {
|
|
|
- const stageOrder = parseInt(ctx.params.order);
|
|
|
- ctx.stage = await ctx.service.stage.getDataByCondition({
|
|
|
- tid: ctx.tender.id,
|
|
|
- order: stageOrder,
|
|
|
- });
|
|
|
- if (ctx.stage.status === auditConst.status.uncheck && ctx.stage.user_id !== ctx.session.sessionUser.accountId) {
|
|
|
- throw '数据错误';
|
|
|
- }
|
|
|
+ async _getStageAuditViewData (ctx) {
|
|
|
const times = ctx.stage.status === auditConst.status.checkNo ? ctx.stage.times - 1 : ctx.stage.times;
|
|
|
- ctx.stage.auditors = await ctx.service.stageAudit.getAuditors(ctx.stage.id, times);
|
|
|
- ctx.stage.curAuditor = await ctx.service.stageAudit.getCurAuditor(ctx.stage.id, times);
|
|
|
- ctx.stage.flowOrder = ctx.stage.curAuditor ? ctx.stage.curAuditor.order : 0;
|
|
|
ctx.stage.user = await ctx.service.projectAccount.getAccountInfoById(ctx.stage.user_id);
|
|
|
ctx.stage.auditHistory = [];
|
|
|
if (ctx.stage.times > 1) {
|
|
@@ -148,12 +137,17 @@ module.exports = app => {
|
|
|
*/
|
|
|
async index(ctx) {
|
|
|
try {
|
|
|
- await this._getStage(ctx);
|
|
|
+ await this._getStageAuditViewData(ctx);
|
|
|
const renderData = await this._getDefaultRenderData(ctx);
|
|
|
[renderData.ledgerSpread, renderData.posSpread] = this._getSpreadSetting();
|
|
|
renderData.changeConst = changeConst;
|
|
|
renderData.ledgerData = await ctx.service.ledger.getDataByTenderId(ctx.tender.id, -1);
|
|
|
- renderData.curStageData = await ctx.service.stageBills.getAuditorStageData(ctx.tender.id, ctx.stage.id, ctx.stage.times, 0);
|
|
|
+ // 当前操作人查看最新数据,其他人查看历史数据
|
|
|
+ if (ctx.stage.readOnly) {
|
|
|
+ renderData.curStageData = await ctx.service.stageBills.getAuditorStageData(ctx.tender.id, ctx.stage.id, ctx.stage.curTimes, ctx.stage.curOrder);
|
|
|
+ } else {
|
|
|
+ renderData.curStageData = await ctx.service.stageBills.getLastestStageData(ctx.tender.id, ctx.stage.id);
|
|
|
+ }
|
|
|
renderData.jsFiles = this.app.jsFiles.common.concat(this.app.jsFiles.stage.index);
|
|
|
// 查询截止上期数据
|
|
|
if (ctx.stage.order > 1) {
|
|
@@ -175,15 +169,18 @@ module.exports = app => {
|
|
|
*/
|
|
|
async getStagePosData(ctx) {
|
|
|
try {
|
|
|
- await this._getStage(ctx);
|
|
|
const condition = JSON.parse(ctx.request.body.data) || {};
|
|
|
condition.tid = ctx.tender.id;
|
|
|
const responseData = {err: 0, msg: '', data: {}};
|
|
|
responseData.data.pos = await ctx.service.pos.getPosData(condition);
|
|
|
// 根据当前人,或指定对象查询数据
|
|
|
- responseData.data.curStageData = await ctx.service.stagePos.getAuditorStageData(ctx.tender.id,
|
|
|
- ctx.stage.id, ctx.stage.times, ctx.stage.curAuditor ? ctx.stage.curAuditor.order : 0,
|
|
|
- this.app._.map(responseData.data.pos, 'id'));
|
|
|
+ if (ctx.stage.readOnly) {
|
|
|
+ responseData.data.curStageData = await ctx.service.stagePos.getAuditorStageData(ctx.tender.id,
|
|
|
+ ctx.stage.id, ctx.stage.curTimes, ctx.stage.curOrder, this.app._.map(responseData.data.pos, 'id'));
|
|
|
+ } else {
|
|
|
+ responseData.data.curStageData = await ctx.service.stagePos.getLastestStageData(ctx.tender.id,
|
|
|
+ ctx.stage.id, this.app._.map(responseData.data.pos, 'id'));
|
|
|
+ }
|
|
|
// 查询截止上期数据
|
|
|
if (ctx.stage.order > 1) {
|
|
|
responseData.data.preStageData = await ctx.service.stagePosFinal.getFinalData(ctx.tender.data, ctx.stage);
|
|
@@ -204,15 +201,9 @@ module.exports = app => {
|
|
|
*/
|
|
|
async updateStageData(ctx) {
|
|
|
try {
|
|
|
- await this._getStage(ctx);
|
|
|
// 检查登录用户,是否可操作
|
|
|
- if (ctx.session.sessionUser.accountId === ctx.stage.user_id) {
|
|
|
- if (ctx.stage.status === auditConst.status.checking || ctx.stage.status === auditConst.status.checked) {
|
|
|
- throw '该计量期当前您无权操作';
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 检查是否可修改
|
|
|
- //const curAuditor = await ctx.service.stageAudit.get
|
|
|
+ if (ctx.stage.readOnly) {
|
|
|
+ throw '该计量期当前您无权操作';
|
|
|
}
|
|
|
|
|
|
const data = JSON.parse(ctx.request.body.data);
|
|
@@ -236,7 +227,7 @@ module.exports = app => {
|
|
|
*/
|
|
|
async detail(ctx) {
|
|
|
try {
|
|
|
- await this._getStage(ctx);
|
|
|
+ await this._getStageAuditViewData(ctx);
|
|
|
const renderData = await this._getDefaultRenderData(ctx);
|
|
|
renderData.jsFiles = this.app.jsFiles.common.concat(this.app.jsFiles.stage.detail);
|
|
|
renderData.imType = tenderConst.imType;
|
|
@@ -254,12 +245,9 @@ module.exports = app => {
|
|
|
*/
|
|
|
async buildDetailData (ctx) {
|
|
|
try {
|
|
|
- await this._getStage(ctx);
|
|
|
// 检查登录用户,是否可操作
|
|
|
- if (ctx.session.sessionUser.accountId === ctx.stage.user_id) {
|
|
|
- if (ctx.stage.status === auditConst.status.checking || ctx.stage.status === auditConst.status.checked) {
|
|
|
- throw '该计量期当前您无权操作';
|
|
|
- }
|
|
|
+ if (ctx.stage.readOnly) {
|
|
|
+ throw '该计量期当前您无权操作';
|
|
|
}
|
|
|
|
|
|
const data = JSON.parse(ctx.request.body.data);
|
|
@@ -279,29 +267,26 @@ module.exports = app => {
|
|
|
*/
|
|
|
async loadDetailRelaData(ctx) {
|
|
|
try {
|
|
|
- await this._getStage(ctx);
|
|
|
const data = JSON.parse(ctx.request.body.data);
|
|
|
// 加载台账数据
|
|
|
if (data.loadType === 'ledger') {
|
|
|
const ledgerData = await ctx.service.ledger.getDataByTenderId(ctx.tender.id, -1);
|
|
|
ctx.body = {err: 0, msg: '', data: ledgerData };
|
|
|
} else if (data.loadType === 'all') {
|
|
|
- const ledger = await ctx.service.ledger.getDataByTenderId(ctx.tender.id, -1);
|
|
|
- const curStage = await ctx.service.stageBills.getLastestStageData(ctx.tender.id, ctx.stage.id);
|
|
|
- const stageDetail = await ctx.service.stageDetail.getLastestStageData(ctx.tender.id, ctx.stage.id);
|
|
|
- ctx.body = {
|
|
|
- err: 0,
|
|
|
- msg: '',
|
|
|
- data: {
|
|
|
- ledger,
|
|
|
- curStage,
|
|
|
- stageDetail,
|
|
|
- }
|
|
|
- };
|
|
|
+ const result = {};
|
|
|
+ result.ledger = await ctx.service.ledger.getDataByTenderId(ctx.tender.id, -1);
|
|
|
+ if (ctx.stage.readOnly) {
|
|
|
+ result.curStage = await ctx.service.stageBills.getAuditorStageData(ctx.tender.id, ctx.stage.id, ctx.stage.curTimes, ctx.stage.curOrder);
|
|
|
+ result.stageDetail = await ctx.service.stageDetail.getAuditorStageData(ctx.tender.id, ctx.stage.id, ctx.stage.curTimes, ctx.stage.curOrder);
|
|
|
+ } else {
|
|
|
+ result.curStage = await ctx.service.stageBills.getLastestStageData(ctx.tender.id, ctx.stage.id);
|
|
|
+ result.stageDetail = await ctx.service.stageDetail.getLastestStageData(ctx.tender.id, ctx.stage.id);
|
|
|
+ }
|
|
|
+ ctx.body = { err: 0, msg: '', data: result };
|
|
|
}
|
|
|
} catch (err) {
|
|
|
this.log(err);
|
|
|
- ctx.body = {err: 1, msg: err.toString(), data: null};
|
|
|
+ ctx.body = { err: 1, msg: err.toString(), data: null };
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -312,12 +297,9 @@ module.exports = app => {
|
|
|
*/
|
|
|
async setAdvancedConfig(ctx) {
|
|
|
try {
|
|
|
- await this._getStage(ctx);
|
|
|
// 检查登录用户,是否可操作
|
|
|
- if (ctx.session.sessionUser.accountId === ctx.stage.user_id) {
|
|
|
- if (ctx.stage.status === auditConst.status.checking || ctx.stage.status === auditConst.status.checked) {
|
|
|
- throw '该计量期当前您无权操作';
|
|
|
- }
|
|
|
+ if (ctx.stage.readOnly) {
|
|
|
+ throw '该计量期当前您无权操作';
|
|
|
}
|
|
|
|
|
|
const data = JSON.parse(ctx.request.body.data);
|
|
@@ -337,15 +319,9 @@ module.exports = app => {
|
|
|
*/
|
|
|
async saveDetailData(ctx) {
|
|
|
try {
|
|
|
- await this._getStage(ctx);
|
|
|
// 检查登录用户,是否可操作
|
|
|
- if (ctx.session.sessionUser.accountId === ctx.stage.user_id) {
|
|
|
- if (ctx.stage.status === auditConst.status.checking || ctx.stage.status === auditConst.status.checked) {
|
|
|
- throw '该计量期当前您无权操作';
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 检查是否可修改
|
|
|
- //const curAuditor = await ctx.service.stageAudit.get
|
|
|
+ if (ctx.stage.readOnly) {
|
|
|
+ throw '该计量期当前您无权操作';
|
|
|
}
|
|
|
|
|
|
const data = JSON.parse(ctx.request.body.data);
|
|
@@ -365,6 +341,9 @@ module.exports = app => {
|
|
|
*/
|
|
|
async addCalcImage(ctx) {
|
|
|
try {
|
|
|
+ if (ctx.stage.readOnly) {
|
|
|
+ throw '该计量期当前您无权操作';
|
|
|
+ }
|
|
|
const stream = await ctx.getFileStream();
|
|
|
const create_time = Date.parse(new Date()) / 1000;
|
|
|
const fileInfo = path.parse(stream.filename);
|
|
@@ -384,15 +363,9 @@ module.exports = app => {
|
|
|
*/
|
|
|
async mergeCalcImage(ctx) {
|
|
|
try {
|
|
|
- await this._getStage(ctx);
|
|
|
// 检查登录用户,是否可操作
|
|
|
- if (ctx.session.sessionUser.accountId === ctx.stage.user_id) {
|
|
|
- if (ctx.stage.status === auditConst.status.checking || ctx.stage.status === auditConst.status.checked) {
|
|
|
- throw '该计量期当前您无权操作';
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 检查是否可修改
|
|
|
- //const curAuditor = await ctx.service.stageAudit.get
|
|
|
+ if (ctx.stage.readOnly) {
|
|
|
+ throw '该计量期当前您无权操作';
|
|
|
}
|
|
|
const data = JSON.parse(ctx.request.body.data);
|
|
|
|
|
@@ -429,7 +402,7 @@ module.exports = app => {
|
|
|
*/
|
|
|
async pay(ctx) {
|
|
|
try {
|
|
|
- await this._getStage(ctx);
|
|
|
+ await this._getStageAuditViewData(ctx);
|
|
|
const renderData = await this._getDefaultRenderData(ctx);
|
|
|
const dealPay = await ctx.service.stagePay.getStagePays(ctx.stage);
|
|
|
if (dealPay && dealPay.length > 0) {
|
|
@@ -459,16 +432,9 @@ module.exports = app => {
|
|
|
*/
|
|
|
async savePayData(ctx) {
|
|
|
try {
|
|
|
- await this._getStage(ctx);
|
|
|
// 检查登录用户,是否可操作
|
|
|
- if (ctx.session.sessionUser.accountId === ctx.stage.user_id) {
|
|
|
- if (ctx.stage.status === auditConst.status.checking || ctx.stage.status === auditConst.status.checked) {
|
|
|
- throw '该计量期当前您无权操作';
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (!ctx.stage.curAuditor || ctx.stage.curAuditor.id !== ctx.session.sessionUser.accountId) {
|
|
|
- throw '该计量期当前您无权操作';
|
|
|
- }
|
|
|
+ if (ctx.stage.readOnly) {
|
|
|
+ throw '该计量期当前您无权操作';
|
|
|
}
|
|
|
|
|
|
const data = JSON.parse(ctx.request.body.data);
|
|
@@ -541,7 +507,6 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- await this._getStage(ctx);
|
|
|
const chapterDetail = JSON.parse(JSON.stringify(payConst.chapterDetail));
|
|
|
const calcDetail = _.sortBy(chapterDetail, ['cType']);
|
|
|
for (const cd of calcDetail) {
|
|
@@ -602,11 +567,7 @@ module.exports = app => {
|
|
|
*/
|
|
|
async change(ctx) {
|
|
|
try {
|
|
|
- await this._getStage(ctx);
|
|
|
const renderData = await this._getDefaultRenderData(ctx);
|
|
|
- // renderData.changes = await ctx.service.change.getAllDataByCondition({
|
|
|
- // where: {tid: ctx.tender.id, status: changeAudit.status.checked},
|
|
|
- // });
|
|
|
renderData.ledger = await ctx.service.ledger.getDataByTenderId(ctx.tender.id, -1);
|
|
|
renderData.changes = await ctx.service.change.getChangeAndUsedInfo(ctx.tender.id);
|
|
|
if (renderData.changes.length > 0) {
|
|
@@ -629,7 +590,10 @@ module.exports = app => {
|
|
|
*/
|
|
|
async searchValidChange(ctx) {
|
|
|
try {
|
|
|
- await this._getStage(ctx);
|
|
|
+ // if (ctx.stage.readOnly) {
|
|
|
+ // throw '您无权调用变更令';
|
|
|
+ // }
|
|
|
+
|
|
|
const data = JSON.parse(ctx.request.body.data);
|
|
|
if (!data.bills && !data.pos) {
|
|
|
throw '数据错误';
|
|
@@ -651,7 +615,10 @@ module.exports = app => {
|
|
|
*/
|
|
|
async useChange(ctx) {
|
|
|
try {
|
|
|
- await this._getStage(ctx);
|
|
|
+ if (ctx.stage.readOnly) {
|
|
|
+ throw '您无权使用变更令';
|
|
|
+ }
|
|
|
+
|
|
|
const data = JSON.parse(ctx.request.body.data);
|
|
|
if (!data.target || (!data.target.bills && !data.target.pos) || !data.change) {
|
|
|
throw '调用变更令数据错误'
|
|
@@ -675,7 +642,6 @@ module.exports = app => {
|
|
|
*/
|
|
|
async changeDetail(ctx) {
|
|
|
try {
|
|
|
- await this._getStage(ctx);
|
|
|
const data = JSON.parse(ctx.request.body.data);
|
|
|
if (!data.cid) {
|
|
|
throw '查询数据错误';
|
|
@@ -697,7 +663,6 @@ module.exports = app => {
|
|
|
*/
|
|
|
async addAudit(ctx) {
|
|
|
try {
|
|
|
- await this._getStage(ctx);
|
|
|
const data = JSON.parse(ctx.request.body.data);
|
|
|
const id = this.app._.toInteger(data.auditorId);
|
|
|
if (isNaN(id) || id <= 0) {
|
|
@@ -735,7 +700,6 @@ module.exports = app => {
|
|
|
*/
|
|
|
async deleteAudit(ctx) {
|
|
|
try {
|
|
|
- await this._getStage(ctx);
|
|
|
const data = JSON.parse(ctx.request.body.data);
|
|
|
const id = data.auditorId instanceof Number ? data.auditorId : this.app._.toNumber(data.auditorId);
|
|
|
if (isNaN(id) || id <= 0) {
|
|
@@ -760,8 +724,6 @@ module.exports = app => {
|
|
|
*/
|
|
|
async startAudit(ctx) {
|
|
|
try {
|
|
|
- await this._getStage(ctx);
|
|
|
-
|
|
|
// 检查权限等
|
|
|
if (!ctx.stage) {
|
|
|
throw '数据错误';
|
|
@@ -789,7 +751,6 @@ module.exports = app => {
|
|
|
*/
|
|
|
async checkAudit(ctx) {
|
|
|
try {
|
|
|
- await this._getStage(ctx);
|
|
|
if (!this.ctx.stage || (this.ctx.stage.status !== auditConst.status.checking && this.ctx.stage.status !== auditConst.status.checkNoPre)) {
|
|
|
throw '当前期数据有误';
|
|
|
}
|
|
@@ -858,7 +819,6 @@ module.exports = app => {
|
|
|
*/
|
|
|
async gather(ctx) {
|
|
|
try {
|
|
|
- await this._getStage(ctx);
|
|
|
const renderData = await this._getDefaultRenderData(ctx);
|
|
|
[renderData.gclSpread, renderData.leafXmjSpread] = this._getGatherSpreadSetting();
|
|
|
renderData.ledger = await ctx.service.ledger.getDataByTenderId(ctx.tender.id, -1);
|
|
@@ -904,7 +864,6 @@ module.exports = app => {
|
|
|
return [ledger, pos];
|
|
|
};
|
|
|
try {
|
|
|
- await this._getStage(ctx);
|
|
|
const renderData = await this._getDefaultRenderData(ctx);
|
|
|
[renderData.ledgerSpread, renderData.posSpread] = getCompareSpreadSetting();
|
|
|
renderData.ledger = await ctx.service.ledger.getDataByTenderId(ctx.tender.id, -1);
|
|
@@ -922,7 +881,6 @@ module.exports = app => {
|
|
|
|
|
|
async compareAuditor(ctx) {
|
|
|
try {
|
|
|
- await this._getStage(ctx);
|
|
|
const data = JSON.parse(ctx.request.body.data);
|
|
|
const result = [];
|
|
|
for (const order of data.auditors) {
|
|
@@ -945,7 +903,6 @@ module.exports = app => {
|
|
|
*/
|
|
|
async report(ctx) {
|
|
|
try {
|
|
|
- await this._getStage(ctx);
|
|
|
const renderData = await this._getDefaultRenderData(ctx);
|
|
|
await this.layout('stage/report.ejs', renderData, 'stage/report_modal.ejs');
|
|
|
} catch (err) {
|