fix(service): 提现成功时同步扣减租户冻结金额
This commit is contained in:
@@ -3,7 +3,9 @@ package com.yolo.keyboard.service.tenantwithdraworder;
|
||||
import com.yolo.keyboard.controller.admin.tenantwithdraworder.vo.KeyboardTenantWithdrawOrderPageReqVO;
|
||||
import com.yolo.keyboard.controller.admin.tenantwithdraworder.vo.KeyboardTenantWithdrawOrderRespVO;
|
||||
import com.yolo.keyboard.controller.admin.tenantwithdraworder.vo.KeyboardTenantWithdrawOrderSaveReqVO;
|
||||
import com.yolo.keyboard.dal.dataobject.tenantbalance.TenantBalanceDO;
|
||||
import com.yolo.keyboard.dal.dataobject.tenantwithdraworder.KeyboardTenantWithdrawOrderDO;
|
||||
import com.yolo.keyboard.dal.mysql.tenantbalance.TenantBalanceMapper;
|
||||
import com.yolo.keyboard.dal.mysql.tenantwithdraworder.KeyboardTenantWithdrawOrderMapper;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageResult;
|
||||
import com.yolo.keyboard.framework.common.util.object.BeanUtils;
|
||||
@@ -15,7 +17,9 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -39,6 +43,9 @@ public class KeyboardTenantWithdrawOrderServiceImpl implements KeyboardTenantWit
|
||||
@Resource
|
||||
private TenantMapper tenantMapper;
|
||||
|
||||
@Resource
|
||||
private TenantBalanceMapper tenantBalanceMapper;
|
||||
|
||||
@Override
|
||||
public Long createTenantWithdrawOrder(KeyboardTenantWithdrawOrderSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
@@ -50,12 +57,36 @@ public class KeyboardTenantWithdrawOrderServiceImpl implements KeyboardTenantWit
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void updateTenantWithdrawOrder(KeyboardTenantWithdrawOrderSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateTenantWithdrawOrderExists(updateReqVO.getId());
|
||||
// 更新
|
||||
KeyboardTenantWithdrawOrderDO existingOrder = tenantWithdrawOrderMapper.selectById(updateReqVO.getId());
|
||||
if (existingOrder == null) {
|
||||
throw exception(TENANT_WITHDRAW_ORDER_NOT_EXISTS);
|
||||
}
|
||||
|
||||
// 更新订单
|
||||
KeyboardTenantWithdrawOrderDO updateObj = BeanUtils.toBean(updateReqVO, KeyboardTenantWithdrawOrderDO.class);
|
||||
tenantWithdrawOrderMapper.updateById(updateObj);
|
||||
|
||||
// 如果提现状态更新为成功(PAID),则扣除提现用户的冻结金额
|
||||
String newStatus = updateReqVO.getStatus();
|
||||
if ("PAID".equals(newStatus) && !"PAID".equals(existingOrder.getStatus())) {
|
||||
// 获取提现用户的余额记录
|
||||
TenantBalanceDO balance = tenantBalanceMapper.selectById(existingOrder.getTenantId());
|
||||
if (balance != null) {
|
||||
// 扣除冻结金额
|
||||
BigDecimal frozenAmt = balance.getFrozenAmt() != null ? balance.getFrozenAmt() : BigDecimal.ZERO;
|
||||
BigDecimal withdrawAmount = existingOrder.getAmount();
|
||||
BigDecimal newFrozenAmt = frozenAmt.subtract(withdrawAmount);
|
||||
// 确保冻结金额不为负数
|
||||
if (newFrozenAmt.compareTo(BigDecimal.ZERO) < 0) {
|
||||
newFrozenAmt = BigDecimal.ZERO;
|
||||
}
|
||||
balance.setFrozenAmt(newFrozenAmt);
|
||||
tenantBalanceMapper.updateById(balance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user