From 49e96cc15baf35d710fe3a049fb97aff6a1af132 Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期二, 25 二月 2025 19:35:33 +0800 Subject: [PATCH] 修改分佣逻辑 --- ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopController.java | 87 ++++++++++++++++++++----------------------- 1 files changed, 41 insertions(+), 46 deletions(-) diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopController.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopController.java index 438422a..de23686 100644 --- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopController.java +++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopController.java @@ -870,18 +870,43 @@ */ @GetMapping("/getServiceProvider") public R<Shop> getServiceProvider(Long userId){ - List<AppUser> allSuperiors = getAllSuperiors(userId); - //当前绑定门店的店铺信息(服务商) - Shop serviceProvider = null; - for (AppUser allSuperior : allSuperiors) { - List<Shop> shopList = shopService.lambdaQuery().eq(Shop::getAppUserId, allSuperior.getId()).eq(Shop::getDelFlag,0).list(); - if (!CollectionUtils.isEmpty(shopList)){ - serviceProvider = shopList.get(0); - break; + //向上找获取第一个开店的门店 + List<Shop> list = shopService.list(new LambdaQueryWrapper<Shop>().eq(Shop::getDelFlag, 0).eq(Shop::getStatus, 1)); + AppUser appUser = appUserClient.getAppUserById(userId); + //上级集合,防止循环关联 + Set<Long> pid = new HashSet<>(); + Shop shop = getSuperiorStore(appUser, list, 1, 1, pid); + return R.ok(shop); + } + + + + public Shop getSuperiorStore(AppUser appUser, List<Shop> list, Integer hierarchy, Integer num, Set<Long> pid){ + if(null == appUser.getInviteUserId()){ + return null; + } + if(pid.contains(appUser.getInviteUserId())){ + return null; + } + AppUser appUser1 = appUserClient.getAppUserById(appUser.getInviteUserId()); + if(null != appUser1){ + Optional<Shop> first = list.stream().filter(shop -> shop.getAppUserId().equals(appUser1.getId())).findFirst(); + if(first.isPresent()){ + if(hierarchy.equals(num)){ + return first.get(); + } + num++; } } - return R.ok(serviceProvider); + return getSuperiorStore(appUser1, list, hierarchy, num, pid); } + + + + + + + /** * 获取指定用户的高级服务商 @@ -889,43 +914,13 @@ */ @GetMapping("/getSuperiorServiceProvider") public R<Shop> getSuperiorServiceProvider(Long userId){ - List<AppUser> allSuperiors = getAllSuperiors(userId); - Long techerId = null; - for (AppUser allSuperior : allSuperiors) { - List<Shop> shopList = shopService.lambdaQuery().eq(Shop::getAppUserId, allSuperior.getId()).eq(Shop::getDelFlag,0).list(); - if (!CollectionUtils.isEmpty(shopList)){ - techerId = allSuperior.getId(); - break; - } - } - if (techerId == null){ - return R.fail("暂无高级服务商"); - } - List<AppUser> allSuperiors1 = getAllSuperiors(techerId); - for (AppUser allSuperior : allSuperiors1) { - List<Shop> shopList = shopService.lambdaQuery().eq(Shop::getAppUserId, allSuperior.getId()).eq(Shop::getDelFlag,0).list(); - if (!CollectionUtils.isEmpty(shopList)){ - return R.ok(shopList.get(0)); - } - } - return R.fail("暂无高级服务商"); - } - - - public List<AppUser> getAllSuperiors(Long userId) { - List<AppUser> allSuperiors = new ArrayList<>(); - - // 获取当前用户的直接上级 - AppUser currentUser = appUserClient.getAppUserById(userId); - if (currentUser != null && currentUser.getInviteUserId() != null) { - AppUser superior = appUserClient.getAppUserById(currentUser.getInviteUserId()); - if (superior != null) { - allSuperiors.add(superior); // 添加直接上级 - allSuperiors.addAll(getAllSuperiors(superior.getId())); // 递归添加上级的上级 - } - } - - return allSuperiors; + //向上找获取第一个开店的门店 + List<Shop> list = shopService.list(new LambdaQueryWrapper<Shop>().eq(Shop::getDelFlag, 0).eq(Shop::getStatus, 1)); + AppUser appUser = appUserClient.getAppUserById(userId); + //上级集合,防止循环关联 + Set<Long> pid = new HashSet<>(); + Shop shop = getSuperiorStore(appUser, list, 2, 1, pid); + return R.ok(shop); } } -- Gitblit v1.7.1