From 031c084f8f31bc7040f52768e6cdaba291ef4637 Mon Sep 17 00:00:00 2001
From: KKSU <15274802129@163.com>
Date: Wed, 10 Jan 2024 15:00:02 +0800
Subject: [PATCH] 权益积分设置,提现扣除权益积分,下单购买套餐回去对应倍数的权益积分

---
 src/main/java/cc/mrbird/febs/common/enumerates/MoneyFlowTypeEnum.java             |    7 +++
 src/main/java/cc/mrbird/febs/mall/controller/AdminSystemController.java           |    4 ++
 src/main/java/cc/mrbird/febs/mall/service/impl/AgentServiceImpl.java              |   30 +++++++++++++--
 src/main/java/cc/mrbird/febs/mall/controller/ViewSystemController.java            |    6 +++
 src/main/java/cc/mrbird/febs/mall/service/impl/MallMemberWithdrawServiceImpl.java |   21 ++++++++++
 src/main/java/cc/mrbird/febs/common/enumerates/DataDictionaryEnum.java            |    3 +
 src/main/java/cc/mrbird/febs/mall/vo/AdminPerkSetVo.java                          |    5 ++
 src/main/java/cc/mrbird/febs/common/enumerates/FlowTypeEnum.java                  |    5 ++
 src/main/java/cc/mrbird/febs/mall/entity/MallMemberWallet.java                    |    5 ++
 src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallMemberServiceImpl.java    |    1 
 src/main/resources/templates/febs/views/modules/system/perkSet.html               |   11 +++++
 11 files changed, 91 insertions(+), 7 deletions(-)

diff --git a/src/main/java/cc/mrbird/febs/common/enumerates/DataDictionaryEnum.java b/src/main/java/cc/mrbird/febs/common/enumerates/DataDictionaryEnum.java
index 2c105ef..537343b 100644
--- a/src/main/java/cc/mrbird/febs/common/enumerates/DataDictionaryEnum.java
+++ b/src/main/java/cc/mrbird/febs/common/enumerates/DataDictionaryEnum.java
@@ -5,7 +5,8 @@
 
 @Getter
 public enum DataDictionaryEnum {
-
+    //权益额度增加倍数
+    EQUITY_LIMIT_TIMES("EQUITY_LIMIT_TIMES", "EQUITY_LIMIT_TIMES"),
     //积分池设置{"everydayRatio":10,"dividEquallyRatio":1}每日订单的百分之几,增加到积分池;每日平分百分比
     SCORE_POOR_RADIO("SCORE_POOR", "SCORE_POOR_RADIO"),
 
diff --git a/src/main/java/cc/mrbird/febs/common/enumerates/FlowTypeEnum.java b/src/main/java/cc/mrbird/febs/common/enumerates/FlowTypeEnum.java
index 6c09b78..8d9ba3d 100644
--- a/src/main/java/cc/mrbird/febs/common/enumerates/FlowTypeEnum.java
+++ b/src/main/java/cc/mrbird/febs/common/enumerates/FlowTypeEnum.java
@@ -11,6 +11,11 @@
 
 
     /**
+     * 权益积分
+     */
+    EQUITY_LIMIT(6),
+
+    /**
      * 余额
      */
     BALANCE(1),
diff --git a/src/main/java/cc/mrbird/febs/common/enumerates/MoneyFlowTypeEnum.java b/src/main/java/cc/mrbird/febs/common/enumerates/MoneyFlowTypeEnum.java
index e170980..d5ff1ec 100644
--- a/src/main/java/cc/mrbird/febs/common/enumerates/MoneyFlowTypeEnum.java
+++ b/src/main/java/cc/mrbird/febs/common/enumerates/MoneyFlowTypeEnum.java
@@ -133,7 +133,12 @@
     /**
      * 积分转余额
      */
-    SCORE_TO_CASH(26);
+    SCORE_TO_CASH(26),
+
+    /**
+     * 套餐产生权益积分
+     */
+    TC_TO_EQUITY_LIMIT(27);
 
     private final int value;
 
diff --git a/src/main/java/cc/mrbird/febs/mall/controller/AdminSystemController.java b/src/main/java/cc/mrbird/febs/mall/controller/AdminSystemController.java
index 9b1cf80..1069031 100644
--- a/src/main/java/cc/mrbird/febs/mall/controller/AdminSystemController.java
+++ b/src/main/java/cc/mrbird/febs/mall/controller/AdminSystemController.java
@@ -72,6 +72,10 @@
                 PerkEnum.PARTNER_CASH_PERK_PERCENT.getType(),
                 PerkEnum.PARTNER_CASH_PERK_PERCENT.getCode(),
                 adminPerkSetVo.getPartnerCashPerkPercent());
