Pu Zhibing
2025-04-22 fd7b8fb7c89832c28a838b0449bbb8a392433ee2
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java
@@ -1,8 +1,10 @@
package com.ruoyi.account.controller;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
@@ -31,7 +33,6 @@
import com.ruoyi.other.api.domain.VipSetting;
import com.ruoyi.other.api.feignClient.ShopBalanceStatementClient;
import com.ruoyi.other.api.feignClient.ShopClient;
import com.ruoyi.other.api.feignClient.StoreClient;
import com.ruoyi.other.api.feignClient.VipSettingClient;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.feignClient.SysUserClient;
@@ -73,8 +74,6 @@
    @Resource
    private AppUserService appUserService;
    @Resource
    private StoreClient storeClient;
    @Resource
    private UserCouponService userCouponService;
    @Resource
@@ -83,8 +82,6 @@
    private VipSettingClient vipSettingClient;
    @Resource
    private UserPointService userPointService;
    @Resource
    private VipSettingService vipSettingService;
    @Resource
    private AppUserMapper appUserMapper;
    @Resource
@@ -102,12 +99,17 @@
    @Resource
    private BalanceChangeRecordService balanceChangeRecordService;
    @Resource
    private BalanceChangeRecordCopyService balanceChangeRecordCopyService;
    @Resource
    private UserChangeLogService userChangeLogService;
    @Resource
    private RedisService redisService;
    @Resource
    private WeChatUtil weChatUtil;
    @Resource
    private IAppUserGiveawayTemporaryService appUserGiveawayTemporaryService;
    
    @Value("${file.upload.location}")
    private String filePath;
@@ -131,6 +133,7 @@
    @PostMapping("/getAppUserById")
    public AppUser getAppUserById(@RequestParam("id") Long id) {
        System.out.println("根据id获取用户:"+id);
        return appUserService.getById(id);
    }
@@ -171,7 +174,7 @@
    @PostMapping("/getCouponCount")
    public R<Long> getCouponCount(@RequestParam("userId") Long userId, @RequestParam("couponId") Integer couponId) {
        LambdaQueryChainWrapper<UserCoupon> chainWrapper = userCouponService.lambdaQuery().eq(UserCoupon::getCouponId, couponId);
        if(null != userId && -1 == userId){
        if(null != userId && -1 != userId){
            chainWrapper.eq(UserCoupon::getAppUserId, userId);
        }
        Long count = chainWrapper.count();
@@ -275,19 +278,61 @@
        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;
            }
        }
        if (user.getShopName() == null){
            user.setShopName("");
        }
        if (user.getShopCover() == null){
            user.setShopCover("");
        }
        if (user.getShopAddress() == null){
            user.setShopAddress("");
        }
        //指导老师
        allSuperiors.stream()
                .filter(superiors -> superiors.getVipId() != null && superiors.getVipId() > 3)
                .findFirst()
                .ifPresent(superiors -> {
                    user.setTeacher(superiors.getName());
                    user.setTeacherPhone(superiors.getPhone());
                });
        if (user.getTeacher() == null){
            user.setTeacher("");
        }
        if (user.getTeacherPhone() == null){
            user.setTeacherPhone("");
        }
        //获取绑定上级
        if (user.getInviteUserId() != null) {
            AppUser byId = appUserService.getById(user.getInviteUserId());
            user.setTopUser(byId);
            if(null != byId){
                user.setTopUser(byId);
            }else{
                user.setTopUser(new AppUser());
            }
        }else {
            AppUser topUser = new AppUser();
            user.setTopUser(topUser);
        }
        //获取绑定下级列表
        List<AppUser> list = appUserService.lambdaQuery()
@@ -332,7 +377,6 @@
                    .eq(AppUser::getDelFlag, 0)
                    .ne(AppUser::getStatus, 3)
                    .count();
            vip1Count1 += count1;
            Long count2 = appUserService.lambdaQuery()
                    .eq(AppUser::getVipId, 2)
