luodangjia
2024-12-19 60f70f7409ec1ece8905e088fb43e0cb0258a70b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.ruoyi.account.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.other.api.enums.WithdrawalAuditStatus;
import com.ruoyi.account.api.model.AppUser;
import com.ruoyi.account.api.model.WithdrawalRequests;
import com.ruoyi.account.service.AppUserService;
import com.ruoyi.account.service.WalletService;
import com.ruoyi.account.service.WithdrawalRequestsService;
import com.ruoyi.account.vo.WalletVO;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.other.api.domain.VipSetting;
import com.ruoyi.other.api.feignClient.RemoteVipSettingClient;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
 
@Service
public class WalletServiceImpl implements WalletService {
    @Resource
    private AppUserService appUserService;
    @Resource
    private RemoteVipSettingClient remoteVipSettingClient;
    @Resource
    private WithdrawalRequestsService withdrawalRequestsService;
 
    @Override
    public WalletVO getWalletByUserId(Long userId) {
        AppUser appUser = appUserService.getById(userId);
        if (appUser == null) {
            throw new RuntimeException("用户不存在");
        }
        Integer vipId = appUser.getVipId();
        R<VipSetting> r = remoteVipSettingClient.getVipSettingById(vipId);
        VipSetting data = r.getData();
        if (data == null) {
            throw new RuntimeException("会员设置信息为空");
        }
 
        // 获取提现审核中的金额
        List<WithdrawalRequests> waitAuditList = withdrawalRequestsService.list(new LambdaQueryWrapper<WithdrawalRequests>()
                .eq(WithdrawalRequests::getAppUserId, userId)
                .eq(WithdrawalRequests::getAuditStatus, WithdrawalAuditStatus.WAIT_AUDIT));
 
        WalletVO walletVO = new WalletVO();
        walletVO.setWithdrawalAmount(appUser.getWithdrawableAmount());
        walletVO.setWithdrawnAmount(appUser.getWithdrawnAmount());
        walletVO.setVipWithdrawalMinAmount(data.getVipWithdrawalMinAmount());
        walletVO.setTotalRechargeAmount(appUser.getTotalRechargeAmount());
        walletVO.setTotalRedPacketAmount(appUser.getTotalRedPacketAmount());
        walletVO.setTotalDistributionAmount(appUser.getTotalDistributionAmount());
        walletVO.setAuditAmount(waitAuditList.stream()
                .map(WithdrawalRequests::getWithdrawalAmount)
                .reduce(BigDecimal.ZERO, BigDecimal::add));
        walletVO.setBalance(appUser.getBalance());
        return walletVO;
    }
 
}