no message

This commit is contained in:
cb 2025-10-11 10:12:59 +08:00
parent 9bb52b5ffb
commit 5489aaa620
3 changed files with 88 additions and 36 deletions

View File

@ -2399,6 +2399,29 @@ public class OrderController extends BaseController {
financialMasterService.insertFinancialMaster(serviceFinancialMaster);
Assert.notNull(serviceFinancialMaster.getId(), "ServiceFinancialMaster.id is null!");
// 从配件订单财务主单中扣除服务金额
FinancialMaster accessoryFinancialMaster = financialMasterService.selectByOrderMasterId(accessoryOrderMaster.getId());
if (accessoryFinancialMaster != null) {
BigDecimal currentServerMoney = accessoryFinancialMaster.getServerMoney();
if (currentServerMoney == null) {
currentServerMoney = BigDecimal.ZERO;
}
// 检查扣除后金额是否为负数
BigDecimal newServerMoney = currentServerMoney.subtract(serviceMoney);
if (newServerMoney.compareTo(BigDecimal.ZERO) < 0) {
throw new RuntimeException("配件订单财务主单服务金额不足,无法扣除服务金额。当前服务金额:" + currentServerMoney + ",需扣除:" + serviceMoney);
}
// 更新配件订单财务主单的serverMoney
accessoryFinancialMaster.setServerMoney(newServerMoney);
financialMasterService.updateFinancialMaster(accessoryFinancialMaster);
} else {
logger.warn("配件订单[{}]未找到对应的财务主单,无法扣除服务金额", accessoryOrderMaster.getCode());
}
if (!CollectionUtils.isEmpty(serviceGoodsList)) {
Goods firstServiceGoods = serviceGoodsList.get(0); // 取第一个服务商品
OrderGoods serviceOrderGoods = new OrderGoods();

View File

@ -1168,6 +1168,65 @@ public class OrderDetailController extends BaseController {
e.printStackTrace();
}
}
if (orderDetail.getIsQuicklyDelivery()==1) {
// 立即发货时更新订单商品的已发货数量
logger.info("立即发货订单[{}]开始更新商品已发货数量", orderDetail.getId());
try {
// 获取子订单商品列表
List<OrderGoods> detailGoodsList = orderGoodsService.selectByOrderDetailId(orderDetail.getId());
// 获取主订单商品列表
List<OrderGoods> masterGoodsList = orderGoodsService.selectByOrderMasterId(orderDetail.getOrderMasterId());
logger.info("立即发货订单[{}]子订单商品数量:{},主订单商品数量:{}",
orderDetail.getId(), detailGoodsList.size(), masterGoodsList.size());
// 对每个子订单商品进行处理
for (OrderGoods detailGoods : detailGoodsList) {
// 找到对应的主订单商品
OrderGoods masterGoods = masterGoodsList.stream()
.filter(mg -> mg.getGoodsStandardId().equals(detailGoods.getGoodsStandardId()))
.findFirst()
.orElse(null);
if (masterGoods != null) {
// 计算已分配给其他子订单的数量
// 查询该主单下该规格商品已分配数量排除当前子单
Integer allocatedNum = masterGoods.getServerGoodsNum() != null ? masterGoods.getServerGoodsNum() : 0;
// 计算剩余可发货数量 = 主单商品总数 - 已分配数量
int remainingNum = masterGoods.getGoodsNum() - allocatedNum;
// 设置已发货数量 = Math.min(子单商品数量, Math.max(0, 剩余可发货数量))
int serverNum = Math.min(detailGoods.getGoodsNum(), Math.max(0, remainingNum));
logger.info("立即发货订单[{}]商品[{}]数量计算:子单数量={},主单总数={},已分配={},剩余={},发货数量={}",
orderDetail.getId(), detailGoods.getGoodsStandardId(),
detailGoods.getGoodsNum(), masterGoods.getGoodsNum(), allocatedNum, remainingNum, serverNum);
// 更新子订单商品的serverGoodsNum字段
detailGoods.setServerGoodsNum(serverNum);
orderGoodsService.updateOrderGoods(detailGoods);
// 更新主订单商品的serverGoodsNum字段
Integer currentMasterServerNum = masterGoods.getServerGoodsNum() != null ? masterGoods.getServerGoodsNum() : 0;
masterGoods.setServerGoodsNum(currentMasterServerNum + serverNum);
orderGoodsService.updateOrderGoods(masterGoods);
logger.info("立即发货订单[{}]商品[{}]更新完成:子单发货数量={},主单累计发货数量={}",
orderDetail.getId(), detailGoods.getGoodsStandardId(), serverNum, masterGoods.getServerGoodsNum());
} else {
logger.warn("立即发货订单[{}]未找到对应的主订单商品商品规格ID{}",
orderDetail.getId(), detailGoods.getGoodsStandardId());
}
}
logger.info("立即发货订单[{}]商品已发货数量更新成功", orderDetail.getId());
} catch (Exception e) {
logger.error("立即发货订单[{}]更新商品已发货数量失败:{}", orderDetail.getId(), e.getMessage(), e);
throw new RuntimeException("更新商品已发货数量失败:" + e.getMessage());
}
}
return toAjax(orderDetailService.updateOrderDetail(orderDetail));
}