@@ -340,42 +384,36 @@
                    .eq(AppUser::getDelFlag, 0)
                    .ne(AppUser::getStatus, 3)
                    .count();
            vip1Count2 += count2;
            Long count3 = appUserService.lambdaQuery()
                    .eq(AppUser::getVipId, 3)
                    .eq(AppUser::getInviteUserId, appUser.getId())
                    .eq(AppUser::getDelFlag, 0)
                    .ne(AppUser::getStatus, 3)
                    .count();
            vip1Count3 += count3;
            Long count4 = appUserService.lambdaQuery()
                    .eq(AppUser::getVipId, 4)
                    .eq(AppUser::getInviteUserId, appUser.getId())
                    .eq(AppUser::getDelFlag, 0)
                    .ne(AppUser::getStatus, 3)
                    .count();
            vip1Count4 += count4;
            Long count5 = appUserService.lambdaQuery()
                    .eq(AppUser::getVipId, 5)
                    .eq(AppUser::getInviteUserId, appUser.getId())
                    .eq(AppUser::getDelFlag, 0)
                    .ne(AppUser::getStatus, 3)
                    .count();
            vip1Count5 += count5;
            Long count6 = appUserService.lambdaQuery()
                    .eq(AppUser::getVipId, 6)
                    .eq(AppUser::getInviteUserId, appUser.getId())
                    .eq(AppUser::getDelFlag, 0)
                    .ne(AppUser::getStatus, 3)
                    .count();
            vip1Count6 += count6;
            Long count7 = appUserService.lambdaQuery()
                    .eq(AppUser::getVipId, 7)
                    .eq(AppUser::getInviteUserId, appUser.getId())
                    .eq(AppUser::getDelFlag, 0)
                    .ne(AppUser::getStatus, 3)
                    .count();
            vip1Count7 += count7;
            appUser.setCount1(count1);
            appUser.setCount2(count2);
            appUser.setCount3(count3);
@@ -384,6 +422,7 @@
            appUser.setCount6(count6);
            appUser.setCount7(count7);
        }
        user.setBottomUsers(list);
        user.setCount1(vip1Count1);
        user.setCount2(vip1Count2);
@@ -399,23 +438,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("绑定关系已存在!");
        }
//        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)
                .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();
@@ -436,58 +494,41 @@
            appUserService.updateById(user);
        }
        
        //当前用户的推荐人信息
        if (user.getInviteUserId() != null) {
            AppUser inviteUser = appUserService.getById(user.getInviteUserId());
            user.setInviteUserName(inviteUser.getName());
        //指导老师
        List<AppUser> allSuperiors = getAllSuperiors(userId);
        allSuperiors.stream()
                .filter(superiors -> superiors.getVipId() != null && superiors.getVipId() > 3)
                .findFirst()
                .ifPresent(superiors -> {
                    user.setTeacher(superiors.getName());
                });
        Shop shop1 = shopClient.getServiceProvider(userId).getData();
        if(null != shop1){
            user.setShopName(shop1.getName());
            user.setShopId(shop1.getId());
        }
        //当前绑定门店的店铺信息
        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);
        // 获取当前用户的所有下级
        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<AppUser> allSubordinates = appUserService.list(new LambdaQueryWrapper<AppUser>()
                .eq(AppUser::getInviteUserId, user.getId()).eq(AppUser::getDelFlag, 0)
                .ne(AppUser::getStatus, 3));
        Long count1 = allSubordinates.stream().filter(s->s.getVipId() == 1).count();
        user.setCount1(count1);
        Long count2 = allSubordinates.stream().filter(s->s.getVipId() == 2).count();
        user.setCount2(count2);
        Long count3 = allSubordinates.stream().filter(s->s.getVipId() == 3).count();
        user.setCount3(count3);
        Long count4 = allSubordinates.stream().filter(s->s.getVipId() == 4).count();
        user.setCount4(count4);
        Long count5 = allSubordinates.stream().filter(s->s.getVipId() == 5).count();
        user.setCount5(count5);
        Long count6 = allSubordinates.stream().filter(s->s.getVipId() == 6).count();
        user.setCount6(count6);
        Long count7 = allSubordinates.stream().filter(s->s.getVipId() == 7).count();
        user.setCount7(count7);
        List<UserSignRecord> list = userSignRecordService.lambdaQuery().eq(UserSignRecord::getSignDay, LocalDate.now())
                .eq(UserSignRecord::getAppUserId,userId).list();
        if (!list.isEmpty()) {
@@ -495,8 +536,32 @@
        } else {
            user.setIsSign(0);
        }
        List<AppUserGiveawayTemporary> temporaryList = appUserGiveawayTemporaryService.list(new LambdaQueryWrapper<AppUserGiveawayTemporary>()
                .eq(AppUserGiveawayTemporary::getAppUserId, userId));
        user.setLavePoint(temporaryList.stream().mapToInt(AppUserGiveawayTemporary::getTotalPoint).sum() + user.getTotalPoint());
        return R.ok(user);
    }
    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) {
@@ -511,10 +576,42 @@
        }
        return allSubordinates;
    }
    /**
     * 获取门店作为服务商的所有用户
     * @param shopId
     * @return
     */
    public Set<Long> getShopServerUser(Integer shopId){
        Shop shop = shopClient.getShopById(shopId).getData();
        List<Shop> shopList = shopClient.getAllShop().getData();
        List<Long> appUserIds = shopList.stream().map(Shop::getAppUserId).collect(Collectors.toList());
        Long appUserId = shop.getAppUserId();
        //所有未开店的用户
        List<AppUser> list = appUserService.list(new LambdaQueryWrapper<AppUser>().eq(AppUser::getDelFlag, 0)
                .ne(AppUser::getStatus, 3).notIn(AppUser::getId, appUserIds));
        Set<Long> ids = new HashSet<>();
        getShopServerUser(appUserId, list, ids);
        return ids;
    }
    public void getShopServerUser(Long appUserId, List<AppUser> appUserList, Set<Long> ids){
        List<AppUser> collect = appUserList.stream().filter(s->s.getInviteUserId().equals(appUserId)).collect(Collectors.toList());
        if(collect.size() == 0){
            return;
        }
        Set<Long> appUserSet = collect.stream().map(AppUser::getId).collect(Collectors.toSet());
        if(ids.containsAll(appUserSet)){
            return;
        }
        ids.addAll(appUserSet);
        for (AppUser appUser : collect) {
            getShopServerUser(appUser.getId(), appUserList, ids);
        }
    }
