From f012423a2fac597b215a89c82f2fb627895580b5 Mon Sep 17 00:00:00 2001
From: KKSU <15274802129@163.com>
Date: Mon, 20 May 2024 17:59:29 +0800
Subject: [PATCH] 会员等级升级

---
 src/main/java/cc/mrbird/febs/common/enumerates/MemberLevelNewEnum.java |    3 +
 src/main/java/cc/mrbird/febs/mall/service/impl/AgentServiceImpl.java   |   57 ++++++++--------------------
 src/main/java/cc/mrbird/febs/mall/mapper/MallMemberMapper.java         |    2 +
 src/main/resources/mapper/modules/MallMemberMapper.xml                 |    6 +++
 4 files changed, 27 insertions(+), 41 deletions(-)

diff --git a/src/main/java/cc/mrbird/febs/common/enumerates/MemberLevelNewEnum.java b/src/main/java/cc/mrbird/febs/common/enumerates/MemberLevelNewEnum.java
index 9aa1a22..07aeb2f 100644
--- a/src/main/java/cc/mrbird/febs/common/enumerates/MemberLevelNewEnum.java
+++ b/src/main/java/cc/mrbird/febs/common/enumerates/MemberLevelNewEnum.java
@@ -8,7 +8,8 @@
 @Getter
 public enum MemberLevelNewEnum {
 //    SEVEN_LEVEL("SEVEN_LEVEL",6),
-//    SIX_LEVEL("SIX_LEVEL",5),
+//    SIX_LEVEL("SIX_LEVEL",6),
+    SIX_LEVEL("SIX_LEVEL",6,"六星"),
     WU_LEVEL("WU_LEVEL",5,"五星"),
     SI_LEVEL("SI_LEVEL",4,"四星"),
     SAN_LEVEL("SAN_LEVEL",3,"三星"),
diff --git a/src/main/java/cc/mrbird/febs/mall/mapper/MallMemberMapper.java b/src/main/java/cc/mrbird/febs/mall/mapper/MallMemberMapper.java
index ca5d84c..6fadd78 100644
--- a/src/main/java/cc/mrbird/febs/mall/mapper/MallMemberMapper.java
+++ b/src/main/java/cc/mrbird/febs/mall/mapper/MallMemberMapper.java
@@ -93,6 +93,8 @@
 
     List<MallMember> selectMemberWithLevel(String level);
 
+    List<MallMember> selectMemberWithLevelAndMemberId(@Param("level")String level,@Param("memberId")Long memberId);
+
     List<Long> selectMemberIdWithLevel(String levelParam);
 
     List<MallMember> selectAllChildAgentListByInviteIdAndStoreMaster(@Param("inviteId")String inviteId,@Param("state")Integer state);
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 03d340b..2665cb0 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
@@ -60,6 +60,7 @@
     private final MallProductNftMapper mallProductNftMapper;
     private final AgentProducer agentProducer;
     private final MallMemberAmountMapper mallMemberAmountMapper;
+    private final IMemberProfitService iMemberProfitService;
 
     @Override
     @Transactional(rollbackFor = Exception.class)
@@ -1176,40 +1177,15 @@
                                         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);
+
                                 BigDecimal basicPerkDirect = nftTotal.multiply(basicPerkDirectPercent).setScale(2, BigDecimal.ROUND_DOWN);
