From 39d9cf6ff15636c1ec59853706d7807667318ec8 Mon Sep 17 00:00:00 2001 From: Derran Date: Tue, 4 Mar 2025 15:35:34 +0800 Subject: [PATCH] =?UTF-8?q?=E9=AB=98=E7=BA=A7=E7=BA=A2=E5=A8=98=E5=91=A8?= =?UTF-8?q?=E8=96=AA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/WalletAccountQueryServiceImpl.java | 65 ++++++++++++++----- 1 file changed, 47 insertions(+), 18 deletions(-) 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 b395cff..8ad439f 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 @@ -12,18 +12,21 @@ import com.qniao.dam.domain.aggregate.walletaccount.valueobj.WalletAccountRecord import com.qniao.dam.domian.aggregate.walletaccount.constant.IdentityTypeEnum; import com.qniao.dam.domian.aggregate.walletaccount.constant.TradeTypeEnum; import com.qniao.dam.infrastructure.easyexcel.EasyExcelUtil; +import com.qniao.dam.infrastructure.persistent.dao.domain.MatchmakerDao; import com.qniao.dam.infrastructure.persistent.dao.domain.WalletAccountRecordDao; import com.qniao.dam.infrastructure.persistent.dao.view.WalletAccountViewDao; import com.qniao.dam.query.matchmaker.MatchmakerQueryService; import com.qniao.dam.query.walletaccount.WalletAccountQueryService; import com.qniao.dam.domain.aggregate.walletaccount.entity.WalletAccount; import com.qniao.dam.infrastructure.persistent.dao.domain.WalletAccountDao; +import com.qniao.dau.domian.aggregate.matchmaker.constant.MatchmakerLevelEnum; import com.qniao.framework.utils.PageUtil; import com.qniao.framework.utils.TypeConvertUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.math.BigDecimal; +import java.time.DayOfWeek; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.ArrayList; @@ -83,24 +86,60 @@ public class WalletAccountQueryServiceImpl implements WalletAccountQueryService } /** - * 可提现金额(参考工资为例,15号后结上一个月之前的,15-1-14则结算前两个月之前的) + * 普通红娘,可提现金额(参考工资为例,15号后结上一个月之前的,15-1-14则结算前两个月之前的) + * 高级红娘以上按照周薪制,每周三提现前一周 * * @param walletAccount * @return */ public BigDecimal countAvailableWithdrawBalance(WalletAccount walletAccount) { BigDecimal availableBalance = walletAccount.getAvailableBalance(); - LocalDate date = LocalDate.now(); - int month = 0; - if (date.getDayOfMonth() < 15) { - //可结算上一个月 - month = 1; + BigDecimal unavailableWithdrawBalance; + MatchmakerLevelEnum matchmakerLevel = matchmakerQueryService.queryLevelByUserId(walletAccount.getUserId()); + if (Objects.isNull(matchmakerLevel) || matchmakerLevel.getLevel() < MatchmakerLevelEnum.MATCHMAKER_PARTNER.getLevel()) { + //普通提现 月薪 + LocalDate date = LocalDate.now(); + int months = 0; + if (date.getDayOfMonth() < 15) { + //可结算上一个月 + months = 1; + } + //不可提现的金额 + unavailableWithdrawBalance = countUnavailableWithdrawBalanceByMonth(walletAccount.getId(), date, months); + } else { + // 高级红娘以上 周薪制 + LocalDate date = LocalDate.now(); + DayOfWeek dayOfWeek = date.getDayOfWeek(); + int days = dayOfWeek.getValue() - 1; + if (dayOfWeek.getValue() < DayOfWeek.WEDNESDAY.getValue()) { + //可结算上一个周 + days += DayOfWeek.SUNDAY.getValue(); + } + //不可提现的金额 + unavailableWithdrawBalance = countUnavailableWithdrawBalanceByDays(walletAccount.getId(), date, days); } - //不可提现的金额 - BigDecimal unavailableWithdrawBalance = countUnavailableWithdrawBalance(walletAccount.getId(), date, month); return availableBalance.compareTo(unavailableWithdrawBalance) > 0 ? availableBalance.subtract(unavailableWithdrawBalance) : BigDecimal.ZERO; } + private BigDecimal countUnavailableWithdrawBalanceByMonth(Long walletAccountId, LocalDate date, int months) { + LocalDateTime dateTime = date.minusMonths(months).withDayOfMonth(1).atStartOfDay(); + return countUnavailableWithdrawBalance(walletAccountId, dateTime); + } + + private BigDecimal countUnavailableWithdrawBalance(Long walletAccountId, LocalDateTime dateTime) { + 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); + } + + private BigDecimal countUnavailableWithdrawBalanceByDays(Long walletAccountId, LocalDate date, int days) { + LocalDateTime dateTime = date.minusDays(days).atStartOfDay(); + return countUnavailableWithdrawBalance(walletAccountId, dateTime); + } + @Override public IPage pageWalletAccountRecordByOperator(PageUtil pageUtil, UsePageWalletAccountRecordByOperatorQueryParams queryParams) { IPage page = walletAccountViewDao.pageWalletAccountRecordByOperator(pageUtil.toPageWithoutOrders(), queryParams); @@ -141,16 +180,6 @@ public class WalletAccountQueryServiceImpl implements WalletAccountQueryService return list; } - 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) {