From 2cab5d0b73f76dfdd1405b0e894f7f228ee0d7fc Mon Sep 17 00:00:00 2001 From: 18650502300 <18650502300@163.com> Date: Mon, 24 Mar 2025 08:38:57 +0800 Subject: [PATCH] 111 --- .../service/impl/EtOrderServiceImpl.java | 86 ++++++++++--------- 1 file changed, 46 insertions(+), 40 deletions(-) diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java index 1a11870..1765e4e 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java @@ -902,49 +902,55 @@ public class EtOrderServiceImpl implements IEtOrderService EtOrder etOrder1 = new EtOrder(); etOrder1.setStatus(ServiceConstants.ORDER_STATUS_ORDER_END); etOrder1.setOrderId(etOrder.getOrderId()); - int updateEtOrder = etOrderMapper.updateEtOrder(etOrder1); - if(updateEtOrder == 0){ - throw new ServiceException("还车审核失败,更新订单失败"); - } - Boolean refunded = isRefunded(etOrder.getUserId()); - if(!refunded){ - /** 2.退剩余押金 = 押金 - 扣除金额*/ - EtOrder depositOrder = getDepositOrder(etOrder.getUserId()); - BigDecimal deductionAmount = new BigDecimal(etOrder.getDeductionAmount()); - BigDecimal residualDeposit = depositOrder.getTotalFee().subtract(deductionAmount);//抵扣后的金额 - String refNo = IdUtils.getOrderNo("ref"); - wxPayService.refund(depositOrder, "还车审核通过后退押金",residualDeposit,refNo); - /** 3.记录退款表 创建退款对象*/ - depositOrder.setReason("还车审核通过后退押金"); - if(deductionAmount.compareTo(BigDecimal.ZERO) > 0){ - EtRefund refund1= createRefund(depositOrder, residualDeposit, null, null, null, null, refNo,ServiceConstants.REFUND_TYPE_DEPOSIT); - int i = etRefundService.insertEtRefund(refund1); - if(i == 0){ - log.info("【还车审核通过】保存退款对象失败"); - throw new ServiceException("【还车审核通过】,保存退款对象失败"); + Boolean execute = transactionTemplate.execute(e -> { + int updateEtOrder = etOrderMapper.updateEtOrder(etOrder1); + if(updateEtOrder == 0){ + throw new ServiceException("还车审核失败,更新订单失败"); + } + Boolean refunded = isRefunded(etOrder.getUserId()); + if(!refunded){ + /** 2.退剩余押金 = 押金 - 扣除金额*/ + EtOrder depositOrder = getDepositOrder(etOrder.getUserId()); + BigDecimal deductionAmount = new BigDecimal(etOrder.getDeductionAmount()); + BigDecimal residualDeposit = depositOrder.getTotalFee().subtract(deductionAmount);//抵扣后的金额 + String refNo = IdUtils.getOrderNo("ref"); + /** 3.记录退款表 创建退款对象*/ + depositOrder.setReason("还车审核通过后退押金"); + if(deductionAmount.compareTo(BigDecimal.ZERO) > 0){ + EtRefund refund1= createRefund(depositOrder, residualDeposit, null, null, null, null, refNo,ServiceConstants.REFUND_TYPE_DEPOSIT); + int i = etRefundService.insertEtRefund(refund1); + if(i == 0){ + log.info("【还车审核通过】保存退款对象失败"); + throw new ServiceException("【还车审核通过】,保存退款对象失败"); + } } - } - /** 4.更新用户余额*/ - AsUser asUser = asUserService.selectUserById(depositOrder.getUserId()); - if(asUser!=null){ - // 更新用户并更新缓存 - asUser.setBalance(BigDecimal.ZERO); - if (asUserService.updateUserProfile(asUser) > 0) - { - log.info("【还车审核通过】更新用户信息成功:"+ JSON.toJSON(asUser)); - }else{ - throw new ServiceException("【还车审核通过】,更新用户信息失败"); + /** 4.更新用户余额*/ + AsUser asUser = asUserService.selectUserById(depositOrder.getUserId()); + if(asUser!=null){ + // 更新用户并更新缓存 + asUser.setBalance(BigDecimal.ZERO); + if (asUserService.updateUserProfile(asUser) > 0) + { + log.info("【还车审核通过】更新用户信息成功:"+ JSON.toJSON(asUser)); + }else{ + throw new ServiceException("【还车审核通过】,更新用户信息失败"); + } } + if(deductionAmount.compareTo(BigDecimal.ZERO) >= 0){//抵扣金额大于0时,增加车损收入 + /** 押金抵扣后生成资金流水记录 */ + etOrder.setPayFee(deductionAmount); + callbackService.capitalFlowRecords(etOrder,ServiceConstants.FLOW_TYPE_INCOME,ServiceConstants.ORDER_TYPE_VEHICLE_DAMAGE, + ServiceConstants.OWNER_TYPE_OPERATOR,null,ServiceConstants.PAY_TYPE_YJ,null,null); + } + if(BigDecimal.ZERO.compareTo(residualDeposit) < 0){ + wxPayService.refund(depositOrder, "还车审核通过后退押金",residualDeposit,refNo); + } + }else{ + log.info("【还车审核通过】当前用户押金已退款!!------不退押金"); } - if(deductionAmount.compareTo(BigDecimal.ZERO) >= 0){//抵扣金额大于0时,增加车损收入 - /** 押金抵扣后生成资金流水记录 */ - etOrder.setPayFee(deductionAmount); - callbackService.capitalFlowRecords(etOrder,ServiceConstants.FLOW_TYPE_INCOME,ServiceConstants.ORDER_TYPE_VEHICLE_DAMAGE, - ServiceConstants.OWNER_TYPE_OPERATOR,null,ServiceConstants.PAY_TYPE_YJ,null,null); - } - }else{ - log.info("【还车审核通过】当前用户押金已退款!!------不退押金"); - } + return Boolean.TRUE; + }); + if(Boolean.FALSE.equals(execute))throw new ServiceException("官方审核通过失败"); return true; }