|
|
@@ -0,0 +1,154 @@
|
|
|
+'use strict';
|
|
|
+
|
|
|
+const audit = require('../const/audit');
|
|
|
+
|
|
|
+module.exports = app => {
|
|
|
+ class WeappMeasureController extends app.BaseController {
|
|
|
+ async stage(ctx) {
|
|
|
+ try {
|
|
|
+ const tenderId = ctx.params.id;
|
|
|
+ const tender = await this.ctx.service.tender.getDataById(tenderId);
|
|
|
+ if (!tender) {
|
|
|
+ ctx.body = { code: -1, msg: '标段不存在', data: null };
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const renderData = {
|
|
|
+ tender: tender.data
|
|
|
+ };
|
|
|
+
|
|
|
+ tender.info = await ctx.service.tenderInfo.getTenderInfo(tenderId);
|
|
|
+ ctx.tender = tender;
|
|
|
+ if (!ctx.tender.isTourist) {
|
|
|
+ ctx.tender.isTourist = false; // 设置默认值
|
|
|
+ }
|
|
|
+
|
|
|
+ renderData.stages = await ctx.service.stage.getValidStages(tenderId, this.ctx.session.sessionUser.is_admin);
|
|
|
+ for (const s of renderData.stages) {
|
|
|
+ if (!s.final_auditor_str || s.status !== audit.stage.status.checked) {
|
|
|
+ if (s.status === audit.stage.status.checkNoPre) s.status = audit.stage.status.checking;
|
|
|
+ if (s.status !== audit.stage.status.checkNo) s.curAuditors = await ctx.service.stageAudit.getAuditorsByStatus(s.id, s.status, s.times);
|
|
|
+ if (s.status === audit.stage.status.checked) {
|
|
|
+ const final_auditor_str = (s.curAuditors[0].audit_type === audit.auditType.key.common)
|
|
|
+ ? `${s.curAuditors[0].name}${(s.curAuditors[0].role ? '-' + s.curAuditors[0].role : '')}`
|
|
|
+ : ctx.helper.transFormToChinese(s.curAuditors[0].audit_order) + '审';
|
|
|
+ await ctx.service.stage.defaultUpdate({ id: s.id, final_auditor_str });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ renderData.unCompleteStageCount = renderData.stages.filter(s => {
|
|
|
+ return s.status !== audit.stage.status.checked;
|
|
|
+ }).length;
|
|
|
+ ctx.body = { code: 0, msg: '', data: renderData };
|
|
|
+
|
|
|
+ } catch (err) {
|
|
|
+ this.log(err);
|
|
|
+ ctx.body = { code: 1, msg: err.toString(), data: null };
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async detail(ctx) {
|
|
|
+ try {
|
|
|
+ const stageId = ctx.params.stageId;
|
|
|
+ const stage = await ctx.service.stage.getDataById(stageId);
|
|
|
+
|
|
|
+ if (!stage) {
|
|
|
+ ctx.body = { code: -1, msg: '计量期不存在', data: null };
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const tender = await ctx.service.tender.getDataById(stage.tid);
|
|
|
+ if (!tender) {
|
|
|
+ ctx.body = { code: -1, msg: '标段不存在', data: null };
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ctx.tender = tender;
|
|
|
+ if (!ctx.tender.isTourist) {
|
|
|
+ ctx.tender.isTourist = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ await ctx.service.stage.loadStageUser(stage);
|
|
|
+ await ctx.service.stage.loadStageAuditViewData(stage);
|
|
|
+
|
|
|
+ if (!stage.final_auditor_str || stage.status !== audit.stage.status.checked) {
|
|
|
+ if (stage.status === audit.stage.status.checkNoPre) {
|
|
|
+ stage.status = audit.stage.status.checking;
|
|
|
+ }
|
|
|
+ if (stage.status !== audit.stage.status.checkNo) {
|
|
|
+ stage.curAuditors = await ctx.service.stageAudit.getAuditorsByStatus(stage.id, stage.status, stage.times);
|
|
|
+ }
|
|
|
+ if (stage.status === audit.stage.status.checked) {
|
|
|
+ const final_auditor_str = (stage.curAuditors[0].audit_type === audit.auditType.key.common)
|
|
|
+ ? `${stage.curAuditors[0].name}${(stage.curAuditors[0].role ? '-' + stage.curAuditors[0].role : '')}`
|
|
|
+ : ctx.helper.transFormToChinese(stage.curAuditors[0].audit_order) + '审';
|
|
|
+ await ctx.service.stage.defaultUpdate({ id: stage.id, final_auditor_str });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ stage.tp = ctx.helper.sum([stage.contract_tp, stage.qc_tp, stage.pc_tp]);
|
|
|
+ stage.pre_tp = ctx.helper.add(stage.pre_contract_tp, stage.pre_qc_tp);
|
|
|
+ stage.end_tp = ctx.helper.add(stage.pre_tp, stage.tp);
|
|
|
+
|
|
|
+ ctx.body = { code: 0, msg: '', data: stage };
|
|
|
+
|
|
|
+ } catch (err) {
|
|
|
+ this.log(err);
|
|
|
+ ctx.body = { code: -1, msg: err.toString(), data: null };
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async checkAudit(ctx) {
|
|
|
+ try {
|
|
|
+ const stageId = ctx.params.stageId;
|
|
|
+ const stage = await ctx.service.stage.getDataById(stageId);
|
|
|
+
|
|
|
+ if (!stage) {
|
|
|
+ ctx.body = { code: -1, msg: '计量期不存在', data: null };
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ ctx.stage = stage;
|
|
|
+ await ctx.service.stage.loadStageUser(stage);
|
|
|
+ await ctx.service.stage.loadPreCheckedStage(stage);
|
|
|
+ await ctx.service.stage.doCheckStage(stage);
|
|
|
+ await ctx.service.stage.loadStageAuditViewData(stage);
|
|
|
+
|
|
|
+ if (ctx.stage.readOnly) {
|
|
|
+ ctx.body = { code: -1, msg: '该计量期当前您无权操作', data: null };
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (ctx.stage.revising) {
|
|
|
+ ctx.body = { code: -1, msg: '台账修订中,请勿修改提交期数据', data: null };
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (ctx.stage.assist && ctx.stage.assist.confirm) {
|
|
|
+ ctx.body = { code: -1, msg: '协同数据已确认,如需修改,请撤销上报或重新审批', data: null };
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (ctx.stage.status !== audit.stage.status.checking && ctx.stage.status !== audit.stage.status.checkNoPre) {
|
|
|
+ ctx.body = { code: -1, msg: '当前期数据有误', data: null };
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (ctx.stage.curAuditorIds && ctx.stage.curAuditorIds.indexOf(ctx.session.sessionUser.accountId) < 0) {
|
|
|
+ ctx.body = { code: -1, msg: '您无权进行该操作', data: null };
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const data = ctx.request.body;
|
|
|
+ data.checkType = parseInt(data.checkType);
|
|
|
+
|
|
|
+ if (!data.checkType || isNaN(data.checkType)) {
|
|
|
+ ctx.body = { code: -1, msg: '提交数据错误', data: null };
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ await ctx.service.stageAudit.check(ctx.stage.id, data, ctx.stage.times);
|
|
|
+ ctx.body = { code: 0, msg: '审批成功', data: null };
|
|
|
+ } catch (err) {
|
|
|
+ this.log(err);
|
|
|
+ ctx.body = { code: -1, msg: err.toString() || '提交失败', data: null };
|
|
|
+ ctx.session.postError = err.toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return WeappMeasureController;
|
|
|
+};
|