Jelajahi Sumber

首次提交

Yangzw 2 bulan lalu
induk
melakukan
c30fd785ba

+ 12 - 21
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/sharepath/vo/SharePathPageReqVO.java

@@ -22,31 +22,22 @@ public class SharePathPageReqVO extends PageParam {
     @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
     private LocalDateTime[] createTime;
 
-    @Schema(description = "推荐人")
-    private Long ancestor;
+    @Schema(description = "用户id")
+    private Long userId;
 
-    @Schema(description = "直推人")
-    private Long descendant;
+    @Schema(description = "用户名")
+    private String userName;
 
-    @Schema(description = "顺序")
-    private Integer sort;
+    @Schema(description = "用户电话")
+    private String phone;
 
+    @Schema(description = "上级用户id")
+    private Long parentId;
 
-    @Schema(description = "推荐人姓名", example = "王五")
-    private String ancName;
+    @Schema(description = "分区用户id")
+    private Long areaId;
 
-    @Schema(description = "推荐人手机号")
-    private String ancPhone;
-
-    @Schema(description = "直推人姓名", example = "李四")
-    private String descName;
-
-    @Schema(description = "推荐人手机号")
-    private String descPhone;
-
-    @Schema(description = "直推人昵称", example = "张三")
-    private String descNickName;
-    @Schema(description = "推荐人昵称", example = "非繁人")
-    private String ancNickName;
+    @Schema(description = "推荐人id")
+    private Long referrerId;
 
 }

+ 31 - 36
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/sharepath/vo/SharePathRespVO.java

@@ -10,55 +10,50 @@ import com.alibaba.excel.annotation.*;
 @ExcelIgnoreUnannotated
 public class SharePathRespVO {
 
-    @Schema(description = "层级")
-    @ExcelProperty("层级")
-    private Integer depth;
-
     @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
     @ExcelProperty("创建时间")
     private LocalDateTime createTime;
 
-    @Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "12537")
-    @ExcelProperty("id")
-    private Long id;
+    @Schema(description = "头像")
+    private String avatar;
 
-    @Schema(description = "推荐人")
-    @ExcelProperty("推荐人")
-    private Long ancestor;
+    @Schema(description = "身价等级")
+    private String socialStatusLevel;
 
-    @Schema(description = "直推人")
-    @ExcelProperty("直推人")
-    private Long descendant;
+    @Schema(description = "身价等级名称")
+    private String socialStatusLevelName;
 
-    @Schema(description = "顺序")
-    @ExcelProperty("顺序")
-    private Integer sort;
+    @Schema(description = "后代人数")
+    private Long descendantsCount;
 
+    @Schema(description = "最高可获取积分(峰值 / 最大值)")
+    private Long high_quota;
 
-    @Schema(description = "推荐人姓名", example = "王五")
-    @ExcelProperty("推荐人姓名")
-    private String ancName;
+    //    @Schema(description = "剩余的合赢奖额度 + 待确权直推奖")
+    @Schema(description = "分区额度")
+    private Long residueSocial;
 
-    @Schema(description = "推荐人手机号")
-    @ExcelProperty("推荐人手机号")
-    private String ancPhone;
+    @Schema(description = "用户名")
+    private String userName;
 
-    @Schema(description = "直推人姓名", example = "李四")
-    @ExcelProperty("直推人姓名")
-    private String descName;
+    @Schema(description = "层级")
+    private Integer depth;
 
-    @Schema(description = "推荐人手机号")
-    @ExcelProperty("推荐人手机号")
-    private String descPhone;
+    @Schema(description = "用户id")
+    private Long userId;
 
-    @Schema(description = "推荐人昵称", example = "非繁人")
-    @ExcelProperty("推荐人昵称")
-    private String ancNickName;
+    @Schema(description = "用户电话")
+    private String phone;
 
-    @Schema(description = "直推人昵称", example = "张三")
-    @ExcelProperty("直推人昵称")
-    private String descNickName;
+    @Schema(description = "上级用户id")
+    private Long parentId;
 
-    @Schema(description = "用户头像")
-    private String avatar;
+    @Schema(description = "左区用户id")
+    private Long leftChildId;
+
+    @Schema(description = "右区用户id")
+    private Long rightChildId;
+
+    @Schema(description = "推荐人id")
+    private Long referrerId;
 }

+ 14 - 22
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/sharepath/vo/SharePathSaveReqVO.java

@@ -19,32 +19,24 @@ public class SharePathSaveReqVO {
     @Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "12537")
     private Long id;
 
-    @Schema(description = "推荐人")
-    private Long ancestor;
+    @Schema(description = "用户id")
+    private Long userId;
 
-    @Schema(description = "直推人")
-    private Long descendant;
+    @Schema(description = "用户名")
+    private String userName;
 
-    @Schema(description = "顺序")
-    private Integer sort;
+    @Schema(description = "用户电话")
+    private String phone;
 
-    @Schema(description = "链接来源")
-    private Long source;
+    @Schema(description = "上级用户id")
+    private Long parentId;
 
+    @Schema(description = "左区用户id")
+    private Long leftChildId;
 
-    @Schema(description = "推荐人姓名", example = "王五")
-    private String ancName;
+    @Schema(description = "右区用户id")
+    private Long rightChildId;
 
