|
@@ -0,0 +1,226 @@
|
|
|
|
|
+'use strict';
|
|
|
|
|
+
|
|
|
|
|
+const auditConst = require('../const/audit').material;
|
|
|
|
|
+const auditType = require('../const/audit').auditType;
|
|
|
|
|
+const materialConst = require('../const/material');
|
|
|
|
|
+
|
|
|
|
|
+module.exports = app => {
|
|
|
|
|
+ class WeappMaterialController extends app.BaseController {
|
|
|
|
|
+
|
|
|
|
|
+ async index(ctx) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (!ctx.tender.info.isTourist) {
|
|
|
|
|
+ ctx.tender.info.isTourist = false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const subProject = await ctx.service.subProject.getDataById(ctx.tender.data.spid);
|
|
|
|
|
+ subProject.page_show = ctx.service.subProject.getPageShow(subProject.page_show);
|
|
|
|
|
+ if (!subProject.page_show.openMaterial) {
|
|
|
|
|
+ ctx.body = { code: -1, msg: '该功能已关闭', data: null };
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const materials = await ctx.service.material.getValidMaterials(ctx.tender.id);
|
|
|
|
|
+
|
|
|
|
|
+ for (const m of materials) {
|
|
|
|
|
+ if (!m.final_auditor_str || m.status !== auditConst.status.checked) {
|
|
|
|
|
+ m.curAuditors = await ctx.service.materialAudit.getAuditorsByStatus(m.id, m.status, m.times);
|
|
|
|
|
+ if (m.status === auditConst.status.checked && m.curAuditors.length > 0) {
|
|
|
|
|
+ const final_auditor_str = (m.curAuditors[0].audit_type === auditType.key.common)
|
|
|
|
|
+ ? `${m.curAuditors[0].name}${(m.curAuditors[0].role ? '-' + m.curAuditors[0].role : '')}`
|
|
|
|
|
+ : ctx.helper.transFormToChinese(m.curAuditors[0].audit_order) + '审';
|
|
|
|
|
+ await ctx.service.material.defaultUpdate({ id: m.id, final_auditor_str });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ m.decimal = m.decimal ? JSON.parse(m.decimal) : materialConst.decimal;
|
|
|
|
|
+ m.exponent_decimal = m.exponent_decimal ? JSON.parse(m.exponent_decimal) : materialConst.exponent_decimal;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const lastMaterial = materials.length > 0 ? materials[0] : null;
|
|
|
|
|
+ const openMaterialTax = subProject.page_show.openMaterialTax;
|
|
|
|
|
+
|
|
|
|
|
+ let allMaterialTax = true;
|
|
|
|
|
+ let actualOpenMaterialTax = openMaterialTax;
|
|
|
|
|
+ const materialTotalPrice = {
|
|
|
|
|
+ m_tp: 0,
|
|
|
|
|
+ tax_tp: 0,
|
|
|
|
|
+ ex_tp: 0,
|
|
|
|
|
+ ex_tax_tp: 0,
|
|
|
|
|
+ m_tax_tp: 0,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ for (const m of materials) {
|
|
|
|
|
+ if (allMaterialTax && m.material_tax === 0) {
|
|
|
|
|
+ allMaterialTax = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!openMaterialTax && m.material_tax === 1) {
|
|
|
|
|
+ actualOpenMaterialTax = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ materialTotalPrice.m_tp = ctx.helper.add(materialTotalPrice.m_tp, ctx.helper.round(m.m_tp, m.decimal.tp));
|
|
|
|
|
+ materialTotalPrice.tax_tp = !m.material_tax
|
|
|
|
|
+ ? ctx.helper.add(materialTotalPrice.tax_tp, ctx.helper.round(ctx.helper.mul(m.m_tp, 1 + m.rate / 100), m.decimal.tp))
|
|
|
|
|
+ : materialTotalPrice.tax_tp;
|
|
|
|
|
+ materialTotalPrice.ex_tp = ctx.helper.add(materialTotalPrice.ex_tp, ctx.helper.round(m.ex_tp, m.decimal.tp));
|
|
|
|
|
+ materialTotalPrice.ex_tax_tp = ctx.helper.add(materialTotalPrice.ex_tax_tp, ctx.helper.round(m.ex_tax_tp, m.exponent_decimal.tp));
|
|
|
|
|
+ materialTotalPrice.m_tax_tp = m.material_tax
|
|
|
|
|
+ ? ctx.helper.add(materialTotalPrice.m_tax_tp, ctx.helper.round(m.m_tax_tp, m.decimal.tp))
|
|
|
|
|
+ : materialTotalPrice.m_tax_tp;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ materialTotalPrice.total_tp = ctx.helper.add(materialTotalPrice.m_tp, materialTotalPrice.ex_tp);
|
|
|
|
|
+ materialTotalPrice.total_tax_tp = ctx.helper.add(materialTotalPrice.tax_tp, materialTotalPrice.ex_tax_tp);
|
|
|
|
|
+
|
|
|
|
|
+ const renderData = {
|
|
|
|
|
+ tender: ctx.tender.data,
|
|
|
|
|
+ materials,
|
|
|
|
|
+ lastMaterial,
|
|
|
|
|
+ openMaterialTax: actualOpenMaterialTax,
|
|
|
|
|
+ allMaterialTax,
|
|
|
|
|
+ materialTotalPrice,
|
|
|
|
|
+ };
|
|
|
|
|
+ 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 materialId = ctx.params.mid;
|
|
|
|
|
+ const material = await ctx.service.material.getDataById(materialId);
|
|
|
|
|
+
|
|
|
|
|
+ if (!material) {
|
|
|
|
|
+ ctx.body = { code: -1, msg: '材料调差期不存在', data: null };
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!ctx.tender.isTourist) {
|
|
|
|
|
+ ctx.tender.isTourist = false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const subProject = await ctx.service.subProject.getDataById(ctx.tender.data.spid);
|
|
|
|
|
+ subProject.page_show = ctx.service.subProject.getPageShow(subProject.page_show);
|
|
|
|
|
+
|
|
|
|
|
+ const tenderMsg = await ctx.service.tender.getTender(ctx.tender.id, ['material_col_show']);
|
|
|
|
|
+ const materialColShow = tenderMsg.material_col_show
|
|
|
|
|
+ ? JSON.parse(tenderMsg.material_col_show)
|
|
|
|
|
+ : ctx.helper._.cloneDeep(require('../const/tender').materialColShow);
|
|
|
|
|
+
|
|
|
|
|
+ await ctx.service.material.loadMaterialUser(material);
|
|
|
|
|
+ await ctx.service.material.loadMaterialAuditViewData(material);
|
|
|
|
|
+
|
|
|
|
|
+ material.auditHistory = material.auditHistory && material.auditHistory.length && material.auditHistory[material.auditHistory.length - 1].reduce((prev, curr, idx) => {
|
|
|
|
|
+ if (idx === 0) {
|
|
|
|
|
+ const reportor = {
|
|
|
|
|
+ audit_id: material.user.id,
|
|
|
|
|
+ audit_order: 0,
|
|
|
|
|
+ audit_type: 1,
|
|
|
|
|
+ status: material.status === auditConst.status.uncheck ? auditConst.status.uncheck : auditConst.status.checked,
|
|
|
|
|
+ times: material.status === auditConst.status.checkNo ? material.times - 1 : material.times,
|
|
|
|
|
+ begin_time: curr.begin_time,
|
|
|
|
|
+ end_time: curr.begin_time,
|
|
|
|
|
+ name: material.user.name,
|
|
|
|
|
+ company: material.user.company,
|
|
|
|
|
+ role: material.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;
|
|
|
|
|
+ }, []);
|
|
|
|
|
+
|
|
|
|
|
+ material.decimal = material.decimal ? JSON.parse(material.decimal) : materialConst.decimal;
|
|
|
|
|
+ material.exponent_decimal = material.exponent_decimal ? JSON.parse(material.exponent_decimal) : materialConst.exponent_decimal;
|
|
|
|
|
+
|
|
|
|
|
+ const openMaterialTax = subProject.page_show.openMaterialTax;
|
|
|
|
|
+ let allMaterialTax = true;
|
|
|
|
|
+ let actualOpenMaterialTax = openMaterialTax;
|
|
|
|
|
+
|
|
|
|
|
+ if (allMaterialTax && material.material_tax === 0) {
|
|
|
|
|
+ allMaterialTax = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!openMaterialTax && material.material_tax === 1) {
|
|
|
|
|
+ actualOpenMaterialTax = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ material.rate_tp = material.material_tax
|
|
|
|
|
+ ? null
|
|
|
|
|
+ : ctx.helper.round(ctx.helper.mul(material.m_tp, 1 + material.rate / 100), material.decimal.tp);
|
|
|
|
|
+
|
|
|
|
|
+ material.openMaterialTax = actualOpenMaterialTax;
|
|
|
|
|
+ material.allMaterialTax = allMaterialTax;
|
|
|
|
|
+ material.materialColShow = materialColShow;
|
|
|
|
|
+
|
|
|
|
|
+ ctx.body = { code: 0, msg: '', data: material };
|
|
|
|
|
+
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ this.log(err);
|
|
|
|
|
+ ctx.body = { code: -1, msg: err.toString(), data: null };
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ async checkAudit(ctx) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const materialId = ctx.params.materialId;
|
|
|
|
|
+ const material = await ctx.service.material.getDataById(materialId);
|
|
|
|
|
+
|
|
|
|
|
+ if (!material) {
|
|
|
|
|
+ ctx.body = { code: -1, msg: '材料调差期不存在', data: null };
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ctx.material = material;
|
|
|
|
|
+ await ctx.service.material.loadMaterialUser(material);
|
|
|
|
|
+
|
|
|
|
|
+ if (ctx.material.readOnly) {
|
|
|
|
|
+ ctx.body = { code: -1, msg: '该材料调差期当前您无权操作', data: null };
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (ctx.material.status !== auditConst.status.checking && ctx.material.status !== auditConst.status.checkNoPre) {
|
|
|
|
|
+ ctx.body = { code: -1, msg: '当前期数据有误', data: null };
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (ctx.material.curAuditorIds && ctx.material.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.materialAudit.check(ctx.material.id, data, ctx.material.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 WeappMaterialController;
|
|
|
|
|
+};
|