From 199861555473ab50f2fafa3d58e42e64e838c039 Mon Sep 17 00:00:00 2001
From: luofl <1442745593@qq.com>
Date: 星期一, 24 二月 2025 22:47:18 +0800
Subject: [PATCH] 修改物流信息导入模板

---
 ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java |  227 +++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 174 insertions(+), 53 deletions(-)

diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java
index e9b6927..df64f87 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java
@@ -131,6 +131,7 @@
 
     @PostMapping("/getAppUserById")
     public AppUser getAppUserById(@RequestParam("id") Long id) {
+        System.out.println("根据id获取用户:"+id);
         return appUserService.getById(id);
     }
 
@@ -233,7 +234,7 @@
         if(StringUtils.isEmpty(user.getQrCode())){
             //获取微信推广二维码
             String fileName = UUID.randomUUID() + ".jpg";
-            String getwxacodeunlimit = weChatUtil.getwxacodeunlimit("pages/login/login", "id=" + user.getId(), EnvVersion.RELEASE, filePath + fileName);
+            String getwxacodeunlimit = weChatUtil.getwxacodeunlimit("pages/start/start", "id=" + user.getId(), EnvVersion.RELEASE, filePath + fileName);
             user.setQrCode(getwxacodeunlimit);
             appUserService.updateById(user);
         }
@@ -275,14 +276,31 @@
         Long userId = tokenService.getLoginUserApplet().getUserid();
         //获取绑定门店
         AppUser user = appUserService.getById(userId);
