| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- 'use strict';
- const auditConsts = 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 !== auditConsts.stage.status.checked) {
- if (s.status === auditConsts.stage.status.checkNoPre) s.status = auditConsts.stage.status.checking;
- if (s.status !== auditConsts.stage.status.checkNo) s.curAuditors = await ctx.service.stageAudit.getAuditorsByStatus(s.id, s.status, s.times);
- if (s.status === auditConsts.stage.status.checked) {
- const final_auditor_str = (s.curAuditors[0].audit_type === auditConsts.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 !== auditConsts.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);
- stage.auditHistory = stage.auditHistory && stage.auditHistory.length && stage.auditHistory[stage.auditHistory.length - 1].reduce((prev, curr, idx) => {
- if (idx === 0) {
- const reportor = {
- audit_id: stage.user.id,
- audit_order: 0,
- audit_type: 1,
- status: stage.status === auditConsts.stage.status.uncheck ? auditConsts.stage.status.uncheck : auditConsts.stage.status.checked,
- times: stage.status === auditConsts.stage.status.checkNo ? stage.times - 1 : stage.times,
- begin_time: curr.begin_time,
- end_time: curr.begin_time,
- name: stage.user.name,
- company: stage.user.company,
- role: stage.user.role,
- mobile: '',
- opinion: '',
- };
- prev.push({
- name: '原报',
- status: reportor.status,
- audit_type: reportor.audit_type,
- auditors: [reportor],
- });
- }
- prev.push({
- name: curr.is_final ? '终审' : `${curr.audit_order}审`,
- audit_type: curr.audit_type,
- status: curr.status,
- auditors: curr.auditors,
- });
- return prev;
- }, []);
- if (!stage.final_auditor_str || stage.status !== auditConsts.stage.status.checked) {
- if (stage.status === auditConsts.stage.status.checkNoPre) {
- stage.status = auditConsts.stage.status.checking;
- }
- if (stage.status !== auditConsts.stage.status.checkNo) {
- stage.curAuditors = await ctx.service.stageAudit.getAuditorsByStatus(stage.id, stage.status, stage.times);
- }
- if (stage.status === auditConsts.stage.status.checked) {
- const final_auditor_str = (stage.curAuditors[0].audit_type === auditConsts.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 !== auditConsts.stage.status.checking && ctx.stage.status !== auditConsts.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;
- };
|