bd提现接口新增

This commit is contained in:
tianfeng 2025-10-30 19:56:05 +08:00
parent 9d3abee0ce
commit 31a2522c64
12 changed files with 149 additions and 5 deletions

View File

@ -20,6 +20,11 @@ public enum UserBankWaterEvent {
*/
TRANSFER_GOLD("Transfer"),
/**
* 申请提现
*/
APPLY_WITHDRAW("Apply Withdraw"),
/**
* 接收转账.
*/

View File

@ -5,6 +5,7 @@ import com.red.circle.common.business.dto.cmd.app.AppFlowCmd;
import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.other.app.dto.clientobject.team.*;
import com.red.circle.other.app.dto.cmd.activity.LotteryWithdrawCmd;
import com.red.circle.other.app.dto.cmd.team.BdInviteQryCmd;
import com.red.circle.other.app.dto.cmd.team.DbInviteAgentCmd;
import com.red.circle.other.app.dto.cmd.team.DbInviteMessageProcessCmd;
@ -285,4 +286,18 @@ public class TeamBdRestController extends BaseController {
return teamBdBillService.queryMonthlyIncome(cmd);
}
/**
* 提交提现申请.
*
* @eo.name 提交提现申请.
* @eo.url /withdraw/apply
* @eo.method post
* @eo.request-type json
*/
@PostMapping("/withdraw/apply")
public void applyWithdraw(@RequestBody @Validated LotteryWithdrawCmd cmd) {
teamBdBillService.applyWithdraw(cmd);
}
}

View File

