From 165a67bdad4c4ca98c284dd831584d36209fa8ea Mon Sep 17 00:00:00 2001
From: KKSU <15274802129@163.com>
Date: Wed, 27 Dec 2023 15:28:57 +0800
Subject: [PATCH] 直推奖励,冻结的用户,则直推奖励销毁,用户未冻结才能领取成功

---
 src/main/java/cc/mrbird/febs/mall/service/impl/AgentServiceImpl.java         |   89 +++++++++++++++++++++++++++++
 src/main/java/cc/mrbird/febs/common/utils/AppContants.java                   |    6 ++
 src/main/java/cc/mrbird/febs/common/enumerates/DataDictionaryEnum.java       |    3 +
 src/main/java/cc/mrbird/febs/mall/service/impl/MallMoneyFlowServiceImpl.java |    5 +
 src/main/java/cc/mrbird/febs/mall/quartz/ProfitJob.java                      |   10 +++
 src/main/resources/mapper/modules/MallMemberAmountMapper.xml                 |    8 ++
 src/main/java/cc/mrbird/febs/common/enumerates/MoneyFlowTypeNewEnum.java     |    3 +
 src/main/java/cc/mrbird/febs/mall/service/IMallMoneyFlowService.java         |    1 
 src/main/java/cc/mrbird/febs/mall/mapper/MallMemberAmountMapper.java         |    2 
 src/main/java/cc/mrbird/febs/mall/service/IAgentService.java                 |    2 
 10 files changed, 128 insertions(+), 1 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 2e8fb3e..4a538bc 100644
--- a/src/main/java/cc/mrbird/febs/common/enumerates/DataDictionaryEnum.java
+++ b/src/main/java/cc/mrbird/febs/common/enumerates/DataDictionaryEnum.java
@@ -5,6 +5,9 @@
 
 @Getter
 public enum DataDictionaryEnum {
+    //直推补贴
+    BASIC_PERK_DIRECT_FROZEN("BASIC_PERK_DIRECT_FROZEN","BASIC_PERK_DIRECT_FROZEN"),
+    BASIC_PERK_DIRECT("BASIC_PERK_DIRECT","BASIC_PERK_DIRECT"),
     /**
      * 预约开始时间
      * 预约结束时间
diff --git a/src/main/java/cc/mrbird/febs/common/enumerates/MoneyFlowTypeNewEnum.java b/src/main/java/cc/mrbird/febs/common/enumerates/MoneyFlowTypeNewEnum.java
index 831f5f4..e74ef83 100644
--- a/src/main/java/cc/mrbird/febs/common/enumerates/MoneyFlowTypeNewEnum.java
+++ b/src/main/java/cc/mrbird/febs/common/enumerates/MoneyFlowTypeNewEnum.java
@@ -10,6 +10,9 @@
  **/
 @Getter
 public enum MoneyFlowTypeNewEnum {
+    BASIC_PERK_DIRECT_DONE(18,"直推奖励"),
+    BASIC_PERK_DIRECT_WRONG(17,"账户冻结,遗憾错失直推奖励"),
+    BASIC_PERK_DIRECT(16,"即将获得直推奖励"),
     SYSTEM_PEY(15,"系统拨付"),
     NFT_OUT_FEE_FCM(14,"NFT提现GFA手续费"),
     TOKEN_BUY_FROZEN_RETURN(13,"预约门票"),
diff --git a/src/main/java/cc/mrbird/febs/common/utils/AppContants.java b/src/main/java/cc/mrbird/febs/common/utils/AppContants.java
index e167981..114c610 100644
--- a/src/main/java/cc/mrbird/febs/common/utils/AppContants.java
+++ b/src/main/java/cc/mrbird/febs/common/utils/AppContants.java
@@ -76,4 +76,10 @@
     public static final String MEMBER_WITHDRAW_VOUCHER = "凭证提现";
     public static final String MEMBER_WITHDRAW_VOUCHER_AMOUNT = "凭证现金提现";
 
+
+
+    public static final int MEMBER_FLOW_ING = 1;
+
+    public static final int MEMBER_FLOW_DONE = 2;
+
 }
diff --git a/src/main/java/cc/mrbird/febs/mall/mapper/MallMemberAmountMapper.java b/src/main/java/cc/mrbird/febs/mall/mapper/MallMemberAmountMapper.java
index ccf187e..097af8b 100644
--- a/src/main/java/cc/mrbird/febs/mall/mapper/MallMemberAmountMapper.java
+++ b/src/main/java/cc/mrbird/febs/mall/mapper/MallMemberAmountMapper.java
@@ -19,4 +19,6 @@
     void updateTrendsNftById(@Param("record")MallMemberAmount mallMemberAmount);
 
     void updateFrozenNftById(@Param("record")MallMemberAmount mallMemberAmount);
+
+    void updateTrendsNftAndFrozenNftById(@Param("record")MallMemberAmount mallMemberAmount);
 }