-        if (user.getShopId() != null) {
-            R<Shop> storeById = storeClient.getStoreById(user.getShopId());
-            if (storeById.getData() != null) {
-                user.setShopName(storeById.getData().getName());
-                user.setShopCover(storeById.getData().getHomePicture());
-                user.setShopAddress(storeById.getData().getAddress());
+
+
+        //当前用户的推荐人信息(指导老师)
+        List<AppUser> allSuperiors = getAllSuperiors(userId);
+        //当前绑定门店的店铺信息
+        for (AppUser allSuperior : allSuperiors) {
+            List<Shop> shopList = shopClient.getShopByUserId(allSuperior.getId()).getData();
+            if (!CollectionUtils.isEmpty(shopList)){
+                user.setShopName(shopList.get(0).getName());
+                user.setShopCover(shopList.get(0).getHomePicture());
+                user.setShopAddress(shopList.get(0).getAddress());
+                break;
             }
         }
+
+        //指导老师
+        allSuperiors.stream()
+                .filter(superiors -> superiors.getVipId() != null && superiors.getVipId() > 3)
+                .findFirst()
+                .ifPresent(superiors -> {
+                    user.setTeacher(superiors.getName());
+                    user.setTeacherPhone(superiors.getPhone());
+                });
+
+
 
         //获取绑定上级
         if (user.getInviteUserId() != null) {
@@ -399,13 +417,42 @@
     @GetMapping("/change")
     @ApiOperation(value = "推广中心", tags = {"小程序-推广中心"})
     public R<AppUser> change(@ApiParam("换绑用户手机号") String phone) {
+
         Long userId1 = tokenService.getLoginUserApplet().getUserid();
         AppUser byId = appUserService.getById(userId1);
+
+
+
+//        List<AppUser> appUserList = appUserService.list(new LambdaQueryWrapper<AppUser>()
+//                .eq(AppUser::getInviteUserId, userId1)
+//                .eq(AppUser::getPhone, phone));
+//        if (!CollectionUtils.isEmpty(appUserList)){
+//            return R.fail("绑定关系已存在!");
+//        }
         //获取绑定门店
-        AppUser user = appUserService.lambdaQuery().eq(AppUser::getPhone, phone).one();
+        AppUser user = appUserService.lambdaQuery()
+                .eq(AppUser::getPhone, phone)
+                .eq(AppUser::getDelFlag, 0)
+                .eq(AppUser::getStatus, 1)
+                .one();
+
+
+        // 获取当前用户的所有下级
+        List<AppUser> allSubordinates = getAllSubordinates(byId.getId());
+        long count = allSubordinates.stream().filter(appUser -> appUser.getId().equals(user.getId())).count();
+        if (count > 0) {
+            return R.fail("绑定关系已存在!");
+        }
+
         if (user == null) {
             return R.fail("当前手机号未注册");
         }
+
+        Long userId = user.getId();
+        if (userId.equals(byId.getId())) {
+            return R.fail("不能选择自己为绑定人。");
+        }
+
         byId.setInviteUserId(user.getId());
         appUserService.updateById(byId);
         return R.ok();
@@ -418,40 +465,76 @@
         Long userId = tokenService.getLoginUserApplet().getUserid();
         //当前用户信息
         AppUser user = appUserService.getById(userId);
-        //当前用户的推荐人信息
-        if (user.getInviteUserId() != null) {
-            AppUser inviteUser = appUserService.getById(user.getInviteUserId());
-            user.setInviteUserName(inviteUser.getName());
+        if(StringUtils.isEmpty(user.getQrCode())){
+            //获取微信推广二维码
+            String fileName = UUID.randomUUID() + ".jpg";
+            String getwxacodeunlimit = weChatUtil.getwxacodeunlimit("pages/start/start", "id=" + user.getId(), EnvVersion.RELEASE, filePath + fileName);
+            user.setQrCode(getwxacodeunlimit);
+            appUserService.updateById(user);
         }
-        //当前绑定门店的店铺信息
-        if (user.getShopId() != null) {
-            R<Shop> storeById = shopClient.getShopById(user.getShopId());
-            if (storeById.getData() != null) {
-                Shop shop = storeById.getData();
-                user.setShopName(shop.getName());
+        
+        //指导老师
+        List<AppUser> allSuperiors = getAllSuperiors(userId);
+        allSuperiors.stream()
+                .filter(superiors -> superiors.getVipId() != null && superiors.getVipId() > 3)
+                .findFirst()
+                .ifPresent(superiors -> {
+                    user.setTeacher(superiors.getName());
+                });
+        //当前绑定门店的店铺信息(服务商)
+        for (AppUser allSuperior : allSuperiors) {
+            List<Shop> shopList = shopClient.getShopByUserId(allSuperior.getId()).getData();
+            if (!CollectionUtils.isEmpty(shopList)){
+                user.setShopName(shopList.get(0).getName());
+                break;
             }
         }
-        List<AppUser> appUserList = appUserService.list(new LambdaQueryWrapper<AppUser>()
-                .ne(AppUser::getStatus, 3)
-                .eq(AppUser::getDelFlag, 0));
+//        if (user.getShopId() != null) {
+//            R<Shop> storeById = shopClient.getShopById(user.getShopId());
+//            if (storeById.getData() != null) {
+//                Shop shop = storeById.getData();
+//                user.setShopName(shop.getName());
+//            }
+//        }
         ArrayList<Long> userIds = new ArrayList<>();
         userIds.add(userId);
-        getUserAncestorList(user,userIds,new ArrayList<>(),appUserList);
-//        Long count1 = appUserService.lambdaQuery().ne(AppUser::getStatus,3).eq(AppUser::getVipId, 1).eq(AppUser::getInviteUserId, userId).or().eq(AppUser::getTopInviteId,userId).count();
-//        Long count2 = appUserService.lambdaQuery().ne(AppUser::getStatus,3).eq(AppUser::getVipId, 2).eq(AppUser::getInviteUserId, userId).or().eq(AppUser::getTopInviteId,userId).count();
-//        Long count3 = appUserService.lambdaQuery().ne(AppUser::getStatus,3).eq(AppUser::getVipId, 3).eq(AppUser::getInviteUserId, userId).or().eq(AppUser::getTopInviteId,userId).count();
-//        Long count4 = appUserService.lambdaQuery().ne(AppUser::getStatus,3).eq(AppUser::getVipId, 4).eq(AppUser::getInviteUserId, userId).or().eq(AppUser::getTopInviteId,userId).count();
-//        Long count5 = appUserService.lambdaQuery().ne(AppUser::getStatus,3).eq(AppUser::getVipId, 5).eq(AppUser::getInviteUserId, userId).or().eq(AppUser::getTopInviteId,userId).count();
-//        Long count6 = appUserService.lambdaQuery().ne(AppUser::getStatus,3).eq(AppUser::getVipId, 6).eq(AppUser::getInviteUserId, userId).or().eq(AppUser::getTopInviteId,userId).count();
-//        Long count7 = appUserService.lambdaQuery().ne(AppUser::getStatus,3).eq(AppUser::getVipId, 7).eq(AppUser::getInviteUserId, userId).or().eq(AppUser::getTopInviteId,userId).count();
-//        user.setCount1(count1);
-//        user.setCount2(count2);
-//        user.setCount3(count3);
-//        user.setCount4(count4);
-//        user.setCount5(count5);
-//        user.setCount6(count6);
-//        user.setCount7(count7);
-
+        // 获取当前用户的所有下级
+        List<AppUser> allSubordinates = getAllSubordinates(userId);
+        // 统计下级中每种会员类型的人数
+        Map<Integer, Long> countMap = allSubordinates.stream()
+                .collect(Collectors.groupingBy(AppUser::getVipId, Collectors.counting()));
+        countMap.forEach((vipId, count) -> {
+            switch (vipId) {
+                case 1:
+                    Long count1 = user.getCount1() == null ? 0 : user.getCount1();
+                    user.setCount1(count1 + count);
+                    break;
+                case 2:
+                    Long count2 = user.getCount2() == null ? 0 : user.getCount2();
+                    user.setCount2(count2 + count);
+                    break;
+                case 3:
+                    Long count3 = user.getCount3() == null ? 0 : user.getCount3();
+                    user.setCount3(count3 + count);
+                    break;
+                case 4:
+                    Long count4 = user.getCount4() == null ? 0 : user.getCount4();
+                    user.setCount4(count4 + count);
+                    break;
+                case 5:
+                    Long count5 = user.getCount5() == null ? 0 : user.getCount5();
+                    user.setCount5(count5 + count);
+                    break;
+                case 6:
+                    Long count6 = user.getCount6() == null ? 0 : user.getCount6();
+                    user.setCount6(count6 + count);
+                    break;
+                case 7:
+                    Long count7 = user.getCount7() == null ? 0 : user.getCount7();
+                    user.setCount7(count7 + count);
+                    break;
+            }
+        });
         List<UserSignRecord> list = userSignRecordService.lambdaQuery().eq(UserSignRecord::getSignDay, LocalDate.now())
                 .eq(UserSignRecord::getAppUserId,userId).list();
         if (!list.isEmpty()) {
@@ -461,20 +544,45 @@
         }
         return R.ok(user);
     }
-    public void getUserAncestorList(AppUser user,List<Long> userIds, List<AppUser> children,List<AppUser> list) {
-        children = list.stream().filter(u -> userIds.contains(u.getInviteUserId()) || userIds.contains(u.getTopInviteId())).collect(Collectors.toList());
-        if(!CollectionUtils.isEmpty(children)){
-            user.setCount1((user.getCount1() == null ? 0L : user.getCount1()) + children.stream().filter(e->e.getVipId() == 1).count());
-            user.setCount2((user.getCount2() == null ? 0L : user.getCount2()) + children.stream().filter(e->e.getVipId() == 2).count());
-            user.setCount3((user.getCount3() == null ? 0L : user.getCount3()) + children.stream().filter(e->e.getVipId() == 3).count());
-            user.setCount4((user.getCount4() == null ? 0L : user.getCount4()) + children.stream().filter(e->e.getVipId() == 4).count());
-            user.setCount5((user.getCount5() == null ? 0L : user.getCount5()) + children.stream().filter(e->e.getVipId() == 5).count());
-            user.setCount6((user.getCount6() == null ? 0L : user.getCount6()) + children.stream().filter(e->e.getVipId() == 6).count());
-            user.setCount7((user.getCount7() == null ? 0L : user.getCount7()) + children.stream().filter(e->e.getVipId() == 7).count());
-            List<Long> userIdList = children.stream().map(AppUser::getId).collect(Collectors.toList());
-            getUserAncestorList(user,userIdList, children,list);
+
+
+    public List<AppUser> getAllSuperiors(Long userId) {
+        List<AppUser> allSuperiors = new ArrayList<>();
+
+        // 获取当前用户的直接上级
+        AppUser currentUser = appUserService.getById(userId);
+        if (currentUser != null && currentUser.getInviteUserId() != null) {
+            AppUser superior = appUserService.getById(currentUser.getInviteUserId());
+            if (superior != null) {
+                allSuperiors.add(superior); // 添加直接上级
+                allSuperiors.addAll(getAllSuperiors(superior.getId())); // 递归添加上级的上级
+            }
         }
+
+        return allSuperiors;
     }
+
+
+    
+    // 递归获取指定用户的所有下级
+    public List<AppUser> getAllSubordinates(Long userId) {
+        List<AppUser> allSubordinates = new ArrayList<>();
+
+        List<AppUser> directChildren = appUserService.list(new LambdaQueryWrapper<AppUser>()
+                .eq(AppUser::getInviteUserId, userId));
+
+        for (AppUser child : directChildren) {
+            allSubordinates.add(child); // 添加直接下级
+            allSubordinates.addAll(getAllSubordinates(child.getId())); // 递归添加间接下级
+        }
+        return allSubordinates;
+    }
+
+
+
+
+
+
 
     @GetMapping("/index/change")
     @ApiOperation(value = "修改个人资料", tags = {"小程序-个人中心首页"})
@@ -740,6 +848,14 @@
         if (userId.equals(inviteId)) {
             return R.fail("不能选择自己为绑定人。");
         }
+
+        List<AppUser> appUserList = appUserService.list(new LambdaQueryWrapper<AppUser>()
+                .eq(AppUser::getInviteUserId, id)
+                .eq(AppUser::getId, inviteId));
+        if (!CollectionUtils.isEmpty(appUserList)){
+            return R.fail("绑定关系已存在!");
+        }
+
         byId.setInviteUserId(inviteId);
         byId.setTopInviteId(getTop(inviteId));
         appUserService.updateById(byId);
@@ -1007,7 +1123,9 @@
                     List<AppUser> list = appUserService.list(new LambdaQueryWrapper<AppUser>().eq(AppUser::getShopId, objectId).eq(AppUser::getDelFlag, 0).eq(AppUser::getStatus, 1));
                     List<Long> appUserIds = list.stream().map(AppUser::getId).collect(Collectors.toList());
                     Set<Long> data = orderClient.getAppUserByShoppingShop(objectId).getData();
-                    appUserIds.addAll(data);
+                    if(null != data){
+                        appUserIds.addAll(data);
+                    }
                     if(appUserIds.size() == 0){
                         appUserIds.add(-1L);
                     }
@@ -1043,9 +1161,12 @@
                 }
             }
         });
+        Integer objectId = 0;
+        if(sysUser.getRoleType() == 2){
+            objectId = sysUser.getObjectId();
+        }
 
-
-        R<Map<String, BigDecimal>> shopStatistics = shopClient.getShopStatistics();
+        R<Map<String, BigDecimal>> shopStatistics = shopClient.getShopStatistics(objectId);
         Map<String, BigDecimal> data = shopStatistics.getData();
         BigDecimal totalServiceFee = BigDecimal.ZERO;
         BigDecimal totalUserCommission = BigDecimal.ZERO;
@@ -1097,7 +1218,6 @@
             totalPartnerCommission = totalPartnerCommission.add(dailyCommissions.getOrDefault(7, BigDecimal.ZERO));
 
             // 用户分销总金额
-
             BigDecimal add = commissionDate.getNormalCommission().add(commissionDate.getGoldCommission()).add(commissionDate.getDiamondCommission()).add(commissionDate.getAgentCommission())
                     .add(commissionDate.getSuperAgentCommission()).add(commissionDate.getTopAgentCommission()).add(commissionDate.getPartnerCommission());
             commissionDate.setTotalCommission(add);
@@ -1206,5 +1326,6 @@
                 .set(AppUser::getUserType,1));
         return R.ok();
     }
+
 }
 

--
Gitblit v1.7.1