From f0dbcbe3f79900a3f6cacea04893697b9187946a Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Mon, 21 Aug 2023 11:59:44 +0800
Subject: [PATCH] 赠送积分更新状态

---
 src/main/java/cc/mrbird/febs/rabbit/consumer/AgentConsumer.java                 |    1 -
 src/main/java/cc/mrbird/febs/mall/service/impl/AgentServiceImpl.java            |   35 +++++++++++++++++++++++++++++++++++
 src/main/java/cc/mrbird/febs/common/enumerates/DataDictionaryEnum.java          |    2 ++
 src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java |   13 +++++++++++++
 4 files changed, 50 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 bf7c74b..a13dc86 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,8 @@
 
 @Getter
 public enum DataDictionaryEnum {
+    // 拿下一级(直推的)收入的百分之五十
+    MEMBER_RETURN_PERCENT_UP("MEMBER_RETURN_PERCENT_UP", "MEMBER_RETURN_PERCENT_UP"),
     // 上级返佣金比例,返回到余额
     MEMBER_RETURN_PERCENT("MEMBER_RETURN_PERCENT", "MEMBER_RETURN_PERCENT"),
     // 积分兑换比例  1,则1积分等于一元 2则2积分等于一元
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 831954a..1db5c81 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
@@ -366,6 +366,7 @@
          */
         //是否返利
         BigDecimal amountBigDecimal = new BigDecimal(StrUtil.isEmpty(amount) ? "0" : amount);
+        BigDecimal parentUpAmount = BigDecimal.ZERO;
         if(BigDecimal.ZERO.compareTo(amountBigDecimal) < 0){
             if(ObjectUtil.isNotEmpty(mallMember.getReferrerId())){
                 String referrerId = mallMember.getReferrerId();
@@ -393,6 +394,40 @@
                             1,
                             FlowTypeEnum.BALANCE.getValue(),
                             2);
+                    parentUpAmount = amountActual;
+                }
+
+                /**
+                 * 拿下一级(直推的)收入的百分之五十
+                 */
+                if(ObjectUtil.isNotEmpty(mallMemberParent.getReferrerId())){
+                    String referrerIdParentUp = mallMemberParent.getReferrerId();
+                    MallMember mallMemberParentUp = memberMapper.selectInfoByInviteId(referrerIdParentUp);
+                    Long idParentUp = mallMemberParentUp.getId();
+                    MallMoneyFlow mallMoneyFlowParentUp = mallMoneyFlowMapper.selectOneByOrderNoAndMemberIdAndRtMemberId(mallOrderInfo.getOrderNo()
+                            , idParentUp
+                            , id);
+                    if(ObjectUtil.isEmpty(mallMoneyFlowParentUp)){
+                        DataDictionaryCustom returnPercentUpDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                                DataDictionaryEnum.MEMBER_RETURN_PERCENT_UP.getType(),
+                                DataDictionaryEnum.MEMBER_RETURN_PERCENT_UP.getCode()
+                        );
+                        String returnPercentUpStr = StrUtil.isEmpty(returnPercentUpDic.getValue()) ? "50" : returnPercentUpDic.getValue();
+                        BigDecimal returnPercentUp = new BigDecimal(returnPercentUpStr).divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN);
+                        BigDecimal amountActualUp = parentUpAmount.multiply(returnPercentUp).setScale(2, BigDecimal.ROUND_DOWN);
+
+                        mallMoneyFlowService.addMoneyFlow(
+                                idParentUp,
+                                amountActualUp,
+                                MoneyFlowTypeEnum.DYNAMIC_ACHIEVE.getValue(),
+                                mallOrderInfo.getOrderNo(),
+                                "直推奖",
+                                "直推奖",
+                                id,
+                                1,
+                                FlowTypeEnum.BALANCE.getValue(),
+                                2);
+                    }
                 }
             }
         }
diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java
index 2c3fde2..aa7fd5e 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java
@@ -693,6 +693,19 @@
                 mallMoneyFlowMapper.updateById(mallMoneyFlow);
                 memberWalletService.add(mallMoneyFlow.getAmount(), parentId, "balance");
             }
+
+            if(ObjectUtil.isNotEmpty(mallMemberParent.getReferrerId())){
+                String referrerIdUp = mallMemberParent.getReferrerId();
+                MallMember mallMemberParentUp = memberMapper.selectInfoByInviteId(referrerIdUp);
+                Long parentIdUp = mallMemberParentUp.getId();
+                MallMoneyFlow mallMoneyFlowUp = mallMoneyFlowMapper.selectOneByOrderNoAndMemberIdAndRtMemberId(orderNo, parentIdUp, parentId);
+                if(ObjectUtil.isNotEmpty(mallMoneyFlowUp)){
+                    mallMoneyFlowUp.setStatus(2);
+                    mallMoneyFlowUp.setIsReturn(1);
+                    mallMoneyFlowMapper.updateById(mallMoneyFlowUp);
+                    memberWalletService.add(mallMoneyFlow.getAmount(), parentIdUp, "balance");
+                }
+            }
         }
         List<MallOrderItem> mallOrderItemList = mallOrderItemMapper.selectListByOrderId(orderInfo.getId());
         if(CollUtil.isNotEmpty(mallOrderItemList)){
diff --git a/src/main/java/cc/mrbird/febs/rabbit/consumer/AgentConsumer.java b/src/main/java/cc/mrbird/febs/rabbit/consumer/AgentConsumer.java
index 2c420a4..0e1edcf 100644
--- a/src/main/java/cc/mrbird/febs/rabbit/consumer/AgentConsumer.java
+++ b/src/main/java/cc/mrbird/febs/rabbit/consumer/AgentConsumer.java
@@ -4,7 +4,6 @@
 import cc.mrbird.febs.mall.service.IApiMallOrderInfoService;
 import cc.mrbird.febs.mall.service.IMemberProfitService;
 import cc.mrbird.febs.rabbit.constants.QueueConstants;
-import cc.mrbird.febs.rabbit.enumerates.RabbitQueueEnum;
 import com.rabbitmq.client.Channel;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.amqp.core.Message;

--
Gitblit v1.9.1