-    @Schema(description = "推荐人手机号")
-    private String ancPhone;
-
-    @Schema(description = "直推人姓名", example = "李四")
-    private String descName;
-
-    @Schema(description = "推荐人手机号")
-    private String descPhone;
-    @Schema(description = "推荐人昵称", example = "非繁人")
-    private String ancNickName;
-    @Schema(description = "直推人昵称", example = "张三")
-    private String descNickName;
+    @Schema(description = "推荐人id")
+    private Long referrerId;
 }

+ 5 - 13
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/sharepath/vo/TreeNode.java

@@ -13,20 +13,12 @@ import java.util.List;
 @AllArgsConstructor
 public class TreeNode {
     private Long userId;
-    private String name; // 节点名称
-    private String nickname;
+    private String userName; // 节点名称
     private String phone;
-    private Integer deep;
-    private Integer value; // 节点值,某些节点可能没有值
+    private Integer depth;
     private Long parentId; // 父亲Id
-    private Boolean hasSon;
-    private Integer sort;
+    private Long referrerId;    //推荐人id
+    private Long leftChildId;
+    private Long rightChildId;
     private List<TreeNode> children; // 子节点列表
-
-    public Boolean getHasSon() {
-        if (children == null) {
-            return false;
-        }
-        return !children.isEmpty();
-    }
 }

+ 29 - 14
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/sharepath/SharePathService.java

@@ -10,7 +10,6 @@ import cn.newfeifan.mall.module.distri.dal.dataobject.sharepath.SharePathDO;
 import cn.newfeifan.mall.framework.common.pojo.PageResult;
 import cn.newfeifan.mall.module.member.controller.admin.user.vo.MemberUserRespVO;
 import cn.newfeifan.mall.module.member.controller.admin.user.vo.MemberUserUpdateReqVO;
-import cn.newfeifan.mall.module.member.dal.dataobject.user.MemberUserDO;
 
 /**
  * 分销用户关系 Service 接口
@@ -75,22 +74,13 @@ public interface SharePathService {
 
 
     /**
-     * 获取儿子订单计算分区
+     * 获取分区订单计算分区
      *
      * @param userId 用户id
      * @return 订单计算
      */
-    List<OrderCalcDO> selectSons(Long userId, List<Long> userIds);
+    List<OrderCalcDO> selectArea(Long userId, List<Long> userIds);
 
-    /**
-     * 获取兄弟订单分区
-     *
-     * @param userId  用户id
-     * @param userId1 ids
-     * @param user 用户
-     * @return 订单计算
-     */
-    List<OrderCalcDO> selectBrothers(Long userId, List<Long> userId1, MemberUserDO user);
 
     Long queryParentBySonUserId(Long userId);
 
@@ -102,8 +92,6 @@ public interface SharePathService {
     PageResult<SharePathRespVO> getDescendants(SharePathPageReqVO pageReqVO);
     TreeNode getTree(Long userId,  Integer maxDepth);
 
-    TreeNode getTreeByNameOrMobile(SharePathTreeReqVO sharePathTreeReqVO);
-
     MemberUserRespVO getMemberUser(Long userId);
 
     /**
@@ -112,4 +100,31 @@ public interface SharePathService {
      * @param updateReqVO 更新信息
      */
     void updateUser(MemberUserUpdateReqVO updateReqVO);
+
+    /**
+     * 获得区域人员列表
+     * @param pageReqVO 分页查询
+     * @return 列表
+     */
+    PageResult<SharePathRespVO> getAreaChildren(@Valid SharePathPageReqVO pageReqVO);
+
+    /**
+     * 获取所有用户的关系网
+     */
+    List<SharePathDO> selectList();
+
+    /**
+     * 获取推荐人数
+     * @param userId 用户id
+     * @return 人数
+     */
+    Integer getReferrerNumber(Long userId);
+
+    /**
+     * 获取用户团队下的所有id
+     * @param userId 用户id
+     * @param maxDepth 层级
+     * @return ids
+     */
+    List<Long> getUserIds(Long userId, Integer maxDepth);
 }

+ 187 - 218
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/sharepath/SharePathServiceImpl.java

@@ -1,6 +1,7 @@
 package cn.newfeifan.mall.module.distri.service.sharepath;
 
 import cn.newfeifan.mall.framework.mybatis.core.query.LambdaQueryWrapperX;
+import cn.newfeifan.mall.module.distri.controller.admin.duser.vo.DuserSaveReqVO;
 import cn.newfeifan.mall.module.distri.dal.dataobject.duser.DuserDO;
 import cn.newfeifan.mall.module.distri.dal.dataobject.integral.IntegralDO;
 import cn.newfeifan.mall.module.distri.dal.dataobject.ordercalc.OrderCalcDO;
@@ -19,8 +20,8 @@ import cn.newfeifan.mall.module.member.controller.admin.user.vo.MemberUserUpdate
 import cn.newfeifan.mall.module.member.convert.user.MemberUserConvert;
 import cn.newfeifan.mall.module.member.dal.dataobject.user.MemberUserDO;
 import cn.newfeifan.mall.module.member.service.user.MemberUserService;