@@ -605,14 +702,82 @@
        return R.ok(list);
    }
    @GetMapping("/getUserPointsPage")
    @ApiOperation(value = "用户列表", tags = {"管理后台"})
    public R<IPage<AppUser>> getUserPointsPage(@ApiParam("页码") @RequestParam Integer pageNum,
                                            @ApiParam("每一页数据大小") Integer pageSize,
                                            AppUser appUser) {
        Long userId = tokenService.getLoginUser().getUserid();
        SysUser data = sysUserClient.getSysUser(userId).getData();
        QueryWrapper<AppUser> queryWrapper = new QueryWrapper<>();
        if (data.getRoleType() == 2) {
            Integer shopId = data.getObjectId();
            List<Order> orders = orderClient.getRedeemedOrdersByShop(shopId).getData();
            List<Long> userIds = orders.stream().map(Order::getAppUserId).collect(Collectors.toList());
            //门店作为服务商的用户
            Set<Long> shopServerUser = getShopServerUser(shopId);
            userIds.addAll(shopServerUser);
            queryWrapper.in(!CollectionUtils.isEmpty(userIds), "id", userIds)
                    .like(StringUtils.isNotEmpty( appUser.getName()),"name", appUser.getName());
        }
        queryWrapper.eq("del_flag", 0);
        queryWrapper.ne("status", 3);
        List<AppUser> appUserList = appUserService.list(queryWrapper);
        Page<AppUser> objectPage = Page.of(pageNum, pageSize);
        objectPage.setRecords(appUserList);
        return R.ok(objectPage);
    }
    /**
     * 获取用户列表
     */
    @GetMapping("/getAppuserPage")
    @ApiOperation(value = "用户列表", tags = {"管理后台"})
    public R<IPage<AppUser>> getAppuserPage(@ApiParam("页码") @RequestParam Integer pageNum,
                                            @ApiParam("每一页数据大小") Integer pageSize,
                                            AppUser appUser) {
                                               @ApiParam("每一页数据大小") Integer pageSize,
                                               AppUser appUser){
        Long userid = tokenService.getLoginUser().getUserid();
        SysUser sysUser = sysUserClient.getSysUser(userid).getData();
        Integer shopId = null;
        Set<Long> userId = null;
        if(sysUser.getRoleType() == 2){
            shopId = sysUser.getObjectId();
            userId = orderClient.getAppUserByShoppingShop(shopId).getData();
        }
        appUser.setExcludeStatus(3);
        IPage<AppUser> appuserPage = appUserService.getAppuserPage(pageNum, pageSize, appUser, shopId, userId);
        for (AppUser record : appuserPage.getRecords()) {
            List<AppUserGiveawayTemporary> list = appUserGiveawayTemporaryService.list(new LambdaQueryWrapper<AppUserGiveawayTemporary>().eq(AppUserGiveawayTemporary::getAppUserId, record.getId()));
            int sum = list.stream().mapToInt(AppUserGiveawayTemporary::getTotalPoint).sum();
            if (record.getInviteUserId() != null) {
                AppUser byId1 = appUserService.getById(record.getInviteUserId());
                if (byId1!=null) {
                    record.setInviteUserName(byId1.getName());
                }
            }
            Shop shop1 = shopClient.getServiceProvider(record.getId()).getData();
            if(null != shop1){
                record.setShopName(shop1.getName());
                record.setShopId(shop1.getId());
            }
            record.setTotalPoint(record.getUserTotalPoint() + sum);
        }
        return R.ok(appuserPage);
    }
    /**
     * 获取用户积分列表
     */
    @GetMapping("/getUserPotPage")
    public R<IPage<AppUser>> getUserPotPage(@ApiParam("页码") @RequestParam Integer pageNum,
                                               @ApiParam("每一页数据大小") Integer pageSize,
                                               AppUser appUser) {
        Long userid = tokenService.getLoginUser().getUserid();
        SysUser sysUser = sysUserClient.getSysUser(userid).getData();
        Integer shopId = null;
@@ -635,9 +800,11 @@
                    record.setShopName(shopById.getData().getName());
                }
            }
            record.setTotalPoint(record.getUserTotalPoint());
        }
        return R.ok(appuserPage);
    }
    @GetMapping("/shop/getAppuserPage")
    @ApiOperation(value = "用户列表", tags = {"门店后台"})
