diff --git a/src/main/java/com/greenorange/promotion/controller/userInfo/UserMainInfoController.java b/src/main/java/com/greenorange/promotion/controller/userInfo/UserMainInfoController.java index 40b60e7..0fb61a3 100644 --- a/src/main/java/com/greenorange/promotion/controller/userInfo/UserMainInfoController.java +++ b/src/main/java/com/greenorange/promotion/controller/userInfo/UserMainInfoController.java @@ -31,6 +31,7 @@ import jakarta.validation.Valid; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -81,6 +82,7 @@ public class UserMainInfoController { userMainInfoMap.put(userMainInfo.getUserId(), userMainInfo); } List userMemberInfoVOList = new ArrayList<>(); + BigDecimal totalEarnings = BigDecimal.ZERO; for (UserInfo userInfo : userInfoList) { Long id = userInfo.getId(); UserInfo userInformation = userInfoMap.get(id); @@ -94,14 +96,17 @@ public class UserMainInfoController { .registerTime(userInformation.getCreateTime()) .build(); userMemberInfoVOList.add(userMemberInfoVO); + totalEarnings = totalEarnings.add(userMainInfo.getParentEarnings()); } UserInfo userInfo = userInfoService.getById(userId); UserTeamInfoVO userTeamInfoVO = commonService.copyProperties(userInfo, UserTeamInfoVO.class); userTeamInfoVO.setDirectAgentSize(userInfoList.size()); + userTeamInfoVO.setTeamEarnings(totalEarnings); LambdaQueryWrapper userMainInfoLambdaQueryWrapper = new LambdaQueryWrapper<>(); userMainInfoLambdaQueryWrapper.eq(UserMainInfo::getUserId, userId); UserMainInfo userMainInfo = userMainInfoService.getOne(userMainInfoLambdaQueryWrapper); + userTeamInfoVO.setTeamSize(userMainInfo.getTeamSize()); userTeamInfoVO.setInviteQrCode(userMainInfo.getInviteQrCode()); userTeamInfoVO.setUserMemberInfoVOList(userMemberInfoVOList); diff --git a/src/main/java/com/greenorange/promotion/service/userInfo/impl/UserInfoServiceImpl.java b/src/main/java/com/greenorange/promotion/service/userInfo/impl/UserInfoServiceImpl.java index 458e5fe..a1c25ad 100644 --- a/src/main/java/com/greenorange/promotion/service/userInfo/impl/UserInfoServiceImpl.java +++ b/src/main/java/com/greenorange/promotion/service/userInfo/impl/UserInfoServiceImpl.java @@ -142,11 +142,10 @@ public class UserInfoServiceImpl extends ServiceImpl String invitationCode = userInfoRegisterRequest.getInvitationCode(); LambdaQueryWrapper invitedLambdaQueryWrapper = new LambdaQueryWrapper<>(); - invitedLambdaQueryWrapper.eq(UserInfo::getInvitationCode, invitationCode); + invitedLambdaQueryWrapper.eq(UserInfo::getInvitationCode, invitationCode).eq(UserInfo::getUserRole, UserConstant.DEFAULT_ROLE); UserInfo parentUserInfo = this.getOne(invitedLambdaQueryWrapper); ThrowUtils.throwIf(parentUserInfo == null, ErrorCode.OPERATION_ERROR, "邀请码错误"); - UserInfo myUserInfo = commonService.copyProperties(userInfoRegisterRequest, UserInfo.class); // 判断当前用户是否是根节点 List userInfoList = commonService.findByFieldEqTargetField(UserInfo::getUserRole, UserConstant.DEFAULT_ROLE, this); @@ -160,6 +159,14 @@ public class UserInfoServiceImpl extends ServiceImpl UserMainInfo userMainInfo = new UserMainInfo(); userMainInfo.setUserId(myUserInfo.getId()); + // 批量更新父级用户团队人数 + List pathToRoot = this.findPathToRoot(myUserInfo.getId()); + List userMainInfoList = commonService.findByFieldInTargetField(pathToRoot, userMainInfoService, id -> id, UserMainInfo::getUserId); + for (UserMainInfo mainInfo : userMainInfoList) { + mainInfo.setTeamSize(mainInfo.getTeamSize() + 1); + } + userMainInfoService.updateBatchById(userMainInfoList); + // 生成邀请二维码 try { String view = wechatGetQrcodeService.getWxQrCode(myUserInfo.getInvitationCode()); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index ad9a171..a17ec4c 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,4 +1,4 @@ spring: profiles: - active: dev + active: test