View File

@ -2636,7 +2636,7 @@ public class OrderMasterController extends BaseController {
// 调用支付撤销接口进行退款
logger.info("开始调用支付撤销接口paymentId={}, refundAmount={}", financialMaster.getPaymentId(), refundAmount);
JSONObject reverseResult = adapayService.payReverse(goodsOrderMasterId, financialMaster.getPaymentId(), refundAmount.toPlainString(), RefundType.ROM);
JSONObject reverseResult = adapayService.payReverse(goodsOrderMaster.getDeptId(), financialMaster.getPaymentId(), refundAmount.toPlainString(), RefundType.ROM);
// 修复退款结果判断逻辑
if (reverseResult != null && reverseResult.containsKey("reverseId") && reverseResult.getString("reverseId") != null) {
@ -2657,49 +2657,19 @@ public class OrderMasterController extends BaseController {
return AjaxResult.success("商品主单退单退款成功退款ID" + reverseId);
} else {
logger.error("退款接口返回的reverseId为空goodsOrderMasterId={}, reverseResult={}", goodsOrderMasterId, reverseResult);
throw new RuntimeException("退款失败退款接口返回的reverseId为空");
}
} else {
logger.error("退款接口返回异常结果goodsOrderMasterId={}, reverseResult={}", goodsOrderMasterId, reverseResult);
throw new RuntimeException("退款失败:退款接口返回异常结果");
}
// 退款失败恢复财务状态
logger.error("退款失败开始恢复财务状态goodsOrderMasterId={}", goodsOrderMasterId);
financialMaster.setPayStatus(1); // 恢复为已支付状态
financialMasterService.updateFinancialMaster(financialMaster);
for (FinancialDetail detail : financialDetails) {
detail.setPayStatus(1); // 恢复为已支付状态
financialDetailService.updateFinancialDetail(detail);
}
return AjaxResult.error("退单成功但退款失败,请联系管理员处理");
} catch (Exception refundException) {
// 退款异常处理 - 改进异常处理和日志记录
// 退款异常处理 - 抛出异常触发事务回滚
logger.error("退款过程中发生异常goodsOrderMasterId={}, 异常类型={}, 异常信息={}",
goodsOrderMasterId, refundException.getClass().getSimpleName(), refundException.getMessage(), refundException);
// 尝试恢复财务状态
try {
FinancialMaster financialMaster = financialMasterService.selectByOrderMasterId(goodsOrderMasterId);
if (financialMaster != null && financialMaster.getPayStatus() == 3) {
financialMaster.setPayStatus(1); // 恢复为已支付状态
financialMasterService.updateFinancialMaster(financialMaster);
List<FinancialDetail> financialDetails = financialDetailService.selectByFinancialMasterId(financialMaster.getId());
for (FinancialDetail detail : financialDetails) {
if (detail.getPayStatus() == 3) {
detail.setPayStatus(1); // 恢复为已支付状态
financialDetailService.updateFinancialDetail(detail);
}
}
logger.info("异常情况下成功恢复财务状态goodsOrderMasterId={}", goodsOrderMasterId);
}
} catch (Exception recoverException) {
logger.error("恢复财务状态时发生异常goodsOrderMasterId={}, 恢复异常信息={}",
goodsOrderMasterId, recoverException.getMessage(), recoverException);
}
return AjaxResult.error("退单成功但退款过程中发生异常:" + refundException.getMessage());
// 抛出RuntimeException触发事务回滚确保退单和退款的原子性
throw new RuntimeException("退款过程中发生异常:" + refundException.getMessage(), refundException);
}
} catch (Exception e) {