From ada59d11d10c4a5db3c748c1997ee4992ee54b3a Mon Sep 17 00:00:00 2001
From: KKSU <15274802129@163.com>
Date: Thu, 11 Jan 2024 14:44:07 +0800
Subject: [PATCH] 套餐

---
 src/main/java/cc/mrbird/febs/mall/service/impl/MallMemberWithdrawServiceImpl.java |   40 ++++++++++++++++++++++++++++++++++++++--
 1 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/MallMemberWithdrawServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/MallMemberWithdrawServiceImpl.java
index 7359cfc..d69c527 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/MallMemberWithdrawServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/MallMemberWithdrawServiceImpl.java
@@ -17,6 +17,7 @@
 import cc.mrbird.febs.mall.service.IMallMemberWithdrawService;
 import cc.mrbird.febs.mall.service.MallMemberService;
 import cc.mrbird.febs.mall.vo.CashOutSettingVo;
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.crypto.SecureUtil;
@@ -28,6 +29,8 @@
 import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
+import java.util.Date;
+import java.util.List;
 
 /**
  * @author wzy
@@ -65,6 +68,20 @@
             cashOutSettingVo = JSONObject.parseObject(dic.getValue(), CashOutSettingVo.class);
         }
 
+        //每日提现额度上限
+        BigDecimal allCashOut = cashOutSettingVo.getAllCashOut();
+        if(withdrawalDto.getAmount().compareTo(allCashOut) > 0){
+            throw new FebsException("限额:"+cashOutSettingVo.getAllCashOut().setScale(2,BigDecimal.ROUND_DOWN));
+        }
+        List<MallMemberWithdraw> mallMemberWithdrawListDone = this.baseMapper.selectListByMemberIdAndDate(memberId,new Date());
+        if(CollUtil.isNotEmpty(mallMemberWithdrawListDone)){
+            BigDecimal amountTCAll = mallMemberWithdrawListDone.stream().map(MallMemberWithdraw::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
+            amountTCAll = amountTCAll.add(withdrawalDto.getAmount());
+            if (amountTCAll.compareTo(allCashOut) > 0) {
+                throw new FebsException("限额:"+cashOutSettingVo.getAllCashOut().setScale(2,BigDecimal.ROUND_DOWN));
+            }
+        }
+
         if (withdrawalDto.getAmount().compareTo(cashOutSettingVo.getMinCashOut()) < 0) {
             throw new FebsException("最小提现金额为"+cashOutSettingVo.getMinCashOut().setScale(2,BigDecimal.ROUND_DOWN));
         }
@@ -78,16 +95,25 @@
         if(wallet.getBalance().compareTo(BigDecimal.ZERO) <= 0){
             throw new FebsException("金额不足");
         }
+        if(wallet.getEquityLimit().compareTo(BigDecimal.ZERO) <= 0){
+            throw new FebsException("权益积分不足");
+        }
         if(withdrawalDto.getAmount().compareTo(wallet.getBalance()) > 0) {
             throw new FebsException("金额不足");
         }
+
+        if(withdrawalDto.getAmount().compareTo(wallet.getEquityLimit()) > 0) {
+            throw new FebsException("权益积分不足");
+        }
+
 //        BigDecimal commission = wallet.getCommission();
 //        if(withdrawalDto.getAmount().compareTo(commission) > 0){
 //            throw new FebsException("金额不足");
 //        }
 
         BigDecimal serviceFee = cashOutSettingVo.getServiceFee().multiply(BigDecimal.valueOf(0.01));
-        walletService.reduce(withdrawalDto.getAmount(), memberId, "balance");
+        walletService.reduce(withdrawalDto.getAmount(), memberId, "balance");//减少余额
+        walletService.reduce(withdrawalDto.getAmount(), memberId, "equityLimit");//减少权益积分
 //        walletService.reduce(withdrawalDto.getAmount(), memberId, "commission");
         String orderNo = MallUtils.getOrderNum("W");
 
@@ -104,6 +130,16 @@
         mallMemberService.addMoneyFlow(memberId,
                 withdrawalDto.getAmount().negate(),
                 MoneyFlowTypeEnum.WITHDRAWAL.getValue(),
+                orderNo,
+                null,
+                null,
+                null,
+                1,
+                FlowTypeEnum.BALANCE.getValue());
+
+        mallMemberService.addMoneyFlow(memberId,
+                withdrawalDto.getAmount().negate(),
+                MoneyFlowTypeEnum.REDUCE_EQUITY_LIMIT.getValue(),
                 orderNo,
                 null,
                 null,
@@ -208,7 +244,7 @@
         );
 
         if(poolScore.compareTo(BigDecimal.ZERO) > 0 && poolCash.compareTo(BigDecimal.ZERO) > 0){
-            BigDecimal divide = poolCash.divide(poolScore, 6, BigDecimal.ROUND_DOWN);
+            BigDecimal divide = poolCash.divide(poolScore, 8, BigDecimal.ROUND_DOWN);
             dataDictionaryCustomMapper.updateDicValueByTypeAndCode(
                     PerkEnum.POOL_SCORE_PRICE.getType(),
                     PerkEnum.POOL_SCORE_PRICE.getCode(),

--
Gitblit v1.9.1