fix(service): 提现成功时同步生成余额流水记录

This commit is contained in:
2026-01-06 19:48:06 +08:00
parent b12f232f56
commit 04755188d6

View File

@@ -4,8 +4,10 @@ import com.yolo.keyboard.controller.admin.tenantwithdraworder.vo.KeyboardTenantW
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.tenantbalancetransaction.TenantBalanceTransactionDO;
import com.yolo.keyboard.dal.dataobject.tenantwithdraworder.KeyboardTenantWithdrawOrderDO;
import com.yolo.keyboard.dal.mysql.tenantbalance.TenantBalanceMapper;
import com.yolo.keyboard.dal.mysql.tenantbalancetransaction.TenantBalanceTransactionMapper;
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;
@@ -20,6 +22,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -46,6 +49,9 @@ public class KeyboardTenantWithdrawOrderServiceImpl implements KeyboardTenantWit
@Resource
private TenantBalanceMapper tenantBalanceMapper;
@Resource
private TenantBalanceTransactionMapper tenantBalanceTransactionMapper;
@Override
public Long createTenantWithdrawOrder(KeyboardTenantWithdrawOrderSaveReqVO createReqVO) {
// 插入
@@ -69,7 +75,7 @@ public class KeyboardTenantWithdrawOrderServiceImpl implements KeyboardTenantWit
KeyboardTenantWithdrawOrderDO updateObj = BeanUtils.toBean(updateReqVO, KeyboardTenantWithdrawOrderDO.class);
tenantWithdrawOrderMapper.updateById(updateObj);
// 如果提现状态更新为成功PAID则扣除提现用户的冻结金额
// 如果提现状态更新为成功PAID则扣除提现用户的冻结金额并创建流水记录
String newStatus = updateReqVO.getStatus();
if ("PAID".equals(newStatus) && !"PAID".equals(existingOrder.getStatus())) {
// 获取提现用户的余额记录
@@ -85,6 +91,20 @@ public class KeyboardTenantWithdrawOrderServiceImpl implements KeyboardTenantWit
}
balance.setFrozenAmt(newFrozenAmt);
tenantBalanceMapper.updateById(balance);
// 创建提现成功的流水记录
TenantBalanceTransactionDO transaction = TenantBalanceTransactionDO.builder()
.bizNo(existingOrder.getBizNo())
.points(withdrawAmount.negate()) // 提现金额(负数表示支出)
.balance(balance.getWithdrawableBalance() != null ? balance.getWithdrawableBalance() : BigDecimal.ZERO) // 当前可提现余额
.tenantId(existingOrder.getTenantId())
.type("WITHDRAW_SUCCESS")
.description("提现成功")
.orderId(existingOrder.getWithdrawNo())
.operatorId(TenantContextHolder.getTenantId())
.createdAt(LocalDateTime.now())
.build();
tenantBalanceTransactionMapper.insert(transaction);
}
}
}