From e6bd2b80d1c035cfef749a98c805632434c3121f Mon Sep 17 00:00:00 2001 From: chenhao <852066789@qq.com> Date: Thu, 26 Jun 2025 11:35:53 +0800 Subject: [PATCH] =?UTF-8?q?fix(order):=20=E4=BF=AE=E5=A4=8D=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E9=87=91=E9=A2=9D=E8=AE=A1=E7=AE=97=E5=92=8C=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 add.html 和 edit.html 中将订单金额输入框设置为只读,防止直接修改 - 添加 setOrderPriceData 函数用于计算和更新订单金额 - 在产品列表中添加计算订单总金额的逻辑 - 更新订单信息时自动计算和设置订单金额 --- .../templates/layout/product-list.html | 18 +++++++++++------- .../resources/templates/project/order/add.html | 2 +- .../templates/project/order/edit.html | 7 +++++-- .../service/impl/ProjectInfoServiceImpl.java | 9 ++++++++- .../impl/ProjectOrderInfoServiceImpl.java | 17 ++++++++++++++++- 5 files changed, 41 insertions(+), 12 deletions(-) diff --git a/ruoyi-admin/src/main/resources/templates/layout/product-list.html b/ruoyi-admin/src/main/resources/templates/layout/product-list.html index b6b369b3..a9ff9dc1 100644 --- a/ruoyi-admin/src/main/resources/templates/layout/product-list.html +++ b/ruoyi-admin/src/main/resources/templates/layout/product-list.html @@ -112,7 +112,7 @@ } }); - function getAllPriceData(){ + function setOrderPriceData(){ let allPrice=0.00; $('#productTable tbody').find('tr').find('.allPrice').each(function (index) { allPrice+=parseFloat($(this).val()) @@ -123,8 +123,11 @@ $('#productTable3 tbody').find('tr').find('.allPrice').each(function (index) { allPrice+=parseFloat($(this).val()) }) - console.log(`allPrice=${allPrice}`) - console.log('allPrice='+allPrice) + let shipmentAmount = $('#shipmentAmount'); + if (shipmentAmount){ + shipmentAmount.val(allPrice) + $('#displayshipmentAmount').val(formatAmountNumber(allPrice)) + } } function addProduct(data) { let length = $('#productTable tbody').find('tr').length @@ -223,10 +226,7 @@ let flag=true console.log(data) if (data){ - console.log(data) - flag =! updatePriceProductList.filter(item=>item===data.productBomCode).length>0; - console.log(flag) } let tr = $(` @@ -288,6 +288,7 @@ $(this).parent().parent().find('.catalogueAllPrice').val((num * cateVal).toFixed(2)) $(this).parent().parent().find('.catalogueAllPrice-formmat').val(formatAmountNumber((num * cateVal).toFixed(2))) } + setOrderPriceData() }) $('.productTable .catalogue-price-format').on('input', function () { let val = $(this).val() @@ -308,7 +309,7 @@ $(this).parent().parent().find('.catalogueAllPrice').val((val * quantity).toFixed(2)) $(this).parent().parent().find('.catalogueAllPrice-formmat').val(formatAmountNumber((val * quantity).toFixed(2))) } - + setOrderPriceData() }) $('.productTable .guidance-discount-format').on('input', function () { let val = $(this).val() @@ -323,6 +324,7 @@ // $(this).parent().parent().find('.allPrice').val((price * quantity).toFixed(2)) // $(this).parent().parent().find('.allPrice-formmat').val(Number((price * quantity).toFixed(2)).toLocaleString("en-US")) // } + setOrderPriceData() }) $('.productTable .discount-format').on('change', function () { let percentageDiscount = $(this).val() @@ -336,6 +338,7 @@ $(this).parent().parent().parent().find('.allPrice').val((price * num).toFixed(2)) let allPrice = $(this).parent().parent().parent().find('.allPrice').val() $(this).parent().parent().parent().find('.allPrice-formmat').val(formatAmountNumber(allPrice)) + setOrderPriceData() }) $('.productTable .price-formmat').change('input', function () { let val = $(this).val() @@ -349,6 +352,7 @@ let discount = (val*1.0000/cataloguePrice).toFixed(4); $(this).parent().parent().find('.discount').val(discount) $(this).parent().parent().find('.discount-format').val(discount * 100) + setOrderPriceData() // $(this).val(formatAmountNumber(val)) }) } diff --git a/ruoyi-admin/src/main/resources/templates/project/order/add.html b/ruoyi-admin/src/main/resources/templates/project/order/add.html index 43aa52c6..e3ad6e13 100644 --- a/ruoyi-admin/src/main/resources/templates/project/order/add.html +++ b/ruoyi-admin/src/main/resources/templates/project/order/add.html @@ -185,7 +185,7 @@ 订单金额* - diff --git a/ruoyi-admin/src/main/resources/templates/project/order/edit.html b/ruoyi-admin/src/main/resources/templates/project/order/edit.html index 2c77ae78..6936cdee 100644 --- a/ruoyi-admin/src/main/resources/templates/project/order/edit.html +++ b/ruoyi-admin/src/main/resources/templates/project/order/edit.html @@ -187,7 +187,7 @@ 订单金额* - @@ -447,6 +447,7 @@ $(function () { let shipmentAmount = [[${projectOrderInfo.shipmentAmount}]] || '' + if (shipmentAmount) { document.getElementById('displayshipmentAmount').value=formatAmountNumber(shipmentAmount); } @@ -815,7 +816,9 @@ ${ addProduct3(ele) }) : ''; window.localStorage.removeItem('getDetail') - + if (!$('#shipmentAmount').val()) { + setOrderPriceData() + } }) } diff --git a/ruoyi-sip/src/main/java/com/ruoyi/sip/service/impl/ProjectInfoServiceImpl.java b/ruoyi-sip/src/main/java/com/ruoyi/sip/service/impl/ProjectInfoServiceImpl.java index 93e48a48..83e06c2a 100644 --- a/ruoyi-sip/src/main/java/com/ruoyi/sip/service/impl/ProjectInfoServiceImpl.java +++ b/ruoyi-sip/src/main/java/com/ruoyi/sip/service/impl/ProjectInfoServiceImpl.java @@ -228,9 +228,9 @@ public class ProjectInfoServiceImpl implements IProjectInfoService { projectInfo.setCompetitor(projectInfo.getCompetitorList().stream().filter(StringUtils::isNotEmpty).collect(Collectors.joining(","))); } //变更属地校验 + List projectOrderInfos = orderInfoService.selectProjectOrderInfoByProjectId(Collections.singletonList(projectInfo.getId())); if (!projectInfo.getAgentCode().equals(oldProjectInfo.getAgentCode())) { //查询订单信息 如果有抛出异常 - List projectOrderInfos = orderInfoService.selectProjectOrderInfoByProjectId(Collections.singletonList(projectInfo.getId())); if (CollUtil.isNotEmpty(projectOrderInfos)) { throw new ServiceException("该项目存在订单流转,无法更改代表处"); } @@ -245,6 +245,13 @@ public class ProjectInfoServiceImpl implements IProjectInfoService { saveOtherInfo(projectInfo); // 记录操作日志 recordOperationLogs(projectInfo, oldProjectInfo); + if (CollUtil.isNotEmpty(projectOrderInfos)){ + ProjectOrderInfo projectOrderInfo = projectOrderInfos.get(0); + ProjectOrderInfo update = new ProjectOrderInfo(); + update.setId(projectOrderInfo.getId()); + update.setProjectId(projectOrderInfo.getProjectId()); + orderInfoService.updateProjectOrderInfo(update); + } return result; } diff --git a/ruoyi-sip/src/main/java/com/ruoyi/sip/service/impl/ProjectOrderInfoServiceImpl.java b/ruoyi-sip/src/main/java/com/ruoyi/sip/service/impl/ProjectOrderInfoServiceImpl.java index 68ac1c74..e2c7eaae 100644 --- a/ruoyi-sip/src/main/java/com/ruoyi/sip/service/impl/ProjectOrderInfoServiceImpl.java +++ b/ruoyi-sip/src/main/java/com/ruoyi/sip/service/impl/ProjectOrderInfoServiceImpl.java @@ -127,6 +127,9 @@ public class ProjectOrderInfoServiceImpl implements IProjectOrderInfoService { projectOrderInfo.setCreateTime(DateUtils.getNowDate()); projectOrderInfo.setCreateBy(ShiroUtils.getUserId().toString()); saveProductInfo(projectOrderInfo, projectOrderInfo.getProjectId()); + List projectProductInfos = productInfoService.selectProjectProductInfoListByProjectId(Collections.singletonList(projectOrderInfo.getProjectId())); + BigDecimal bigDecimal = projectProductInfos.stream().map(ProjectProductInfo::getAllPrice).filter(Objects::nonNull).reduce(BigDecimal::add).get(); + projectOrderInfo.setShipmentAmount(bigDecimal); List contractFileList = projectOrderInfo.getContractFileList(); int i = projectOrderInfoMapper.insertProjectOrderInfo(projectOrderInfo); if (CollUtil.isNotEmpty(contractFileList)) { @@ -135,6 +138,15 @@ public class ProjectOrderInfoServiceImpl implements IProjectOrderInfoService { return i; } + /** + * 为空为不修改数据 项目信息修改金额调用 + * @param projectOrderInfo + * @param projectId + * @author ch + * @date 2025/06/26 11:10 + */ + + private void saveProductInfo(ProjectOrderInfo projectOrderInfo, Long projectId) { //插入产品信息 List projectProductInfoList = projectOrderInfo.getHardwareProjectProductInfoList(); @@ -193,7 +205,7 @@ public class ProjectOrderInfoServiceImpl implements IProjectOrderInfoService { */ @Override public int updateProjectOrderInfo(ProjectOrderInfo projectOrderInfo) { - ProjectOrderInfo existProjectOrderInfo = projectOrderInfoMapper.selectProjectOrderInfoById(projectOrderInfo.getId()); +// ProjectOrderInfo existProjectOrderInfo = projectOrderInfoMapper.selectProjectOrderInfoById(projectOrderInfo.getId()); // if (!existProjectOrderInfo.getAgentName().equals(projectOrderInfo.getAgentName())) { // String orderNumber = generateOrderNumber(projectOrderInfo.getProjectId()); // projectOrderInfo.setOrderCode(orderNumber); @@ -203,6 +215,9 @@ public class ProjectOrderInfoServiceImpl implements IProjectOrderInfoService { projectOrderInfo.setUpdateBy(ShiroUtils.getUserId().toString()); projectOrderInfo.setUpdateTime(DateUtils.getNowDate()); saveProductInfo(projectOrderInfo, projectOrderInfo.getProjectId()); + List projectProductInfos = productInfoService.selectProjectProductInfoListByProjectId(Collections.singletonList(projectOrderInfo.getProjectId())); + BigDecimal bigDecimal = projectProductInfos.stream().map(ProjectProductInfo::getAllPrice).filter(Objects::nonNull).reduce(BigDecimal::add).get(); + projectOrderInfo.setShipmentAmount(bigDecimal); return projectOrderInfoMapper.updateProjectOrderInfo(projectOrderInfo); }