From c6ef77b8deb78189f02750e6e185e506f42dedc0 Mon Sep 17 00:00:00 2001 From: huangyw <1207046171@qq.com> Date: Thu, 8 Aug 2024 14:17:31 +0800 Subject: [PATCH] =?UTF-8?q?release:=20=E6=96=B0=E7=94=A8=E6=88=B7=E9=82=80?= =?UTF-8?q?=E8=AF=B7=E8=8E=B7=E5=BE=97=E7=A7=AF=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../luoo/user/controller/MyController.java | 12 ++++ .../com/luoo/user/dto/UserInfoUpdateDto.java | 3 + .../com/luoo/user/dto/request/LoginReq.java | 2 - .../luoo/user/dto/response/UserRespDTO.java | 15 +++++ .../luoo/user/service/UserInfoService.java | 58 +++++++++++-------- 5 files changed, 64 insertions(+), 26 deletions(-) diff --git a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java index ced94e4..e6b0547 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java @@ -109,6 +109,13 @@ public class MyController extends BaseController { userRespDTO.setEnableComment(user.getEnableComment()); userRespDTO.setPoint(user.getPoint()); + String invitationUserId = user.getInvitationUserId(); + if(StringUtils.isNotEmpty(invitationUserId)) { + UserInfo myInvitationUser = userInfoService.findById(invitationUserId); + userRespDTO.setInvitationUserId(myInvitationUser.getId()); + userRespDTO.setInvitationCode(myInvitationUser.getInvitationCode()); + } + if (null != user.getEnableNotice()) { userRespDTO.setEnableNotice(user.getEnableNotice()); } @@ -150,6 +157,11 @@ public class MyController extends BaseController { // 修改了性别 boolean isChangeSex = !Objects.equals(userInfoUpdateDto.getSex(), user.getSex()); + if(StringUtils.isNotBlank(userInfoUpdateDto.getInvitationCode()) && StringUtils.isBlank(user.getInvitationUserId())) { + // 只有没有被邀请过的才会触发,再次修改无效 + userInfoService.bindInvitationCode(user, userInfoUpdateDto.getInvitationCode()); + } + if (!StringTools.isEmpty(nickName)) { user.setNickName(nickName); rabbitTemplate.convertAndSend("userInfoCommentCache", userLoginDto.getUserId()); diff --git a/luoo_user/src/main/java/com/luoo/user/dto/UserInfoUpdateDto.java b/luoo_user/src/main/java/com/luoo/user/dto/UserInfoUpdateDto.java index 639a976..dc93975 100644 --- a/luoo_user/src/main/java/com/luoo/user/dto/UserInfoUpdateDto.java +++ b/luoo_user/src/main/java/com/luoo/user/dto/UserInfoUpdateDto.java @@ -16,4 +16,7 @@ public class UserInfoUpdateDto { private String signature; @ApiModelProperty(value = "生日,格式为: yyyy.MM.dd") private String birthDay; + + @ApiModelProperty(value = "邀请码,填写的邀请码,不是本人的邀请码") + private String invitationCode; } diff --git a/luoo_user/src/main/java/com/luoo/user/dto/request/LoginReq.java b/luoo_user/src/main/java/com/luoo/user/dto/request/LoginReq.java index 0831ae9..9a14606 100644 --- a/luoo_user/src/main/java/com/luoo/user/dto/request/LoginReq.java +++ b/luoo_user/src/main/java/com/luoo/user/dto/request/LoginReq.java @@ -32,6 +32,4 @@ public class LoginReq implements Serializable { @ApiModelProperty(name = "deviceBrand", value = "设备品牌", required = false) String deviceBrand; - @ApiModelProperty(name = "invitationCode", value = "邀请码", required = false) - String invitationCode; } diff --git a/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java b/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java index 8a6e24e..5acfd6d 100644 --- a/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java +++ b/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java @@ -104,4 +104,19 @@ public class UserRespDTO implements Serializable { * 积分 */ private Integer point; + + /** + * 我的邀请人的邀请码 + */ + private String invitationCode; + + /** + * 我的邀请人 + */ + private String invitationUserId; + + /** + * 我的邀请码 + */ + private String myInvitationCode; } diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserInfoService.java b/luoo_user/src/main/java/com/luoo/user/service/UserInfoService.java index 619cc18..ea74db5 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/UserInfoService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/UserInfoService.java @@ -7,6 +7,7 @@ import com.luoo.user.dao.UserInfoDao; import com.luoo.user.dao.UserPointLogDao; import com.luoo.user.dao.UserRealNameDao; import com.luoo.user.dao.WithdrawDao; +import com.luoo.user.dto.UserInfoUpdateDto; import com.luoo.user.dto.UserQueryReq; import com.luoo.user.dto.UserRealNameCheckDto; import com.luoo.user.dto.UserRealNameFormDto; @@ -270,36 +271,45 @@ public class UserInfoService { if(isNewUser) { // 只有新用户会获得积分 userPointLogService.addByTaskNew(TaskPointIdConstants.NEW_USER_WELCOME_AWARD, userInfo.getId()); - - if(StringUtils.isNotBlank(loginReq.getInvitationCode())) { - // 新用户,且存在邀请码 - UserInfo userInfoDaoByInvitationCode = userInfoDao.findByInvitationCode(loginReq.getInvitationCode()); - if(null != userInfoDaoByInvitationCode) { - userInfo.setInvitationUserId(userInfoDaoByInvitationCode.getId()); - userInfo.setInvitationCode(userInfoDaoByInvitationCode.getInvitationCode()); - userInfoDao.save(userInfo); - - // 邀请码有效,且新用户,则给邀请人积分 - userPointLogService.addByTaskNew(TaskPointIdConstants.NEW_USER_INVITE, userInfoDaoByInvitationCode.getId()); - - List list = userPointLogDao.findUserPointLogsByUserIdAndTaskPointId(userInfoDaoByInvitationCode.getId(), TaskPointIdConstants.NEW_USER_INVITE); - if (list.size() == 3) { - userPointLogService.addByTaskDailyAndUserId(TaskPointIdConstants.INVITE_USER_3, userInfoDaoByInvitationCode.getId()); - } else if (list.size() == 6) { - userPointLogService.addByTaskDailyAndUserId(TaskPointIdConstants.INVITE_USER_6, userInfoDaoByInvitationCode.getId()); - } else if (list.size() == 10) { - userPointLogService.addByTaskDailyAndUserId(TaskPointIdConstants.INVITE_USER_10, userInfoDaoByInvitationCode.getId()); - } else if (list.size() == 20) { - userPointLogService.addByTaskDailyAndUserId(TaskPointIdConstants.INVITE_USER_20, userInfoDaoByInvitationCode.getId()); - } - } - } } return Constants.TOKEN_PREFIX + jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar()); } + /** + * 绑定邀请人 + * + * @param userInfo 用户 + * @param invitationCode 邀请码 + */ + @Transactional(rollbackFor = Exception.class) + public void bindInvitationCode(UserInfo userInfo, String invitationCode) { + if (StringUtils.isNotBlank(invitationCode)) { + UserInfo userInfoDaoByInvitationCode = userInfoDao.findByInvitationCode(invitationCode); + if (null != userInfoDaoByInvitationCode) { + // 设置邀请人 + userInfo.setInvitationUserId(userInfoDaoByInvitationCode.getId()); + this.update(userInfo); + // 邀请人与被邀请人同时获取积分 + userPointLogService.addByTaskDailyAndUserId(TaskPointIdConstants.NEW_USER_INVITE, userInfoDaoByInvitationCode.getId()); + userPointLogService.addByTaskDailyAndUserId(TaskPointIdConstants.NEW_USER_INVITE, userInfo.getId()); + } + + List list = userPointLogDao.findUserPointLogsByUserIdAndTaskPointId(userInfoDaoByInvitationCode.getId(), TaskPointIdConstants.NEW_USER_INVITE); + if (list.size() == 3) { + userPointLogService.addByTaskDailyAndUserId(TaskPointIdConstants.INVITE_USER_3, userInfoDaoByInvitationCode.getId()); + } else if (list.size() == 6) { + userPointLogService.addByTaskDailyAndUserId(TaskPointIdConstants.INVITE_USER_6, userInfoDaoByInvitationCode.getId()); + } else if (list.size() == 10) { + userPointLogService.addByTaskDailyAndUserId(TaskPointIdConstants.INVITE_USER_10, userInfoDaoByInvitationCode.getId()); + } else if (list.size() == 20) { + userPointLogService.addByTaskDailyAndUserId(TaskPointIdConstants.INVITE_USER_20, userInfoDaoByInvitationCode.getId()); + } + + } + } + public String loginOrRegister(UserInfo loginUserInfo) { UserInfo userInfo = userInfoDao.findByMobile(loginUserInfo.getMobile()); boolean isNewUser = false;