diff --git a/src/main/java/cc/mrbird/febs/mall/quartz/ProfitJob.java b/src/main/java/cc/mrbird/febs/mall/quartz/ProfitJob.java
index 9260f64..1fd0fac 100644
--- a/src/main/java/cc/mrbird/febs/mall/quartz/ProfitJob.java
+++ b/src/main/java/cc/mrbird/febs/mall/quartz/ProfitJob.java
@@ -143,6 +143,16 @@
         agentService.timeGetOrderBuyCancel();
     }
 
+
+    /**
+     * 直推奖励
+     * 从冻结到可用
+     */
+    @Scheduled(cron = "0 0 0/2 * * ? ")
+    public void basicMemberPerk() {
+        agentService.basicMemberPerk();
+    }
+
 //    /**
 //     * 卖单
 //     * 看是否是开始显示订单的时间段,超出结束时间的卖单,全部超时失败
diff --git a/src/main/java/cc/mrbird/febs/mall/service/IAgentService.java b/src/main/java/cc/mrbird/febs/mall/service/IAgentService.java
index 019f4bd..f0b1d75 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/IAgentService.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/IAgentService.java
@@ -47,4 +47,6 @@
     void timeGetOrderSell();
 
     void timeGetOrderBuyCancel();
+
+    void basicMemberPerk();
 }
diff --git a/src/main/java/cc/mrbird/febs/mall/service/IMallMoneyFlowService.java b/src/main/java/cc/mrbird/febs/mall/service/IMallMoneyFlowService.java
index 8cea027..e058ce6 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/IMallMoneyFlowService.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/IMallMoneyFlowService.java
@@ -16,5 +16,6 @@
     void addMoneyFlow(Long memberId, BigDecimal amount, Integer type, String orderNo, Long rtMemberId, Integer flowType);
 
     void addMoneyFlow(Long memberId, BigDecimal amount, Integer type, String orderNo, Long rtMemberId, Integer flowType, String description);
+    void addMoneyFlow(Long memberId, BigDecimal amount, Integer type, String orderNo, Long rtMemberId, Integer flowType, String description,Integer isReturn);
 
 }
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 17c155f..39a22e8 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
@@ -871,8 +871,39 @@
                     MallMember mallMember = memberMapper.selectById(memberId);
                     if(ObjectUtil.isNotEmpty(mallMember)){
                         //直推
-                    }
+                        String referrerId = mallMember.getReferrerId();
+                        MallMember directMember = memberMapper.selectInfoByInviteId(referrerId);
+                        if(ObjectUtil.isNotEmpty(directMember)){
+                            BigDecimal basicPerkDirectPercent = new BigDecimal(dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                                    DataDictionaryEnum.BASIC_PERK_DIRECT.getType(),
+                                    DataDictionaryEnum.BASIC_PERK_DIRECT.getCode()
+                            ).getValue()).multiply(new BigDecimal("0.01"));
+                            BigDecimal basicPerkDirect = profit.multiply(basicPerkDirectPercent).setScale(2, BigDecimal.ROUND_DOWN);
+                            /**
+                             * 先插入流水记录,然后定时器每小时,循环一次找寻对应的数据执行
+                             */
+                            String frozenDays = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                                    DataDictionaryEnum.BASIC_PERK_DIRECT_FROZEN.getType(),
+                                    DataDictionaryEnum.BASIC_PERK_DIRECT_FROZEN.getCode()
+                            ).getValue();
+                            String orderNo = MallUtils.getOrderNum("FNFT");
+                            mallMoneyFlowService.addMoneyFlow(
+                                    directMember.getId(),
+                                    basicPerkDirect,
+                                    MoneyFlowTypeNewEnum.BASIC_PERK_DIRECT.getValue(),
+                                    orderNo,
+                                    null,
+                                    FlowTypeNewEnum.NFT.getValue(),
+                                    MoneyFlowTypeNewEnum.BASIC_PERK_DIRECT.getDescrition(),
+                                    AppContants.MEMBER_FLOW_ING);
 
+                            MallMemberAmount mallMemberAmountDirect = mallMemberAmountMapper.selectByMemberId(directMember.getId());
+                            mallMemberAmountDirect.setFrozenNft(mallMemberAmountDirect.getFrozenNft().add(basicPerkDirect));
+                            mallMemberAmountMapper.updateFrozenNftById(mallMemberAmountDirect);
+                        }
+
+
+                    }
                 }
             }
         }
@@ -1036,6 +1067,62 @@
         }
     }
 