-
-                                if(ProductEnum.MEMBER_FROZEN.getValue() == directMember.getIsFrozen()){
-                                    //插入一条流水记录
-                                    String orderNo = MallUtils.getOrderNum("FNFTW");
-                                    mallMoneyFlowService.addMoneyFlow(
-                                            directMember.getId(),
-                                            profit.negate(),
-                                            MoneyFlowTypeNewEnum.BASIC_PERK_DIRECT_WRONG.getValue(),
-                                            orderNo,
-                                            null,
-                                            FlowTypeNewEnum.NFT.getValue(),
-                                            MoneyFlowTypeNewEnum.BASIC_PERK_DIRECT_WRONG.getDescrition(),
-                                            AppContants.MEMBER_FLOW_ING);
-
-                                }else{
-                                    /**
-                                     * 先插入流水记录,然后定时器每小时,循环一次找寻对应的数据执行
-                                     */
-                                    String orderNo = MallUtils.getOrderNum("DNFT");
-                                    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);
+                                /**
+                                 * 如果用户是冻结,则直接销毁
+                                 */
+                                iMemberProfitService.createPerk(directMember,basicPerkDirect.multiply(new BigDecimal("0.5")));
+                                if(StrUtil.isNotEmpty(directMember.getReferrerId())){
+                                    MallMember directMemberDirect = memberMapper.selectInfoByInviteId(directMember.getReferrerId());
+                                    iMemberProfitService.createPerk(directMemberDirect,basicPerkDirect.multiply(new BigDecimal("0.5")));
                                 }
                             }
                         }
@@ -1937,10 +1913,10 @@
             if(ObjectUtil.isEmpty(mallMemberRef)){
                 continue;
             }
-            List<MallMember> mallMembersAll = memberMapper.selectAllChildAgentListByInviteId(referrerId);
-            if(ObjectUtil.isEmpty(mallMembersAll)){
-                continue;
-            }
+//            List<MallMember> mallMembersAll = memberMapper.selectAllChildAgentListByInviteId(referrerId);
+//            if(ObjectUtil.isEmpty(mallMembersAll)){
+//                continue;
+//            }
             List<MallMember> mallMembers = memberMapper.selectByRefererId(referrerId);
             Set<Long> mallMembersSet = mallMembers.stream().map(MallMember::getId).collect(Collectors.toSet());
             mallMembersSet.retainAll(collect);
@@ -1966,14 +1942,15 @@
                 Integer directCntLevel = teamPerkDto.getDirectCnt();
                 Integer teamCnt = teamPerkDto.getTeamCnt();
                 if(directCntLevel <= intersection.size()){
-                    if(teamCnt <= mallMembersAll.size()){
+                    List<MallMember> mallMembersAll = memberMapper.selectMemberWithLevelAndMemberId(level,mallMemberRef.getId());
+                    if(teamCnt <= (CollUtil.isEmpty(mallMembersAll) ? 0 : mallMembersAll.size())){
                         mallMemberRef.setLevel(level);
                         memberMapper.updateById(mallMemberRef);
 
                         String nextLevel = MemberLevelNewEnum.ZERO_LEVEL.getNextLevel(level);
                         level = nextLevel;
-                        if(level.equals(MemberLevelNewEnum.WU_LEVEL.getType()) &&
-                                nextLevel.equals(MemberLevelNewEnum.WU_LEVEL.getType()) ){
+                        if(level.equals(MemberLevelNewEnum.SIX_LEVEL.getType()) &&
+                                nextLevel.equals(MemberLevelNewEnum.SIX_LEVEL.getType()) ){
                             mallMemberRef.setLevel(level);
                             memberMapper.updateById(mallMemberRef);
                             flag = true;
diff --git a/src/main/resources/mapper/modules/MallMemberMapper.xml b/src/main/resources/mapper/modules/MallMemberMapper.xml
index 185854c..d1acebd 100644
--- a/src/main/resources/mapper/modules/MallMemberMapper.xml
+++ b/src/main/resources/mapper/modules/MallMemberMapper.xml
@@ -466,6 +466,12 @@
         where level=#{level}
     </select>
 
+    <select id="selectMemberWithLevelAndMemberId" resultType="cc.mrbird.febs.mall.entity.MallMember">
+        select * from mall_member
+        where level=#{level}
+        and id = #{memberId}
+    </select>
+
     <select id="selectMemberIdWithLevel" resultType="java.lang.Long">
         select id from mall_member
         where level = #{level}

--
Gitblit v1.9.1