陶杰
2024-12-18 07534d5e73eab7d0a9d966c005c8f04e15668565
src/main/java/com/mzl/flower/service/impl/wallet/WalletServiceImpl.java
@@ -5,6 +5,7 @@
import com.mzl.flower.constant.LockConstants;
import com.mzl.flower.dto.request.wallet.QueryWalletAmountDTO;
import com.mzl.flower.dto.response.supplier.SupplierDTO;
import com.mzl.flower.entity.supplier.Supplier;
import com.mzl.flower.entity.wallet.WalletDO;
import com.mzl.flower.enums.TrueOrFalseEnum;
import com.mzl.flower.mapper.wallet.WalletMapper;
@@ -17,6 +18,7 @@
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
@@ -76,6 +78,8 @@
    @Override
    public WalletDO getOrCreateBySupplierId(Long supplierId) {
        WalletDO walletDO=getBySupplierId(supplierId);
        if(null==walletDO){
            RLock lock = redissonClient.getLock(String.format(LockConstants.WALLET_SUPPLIER_ID_KEY, supplierId));
@@ -84,9 +88,12 @@
                    try {
                        walletDO=getBySupplierId(supplierId);
                        if(null!=walletDO) return walletDO;
                        final Supplier supplier = supplierService.getSupplierById(supplierId);
                        // 创建一个钱包
                        walletDO =new WalletDO();
                        walletDO.setUserId(SecurityUtils.getUserId());
                        walletDO.setUserId(supplier.getUserId());
                        walletDO.setSupplierId(supplierId);
                        walletDO.setTotalAmount(BigDecimal.ZERO);
                        walletDO.setWithdrawableAmount(BigDecimal.ZERO);
@@ -130,7 +137,10 @@
    @Override
    public BigDecimal getWaittingSettlementAmount(WalletDO walletDO) {
        if(null!=walletDO && !StringUtils.isEmpty(walletDO.getSupplierId()) && StringUtils.isEmpty(walletDO.getUserId())){
            final Supplier supplier = supplierService.getSupplierById(walletDO.getSupplierId());
            walletDO.setUserId(supplier.getUserId());
        }
        return baseMapper.getWaittingSettlementAmount(walletDO);
    }
@@ -154,15 +164,24 @@
        queryWalletAmountDTO.setStartTime(getWalletOnLineTime());
        queryWalletAmountDTO.setUserId(walletDO.getUserId());
        // 质检扣款
        BigDecimal checkDeduceAmount = walletReduceService.getCheckReduceAmount(queryWalletAmountDTO);
        checkDeduceAmount = checkDeduceAmount != null ? checkDeduceAmount : BigDecimal.ZERO;
        // 质检扣款(缺货和补货)
        BigDecimal checkReplaceLockAmount = walletReduceService.getCheckLackReplaceAmount(queryWalletAmountDTO);
        checkReplaceLockAmount = checkReplaceLockAmount != null ? checkReplaceLockAmount : BigDecimal.ZERO;
        // 质检扣款(降级)
        BigDecimal checkReduceAmount = walletReduceService.getCheckReduceAmount(queryWalletAmountDTO);
        checkReduceAmount = checkReduceAmount != null ? checkReduceAmount : BigDecimal.ZERO;
        // 售后扣款
        BigDecimal saleDeduceAmount = walletReduceService.getSaleReduceAmount(queryWalletAmountDTO);
        saleDeduceAmount = saleDeduceAmount != null ? saleDeduceAmount : BigDecimal.ZERO;
        // 集货站运费
        BigDecimal stationFeeAmount = walletReduceService.getStationFeeAmount(queryWalletAmountDTO);
        stationFeeAmount = stationFeeAmount != null ? stationFeeAmount : BigDecimal.ZERO;
        // 总扣款
        BigDecimal deduceAmount = checkDeduceAmount.add(saleDeduceAmount);
        BigDecimal deduceAmount = checkReplaceLockAmount.add(checkReduceAmount).add(saleDeduceAmount).add(stationFeeAmount);
        return deduceAmount;
    }