-import com.alibaba.druid.util.StringUtils;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 
@@ -66,6 +67,7 @@ public class SharePathServiceImpl implements SharePathService {
     @Resource
     private MemberUserService memberUserService;
     @Resource
+    @Lazy
     private OrderCalcService orderCalcService;
 
     @Resource
@@ -87,36 +89,36 @@ public class SharePathServiceImpl implements SharePathService {
     public void createSharePathByUserId(SharePathSaveReqVO createReqVO, Boolean isNew) {
 
         // 如果直推人为空, 则直接结束
-        if (createReqVO.getDescendant() == null) {
+        if (createReqVO.getUserId() == null) {
             return;
         }
 
         // 判断当前直推人是否有父亲
-        Boolean has = hasParent(createReqVO.getDescendant());
+        Boolean has = hasParent(createReqVO.getUserId());
         if (has) {
             throw exception(HAS_PARENT);
         }
-        if (createReqVO.getAncestor() == null) {
-            createReqVO.setAncestor(BOOS_ID);
+        if (createReqVO.getReferrerId() == null) {
+            createReqVO.setReferrerId(BOOS_ID);
         }
-        MemberUserDO ancestor = memberUserService.getUser(createReqVO.getAncestor());
-        MemberUserDO descendant = memberUserService.getUser(createReqVO.getDescendant());
+        MemberUserDO ancestor = memberUserService.getUser(createReqVO.getReferrerId());
+        MemberUserDO descendant = memberUserService.getUser(createReqVO.getUserId());
 
         // 创建直推人以及推荐人的关系
         // 需要判断当前推荐人跟直推人是否已经存在于用户表(duser)了
         duserService.hasUserAndCreat(createReqVO);
 
         // 存储他们之间的关系
-        if (!Objects.equals(createReqVO.getDescendant(), PT_ID)) {
+        if (!Objects.equals(createReqVO.getUserId(), PT_ID)) {
             sharePathMapper.addNode(
-                    createReqVO.getAncestor(),
+                    createReqVO.getReferrerId(),
                     ancestor.getUsername(),
-                    ancestor.getNickname(),
+                    null,
                     ancestor.getMobile(),
 
-                    createReqVO.getDescendant(),
+                    createReqVO.getUserId(),
                     descendant.getUsername(),
-                    descendant.getNickname(),
+                    null,
                     descendant.getMobile());
         }
 
@@ -124,8 +126,8 @@ public class SharePathServiceImpl implements SharePathService {
             return;
         }
         OrderPercentageDO orderPercentageDO = orderPercentageMapper.selectList().get(0);
-        duserService.updateDuserSocial(createReqVO.getAncestor(), Long.valueOf(orderPercentageDO.getRegisterAncestorSocialStatus()), SocialStatusEnum.REGISTER_ANCESTOR_SOCIAL.getStatus());
-        socialStatusChangeLogService.createSocialStatusChangeLog(createReqVO.getAncestor(), Long.valueOf(orderPercentageDO.getRegisterAncestorSocialStatus()), createReqVO.getAncestor(), SocialStatusEnum.REGISTER_ANCESTOR_SOCIAL);
+        duserService.updateDuserSocial(createReqVO.getReferrerId(), Long.valueOf(orderPercentageDO.getRegisterAncestorSocialStatus()), SocialStatusEnum.REGISTER_ANCESTOR_SOCIAL.getStatus());
+        socialStatusChangeLogService.createSocialStatusChangeLog(createReqVO.getReferrerId(), Long.valueOf(orderPercentageDO.getRegisterAncestorSocialStatus()), createReqVO.getReferrerId(), SocialStatusEnum.REGISTER_ANCESTOR_SOCIAL);
 
     }
 
@@ -139,8 +141,8 @@ public class SharePathServiceImpl implements SharePathService {
             }
             // 如果是没有父亲, 将其推荐人设置为平台
             SharePathSaveReqVO build = SharePathSaveReqVO.builder()
-                    .ancestor(BOOS_ID)
-                    .descendant(userId)
+                    .referrerId(BOOS_ID)
+                    .userId(userId)
                     .build();
             createSharePathByUserId(build, true);
         }
@@ -148,8 +150,7 @@ public class SharePathServiceImpl implements SharePathService {
 
     private Boolean hasParent(Long descendant) {
         List<SharePathDO> sharePathDO = sharePathMapper.selectList(new LambdaQueryWrapperX<SharePathDO>()
-                .eqIfPresent(SharePathDO::getDescendant, descendant)
-                .eqIfPresent(SharePathDO::getDepth, 1));
+                .eqIfPresent(SharePathDO::getUserId, descendant));
         return !sharePathDO.isEmpty();
     }
 
@@ -193,43 +194,20 @@ public class SharePathServiceImpl implements SharePathService {
         if (userId == null) {
             userId = PT_ID;
         }
-        DuserDO sharePathDO = duserService.getDuserByUser(userId);
-        // 查询层级范围
-        List<SharePathDO> sharePathDOS = sharePathMapper.selectList(new LambdaQueryWrapperX<SharePathDO>().eq(SharePathDO::getAncestor, userId)
-                .between(SharePathDO::getDepth, 1, maxDepth));
-
-        List<TreeNode> deep = sharePathDO2TreeNode(sharePathDOS);
-        if (maxDepth > 1) {
-            List<Long> descs = sharePathDOS.stream().filter(k -> k.getDepth() > 1).map(SharePathDO::getDescendant).collect(Collectors.toList());
-            // 获取大于1层级的数据
-            if (!descs.isEmpty()) {
-                List<SharePathDO> descList = sharePathMapper.selectList(new LambdaQueryWrapperX<SharePathDO>().ne(SharePathDO::getAncestor, 1).in(SharePathDO::getDescendant, descs));
-                List<TreeNode> treeNodes1 = sharePathDO2TreeNode(descList);
-//                deep = deep.stream().filter(k -> k.getDeep() == 1).collect(Collectors.toList());
-                deep.addAll(treeNodes1);
-            }
-        }
-        // 只需要深度等于1的数据
-        deep = deep.stream().filter(k -> k.getDeep() == 1).collect(Collectors.toList());
-
-        // 整合结构
-        List<TreeNode> treeNodes = listWithTree(deep, userId);
-
-        return TreeNode.builder()
-                .phone(sharePathDO.getMobile())
-                .name(sharePathDO.getName())
-                .nickname(sharePathDO.getNickName())
-                .children(treeNodes).build();
-    }
-
-    @Override
-    public TreeNode getTreeByNameOrMobile(SharePathTreeReqVO sharePathTreeReqVO) {
-        //拿到当前用户ID
-        Long userId = getUserIdByNameOrMobile(sharePathTreeReqVO.getNickName(), sharePathTreeReqVO.getMobile());
-
-        //拿到推荐人ID
-        Long ancestor = sharePathMapper.selectAncestorByDescendant(userId);
-        return getTree(ancestor, sharePathTreeReqVO.getMaxDepth());
+        // 查询出第一层用户
+        List<SharePathDO> sharePathDOS = sharePathMapper.selectListByUserId(userId, maxDepth);
+        final Long userid = userId;
+        SharePathDO sharePathDO = sharePathDOS.stream()
+                .filter(k -> k.getUserId().equals(userid))
+                .findFirst().get();
+
+        // 转换后的对象
+        List<TreeNode> treeNodes = sharePathDO2TreeNode(sharePathDOS);
+        treeNodes = listWithTree(treeNodes, userId);
+
+        TreeNode bean = BeanUtils.toBean(sharePathDO, TreeNode.class);
+        bean.setChildren(treeNodes);
+        return bean;
     }
 
     @Override
@@ -238,24 +216,29 @@ public class SharePathServiceImpl implements SharePathService {
         MemberUserRespVO memberUserRespVO = MemberUserConvert.INSTANCE.convert03(user);
 
         SharePathDO sharePathDO = sharePathMapper.selectOne(new LambdaQueryWrapper<SharePathDO>()
-                .eq(SharePathDO::getDescendant, userId)
-                .eq(SharePathDO::getDepth, 1)
+                .eq(SharePathDO::getUserId, userId)
         );
         if (sharePathDO != null) {
-            memberUserRespVO.setAncNickName(sharePathDO.getAncNickName());
-            memberUserRespVO.setRecommenderdId(sharePathDO.getAncestor());
+            SharePathDO referrer = sharePathMapper.selectOne(new LambdaQueryWrapper<SharePathDO>()
+                    .eq(SharePathDO::getUserId, sharePathDO.getReferrerId())
+            );
+            if (referrer != null) {
+                memberUserRespVO.setAncNickName(referrer.getUserName());
+                memberUserRespVO.setRecommenderdId(referrer.getUserId());
+            }
         }
 
         DuserDO duser = duserService.getDuserByUser(memberUserRespVO.getId());
         //没有这个用户直接就返回
         if (duser == null) return memberUserRespVO;
+        memberUserRespVO.setCategoryId(duser.getCategoryId());
 
         IntegralDO integral = integralService.getIntegralByUserId(userId);
         if (integral != null) {
-            memberUserRespVO.setCurrentQuota(integral.getCurrentQuota());
-            OrderPercentageDO orderPercentageDO = orderPercentageService.queryStatus();
-            memberUserRespVO.setHighQuotaTotal(integral.getHighQuotaTotal() + new BigDecimal(orderPercentageDO.getBaseMaxQuota()).longValue());
-            memberUserRespVO.setConsumptionPoints(integral.getConsumptionPoints());
+            memberUserRespVO.setRedCurrentQuota(integral.getRedCurrentQuota());
+            memberUserRespVO.setYellowCurrentQuota(integral.getYellowCurrentQuota());
+            memberUserRespVO.setGreenCurrentQuota(integral.getGreenCurrentQuota());
+            memberUserRespVO.setHighQuotaTotal(integral.getHighQuotaTotal());
         }
 
         SocialStatusDO socialStatus = socialStatusService.getSocialStatus(duser.getSocialStatusId());
@@ -272,77 +255,151 @@ public class SharePathServiceImpl implements SharePathService {
         // 判断当前用户是否更新推荐人
         Long ancestor = sharePathMapper.selectAncestorByDescendant(updateReqVO.getId());
         if (!Objects.equals(updateReqVO.getRecommenderdId(), ancestor)) {
-            // 如果用户为游客,将清除游客标识
-            updateReqVO.setVisitor(false);
-
-            // 如果有更新的话,要清除原来的关系树
-            List<SharePathDO> sharePathDOS = sharePathMapper.selectList(new LambdaQueryWrapper<SharePathDO>()
-                    .eq(SharePathDO::getAncestor, updateReqVO.getId()));
-            List<SharePathDO> sharePathDOS1;
-            List<SharePathDO> children = null;
-            if (!sharePathDOS.isEmpty()) {
-                sharePathDOS1 = sharePathMapper.selectList(new LambdaQueryWrapper<SharePathDO>()
-                        .in(SharePathDO::getDescendant, sharePathDOS.stream().map(SharePathDO::getDescendant).collect(Collectors.toList())));
-                children = sharePathMapper.selectList(new LambdaQueryWrapper<SharePathDO>()
-                        .in(SharePathDO::getDescendant, sharePathDOS.stream().map(SharePathDO::getDescendant).collect(Collectors.toList()))
-                        .eq(SharePathDO::getDepth, 1));
-                // 逻辑删除旧的关系树
-                sharePathMapper.deleteBatchIds(sharePathDOS1.stream().map(SharePathDO::getId).collect(Collectors.toList()));
-            }
-            sharePathMapper.delete(new LambdaQueryWrapper<SharePathDO>()
-                    .eq(SharePathDO::getDescendant, updateReqVO.getId()));
-
-            // 添加新的关系树
-            createSharePathByUserId(SharePathSaveReqVO.builder().ancestor(updateReqVO.getRecommenderdId()).descendant(updateReqVO.getId()).build(), false);
-
-            if (children != null && !children.isEmpty()) for (SharePathDO child : children) {
-                createSharePathByUserId(SharePathSaveReqVO.builder().ancestor(child.getAncestor()).descendant(child.getDescendant()).build(), false);
-            }
+            updateUserSharePath(updateReqVO.getId(), updateReqVO.getRecommenderdId());
+        }
 
+        DuserDO duser = duserService.getDuserByUser(updateReqVO.getId());
+        if (!Objects.equals(duser.getCategoryId(), updateReqVO.getCategoryId())) {
+            duser.setCategoryId(updateReqVO.getCategoryId());
+            duserService.updateDuser(BeanUtils.toBean(duser, DuserSaveReqVO.class));
         }
 
         // 更新
         memberUserService.updateUser(updateReqVO);
     }
 
-    private void createSharePath(List<TreeNode> children) {
-        for (TreeNode child : children) {
-            createSharePathByUserId(SharePathSaveReqVO.builder().ancestor(child.getParentId()).descendant(child.getUserId()).build(), false);
-            if (child.getChildren() != null) {
-                createSharePath(child.getChildren());
-            }
-        }
+    @Override
+    public PageResult<SharePathRespVO> getAreaChildren(SharePathPageReqVO pageReqVO) {
+
+        PageResult<SharePathDO> sharePathDOPageResult = new PageResult<>();
+        List<SharePathDO> sharePathDOS = sharePathMapper.selectListPage(pageReqVO.getAreaId(), pageReqVO.getPageSize(), (pageReqVO.getPageNo() - 1) * pageReqVO.getPageSize());
+        List<SharePathDO> totals = sharePathMapper.selectListByUserId(pageReqVO.getAreaId(), 99999);
+
+        sharePathDOPageResult.setList(sharePathDOS);
+        sharePathDOPageResult.setTotal(totals == null ? 0L : totals.size());
+        PageResult<SharePathRespVO> result = BeanUtils.toBean(sharePathDOPageResult, SharePathRespVO.class);
+        List<SharePathRespVO> list = result.getList();
+        list.forEach(sharePath -> sharePath.setAvatar(memberUserService.getUser(sharePath.getUserId()).getAvatar()));
+
+        return result;
     }
 
-    private Long getUserIdByNameOrMobile(String name, String mobile) {
-        if (!StringUtils.isEmpty(name)) {
-            List<DuserDO> duserDOS = duserService.getDuserByName(name);
-            if (duserDOS.isEmpty()) {
-                throw exception(DUSER_NAME_NOT_EXISTS);
-            } else if (duserDOS.size() > 1) {
-                throw exception(DUSER_NAME_IS_NOT_ONLY_ONE);
-            }
+    @Override
+    public List<SharePathDO> selectList() {
+        // 不算平台的
+        return sharePathMapper.selectList(new LambdaQueryWrapper<SharePathDO>().ne(SharePathDO::getUserId, 1L));
+    }
 
-            return duserDOS.get(0).getUserId();
+    @Override
+    public Integer getReferrerNumber(Long userId) {
+        return sharePathMapper.selectCount(new LambdaQueryWrapper<SharePathDO>().eq(SharePathDO::getReferrerId, userId)).intValue();
+    }
+
+    @Override
+    public List<Long> getUserIds(Long userId, Integer maxDepth) {
+        List<SharePathDO> sharePathDOS = sharePathMapper.selectListByUserId(userId, maxDepth);
+        List<Long> collect = sharePathDOS.stream().map(SharePathDO::getUserId).collect(Collectors.toList());
+        collect.remove(0);
+        return collect;
+    }
+
+    /**
+     * 更新用户关系网
+     * @param userId 用户id
+     * @param referrerId 推荐人id
+     */
+    private void updateUserSharePath(Long userId, Long referrerId) {
+        // 获取当前用户的关系网
+        SharePathDO user = sharePathMapper.selectOne(new LambdaQueryWrapper<SharePathDO>()
+                .eq(SharePathDO::getUserId, userId));
+        // 获取上级的关系网
+        SharePathDO parent = sharePathMapper.selectOne(new LambdaQueryWrapper<SharePathDO>()
+                .eq(SharePathDO::getUserId, user.getParentId()));
+
+        // 去除上级用户的分区值
+        if (parent.getLeftChildId() != null && parent.getLeftChildId().equals(user.getUserId())) {
+            parent.setLeftChildId(null);
         } else {
-            DuserDO duserDO = duserService.getDuserByMobile(mobile);
-            if (duserDO == null) {
-                throw exception(DUSER_MOBILE_NOT_EXISTS);
+            parent.setRightChildId(null);
+        }
+        LambdaUpdateWrapper<SharePathDO> wrapper = new LambdaUpdateWrapper<SharePathDO>().eq(SharePathDO::getUserId, parent.getUserId());
+        if (parent.getLeftChildId() == null) {
+            wrapper.set(SharePathDO::getLeftChildId, null);
+        }
+        if (parent.getRightChildId() == null) {
+            wrapper.set(SharePathDO::getRightChildId, null);
+        }
+        sharePathMapper.update(parent, wrapper);
+
+        // 获取推荐人的关系网
+        SharePathDO referrer = sharePathMapper.selectOne(new LambdaQueryWrapper<SharePathDO>()
+                .eq(SharePathDO::getUserId, referrerId));
+
+        // 记录原来的层级
+        Integer depth = user.getDepth();
+        user.setReferrerId(referrerId);
+        user.setDepth(referrer.getDepth() + 1);
+        user.setParentId(referrerId);
+
+        if (referrer.getLeftChildId() == null) {
+            referrer.setLeftChildId(userId);
+            sharePathMapper.update(referrer, new LambdaQueryWrapperX<SharePathDO>().eq(SharePathDO::getUserId, referrer.getUserId()));
+        } else if (referrer.getRightChildId() == null) {    // 判断右区是否有空位
+            referrer.setRightChildId(userId);
+            sharePathMapper.update(referrer, new LambdaQueryWrapperX<SharePathDO>().eq(SharePathDO::getUserId, referrer.getUserId()));
+        } else {
+            // 左区列表
+            List<SharePathDO> leftArea = sharePathMapper.selectListByUserId(referrer.getLeftChildId(), 99999);
+            // 右区列表
+            List<SharePathDO> rightArea = sharePathMapper.selectListByUserId(referrer.getRightChildId(), 99999);
+
+            // 判断左右两区的节点数
+            List<SharePathDO> list = leftArea.size() <= rightArea.size() ? leftArea : rightArea;
+            for (SharePathDO sharePathDO : list) {
+                if (sharePathDO.getLeftChildId() == null) {
+                    user.setDepth(sharePathDO.getDepth() + 1);
+                    user.setParentId(sharePathDO.getUserId());
+
+                    sharePathDO.setLeftChildId(userId);
+                    sharePathMapper.update(sharePathDO, new LambdaQueryWrapperX<SharePathDO>().eq(SharePathDO::getUserId, sharePathDO.getUserId()));
+                    break;
+                } else if (sharePathDO.getRightChildId() == null) {
+                    user.setDepth(sharePathDO.getDepth() + 1);
+                    user.setParentId(sharePathDO.getUserId());
+
+                    sharePathDO.setRightChildId(userId);
+                    sharePathMapper.update(sharePathDO, new LambdaQueryWrapperX<SharePathDO>().eq(SharePathDO::getUserId, sharePathDO.getUserId()));
+                    break;
+                }
             }
-            return duserDO.getUserId();
+            sharePathMapper.updateById(user);
         }
-    }
 
+        // 用户的关系网
+        List<SharePathDO> userArea = sharePathMapper.selectListByUserId(userId, 99999);
+        depth -= user.getDepth();
+
+        // 遍历修改层级
+        for (SharePathDO sharePathDO : userArea) {
+            if (sharePathDO.getUserId().equals(userId)) {
+                continue;
+            }
+
+            sharePathDO.setDepth(sharePathDO.getDepth() - depth);
+        }
+        sharePathMapper.updateBatch(userArea);
+    }
 
     public List<TreeNode> sharePathDO2TreeNode(List<SharePathDO> sharePathDOS) {
         return sharePathDOS.stream().map(k -> TreeNode.builder()
-                .phone(k.getDescPhone())
-                .name(k.getDescName())
-                .deep(k.getDepth())
-                .parentId(k.getAncestor())
-                .userId(k.getDescendant())
-                .sort(k.getSort())
-                .nickname(k.getDescNickName()).build()).collect(Collectors.toList());
+                .phone(k.getPhone())
+                .userName(k.getUserName())
+                .depth(k.getDepth())
+                .parentId(k.getParentId())
+                .userId(k.getUserId())
+                .referrerId(k.getReferrerId())
+                .leftChildId(k.getLeftChildId())
+                .rightChildId(k.getRightChildId()).build()).collect(Collectors.toList());
     }
 
 
@@ -372,21 +429,13 @@ public class SharePathServiceImpl implements SharePathService {
 
     @Override
     public SharePathDO getSharePathByDescendant(Long userId) {
-
-        List<SharePathDO> sharePathDOS = sharePathMapper.selectList(new LambdaQueryWrapperX<SharePathDO>().eqIfPresent(SharePathDO::getDescendant, userId)
-                .eqIfPresent(SharePathDO::getDepth, 1));
-        if (sharePathDOS.isEmpty()) {
-            return null;
-        }
-        return sharePathDOS.get(0);
+        return sharePathMapper.selectOne(new LambdaQueryWrapperX<SharePathDO>().eq(SharePathDO::getUserId, userId));
     }
 
     @Override
-    public List<OrderCalcDO> selectSons(Long userId, List<Long> userIds) {
-        List<SharePathDO> sharePathDOS = sharePathMapper.selectList(new LambdaQueryWrapperX<SharePathDO>()
-                .eq(SharePathDO::getAncestor, userId));
-        List<Long> allDescendants = sharePathDOS.stream().map(SharePathDO::getDescendant).collect(Collectors.toList());
-//        List<Long> allDescendants = sharePathMapper.findAllDescendants(userId);
+    public List<OrderCalcDO> selectArea(Long userId, List<Long> userIds) {
+        List<SharePathDO> sharePathDOS = sharePathMapper.selectListByUserId(userId, 99999);
+        List<Long> allDescendants = sharePathDOS.stream().map(SharePathDO::getUserId).collect(Collectors.toList());
         if (allDescendants.isEmpty()) {
             return Collections.emptyList();
         }
@@ -411,88 +460,15 @@ public class SharePathServiceImpl implements SharePathService {
 
     }
 
-    @Override
-    public List<OrderCalcDO> selectBrothers(Long userId, List<Long> userIds, MemberUserDO user) {
-        List<Long> sortedSiblings = new ArrayList<>();
-        // 先查询出他的父亲
-        List<SharePathDO> sharePathDO = sharePathMapper.selectList(new LambdaQueryWrapperX<SharePathDO>().eq(SharePathDO::getDepth, 1).eq(SharePathDO::getDescendant, userId));
-        if (sharePathDO.isEmpty()) {
-            sortedSiblings = sharePathMapper.findLessSortedSiblings(userId);
-        } else {
-            // 再根据父亲查询他的所有儿子
-//            List<SharePathDO> sharePathDOS = sharePathMapper.selectList(new LambdaQueryWrapperX<SharePathDO>()
-//                    .eq(SharePathDO::getDepth, 1)
-//                    .eq(SharePathDO::getAncestor, sharePathDO.get(0).getAncestor()));
-            // 后续加了游客身份所以,查询的时候要隔离游客的兄弟分区和用户的兄弟分区
-            List<SharePathDO> sharePathDOS = sharePathMapper.selectListByVisitor(sharePathDO.get(0).getAncestor(), user.getVisitor());
-            //最后再进行排序
-            sortedSiblings = filterByDescendant(sharePathDOS, userId);
-            // 查询兄弟的所有儿子
-            sortedSiblings.addAll(findSons(sortedSiblings));
-        }
-
-        if (sortedSiblings.isEmpty()) {
-            return Collections.emptyList();
-        }
-        // 查询出两个list的并集
-        List<Long> unionList = unionList(userIds, sortedSiblings);
-        if (unionList.isEmpty()) {
-            return Collections.emptyList();
-        }
-        // 获取这个分区的所有订单的合赢奖
-        return calcQuota(unionList);
-    }
-
-    private List<Long> findSons(List<Long> sortedSiblings) {
-        List<Long> longs = new ArrayList<>();
-        for (Long sortedSibling : sortedSiblings) {
-            List<SharePathDO> sharePathDOS = sharePathMapper.selectList(new LambdaQueryWrapperX<SharePathDO>()
-                    .eq(SharePathDO::getAncestor, sortedSibling));
-            if (sharePathDOS.isEmpty()) {
-                continue;
-            }
-            List<Long> collect = sharePathDOS.stream().map(SharePathDO::getDescendant).collect(Collectors.toList());
-            longs.addAll(collect);
-        }
-        return longs.stream().distinct().collect(Collectors.toList());
-    }
-
-
-    public List<Long> filterByDescendant(List<SharePathDO> sharePaths, Long descendantId) {
-        // 首先,找到特定 descendantId 的 sort 值
-        SharePathDO reference = sharePaths.stream()
-                .filter(sharePath -> sharePath.getDescendant().equals(descendantId))
-                .findFirst()
-                .orElse(null);
-
-        if (reference == null) {
-            throw new IllegalArgumentException("Descendant with ID " + descendantId + " not found");
-        }
-
-        // 过滤出所有 sort 值大于找到的 sort 值的记录
-        return sharePaths.stream()
-                .filter(sharePath ->
-                        {
-                            if (reference.getSort() != null && sharePath.getSort() != null) {
-                                return sharePath.getSort() > reference.getSort();
-                            }
-                            return false;
-                        }
-                )
-                .map(SharePathDO::getDescendant)
-                .collect(Collectors.toList());
-    }
-
-
     @Override
     public Long queryParentBySonUserId(Long userId) {
 
-        List<SharePathDO> sharePathDO = sharePathMapper.selectList(new LambdaQueryWrapperX<SharePathDO>()
-                .eqIfPresent(SharePathDO::getDescendant, userId).eqIfPresent(SharePathDO::getDepth, 1));
-        if (sharePathDO.isEmpty()) {
+        SharePathDO sharePathDO = sharePathMapper.selectOne(new LambdaQueryWrapperX<SharePathDO>()
+                .eqIfPresent(SharePathDO::getUserId, userId));
+        if (sharePathDO == null) {
             return 1L;
         } else {
-            return sharePathDO.get(0).getAncestor();
+            return sharePathDO.getParentId();
         }
 
 
@@ -502,9 +478,9 @@ public class SharePathServiceImpl implements SharePathService {
     public List<DuserDO> selectSon(Long userId) {
 
         // 查询当前用户的所有后代
-        List<SharePathDO> sharePathDOS = sharePathMapper.selectList(new LambdaQueryWrapperX<SharePathDO>().eqIfPresent(SharePathDO::getAncestor, userId));
+        List<SharePathDO> sharePathDOS = sharePathMapper.selectList(new LambdaQueryWrapperX<SharePathDO>().eqIfPresent(SharePathDO::getReferrerId, userId));
 
-        List<Long> duserId = sharePathDOS.stream().map(SharePathDO::getDescendant).collect(Collectors.toList());
+        List<Long> duserId = sharePathDOS.stream().map(SharePathDO::getUserId).collect(Collectors.toList());
 
         if (duserId.isEmpty()) {
             return Collections.emptyList();
@@ -516,8 +492,8 @@ public class SharePathServiceImpl implements SharePathService {
 
     @Override
     public List<Long> sonsId(Long userId) {
-        List<SharePathDO> sharePathDOS = sharePathMapper.selectList(new LambdaQueryWrapperX<SharePathDO>().eq(SharePathDO::getAncestor, userId));
-        return sharePathDOS.stream().map(SharePathDO::getDescendant).collect(Collectors.toList());
+        List<SharePathDO> sharePathDOS = sharePathMapper.selectList(new LambdaQueryWrapperX<SharePathDO>().eq(SharePathDO::getReferrerId, userId));
+        return sharePathDOS.stream().map(SharePathDO::getUserId).collect(Collectors.toList());
 
     }
 
@@ -533,18 +509,11 @@ public class SharePathServiceImpl implements SharePathService {
 
     @Override
     public PageResult<SharePathRespVO> getDescendants(SharePathPageReqVO pageReqVO) {
-        LambdaQueryWrapperX<SharePathDO> wrapper = new LambdaQueryWrapperX<SharePathDO>()
-                .eq(SharePathDO::getAncestor, pageReqVO.getAncestor());
-        if (pageReqVO.getDepth() != null) {
-            wrapper.eq(SharePathDO::getDepth, 1);
-        } else {
-            wrapper.ne(SharePathDO::getDepth, 1);
-        }
 
         PageResult<SharePathDO> sharePathDOPageResult = sharePathMapper.selectDescendantsPage(pageReqVO);
         PageResult<SharePathRespVO> result = BeanUtils.toBean(sharePathDOPageResult, SharePathRespVO.class);
         List<SharePathRespVO> list = result.getList();
-        list.forEach(sharePath -> sharePath.setAvatar(memberUserService.getUser(sharePath.getDescendant()).getAvatar()));
+        list.forEach(sharePath -> sharePath.setAvatar(memberUserService.getUser(sharePath.getUserId()).getAvatar()));
         return result;
     }
 

+ 0 - 13
feifan-module-mall/feifan-module-product-biz/src/main/java/cn/newfeifan/mall/module/product/controller/admin/skuapply/vo/SkuApplyPageReqVO.java

@@ -51,12 +51,6 @@ public class SkuApplyPageReqVO extends PageParam {
     @Schema(description = "商品体积,单位:m^3 平米")
     private Double volume;
 
-    @Schema(description = "一级分销的佣金,单位:分", example = "7462")
-    private Integer firstBrokeragePrice;
-
-    @Schema(description = "二级分销的佣金,单位:分", example = "32532")
-    private Integer secondBrokeragePrice;
-
     @Schema(description = "商品销量", example = "7812")
     private Integer salesCount;
 
@@ -70,13 +64,6 @@ public class SkuApplyPageReqVO extends PageParam {
     @Schema(description = "商户id", example = "9994")
     private Long merchantId;
 
-    @Schema(description = "高精度价格", example = "15815")
-    private BigDecimal highPrecisionPrice;
-
     @Schema(description = "结算价,单位: 分", example = "21066")
     private Integer settlementPrice;
-
-    @Schema(description = "高精度结算价", example = "1872")
-    private BigDecimal highPrecisionSettlementPrice;
-
 }

+ 2 - 22
feifan-module-mall/feifan-module-product-biz/src/main/java/cn/newfeifan/mall/module/product/dal/dataobject/spuapply/SpuApplyDO.java

@@ -58,9 +58,9 @@ public class SpuApplyDO extends BaseDO {
      */
     private Long categoryId;
     /**
-     * 商品品牌编号
+     * 商品分区编号
      */
-    private Integer brandId;
+    private Long areaId;
     /**
      * 商品封面图
      */
@@ -108,14 +108,6 @@ public class SpuApplyDO extends BaseDO {
      * 物流配置模板编号
      */
     private Long deliveryTemplateId;
-    /**
-     * 赠送积分
-     */
-    private Integer giveIntegral;
-    /**
-     * 分销类型
-     */
-    private Boolean subCommissionType;
     /**
      * 商品销量
      */
@@ -144,18 +136,6 @@ public class SpuApplyDO extends BaseDO {
      * 推广费, 单位: 分,值为sku中最大的推广费
      */
     private Integer promotionFee;
-    /**
-     * 商品支付类别(1 rmb 2积分)
-     */
-    private Integer spuPayType;
-    /**
-     * 高精度
-     */
-    private Boolean highPrecision;
-    /**
-     * 高精度价格
-     */
-    private BigDecimal highPrecisionPrice;
     /**
      * 申请用户id
      */

+ 0 - 5
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/service/order/handler/TradeSeckillOrderHandler.java

@@ -31,8 +31,6 @@ public class TradeSeckillOrderHandler implements TradeOrderHandler {
         Assert.isTrue(orderItems.size() == 1, "秒杀时,只允许选择一个商品");
 
         // 扣减秒杀活动的库存
-        seckillActivityApi.updateSeckillStockDecr(order.getSeckillActivityId(),
-                orderItems.get(0).getSkuId(), orderItems.get(0).getCount());
     }
 
     @Override
@@ -56,9 +54,6 @@ public class TradeSeckillOrderHandler implements TradeOrderHandler {
         if (!TradeOrderTypeEnum.isSeckill(order.getType())) {
             return;
         }
-        // 恢复秒杀活动的库存
-        seckillActivityApi.updateSeckillStockIncr(order.getSeckillActivityId(),
-                orderItem.getSkuId(), orderItem.getCount());
     }
 
 }