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);