no message
This commit is contained in:
parent
9bb52b5ffb
commit
5489aaa620
|
|
@ -2399,6 +2399,29 @@ public class OrderController extends BaseController {
|
||||||
financialMasterService.insertFinancialMaster(serviceFinancialMaster);
|
financialMasterService.insertFinancialMaster(serviceFinancialMaster);
|
||||||
Assert.notNull(serviceFinancialMaster.getId(), "ServiceFinancialMaster.id is null!");
|
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)) {
|
if (!CollectionUtils.isEmpty(serviceGoodsList)) {
|
||||||
Goods firstServiceGoods = serviceGoodsList.get(0); // 取第一个服务商品
|
Goods firstServiceGoods = serviceGoodsList.get(0); // 取第一个服务商品
|
||||||
OrderGoods serviceOrderGoods = new OrderGoods();
|
OrderGoods serviceOrderGoods = new OrderGoods();
|
||||||
|
|
|
||||||
|
|
@ -1168,6 +1168,65 @@ public class OrderDetailController extends BaseController {
|
||||||
e.printStackTrace();
|
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));
|
return toAjax(orderDetailService.updateOrderDetail(orderDetail));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2636,7 +2636,7 @@ public class OrderMasterController extends BaseController {
|
||||||
|
|
||||||
// 调用支付撤销接口进行退款
|
// 调用支付撤销接口进行退款
|
||||||
logger.info("开始调用支付撤销接口,paymentId={}, refundAmount={}", financialMaster.getPaymentId(), refundAmount);
|
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) {
|
if (reverseResult != null && reverseResult.containsKey("reverseId") && reverseResult.getString("reverseId") != null) {
|
||||||
|
|
@ -2657,49 +2657,19 @@ public class OrderMasterController extends BaseController {
|
||||||
return AjaxResult.success("商品主单退单退款成功,退款ID:" + reverseId);
|
return AjaxResult.success("商品主单退单退款成功,退款ID:" + reverseId);
|
||||||
} else {
|
} else {
|
||||||
logger.error("退款接口返回的reverseId为空,goodsOrderMasterId={}, reverseResult={}", goodsOrderMasterId, reverseResult);
|
logger.error("退款接口返回的reverseId为空,goodsOrderMasterId={}, reverseResult={}", goodsOrderMasterId, reverseResult);
|
||||||
|
throw new RuntimeException("退款失败:退款接口返回的reverseId为空");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.error("退款接口返回异常结果,goodsOrderMasterId={}, reverseResult={}", goodsOrderMasterId, reverseResult);
|
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) {
|
} catch (Exception refundException) {
|
||||||
// 退款异常处理 - 改进异常处理和日志记录
|
// 退款异常处理 - 抛出异常触发事务回滚
|
||||||
logger.error("退款过程中发生异常,goodsOrderMasterId={}, 异常类型={}, 异常信息={}",
|
logger.error("退款过程中发生异常,goodsOrderMasterId={}, 异常类型={}, 异常信息={}",
|
||||||
goodsOrderMasterId, refundException.getClass().getSimpleName(), refundException.getMessage(), refundException);
|
goodsOrderMasterId, refundException.getClass().getSimpleName(), refundException.getMessage(), refundException);
|
||||||
|
|
||||||
// 尝试恢复财务状态
|
// 抛出RuntimeException触发事务回滚,确保退单和退款的原子性
|
||||||
try {
|
throw new RuntimeException("退款过程中发生异常:" + refundException.getMessage(), refundException);
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue