From ed76f62db481ab1a8c125cf01d5122d1e1606266 Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期三, 26 二月 2025 01:25:09 +0800 Subject: [PATCH] 修改分佣逻辑 --- ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java | 115 +++++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 86 insertions(+), 29 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 b4a58f0..e139d0f 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); } @@ -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,23 +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("绑定关系已存在!"); - } + + + +// 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,19 +473,21 @@ 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); // 获取当前用户的所有下级 @@ -497,6 +536,25 @@ } 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) { @@ -825,11 +883,9 @@ 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(id).getData(); + if(null != shop1){ + byId.setShopName(shop1.getName()); } R<List<Shop>> shopByUserId = shopClient.getShopByUserId(id); if (shopByUserId.getData() != null) { @@ -1260,5 +1316,6 @@ .set(AppUser::getUserType,1)); return R.ok(); } + } -- Gitblit v1.7.1