@ -82,6 +82,7 @@ public class LotteryExchangeGoldExe {
withdraw.setWithdrawNo(generateExchangeWithdrawNo());
withdraw.setActivityId(cmd.getActivityId());
withdraw.setAmount(cmd.getAmount());
withdraw.setType("EXCHANGE");
withdraw.setStatus(3); // 已完成
withdraw.setDescription("兑换金币: " + goldQuantity + "金币");
withdraw.setCreateTime(TimestampUtils.now());

View File

@ -93,6 +93,7 @@ public class LotteryTransferExe {
withdraw.setWithdrawNo(generateTransferWithdrawNo());
withdraw.setActivityId(cmd.getActivityId());
withdraw.setAmount(cmd.getAmount());
withdraw.setType("TRANSFER");
withdraw.setStatus(3); // 已完成
withdraw.setDescription("转账给用户" + cmd.getAcceptUserId() + ": " + goldQuantity + "金币");
withdraw.setCreateTime(TimestampUtils.now());

View File

@ -70,6 +70,7 @@ public class LotteryWithdrawApplyExe {
withdraw.setContactNumber(cmd.getContactNumber());
withdraw.setDescription(cmd.getDescription());
withdraw.setCardImages(cmd.getCardImages());
withdraw.setType("LOTTERY");
withdraw.setStatus(0); // 待审核
withdraw.setCreateTime(TimestampUtils.now());
withdraw.setUpdateTime(TimestampUtils.now());

View File

@ -49,6 +49,7 @@ public class TeamBdMemberBillListQryExe {
private final UserProfileAppConvertor userProfileAppConvertor;
private final BdTeamLeaderClient bdTeamLeaderClient;
private final TeamMemberService teamMemberService;
private final BusinessDevelopmentBaseInfoService businessDevelopmentBaseInfoService;
/**
* 执行查询.
@ -59,11 +60,10 @@ public class TeamBdMemberBillListQryExe {
public List<TeamBdMemberBillCO> execute(TeamBdMemberBillCmd cmd) {
List<BusinessDevelopmentTeam> bdTeamList = new ArrayList<>();
Boolean bdLeader = bdTeamLeaderClient.check(cmd.getReqUserId()).getBody();
if (Boolean.TRUE.equals(bdLeader)) {
if ("BD".equals(cmd.getType())) {
bdTeamList.addAll(businessDevelopmentTeamService.listByUserId(cmd.getReqUserId()));
} else {
bdTeamList.addAll(buildBdTeamVO(teamMemberService.listTeamMember(cmd.getReqUserId(), 100)));
// bdTeamList.addAll(buildBdTeamVO(teamMemberService.listTeamMember(cmd.getReqUserId(), 100)));
}
// 1. 查询BD关联的所有代理

View File

@ -47,8 +47,7 @@ public class TeamBdMonthlyIncomeQryExe {
// 1. 查询BD关联的所有代理
List<BusinessDevelopmentTeam> bdTeamList = new ArrayList<>();
Boolean bdLeader = bdTeamLeaderClient.check(cmd.getReqUserId()).getBody();
if (Boolean.TRUE.equals(bdLeader)) {
if ("BD".equals(cmd.getType())) {
bdTeamList.addAll(businessDevelopmentTeamService.listByUserId(cmd.getReqUserId()));
} else {
bdTeamList.add(businessDevelopmentTeamService.getByAgentId(cmd.getReqUserId()));

View File

@ -0,0 +1,102 @@
package com.red.circle.other.app.command.bd.query;
import com.red.circle.common.business.core.enums.OpUserType;
import com.red.circle.common.business.core.enums.ReceiptType;
import com.red.circle.framework.core.asserts.ResponseAssert;
import com.red.circle.other.app.dto.cmd.activity.LotteryWithdrawCmd;
import com.red.circle.other.infra.database.rds.entity.activity.LotteryUserProgress;
import com.red.circle.other.infra.database.rds.entity.activity.LotteryWithdraw;
import com.red.circle.other.infra.database.rds.service.activity.LotteryWithdrawService;
import com.red.circle.other.inner.asserts.lottery.LotteryErrorCode;
import com.red.circle.tool.core.date.TimestampUtils;
import com.red.circle.tool.core.num.ArithmeticUtils;
import com.red.circle.tool.core.sequence.IdWorkerUtils;
import com.red.circle.tool.core.tuple.PennyAmount;
import com.red.circle.wallet.inner.endpoint.bank.api.UserBankBalanceClientApi;
import com.red.circle.wallet.inner.endpoint.bank.api.UserBankRunningWaterClientApi;
import com.red.circle.wallet.inner.error.WalletErrorCode;
import com.red.circle.wallet.inner.model.cmd.UserBankBalanceDecrCmd;
import com.red.circle.wallet.inner.model.dto.BankBalanceDTO;
import com.red.circle.wallet.inner.model.dto.UserBankRunningWaterDTO;
import com.red.circle.wallet.inner.model.enums.UserBankWaterEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.Objects;
import java.util.concurrent.ThreadLocalRandom;
@Slf4j
@Component
@RequiredArgsConstructor
public class TeamBdWithdrawExe {
private final LotteryWithdrawService lotteryWithdrawService;
private final UserBankBalanceClientApi userBankBalanceClientApi;
private final UserBankRunningWaterClientApi userBankRunningWaterClientApi;
public void applyWithdraw(LotteryWithdrawCmd cmd) {
Long userId = cmd.requiredReqUserId();
BigDecimal amount = cmd.getAmount();
Long activityId = Long.valueOf(cmd.getActivityId());
BigDecimal balance = userBankBalanceClientApi.getBalance(cmd.requiredReqUserId()).getBody().getAccurateBalance();
// 3. 校验提现金额
ResponseAssert.isTrue(WalletErrorCode.INSUFFICIENT_BALANCE, ArithmeticUtils.gte(balance, cmd.getAmount()));
// 扣钱
UserBankBalanceDecrCmd balanceDecrCmd = new UserBankBalanceDecrCmd().setUserId(cmd.requiredReqUserId()).setAmount(PennyAmount.ofDollar(cmd.getAmount()));
BankBalanceDTO decrUserBankBalanceDTO = userBankBalanceClientApi.decr(balanceDecrCmd).getBody();
ResponseAssert.notNull(WalletErrorCode.INSUFFICIENT_BALANCE, decrUserBankBalanceDTO);
// 银行卡流水
userBankRunningWaterClientApi.add(
new UserBankRunningWaterDTO()
.setId(IdWorkerUtils.getId())
.setUserId(cmd.requiredReqUserId())
.setSysOrigin(cmd.requireReqSysOrigin())
.setType(ReceiptType.EXPENDITURE.getType())
.setAmount(cmd.getAmount())
.setEvent(UserBankWaterEvent.APPLY_WITHDRAW.name())
.setEventDescribe(UserBankWaterEvent.APPLY_WITHDRAW.getDescribe())
.setRemark("Apply Withdraw")
.setTrackId(Objects.toString(cmd.requiredReqUserId()))
.setBalance(decrUserBankBalanceDTO.getAccurateBalance())
.setCreateTime(TimestampUtils.now())
.setUpdateTime(TimestampUtils.now())
.setCreateUser(cmd.getReqUserId())
.setCreateUserOrigin(OpUserType.APP.getType())
);
// 4. 创建提现申请
LotteryWithdraw withdraw = new LotteryWithdraw();
withdraw.setWithdrawNo(generateWithdrawNo());
withdraw.setUserId(userId);
withdraw.setActivityId(activityId);
withdraw.setAmount(amount);
withdraw.setContactNumber(cmd.getContactNumber());
withdraw.setDescription(cmd.getDescription());
withdraw.setCardImages(cmd.getCardImages());
withdraw.setType("MONEY");
withdraw.setStatus(0); // 待审核
withdraw.setCreateTime(TimestampUtils.now());
withdraw.setUpdateTime(TimestampUtils.now());
lotteryWithdrawService.save(withdraw);
log.info("Lottery withdraw application submitted, userId: {}, amount: {}, withdrawNo: {}",
userId, amount, withdraw.getWithdrawNo());
}
/**
* 生成提现单号.
*/
private String generateWithdrawNo() {
return "BD" + System.currentTimeMillis() +
String.format("%06d", ThreadLocalRandom.current().nextInt(1000000));
}
}

View File

@ -3,12 +3,14 @@ package com.red.circle.other.app.service;
import com.red.circle.other.app.command.bd.query.TeamBdMemberBillDetailQryExe;
import com.red.circle.other.app.command.bd.query.TeamBdMemberBillListQryExe;
import com.red.circle.other.app.command.bd.query.TeamBdMonthlyIncomeQryExe;
import com.red.circle.other.app.command.bd.query.TeamBdWithdrawExe;
import com.red.circle.other.app.dto.clientobject.TeamBdMemberBillCO;
import com.red.circle.other.app.dto.clientobject.TeamBdMemberBillDetailCO;
import com.red.circle.other.app.dto.clientobject.TeamBdMonthlyIncomeCO;
import com.red.circle.other.app.dto.cmd.TeamBdMemberBillCmd;
import com.red.circle.other.app.dto.cmd.TeamBdMemberBillDetailCmd;
import com.red.circle.other.app.dto.cmd.TeamBdMonthlyIncomeCmd;
import com.red.circle.other.app.dto.cmd.activity.LotteryWithdrawCmd;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@ -29,6 +31,7 @@ public class TeamBdBillServiceImpl implements TeamBdBillService {
private final TeamBdMemberBillListQryExe teamBdMemberBillListQryExe;
private final TeamBdMemberBillDetailQryExe teamBdMemberBillDetailQryExe;
private final TeamBdMonthlyIncomeQryExe teamBdMonthlyIncomeQryExe;
private final TeamBdWithdrawExe teamBdWithdrawExe;
@Override
public List<TeamBdMemberBillCO> queryMemberBillList(TeamBdMemberBillCmd cmd) {
@ -45,4 +48,9 @@ public class TeamBdBillServiceImpl implements TeamBdBillService {
return teamBdMonthlyIncomeQryExe.execute(cmd);
}
@Override
public void applyWithdraw(LotteryWithdrawCmd cmd) {
teamBdWithdrawExe.applyWithdraw(cmd);
}
}

View File

@ -1,6 +1,7 @@
package com.red.circle.other.app.dto.cmd;
import com.red.circle.common.business.dto.cmd.AppExtCommand;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -14,4 +15,7 @@ import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
public class TeamBdMonthlyIncomeCmd extends AppExtCommand {
@NotBlank
private String type;
}

View File

@ -6,6 +6,7 @@ import com.red.circle.other.app.dto.clientobject.TeamBdMonthlyIncomeCO;
import com.red.circle.other.app.dto.cmd.TeamBdMemberBillCmd;
import com.red.circle.other.app.dto.cmd.TeamBdMemberBillDetailCmd;
import com.red.circle.other.app.dto.cmd.TeamBdMonthlyIncomeCmd;
import com.red.circle.other.app.dto.cmd.activity.LotteryWithdrawCmd;
import java.util.List;
@ -41,4 +42,5 @@ public interface TeamBdBillService {
*/
TeamBdMonthlyIncomeCO queryMonthlyIncome(TeamBdMonthlyIncomeCmd cmd);
void applyWithdraw(LotteryWithdrawCmd cmd);
}

View File

@ -77,6 +77,12 @@ public class LotteryWithdraw {
@TableField("status")
private Integer status;
/**
* 提现类型LOTTERY-抽奖MONEY-美元EXCHANGE-兑换TRANSFER-转账
*/
@TableField("type")
private String type;
/**
* 拒绝原因.
*/