+    @Override
+    public void basicMemberPerk() {
+        QueryWrapper<MallMoneyFlow> queryMallMoneyFlow = new QueryWrapper<>();
+        queryMallMoneyFlow.eq("type",MoneyFlowTypeNewEnum.BASIC_PERK_DIRECT.getValue());
+        queryMallMoneyFlow.eq("is_return",AppContants.MEMBER_FLOW_ING);
+        queryMallMoneyFlow.eq("flow_type",FlowTypeNewEnum.NFT.getValue());
+        List<MallMoneyFlow> mallMoneyFlows = mallMoneyFlowMapper.selectList(queryMallMoneyFlow);
+        if(CollUtil.isNotEmpty(mallMoneyFlows)){
+            return;
+        }
+        for(MallMoneyFlow mallMoneyFlow : mallMoneyFlows){
+            mallMoneyFlow.setIsReturn(AppContants.MEMBER_FLOW_DONE);
+            mallMoneyFlowMapper.updateById(mallMoneyFlow);
+            /**
+             * 如果用户是冻结,则直接销毁
+             */
+            Long memberId = mallMoneyFlow.getMemberId();
+            MallMember mallMember = memberMapper.selectById(memberId);
+            Integer isFrozen = mallMember.getIsFrozen();
+            if(ProductEnum.MEMBER_UNFROZEN.getValue() == isFrozen){
+                MallMemberAmount mallMemberAmount = mallMemberAmountMapper.selectByMemberId(memberId);
+                mallMemberAmount.setFrozenNft(mallMemberAmount.getFrozenNft().subtract(mallMoneyFlow.getAmount()));
+                mallMemberAmountMapper.updateFrozenNftById(mallMemberAmount);
+                //插入一条流水记录
+                String orderNo = MallUtils.getOrderNum("FNFTW");
+                mallMoneyFlowService.addMoneyFlow(
+                        memberId,
+                        mallMoneyFlow.getAmount().negate(),
+                        MoneyFlowTypeNewEnum.BASIC_PERK_DIRECT_WRONG.getValue(),
+                        orderNo,
+                        null,
+                        FlowTypeNewEnum.NFT.getValue(),
+                        MoneyFlowTypeNewEnum.BASIC_PERK_DIRECT_WRONG.getDescrition(),
+                        AppContants.MEMBER_FLOW_ING);
+
+            }else {
+                MallMemberAmount mallMemberAmount = mallMemberAmountMapper.selectByMemberId(memberId);
+                mallMemberAmount.setFrozenNft(mallMemberAmount.getFrozenNft().subtract(mallMoneyFlow.getAmount()));
+                mallMemberAmount.setTrendsNft(mallMemberAmount.getTrendsNft().add(mallMoneyFlow.getAmount()));
+                mallMemberAmountMapper.updateTrendsNftAndFrozenNftById(mallMemberAmount);
+
+                //插入一条流水记录
+                String orderNo = MallUtils.getOrderNum("NFT");
+                mallMoneyFlowService.addMoneyFlow(
+                        memberId,
+                        mallMoneyFlow.getAmount().negate(),
+                        MoneyFlowTypeNewEnum.BASIC_PERK_DIRECT_DONE.getValue(),
+                        orderNo,
+                        null,
+                        FlowTypeNewEnum.NFT.getValue(),
+                        MoneyFlowTypeNewEnum.BASIC_PERK_DIRECT_DONE.getDescrition(),
+                        AppContants.MEMBER_FLOW_DONE);
+            }
+        }
+    }
+
     public void insertSell(Long memberId,BigDecimal nftCnt,BigDecimal nftCntAva,
                            BigDecimal nftFee,BigDecimal fcmFeeCnt){
         String orderNo = MallUtils.getOrderNum("NFT");
diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/MallMoneyFlowServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/MallMoneyFlowServiceImpl.java
index ee0c8e0..8c5ff2a 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/MallMoneyFlowServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/MallMoneyFlowServiceImpl.java
@@ -54,4 +54,9 @@
     public void addMoneyFlow(Long memberId, BigDecimal amount, Integer type, String orderNo, Long rtMemberId, Integer flowType, String description) {
         this.addMoneyFlow(memberId, amount, type, orderNo, description, null, rtMemberId, null, flowType, null);
     }
+
+    @Override
+    public void addMoneyFlow(Long memberId, BigDecimal amount, Integer type, String orderNo, Long rtMemberId, Integer flowType, String description, Integer isReturn) {
+        this.addMoneyFlow(memberId, amount, type, orderNo, description, null, rtMemberId, null, flowType, isReturn);
+    }
 }
diff --git a/src/main/resources/mapper/modules/MallMemberAmountMapper.xml b/src/main/resources/mapper/modules/MallMemberAmountMapper.xml
index 86f5f15..1173316 100644
--- a/src/main/resources/mapper/modules/MallMemberAmountMapper.xml
+++ b/src/main/resources/mapper/modules/MallMemberAmountMapper.xml
@@ -42,4 +42,12 @@
         where id = #{record.id} and revision=#{record.revision}
     </update>
 
+    <update id="updateTrendsNftAndFrozenNftById">
+        update mall_member_amount
+        set revision = revision + 1,
+            frozen_nft = #{record.frozenNft},
+            trends_nft = #{record.trendsNft}
+        where id = #{record.id} and revision=#{record.revision}
+    </update>
+
 </mapper>
\ No newline at end of file

--
Gitblit v1.9.1