From ff3894d916ca2cd9f699ce214233b023930812e7 Mon Sep 17 00:00:00 2001 From: huangyw <1207046171@qq.com> Date: Thu, 21 Nov 2024 18:16:06 +0800 Subject: [PATCH] =?UTF-8?q?release-=20=E9=82=80=E8=AF=B7=E7=A0=81=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E6=98=AF=E8=87=AA=E5=B7=B1=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/constants/ErrorConstants.java | 1 + .../java/com/luoo/user/service/UserInfoService.java | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/luoo_common/src/main/java/constants/ErrorConstants.java b/luoo_common/src/main/java/constants/ErrorConstants.java index 588d783..2f58284 100644 --- a/luoo_common/src/main/java/constants/ErrorConstants.java +++ b/luoo_common/src/main/java/constants/ErrorConstants.java @@ -39,6 +39,7 @@ public class ErrorConstants { public final static String USER_STATUS_ERROR = "用户状态错误"; public final static String USER_NAME_ALREADY_EXISTS = "用户名已存在"; public final static String USER_INVITE_CODE_NOT_EXIST = "邀请码不存在"; + public static final String USER_INVITE_CODE_CANNOT_BE_SELF = "邀请码不能是自己的"; public static final String DEFAULT_ADDRESS_CANNOT_BE_ADDED_AGAIN = "请勿重复添加默认地址!"; // 会员部分 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 e5a7dc5..1c21b53 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 @@ -291,6 +291,10 @@ public class UserInfoService { if (StringUtils.isNotBlank(invitationCode)) { UserInfo userInfoDaoByInvitationCode = userInfoDao.findByInvitationCode(invitationCode); if (null != userInfoDaoByInvitationCode) { + // 不能自己邀请自己 + if (userInfo.getId().equals(userInfoDaoByInvitationCode.getId())) { + throw new BizException(ErrorConstants.USER_INVITE_CODE_CANNOT_BE_SELF); + } // 设置邀请人 userInfo.setInvitationUserId(userInfoDaoByInvitationCode.getId()); this.update(userInfo); @@ -926,10 +930,11 @@ public class UserInfoService { return invitationCode; } - /** - * 邀请码改为: 第一第二位是大写英文,后面四位数字 - * @return 邀请码 - */ + /** + * 邀请码改为: 第一第二位是大写英文,后面四位数字 + * + * @return 邀请码 + */ private static String generateUniqueInvitationCode() { String firstTwoChars = RandomStringUtils.random(2, true, false).toUpperCase(); String lastFourChars = RandomStringUtils.randomNumeric(4);