|
|
@ -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.IdentityTypeEnum; |
|
|
import com.qniao.dam.domian.aggregate.walletaccount.constant.TradeTypeEnum; |
|
|
import com.qniao.dam.domian.aggregate.walletaccount.constant.TradeTypeEnum; |
|
|
import com.qniao.dam.infrastructure.easyexcel.EasyExcelUtil; |
|
|
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.domain.WalletAccountRecordDao; |
|
|
import com.qniao.dam.infrastructure.persistent.dao.view.WalletAccountViewDao; |
|
|
import com.qniao.dam.infrastructure.persistent.dao.view.WalletAccountViewDao; |
|
|
import com.qniao.dam.query.matchmaker.MatchmakerQueryService; |
|
|
import com.qniao.dam.query.matchmaker.MatchmakerQueryService; |
|
|
import com.qniao.dam.query.walletaccount.WalletAccountQueryService; |
|
|
import com.qniao.dam.query.walletaccount.WalletAccountQueryService; |
|
|
import com.qniao.dam.domain.aggregate.walletaccount.entity.WalletAccount; |
|
|
import com.qniao.dam.domain.aggregate.walletaccount.entity.WalletAccount; |
|
|
import com.qniao.dam.infrastructure.persistent.dao.domain.WalletAccountDao; |
|
|
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.PageUtil; |
|
|
import com.qniao.framework.utils.TypeConvertUtils; |
|
|
import com.qniao.framework.utils.TypeConvertUtils; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
import javax.annotation.Resource; |
|
|
import java.math.BigDecimal; |
|
|
import java.math.BigDecimal; |
|
|
|
|
|
import java.time.DayOfWeek; |
|
|
import java.time.LocalDate; |
|
|
import java.time.LocalDate; |
|
|
import java.time.LocalDateTime; |
|
|
import java.time.LocalDateTime; |
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
@ -83,24 +86,60 @@ public class WalletAccountQueryServiceImpl implements WalletAccountQueryService |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 可提现金额(参考工资为例,15号后结上一个月之前的,15-1-14则结算前两个月之前的) |
|
|
|
|
|
|
|
|
* 普通红娘,可提现金额(参考工资为例,15号后结上一个月之前的,15-1-14则结算前两个月之前的) |
|
|
|
|
|
* 高级红娘以上按照周薪制,每周三提现前一周 |
|
|
* |
|
|
* |
|
|
* @param walletAccount |
|
|
* @param walletAccount |
|
|
* @return |
|
|
* @return |
|
|
*/ |
|
|
*/ |
|
|
public BigDecimal countAvailableWithdrawBalance(WalletAccount walletAccount) { |
|
|
public BigDecimal countAvailableWithdrawBalance(WalletAccount walletAccount) { |
|
|
BigDecimal availableBalance = walletAccount.getAvailableBalance(); |
|
|
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; |
|
|
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<WalletAccountRecord>() |
|
|
|
|
|
.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 |
|
|
@Override |
|
|
public IPage<UsePageWalletAccountRecordByOperatorVo> pageWalletAccountRecordByOperator(PageUtil pageUtil, UsePageWalletAccountRecordByOperatorQueryParams queryParams) { |
|
|
public IPage<UsePageWalletAccountRecordByOperatorVo> pageWalletAccountRecordByOperator(PageUtil pageUtil, UsePageWalletAccountRecordByOperatorQueryParams queryParams) { |
|
|
IPage<UsePageWalletAccountRecordByOperatorVo> page = walletAccountViewDao.pageWalletAccountRecordByOperator(pageUtil.toPageWithoutOrders(), queryParams); |
|
|
IPage<UsePageWalletAccountRecordByOperatorVo> page = walletAccountViewDao.pageWalletAccountRecordByOperator(pageUtil.toPageWithoutOrders(), queryParams); |
|
|
@ -141,16 +180,6 @@ public class WalletAccountQueryServiceImpl implements WalletAccountQueryService |
|
|
return list; |
|
|
return list; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private BigDecimal countUnavailableWithdrawBalance(Long walletAccountId, LocalDate date, int month) { |
|
|
|
|
|
LocalDateTime dateTime = date.minusMonths(month).withDayOfMonth(1).atStartOfDay(); |
|
|
|
|
|
return walletAccountRecordDao.selectList(new LambdaQueryWrapper<WalletAccountRecord>() |
|
|
|
|
|
.eq(WalletAccountRecord::getWalletAccountId, walletAccountId) |
|
|
|
|
|
.eq(WalletAccountRecord::getIsIncome, true) |
|
|
|
|
|
.ge(WalletAccountRecord::getCreateTime, dateTime)) |
|
|
|
|
|
.stream().map(WalletAccountRecord::getTradeAmount) |
|
|
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public WalletAccount queryByType(Long identityId, |
|
|
public WalletAccount queryByType(Long identityId, |
|
|
IdentityTypeEnum identityType) { |
|
|
IdentityTypeEnum identityType) { |
|
|
|