From efa87ad171b23b8b7e4555b2acaf2cf2294ea8a1 Mon Sep 17 00:00:00 2001 From: Derran Date: Wed, 13 Nov 2024 16:56:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=82=AC=E8=B5=8F=E6=8B=9B=E4=BA=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/response/UserGetWalletAccountVo.java | 3 ++ .../impl/WalletAccountQueryServiceImpl.java | 35 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/api/query/walletaccount/user/response/UserGetWalletAccountVo.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/api/query/walletaccount/user/response/UserGetWalletAccountVo.java index 1c1378f..08e478e 100644 --- a/dating-agency-mall-server/src/main/java/com/qniao/dam/api/query/walletaccount/user/response/UserGetWalletAccountVo.java +++ b/dating-agency-mall-server/src/main/java/com/qniao/dam/api/query/walletaccount/user/response/UserGetWalletAccountVo.java @@ -23,6 +23,9 @@ public class UserGetWalletAccountVo { @ApiModelProperty("冻结余额") private BigDecimal frozenBalance = BigDecimal.ZERO; + @ApiModelProperty("可提现金额") + private BigDecimal availableWithdrawBalance = BigDecimal.ZERO; + @ApiModelProperty("总提现金额") private BigDecimal totalWithdrawBalance = BigDecimal.ZERO; diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/query/walletaccount/impl/WalletAccountQueryServiceImpl.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/query/walletaccount/impl/WalletAccountQueryServiceImpl.java index 0379a21..0006e4a 100644 --- a/dating-agency-mall-server/src/main/java/com/qniao/dam/query/walletaccount/impl/WalletAccountQueryServiceImpl.java +++ b/dating-agency-mall-server/src/main/java/com/qniao/dam/query/walletaccount/impl/WalletAccountQueryServiceImpl.java @@ -15,10 +15,13 @@ import com.qniao.dam.domain.aggregate.walletaccount.entity.WalletAccount; import com.qniao.dam.infrastructure.persistent.dao.domain.WalletAccountDao; import com.qniao.framework.utils.PageUtil; import com.qniao.framework.utils.TypeConvertUtils; +import com.thoughtworks.xstream.converters.time.LocalDateTimeConverter; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.Objects; @Service @@ -56,15 +59,47 @@ public class WalletAccountQueryServiceImpl implements WalletAccountQueryService if (Objects.nonNull(walletAccount)) { walletAccountVo = TypeConvertUtils.convert(walletAccount, UserGetWalletAccountVo.class); if (Objects.nonNull(walletAccount.getId())) { + //已提现金额 walletAccountVo.setTotalWithdrawBalance(walletAccountRecordDao.selectList(new LambdaQueryWrapper() .eq(WalletAccountRecord::getWalletAccountId, walletAccount.getId()) .eq(WalletAccountRecord::getTradeType, TradeTypeEnum.WITHDRAW)) .stream().map(WalletAccountRecord::getTradeAmount).reduce(BigDecimal.ZERO, BigDecimal::add)); + //可提现金额(参考工资为例,15号后结上一个月之前的,15-1-14则结算前两个月之前的) + walletAccountVo.setAvailableWithdrawBalance(countAvailableWithdrawBalance(walletAccount)); } } return walletAccountVo; } + /** + * 可提现金额(参考工资为例,15号后结上一个月之前的,15-1-14则结算前两个月之前的) + * + * @param walletAccount + * @return + */ + private BigDecimal countAvailableWithdrawBalance(WalletAccount walletAccount) { + BigDecimal availableBalance = walletAccount.getAvailableBalance(); + LocalDate date = LocalDate.now(); + int month = 0; + if (date.getDayOfMonth() < 15) { + //可结算上一个月 + month = 1; + } + //不可提现的金额 + BigDecimal unavailableWithdrawBalance = countUnavailableWithdrawBalance(walletAccount.getId(), date, month); + return availableBalance.compareTo(unavailableWithdrawBalance) > 0 ? availableBalance.subtract(unavailableWithdrawBalance) : BigDecimal.ZERO; + } + + private BigDecimal countUnavailableWithdrawBalance(Long walletAccountId, LocalDate date, int month) { + LocalDateTime dateTime = date.minusMonths(month).withDayOfMonth(1).atStartOfDay(); + return walletAccountRecordDao.selectList(new LambdaQueryWrapper() + .eq(WalletAccountRecord::getWalletAccountId, walletAccountId) + .eq(WalletAccountRecord::getIsIncome, true) + .ge(WalletAccountRecord::getCreateTime, dateTime)) + .stream().map(WalletAccountRecord::getTradeAmount) + .reduce(BigDecimal.ZERO, BigDecimal::add); + } + @Override public WalletAccount queryByType(Long identityId, IdentityTypeEnum identityType) {