diff --git a/rc-service/rc-inner-api/wallet-inner/wallet-inner-model/src/main/java/com/red/circle/wallet/inner/model/enums/UserBankWaterEvent.java b/rc-service/rc-inner-api/wallet-inner/wallet-inner-model/src/main/java/com/red/circle/wallet/inner/model/enums/UserBankWaterEvent.java index 9980fd9b..5b3f8732 100644 --- a/rc-service/rc-inner-api/wallet-inner/wallet-inner-model/src/main/java/com/red/circle/wallet/inner/model/enums/UserBankWaterEvent.java +++ b/rc-service/rc-inner-api/wallet-inner/wallet-inner-model/src/main/java/com/red/circle/wallet/inner/model/enums/UserBankWaterEvent.java @@ -20,6 +20,11 @@ public enum UserBankWaterEvent { */ TRANSFER_GOLD("Transfer"), + /** + * 申请提现 + */ + APPLY_WITHDRAW("Apply Withdraw"), + /** * 接收转账. */ diff --git a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/team/TeamBdRestController.java b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/team/TeamBdRestController.java index 03d3bcfb..f7b4ccba 100644 --- a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/team/TeamBdRestController.java +++ b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/team/TeamBdRestController.java @@ -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); + } + + } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryExchangeGoldExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryExchangeGoldExe.java index e5812940..132c1dbf 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryExchangeGoldExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryExchangeGoldExe.java @@ -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()); diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryTransferExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryTransferExe.java index 1be1759f..33dbddc7 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryTransferExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryTransferExe.java @@ -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()); diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryWithdrawApplyExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryWithdrawApplyExe.java index 205561d6..41c531ca 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryWithdrawApplyExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryWithdrawApplyExe.java @@ -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()); diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/bd/query/TeamBdMemberBillListQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/bd/query/TeamBdMemberBillListQryExe.java index 019e6910..9230255b 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/bd/query/TeamBdMemberBillListQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/bd/query/TeamBdMemberBillListQryExe.java @@ -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 execute(TeamBdMemberBillCmd cmd) { List 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关联的所有代理 diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/bd/query/TeamBdMonthlyIncomeQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/bd/query/TeamBdMonthlyIncomeQryExe.java index 6820ca45..d955d88c 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/bd/query/TeamBdMonthlyIncomeQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/bd/query/TeamBdMonthlyIncomeQryExe.java @@ -47,8 +47,7 @@ public class TeamBdMonthlyIncomeQryExe { // 1. 查询BD关联的所有代理 List 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())); diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/bd/query/TeamBdWithdrawExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/bd/query/TeamBdWithdrawExe.java new file mode 100644 index 00000000..27736943 --- /dev/null +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/bd/query/TeamBdWithdrawExe.java @@ -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)); + } + +} \ No newline at end of file diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/TeamBdBillServiceImpl.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/TeamBdBillServiceImpl.java index f87bf811..c6cc0948 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/TeamBdBillServiceImpl.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/TeamBdBillServiceImpl.java @@ -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 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); + } + } diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/TeamBdMonthlyIncomeCmd.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/TeamBdMonthlyIncomeCmd.java index ef12e3a2..f91533dc 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/TeamBdMonthlyIncomeCmd.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/TeamBdMonthlyIncomeCmd.java @@ -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; + } diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/TeamBdBillService.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/TeamBdBillService.java index 67d15d31..4bd8d29b 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/TeamBdBillService.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/TeamBdBillService.java @@ -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); } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/entity/activity/LotteryWithdraw.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/entity/activity/LotteryWithdraw.java index dd12ff48..c395420c 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/entity/activity/LotteryWithdraw.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/entity/activity/LotteryWithdraw.java @@ -77,6 +77,12 @@ public class LotteryWithdraw { @TableField("status") private Integer status; + /** + * 提现类型:LOTTERY-抽奖,MONEY-美元,EXCHANGE-兑换,TRANSFER-转账 + */ + @TableField("type") + private String type; + /** * 拒绝原因. */