@@ -657,8 +824,10 @@
            for (Order datum : listR.getData()) {
                userIds.add(datum.getAppUserId());
            }
            Set<Long> shopServerUser = getShopServerUser(objectId);
            userIds.addAll(shopServerUser);
        }
        IPage<AppUser> appuserPage = appUserService.getAppuserPage1(pageCurr, pageSize, appUser, objectId, userIds);
        IPage<AppUser> appuserPage = appUserService.getAppuserPage1(pageCurr, pageSize, appUser, userIds);
        return R.ok(appuserPage);
    }
@@ -745,17 +914,17 @@
    }
    private void loginout(Long userId) {
        // 获取所有符合模式的缓存键
        Collection<String> keys = redisService.keys(CacheConstants.LOGIN_TOKEN_KEY + "*");
        if (!CollectionUtils.isEmpty(keys)) {
            for (String key : keys) {
                LoginUser user = redisService.getCacheObject(key);
                if (user == null || user.getUserid() == null) {
                    continue;
                }
                if (user.getUserid().equals(userId)) {
                    redisService.deleteObject(key);
                    break;
                }
        if (CollectionUtils.isEmpty(keys)) {
            return; // 如果没有匹配的键,直接返回
        }
        // 遍历所有键并删除与指定用户ID相关的登录信息
        for (String key : keys) {
            LoginUser user = redisService.getCacheObject(key);
            if (user != null && userId.equals(user.getUserid())) {
                redisService.deleteObject(key);
            }
        }
    }
@@ -825,11 +994,10 @@
        Long userid = tokenService.getLoginUser().getUserid();
        SysUser sysUser = sysUserClient.getSysUser(userid).getData();
        AppUser byId = appUserService.getById(id);
        if (byId.getShopId() != null) {
            R<Shop> shopById = shopClient.getShopById(Integer.parseInt(String.valueOf(byId.getShopId())));
            if (shopById.getData() != null) {
                byId.setShopName(shopById.getData().getName());
            }
        Shop shop1 = shopClient.getServiceProvider(byId.getId()).getData();
        if(null != shop1){
            byId.setShopName(shop1.getName());
            byId.setShopId(shop1.getId());
        }
        R<List<Shop>> shopByUserId = shopClient.getShopByUserId(id);
        if (shopByUserId.getData() != null) {
@@ -991,15 +1159,51 @@
    @GetMapping("/statistics")
    @ApiOperation(value = "用户统计", tags = {"管理后台-首页统计-用户统计"})
    public R<UserStatistics> statistics() {
        Long userid = tokenService.getLoginUser().getUserid();
        SysUser data = sysUserClient.getSysUser(userid).getData();
        Integer shopId = null;
        Set<Long> userId = null;
        if(data.getRoleType() == 2){
            shopId = data.getObjectId();
            userId = orderClient.getAppUserByShoppingShop(shopId).getData();
        Long userId = tokenService.getLoginUser().getUserid();
        SysUser data = sysUserClient.getSysUser(userId).getData();
        QueryWrapper<AppUser> queryWrapper = new QueryWrapper<>();
        if (data.getRoleType() == 2) {
            Integer shopId = data.getObjectId();
            List<Order> orders = orderClient.getRedeemedOrdersByShop(shopId).getData();
            List<Long> userIds = orders.stream().map(Order::getAppUserId).collect(Collectors.toList());
            Set<Long> shopServerUser = getShopServerUser(shopId);
            userIds.addAll(shopServerUser);
            if(userIds.size() == 0){
                userIds.add(-1L);
            }
            queryWrapper.in(!CollectionUtils.isEmpty(userIds), "id", userIds); // userIds 不为空时,查询 id 在 userIds 中
        }
        UserStatistics userStatistics = appUserMapper.getUserStatistics(shopId, userId);
        queryWrapper.eq("del_flag", 0);
        queryWrapper.ne("status", 3);
        List<AppUser> appUserList = appUserService.list(queryWrapper);
        Map<Integer, Long> vipIdCountMap = appUserList.stream()
                .collect(Collectors.groupingBy(AppUser::getVipId, Collectors.counting()));
        UserStatistics userStatistics = new UserStatistics();
        userStatistics.setTotalUser(appUserList.size());
        userStatistics.setConsumerUser(vipIdCountMap.getOrDefault(0, 0L).intValue() +
                vipIdCountMap.getOrDefault(1, 0L).intValue() +
                vipIdCountMap.getOrDefault(2, 0L).intValue() +
                vipIdCountMap.getOrDefault(3, 0L).intValue());
        userStatistics.setCommonUser(vipIdCountMap.getOrDefault(1, 0L).intValue());
        userStatistics.setGoldUser(vipIdCountMap.getOrDefault(2, 0L).intValue());
        userStatistics.setDiamondUser(vipIdCountMap.getOrDefault(3, 0L).intValue());
        userStatistics.setEntrepreneurUser(vipIdCountMap.getOrDefault(4, 0L).intValue() +
                vipIdCountMap.getOrDefault(5, 0L).intValue() +
                vipIdCountMap.getOrDefault(6, 0L).intValue() +
                vipIdCountMap.getOrDefault(7, 0L).intValue());
        userStatistics.setProxyUser(vipIdCountMap.getOrDefault(4, 0L).intValue());
        userStatistics.setAgentUser(vipIdCountMap.getOrDefault(5, 0L).intValue());
        userStatistics.setTotalAgentUser(vipIdCountMap.getOrDefault(6, 0L).intValue());
        userStatistics.setPartnerUser(vipIdCountMap.getOrDefault(7, 0L).intValue());
        long shopUserCount = appUserList.stream()
                .filter(appUser -> appUser.getUserType() == 2)
                .count();
        userStatistics.setShopUser((int) shopUserCount);
        return R.ok(userStatistics);
    }
@@ -1011,8 +1215,8 @@
    public R<UserStatisticsDetail> statisticsDetail(@ApiParam(value = "用户id") Long userId) {
        Long userid = tokenService.getLoginUser().getUserid();
        SysUser data = sysUserClient.getSysUser(userid).getData();
        Integer shopId = null;
        Set<Long> userIds = null;
        Integer shopId = 0;
        Set<Long> userIds = new HashSet<>();
        if(null != userId){
            userIds = new HashSet<>();
            userIds.add(userId);
@@ -1021,12 +1225,18 @@
            shopId = data.getObjectId();
            if(null == userId){
                userIds = orderClient.getAppUserByShoppingShop(shopId).getData();
                Set<Long> shopServerUser = getShopServerUser(shopId);
                userIds.addAll(shopServerUser);
            }else{
                userIds = new HashSet<>();
                userIds.add(userId);
            }
        }
        UserStatisticsDetail userStatisticsDetail = appUserMapper.getUserStatisticsDetail(shopId, userIds);
        UserStatisticsDetail userStatisticsDetail = appUserMapper.getUserStatisticsDetail(null, userIds);
        List<Order> orderList = orderClient.getOrderByAppUserIdsAndWriteOffShop(shopId, userIds).getData();
        BigDecimal shopAmount = orderList.stream().map(Order::getPaymentAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
        userStatisticsDetail.setShopAmount(shopAmount);
        return R.ok(userStatisticsDetail);
    }
@@ -1054,7 +1264,7 @@
                        .eq(BalanceChangeRecord::getVipId, i);
                if(sysUser.getRoleType() == 2){
                    Integer objectId = sysUser.getObjectId();
                    List<AppUser> list = appUserService.list(new LambdaQueryWrapper<AppUser>().eq(AppUser::getShopId, objectId).eq(AppUser::getDelFlag, 0).eq(AppUser::getStatus, 1));
                    List<AppUser> list = appUserService.list(new LambdaQueryWrapper<AppUser>().eq(AppUser::getShopId, objectId).eq(AppUser::getDelFlag, 0).ne(AppUser::getStatus, 1));
                    List<Long> appUserIds = list.stream().map(AppUser::getId).collect(Collectors.toList());
                    Set<Long> data = orderClient.getAppUserByShoppingShop(objectId).getData();
                    if(null != data){
@@ -1066,6 +1276,35 @@
                    queryWrapper.in(BalanceChangeRecord::getAppUserId, appUserIds);
                }
                List<BalanceChangeRecord> list = balanceChangeRecordService.list(queryWrapper);
                for (BalanceChangeRecord balanceChangeRecord : list) {
                    balanceChangeRecord.setChangeAmount(balanceChangeRecord.getChangeAmount().multiply(new BigDecimal(balanceChangeRecord.getChangeDirection())));
                }
                LambdaQueryWrapper<BalanceChangeRecordCopy> queryWrapper1 = new LambdaQueryWrapper<BalanceChangeRecordCopy>()
                        .between(BalanceChangeRecordCopy::getCreateTime, date, date.plusDays(1))
                        .eq(BalanceChangeRecordCopy::getChangeType, 4)
                        .eq(BalanceChangeRecordCopy::getVipId, i);
                if(sysUser.getRoleType() == 2){
                    Integer objectId = sysUser.getObjectId();
                    List<AppUser> list1 = appUserService.list(new LambdaQueryWrapper<AppUser>().eq(AppUser::getShopId, objectId).eq(AppUser::getDelFlag, 0).ne(AppUser::getStatus, 1));
                    List<Long> appUserIds = list1.stream().map(AppUser::getId).collect(Collectors.toList());
                    Set<Long> data = orderClient.getAppUserByShoppingShop(objectId).getData();
                    if(null != data){
                        appUserIds.addAll(data);
                    }
                    if(appUserIds.size() == 0){
                        appUserIds.add(-1L);
                    }
                    queryWrapper1.in(BalanceChangeRecordCopy::getAppUserId, appUserIds);
                }
                List<BalanceChangeRecordCopy> list2 = balanceChangeRecordCopyService.list(queryWrapper1);
                for (BalanceChangeRecordCopy balanceChangeRecordCopy : list2) {
                    BalanceChangeRecord balanceChangeRecord = new BalanceChangeRecord();
                    BeanUtils.copyProperties(balanceChangeRecordCopy, balanceChangeRecord);
                    balanceChangeRecord.setChangeAmount(balanceChangeRecord.getChangeAmount().multiply(new BigDecimal(balanceChangeRecord.getChangeDirection())));
                    list.add(balanceChangeRecord);
                }
                BigDecimal reduce = list.stream().map(BalanceChangeRecord::getChangeAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                String dateKey = date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                dailyVipCommissions.computeIfAbsent(dateKey, k -> new HashMap<>())
@@ -1227,7 +1466,11 @@
    public void vipUpgrade(@RequestParam("appUserId") Long appUserId){
        appUserService.vipUpgrade(appUserId);
    }
    @PostMapping("/vipConsumption")
    public void vipConsumption(@RequestParam("appUserId") Long appUserId){
        appUserService.vipConsumption(appUserId);
    }
    
    /**
     * 检查会员降级
@@ -1260,5 +1503,6 @@
                .set(AppUser::getUserType,1));
        return R.ok();
    }
}