This commit is contained in:
邱贞招 2025-03-24 08:38:57 +08:00
parent fbb70d1969
commit 2cab5d0b73

View File

@ -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;
}