Browse Source

悬赏招亲

master
张彭杰 1 year ago
parent
commit
efa87ad171
2 changed files with 38 additions and 0 deletions
  1. 3
      dating-agency-mall-server/src/main/java/com/qniao/dam/api/query/walletaccount/user/response/UserGetWalletAccountVo.java
  2. 35
      dating-agency-mall-server/src/main/java/com/qniao/dam/query/walletaccount/impl/WalletAccountQueryServiceImpl.java

3
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("冻结余额") @ApiModelProperty("冻结余额")
private BigDecimal frozenBalance = BigDecimal.ZERO; private BigDecimal frozenBalance = BigDecimal.ZERO;
@ApiModelProperty("可提现金额")
private BigDecimal availableWithdrawBalance = BigDecimal.ZERO;
@ApiModelProperty("总提现金额") @ApiModelProperty("总提现金额")
private BigDecimal totalWithdrawBalance = BigDecimal.ZERO; private BigDecimal totalWithdrawBalance = BigDecimal.ZERO;

35
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.dam.infrastructure.persistent.dao.domain.WalletAccountDao;
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 com.thoughtworks.xstream.converters.time.LocalDateTimeConverter;
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.LocalDate;
import java.time.LocalDateTime;
import java.util.Objects; import java.util.Objects;
@Service @Service
@ -56,15 +59,47 @@ public class WalletAccountQueryServiceImpl implements WalletAccountQueryService
if (Objects.nonNull(walletAccount)) { if (Objects.nonNull(walletAccount)) {
walletAccountVo = TypeConvertUtils.convert(walletAccount, UserGetWalletAccountVo.class); walletAccountVo = TypeConvertUtils.convert(walletAccount, UserGetWalletAccountVo.class);
if (Objects.nonNull(walletAccount.getId())) { if (Objects.nonNull(walletAccount.getId())) {
//已提现金额
walletAccountVo.setTotalWithdrawBalance(walletAccountRecordDao.selectList(new LambdaQueryWrapper<WalletAccountRecord>() walletAccountVo.setTotalWithdrawBalance(walletAccountRecordDao.selectList(new LambdaQueryWrapper<WalletAccountRecord>()
.eq(WalletAccountRecord::getWalletAccountId, walletAccount.getId()) .eq(WalletAccountRecord::getWalletAccountId, walletAccount.getId())
.eq(WalletAccountRecord::getTradeType, TradeTypeEnum.WITHDRAW)) .eq(WalletAccountRecord::getTradeType, TradeTypeEnum.WITHDRAW))
.stream().map(WalletAccountRecord::getTradeAmount).reduce(BigDecimal.ZERO, BigDecimal::add)); .stream().map(WalletAccountRecord::getTradeAmount).reduce(BigDecimal.ZERO, BigDecimal::add));
//可提现金额参考工资为例,15号后结上一个月之前的15-1-14则结算前两个月之前的
walletAccountVo.setAvailableWithdrawBalance(countAvailableWithdrawBalance(walletAccount));
} }
} }
return walletAccountVo; 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<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) {

Loading…
Cancel
Save