'use strict'; /** * weapp控制器 * * @author Lan * @date 2025/12/22 * @version */ const auditConst = require('../const/audit'); const measureType = require('../const/tender').measureType; module.exports = app => { class WeappSubpController extends app.BaseController { async subProjectList(ctx) { try { const list = await ctx.service.subProject.getSubProject(ctx.session.sessionProject.id, ctx.session.sessionUser.id, ctx.session.sessionUser.is_admin); ctx.body = { code: 0, msg: '', data: { list, }, }; } catch (error) { this.log(error); ctx.body = { code: -1, msg: '', data: null }; } } async subProjectDetail(ctx) { try { const { id: subProjectId } = ctx.query; if (!subProjectId) { ctx.body = { code: -1, msg: '子项目ID不能为空', data: null }; return; } const subProject = await ctx.service.subProject.getDataById(subProjectId); if (!subProject) { ctx.body = { code: -1, msg: '子项目不存在', data: null }; return; } const pageShow = subProject.page_show ? JSON.parse(subProject.page_show) : {}; const auditList = []; // 获取待审批的计量期列表 const auditStages = await ctx.service.stageAudit.getAuditStageByWap(ctx.session.sessionUser.id, subProjectId); auditList.push(...(auditStages.map(item => ({ ...item, type: 'stage', subType: 'stage' })))); // 获取待审批的变更期 const auditChanges = await ctx.service.changeAudit.getAuditChangeByWap(ctx.session.sessionUser.id, subProjectId); auditList.push(...(auditChanges.map(item => ({ ...item, type: 'change', subType: 'change' })))); // 获取待审批的变更立项 if (pageShow.openChangeProject) { const changeProjects = await ctx.service.changeProjectAudit.getAuditChangeProjectByWap(ctx.session.sessionUser.id, subProjectId); auditList.push(...(changeProjects.map(item => ({ ...item, type: 'change', subType: 'changeProject' })))); } // 获取待审批的变更申请 if (pageShow.openChangeApply) { const changeApplys = await ctx.service.changeApplyAudit.getAuditChangeApplyByWap(ctx.session.sessionUser.id, subProjectId); auditList.push(...(changeApplys.map(item => ({ ...item, type: 'change', subType: 'changeApply' })))); } // 获取待审批的变更方案 if (pageShow.openChangePlan) { const changePlans = await ctx.service.changePlanAudit.getAuditChangePlanByWap(ctx.session.sessionUser.id, subProjectId); auditList.push(...(changePlans.map(item => ({ ...item, type: 'change', subType: 'changePlan' })))); } // 获取待审批的台账修订 const ledgerRevises = await ctx.service.reviseAudit.getAuditReviseByWap(ctx.session.sessionUser.id, subProjectId); auditList.push(...(ledgerRevises.map(item => ({ ...item, type: 'revise', subType: 'revise' })))); // 获取待审批的预付款 const auditAdvance = await ctx.service.advanceAudit.getAuditAdvanceByWap(ctx.session.sessionUser.id, subProjectId); auditList.push(...(auditAdvance.map(item => ({ ...item, type: 'advance', subType: 'advance' })))); // 获取待审批的材料调差 if (pageShow.openMaterial) { const materialList = await ctx.service.materialAudit.getAuditMaterialByWap(ctx.session.sessionUser.id, subProjectId); auditList.push(...(materialList.map(item => ({ ...item, type: 'material', subType: 'material' })))); } // 获取待审批的质量巡检单 if (pageShow.qualityInspection) { const qualityInspectionList = await ctx.service.qualityInspectionAudit.getAuditInspectionByWap(ctx.session.sessionUser.id, subProjectId); auditList.push(...(qualityInspectionList.map(item => ({ ...item, type: 'qualityInspection', subType: 'qualityInspection' })))); } // 获取待审批的安全巡检 if (pageShow.safeInspection) { const safeInspectionList = await ctx.service.safeInspectionAudit.getAuditInspectionByWap(ctx.session.sessionUser.id, subProjectId); auditList.push(...(safeInspectionList.map(item => ({ ...item, type: 'safeInspection', subType: 'safeInspection' })))); } // 获取消息列表 const msgList = await ctx.service.message.getMsgList(ctx.session.sessionProject.id, subProjectId, 1); ctx.body = { code: 0, msg: '', data: { auditList: ctx.helper._.orderBy(auditList, ['begin_time'], ['desc', 'asc']), msgList, }, }; } catch (error) { this.log(error); ctx.body = { code: -1, msg: '', data: null }; } } async tenderInfoDetail(ctx) { try { const { id: tenderId } = ctx.query; const tender = await this.service.tender.getTender(tenderId); const tenderInfo = await this.service.tenderInfo.getTenderInfo(tenderId); if (!tender || !tenderInfo) { throw '标段信息不存在' } let bCalcTp = tender.user_id === ctx.session.sessionUser.accountId && ( tender.ledger_status === auditConst.ledger.status.checkNo || tender.ledger_status === auditConst.ledger.status.uncheck); const stages = await ctx.service.stage.getValidStages(tenderId, false, ctx.session.sessionUser); const lastStage = stages.length > 0 ? stages[0] : null; // await ctx.service.stage.getLastestStage(ctx.tender.id); const [change_tp, change_p_tp, change_n_tp, change_valuation_tp, change_unvaluation_tp] = await ctx.service.change.getChangeTp(tenderId); tender.change_tp = change_tp; tender.change_p_tp = change_p_tp; tender.change_n_tp = change_n_tp; tender.change_valuation_tp = change_valuation_tp; tender.change_unvaluation_tp = change_unvaluation_tp; if (lastStage) { await this.ctx.service.stage.checkStageGatherData(lastStage, ctx.session.sessionUser.is_admin); if ((!bCalcTp) && tender.measure_type === measureType.gcl.value) { bCalcTp = lastStage.status !== auditConst.stage.status.checked && !lastStage.readOnly; } if (bCalcTp) { const sum = await this.ctx.service.ledger.addUp({ tender_id: tenderId/* , is_leaf: true*/ }); tender.total_price = sum.total_price; tender.deal_tp = sum.deal_tp; } tender.sum = tenderInfo.calc_type === 'tp' ? ctx.helper.add(tender.total_price, tender.change_valuation_tp) : ctx.helper.add(tender.total_price, tender.change_tp); tender.gather_tp = ctx.helper.sum([lastStage.contract_tp, lastStage.qc_tp, lastStage.pc_tp]); tender.end_contract_tp = ctx.helper.sum([lastStage.contract_tp, lastStage.pre_contract_tp, lastStage.contract_pc_tp]); tender.end_qc_tp = ctx.helper.sum([lastStage.qc_tp, lastStage.pre_qc_tp, lastStage.qc_pc_tp]); tender.end_positive_qc_tp = ctx.helper.sum([lastStage.positive_qc_tp, lastStage.pre_positive_qc_tp, lastStage.positive_qc_pc_tp]); tender.end_negative_qc_tp = ctx.helper.sum([lastStage.negative_qc_tp, lastStage.pre_negative_qc_tp, lastStage.negative_qc_pc_tp]); tender.end_gather_tp = ctx.helper.add(tender.end_contract_tp, tender.end_qc_tp); tender.pre_gather_tp = ctx.helper.add(lastStage.pre_contract_tp, lastStage.pre_qc_tp); tender.yf_tp = lastStage.yf_tp; tender.sf_tp = lastStage.sf_tp; tender.qc_ratio = ctx.helper.mul(ctx.helper.div(tender.end_qc_tp, tenderInfo.deal_param.contractPrice, 2), 100); tender.pre_ratio = ctx.helper.mul(ctx.helper.div(tender.pre_gather_tp, tender.sum, 2), 100); tender.cur_ratio = ctx.helper.mul(ctx.helper.div(tender.gather_tp, tender.sum, 2), 100); tender.other_tp = ctx.helper.sub(ctx.helper.sub(tender.sum, tender.pre_gather_tp), tender.gather_tp); tender.other_ratio = Math.max(0, 100 - tender.pre_ratio - tender.cur_ratio); tender.end_yf_tp = ctx.helper.add(lastStage.yf_tp, lastStage.pre_yf_tp); tender.end_sf_tp = ctx.helper.add(lastStage.sf_tp, lastStage.pre_sf_tp); tender.undone_tp = ctx.helper.sub(ctx.helper.sub(ctx.helper.add(tender.total_price, change_tp), tender.end_contract_tp), tender.end_qc_tp); } else { if (bCalcTp) { const sum = await this.ctx.service.ledger.addUp({ tender_id: tenderId/* , is_leaf: true*/ }); tender.total_price = sum.total_price; tender.deal_tp = sum.deal_tp; } tender.sum = ctx.helper.add(tender.total_price, tender.change_tp); } ctx.body = { code : 0, msg : '', data : { tender } } } catch (error) { this.log(error); ctx.body = { code: -1, msg: error.toString(), data: null }; } } } return WeappSubpController; };