fix(service): 提现成功时同步生成余额流水记录
This commit is contained in:
@@ -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.KeyboardTenantWithdrawOrderRespVO;
|
||||||
import com.yolo.keyboard.controller.admin.tenantwithdraworder.vo.KeyboardTenantWithdrawOrderSaveReqVO;
|
import com.yolo.keyboard.controller.admin.tenantwithdraworder.vo.KeyboardTenantWithdrawOrderSaveReqVO;
|
||||||
import com.yolo.keyboard.dal.dataobject.tenantbalance.TenantBalanceDO;
|
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.dataobject.tenantwithdraworder.KeyboardTenantWithdrawOrderDO;
|
||||||
import com.yolo.keyboard.dal.mysql.tenantbalance.TenantBalanceMapper;
|
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.dal.mysql.tenantwithdraworder.KeyboardTenantWithdrawOrderMapper;
|
||||||
import com.yolo.keyboard.framework.common.pojo.PageResult;
|
import com.yolo.keyboard.framework.common.pojo.PageResult;
|
||||||
import com.yolo.keyboard.framework.common.util.object.BeanUtils;
|
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 org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -46,6 +49,9 @@ public class KeyboardTenantWithdrawOrderServiceImpl implements KeyboardTenantWit
|
|||||||
@Resource
|
@Resource
|
||||||
private TenantBalanceMapper tenantBalanceMapper;
|
private TenantBalanceMapper tenantBalanceMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TenantBalanceTransactionMapper tenantBalanceTransactionMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long createTenantWithdrawOrder(KeyboardTenantWithdrawOrderSaveReqVO createReqVO) {
|
public Long createTenantWithdrawOrder(KeyboardTenantWithdrawOrderSaveReqVO createReqVO) {
|
||||||
// 插入
|
// 插入
|
||||||
@@ -69,7 +75,7 @@ public class KeyboardTenantWithdrawOrderServiceImpl implements KeyboardTenantWit
|
|||||||
KeyboardTenantWithdrawOrderDO updateObj = BeanUtils.toBean(updateReqVO, KeyboardTenantWithdrawOrderDO.class);
|
KeyboardTenantWithdrawOrderDO updateObj = BeanUtils.toBean(updateReqVO, KeyboardTenantWithdrawOrderDO.class);
|
||||||
tenantWithdrawOrderMapper.updateById(updateObj);
|
tenantWithdrawOrderMapper.updateById(updateObj);
|
||||||
|
|
||||||
// 如果提现状态更新为成功(PAID),则扣除提现用户的冻结金额
|
// 如果提现状态更新为成功(PAID),则扣除提现用户的冻结金额并创建流水记录
|
||||||
String newStatus = updateReqVO.getStatus();
|
String newStatus = updateReqVO.getStatus();
|
||||||
if ("PAID".equals(newStatus) && !"PAID".equals(existingOrder.getStatus())) {
|
if ("PAID".equals(newStatus) && !"PAID".equals(existingOrder.getStatus())) {
|
||||||
// 获取提现用户的余额记录
|
// 获取提现用户的余额记录
|
||||||
@@ -85,6 +91,20 @@ public class KeyboardTenantWithdrawOrderServiceImpl implements KeyboardTenantWit
|
|||||||
}
|
}
|
||||||
balance.setFrozenAmt(newFrozenAmt);
|
balance.setFrozenAmt(newFrozenAmt);
|
||||||
tenantBalanceMapper.updateById(balance);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user