+        commonService.updateDataDic(
+                DataDictionaryEnum.EQUITY_LIMIT_TIMES.getType(),
+                DataDictionaryEnum.EQUITY_LIMIT_TIMES.getCode(),
+                adminPerkSetVo.getEquityLimitTimes());
         return new FebsResponse().success();
     }
 
diff --git a/src/main/java/cc/mrbird/febs/mall/controller/ViewSystemController.java b/src/main/java/cc/mrbird/febs/mall/controller/ViewSystemController.java
index f6170b4..6d12297 100644
--- a/src/main/java/cc/mrbird/febs/mall/controller/ViewSystemController.java
+++ b/src/main/java/cc/mrbird/febs/mall/controller/ViewSystemController.java
@@ -158,6 +158,12 @@
         if (partnerCashPerkPercentDic != null) {
             adminPerkSetVo.setPartnerCashPerkPercent(partnerCashPerkPercentDic.getValue());
         }
+        DataDictionaryCustom equityLimitTimesDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                DataDictionaryEnum.EQUITY_LIMIT_TIMES.getType(),
+                DataDictionaryEnum.EQUITY_LIMIT_TIMES.getCode());
+        if (equityLimitTimesDic != null) {
+            adminPerkSetVo.setEquityLimitTimes(equityLimitTimesDic.getValue());
+        }
 
         model.addAttribute("adminPerkSet", adminPerkSetVo);
         return FebsUtil.view("modules/system/perkSet");
diff --git a/src/main/java/cc/mrbird/febs/mall/entity/MallMemberWallet.java b/src/main/java/cc/mrbird/febs/mall/entity/MallMemberWallet.java
index dd729bf..1204957 100644
--- a/src/main/java/cc/mrbird/febs/mall/entity/MallMemberWallet.java
+++ b/src/main/java/cc/mrbird/febs/mall/entity/MallMemberWallet.java
@@ -43,4 +43,9 @@
      * 佣金
      */
     private BigDecimal commission;
+
+    /**
+     * 权益积分
+     */
+    private BigDecimal equityLimit;
 }
diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallMemberServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallMemberServiceImpl.java
index 6b6f524..220ea2f 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallMemberServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallMemberServiceImpl.java
@@ -219,6 +219,7 @@
 
         //用户增加对应的余额
         iApiMallMemberWalletService.add(mallMemberWithdraw.getAmount(),mallMemberWithdraw.getMemberId(),"balance");
+        iApiMallMemberWalletService.add(mallMemberWithdraw.getAmount(),mallMemberWithdraw.getMemberId(),"equity_limit");
         return new FebsResponse().success();
     }
 
diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/AgentServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/AgentServiceImpl.java
index 22e6b14..1205371 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/AgentServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/AgentServiceImpl.java
@@ -214,6 +214,12 @@
          * 4、董事享受全公司入单分红2%加权(现金)
          * 5、合伙人享全公司入单分红5%加权(现金)
          * 6、入单后,50%入现金池 35%的H金劵入H金劵池,更新价格
+         *
+         *
+         * 新增购买套餐返佣逻辑
+         * 1、买了套餐增加权益额度
+         * 2、权益额度每次提现会减少对应的数额
+         * 3、增加每天返佣固定比例的余额
          */
         //获取当前订单子表信息
         List<MallOrderItem> mallOrderItemList = mallOrderItemMapper.selectbyOrderId(orderId);
@@ -230,6 +236,26 @@
         if(BigDecimal.ZERO.compareTo(amountTCAll) >= 0){
             return;
         }
+
+        MallOrderInfo mallOrderInfo = mallOrderInfoMapper.selectById(orderId);
+        String orderNo = mallOrderInfo.getOrderNo();
+        //购买人
+        Long memberId = mallOrderInfo.getMemberId();
+        DataDictionaryCustom equityLimitTimesDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                DataDictionaryEnum.EQUITY_LIMIT_TIMES.getType(),
+                DataDictionaryEnum.EQUITY_LIMIT_TIMES.getCode());
+        BigDecimal equityLimitTimes = new BigDecimal(equityLimitTimesDic.getValue());
+        BigDecimal equityLimit = amountTCAll.multiply(equityLimitTimes);
+        if(BigDecimal.ZERO.compareTo(equityLimit) < 0){
+            addWalletInfoAndMoneyFlow(equityLimit,
+                    memberId,
+                    "equity_limit",
+                    MoneyFlowTypeEnum.TC_TO_EQUITY_LIMIT.getValue(),
+                    memberId,
+                    FlowTypeEnum.SCORE.getValue(),
+                    orderNo);
+        }
+
         BigDecimal amountTC = new BigDecimal(100);
         //购买套餐按照1000的基数去补贴,如5000,则补贴5次1000
         int times = amountTCAll.divideToIntegralValue(amountTC).intValue();
@@ -238,10 +264,6 @@
         }
 
         for(int i = 0; i < times; i++){
-            MallOrderInfo mallOrderInfo = mallOrderInfoMapper.selectById(orderId);
-            String orderNo = mallOrderInfo.getOrderNo();
-            //购买人
-            Long memberId = mallOrderInfo.getMemberId();
 
             /**
              * 1、购买人获得固定比例的H金劵
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 87f07e9..e61e59c 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
@@ -95,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, "equity_limit");//减少权益积分
 //        walletService.reduce(withdrawalDto.getAmount(), memberId, "commission");
         String orderNo = MallUtils.getOrderNum("W");
 
@@ -127,6 +136,16 @@
                 null,
                 1,
                 FlowTypeEnum.BALANCE.getValue());
+
+        mallMemberService.addMoneyFlow(memberId,
+                withdrawalDto.getAmount().negate(),
+                MoneyFlowTypeEnum.WITHDRAWAL.getValue(),
+                orderNo,
+                null,
+                null,
+                null,
+                1,
+                FlowTypeEnum.EQUITY_LIMIT.getValue());
     }
 
     @Override
diff --git a/src/main/java/cc/mrbird/febs/mall/vo/AdminPerkSetVo.java b/src/main/java/cc/mrbird/febs/mall/vo/AdminPerkSetVo.java
index a2064e1..0b6d194 100644
--- a/src/main/java/cc/mrbird/febs/mall/vo/AdminPerkSetVo.java
+++ b/src/main/java/cc/mrbird/febs/mall/vo/AdminPerkSetVo.java
@@ -30,5 +30,10 @@
      * DIRECTOR_CASH_PERK_PERCENT
      */
     private String directorCashPerkPercent;
+    /**
+     * 权益额度增加倍数
+     * DIRECTOR_CASH_PERK_PERCENT
+     */
+    private String equityLimitTimes;
 
 }
diff --git a/src/main/resources/templates/febs/views/modules/system/perkSet.html b/src/main/resources/templates/febs/views/modules/system/perkSet.html
index cdcd89b..79890a1 100644
--- a/src/main/resources/templates/febs/views/modules/system/perkSet.html
+++ b/src/main/resources/templates/febs/views/modules/system/perkSet.html
@@ -48,6 +48,16 @@
                             <div class="layui-form-mid layui-word-aux">%。</div>
                         </div>
                     </div>
+                    <div class="layui-form-item">
+                        <div class="layui-inline">
+                            <label class="layui-form-label febs-form-item-require">权益倍数:</label>
+                            <div class="layui-form-mid layui-word-aux">购买套餐获得【权益积分】倍数:</div>
+                            <div class="layui-input-inline">
+                                <input type="text" name="equityLimitTimes" lay-verify="required" placeholder="请输入数字" autocomplete="off" class="layui-input">
+                            </div>
+                            <div class="layui-form-mid layui-word-aux">。</div>
+                        </div>
+                    </div>
                 </div>
 
                 <div class="layui-card-footer">
@@ -91,6 +101,7 @@
                 "directCashPerkPercent": adminPerkSet.directCashPerkPercent,
                 "directScorePerkPercent": adminPerkSet.directScorePerkPercent,
                 "partnerCashPerkPercent": adminPerkSet.partnerCashPerkPercent,
+                "equityLimitTimes": adminPerkSet.equityLimitTimes,
                 "directorCashPerkPercent": adminPerkSet.directorCashPerkPercent
             });
         }

--
Gitblit v1.9.1