diff --git a/luoo_common/src/main/java/constants/ErrorConstants.java b/luoo_common/src/main/java/constants/ErrorConstants.java index 6001b96..d4bf5a6 100644 --- a/luoo_common/src/main/java/constants/ErrorConstants.java +++ b/luoo_common/src/main/java/constants/ErrorConstants.java @@ -38,6 +38,7 @@ public class ErrorConstants { public final static String USER_ALREADY_EXISTS_ARTIST = "用户已发起过音乐人审核"; 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 MEMBERSHIP_CODE_NOT_EXISTS = "会员码不存在"; 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 4493852..284d092 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 @@ -18,8 +18,10 @@ import com.luoo.user.pojo.*; import com.luoo.user.service.*; import com.luoo.user.util.EmojiConverterUtil; import com.luoo.user.util.IpUtil; +import com.luoo.user.vo.userinfo.UserInfoForInviteVO; import com.luoo.user.vo.userinfo.UserinfoShippingAddressAppVO; import constants.Constants; +import constants.ErrorConstants; import constants.TaskPointIdConstants; import controller.BaseController; import dto.UserLoginDto; @@ -132,6 +134,17 @@ public class MyController extends BaseController { return Result.success(userRespDTO); } + @ApiOperation(value = "1.1 根据邀请码获取用户部分信息", notes = "无认证") + @GetMapping("/userInfo/invite") + public Result getUserInfoForInvite(String inviteCode) { + UserInfo userInfoByInvitationCode = userInfoService.getUserInfoByInvitationCode(inviteCode); + if(userInfoByInvitationCode != null) { + return Result.success(new UserInfoForInviteVO(userInfoByInvitationCode.getNickName(), userInfoByInvitationCode.getAvatar(), inviteCode)); + } else { + return Result.failed(ErrorConstants.USER_INVITE_CODE_NOT_EXIST); + } + } + @ApiOperation(value = "2.更新个人信息", notes = "游客无法编辑个人信息") @PutMapping("/userInfo") @GlobalInterceptor(checkAppUserLogin = true) 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 333be9c..28d154b 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 @@ -82,10 +82,10 @@ public class UserInfoService { private final UserPointLogDao userPointLogDao; public UserInfoService(UserInfoDao userInfoDao, IdWorker idWorker, RedisTemplate redisTemplate, - RabbitTemplate rabbitTemplate, BCryptPasswordEncoder encoder, HttpServletRequest request, - JwtUtil jwtUtil, UserRealNameDao userRealNameDao, UserBankDao userBankDao, - WithdrawDao withdrawDao, UserPointLogService userPointLogService, - UserPointLogDao userPointLogDao) { + RabbitTemplate rabbitTemplate, BCryptPasswordEncoder encoder, HttpServletRequest request, + JwtUtil jwtUtil, UserRealNameDao userRealNameDao, UserBankDao userBankDao, + WithdrawDao withdrawDao, UserPointLogService userPointLogService, + UserPointLogDao userPointLogDao) { this.userInfoDao = userInfoDao; this.idWorker = idWorker; this.redisTemplate = redisTemplate; @@ -233,8 +233,8 @@ public class UserInfoService { * 注册判断是否有邀请码 * * @param loginUserInfo 登录用户 - * @param loginReq 邀请码 - * @return token + * @param loginReq 邀请码 + * @return token */ public String loginOrRegisterWithInvite(UserInfo loginUserInfo, LoginReq loginReq) { UserInfo userInfo = userInfoDao.findByMobile(loginUserInfo.getMobile()); @@ -269,7 +269,7 @@ public class UserInfoService { userInfoDao.save(userInfo); String token = Constants.TOKEN_PREFIX + jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar()); - if(isNewUser) { + if (isNewUser) { // 只有新用户会获得积分 userPointLogService.addByTaskNew(TaskPointIdConstants.NEW_USER_WELCOME_AWARD, token); } @@ -279,7 +279,7 @@ public class UserInfoService { /** * 绑定邀请人 * - * @param userInfo 用户 + * @param userInfo 用户 * @param invitationCode 邀请码 */ @Transactional(rollbackFor = Exception.class) @@ -343,7 +343,7 @@ public class UserInfoService { String token = Constants.TOKEN_PREFIX + jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar()); - if(isNewUser) { + if (isNewUser) { // 只有新用户会获得积分 userPointLogService.addByTaskNew(TaskPointIdConstants.NEW_USER_WELCOME_AWARD, token); } @@ -383,7 +383,7 @@ public class UserInfoService { userInfoDao.save(userInfo); String token = Constants.TOKEN_PREFIX + jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar()); - if(isNewUser) { + if (isNewUser) { // 只有新用户会获得积分 userPointLogService.addByTaskNew(TaskPointIdConstants.NEW_USER_WELCOME_AWARD, token); } @@ -469,7 +469,7 @@ public class UserInfoService { userInfoDao.save(userInfo); String token = Constants.TOKEN_PREFIX + jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar()); - if(isNewUser) { + if (isNewUser) { // 只有新用户会获得积分 userPointLogService.addByTaskNew(TaskPointIdConstants.NEW_USER_WELCOME_AWARD, token); } @@ -804,9 +804,9 @@ public class UserInfoService { /** * 分页查询用户的提现记录 * - * @param token 登录token - * @param page 页码 - * @param size 每页数量 + * @param token 登录token + * @param page 页码 + * @param size 每页数量 * @return 列表 */ public PageResult withdrawPageResult(String token, Integer page, Integer size) { @@ -820,7 +820,7 @@ public class UserInfoService { long totalElements = withdrawPage.getTotalElements(); List content = withdrawPage.getContent(); for (Withdraw withdraw : content) { - if(withdraw.getState() != null) { + if (withdraw.getState() != null) { withdraw.setStateStr(Objects.requireNonNull(WithdrawStateEnum.getByCode(withdraw.getState())).getDesc()); } } @@ -843,21 +843,21 @@ public class UserInfoService { /** * 确定身份以及判断是否二维码过期等 * - * @param userId 用户id - * @param token 二维码uuid - * @param type 类型,1-扫码 2-确认 - * @return token + * @param userId 用户id + * @param token 二维码uuid + * @param type 类型,1-扫码 2-确认 + * @return token */ public void scan(String userId, String token, Integer type) throws Exception { Object o = redisTemplate.opsForValue().get(token); if (o == null) { throw new BizException("二维码失效!"); } - if(!String.valueOf(o).equals("0") && !String.valueOf(o).equals("1")) { + if (!String.valueOf(o).equals("0") && !String.valueOf(o).equals("1")) { throw new BizException("登录认证已完成"); } - if(type == 1) { + if (type == 1) { // 扫码 redisTemplate.opsForValue().set(token, 1, 60, TimeUnit.SECONDS); } else { @@ -884,7 +884,7 @@ public class UserInfoService { public String createInvitationCode(String token) { UserLoginDto user = jwtUtil.getUserLoginDto(token); UserInfo byId = userInfoDao.getById(user.getUserId()); - if(StringUtils.isNotBlank(byId.getInvitationCode())) { + if (StringUtils.isNotBlank(byId.getInvitationCode())) { return byId.getInvitationCode(); } @@ -907,4 +907,14 @@ public class UserInfoService { public List getExpireVipList() { return userInfoDao.getExpireVipList(); } + + /** + * 根据邀请码查询用户信息 + * + * @param invitationCode 邀请码 + * @return 用户信息 + */ + public UserInfo getUserInfoByInvitationCode(String invitationCode) { + return userInfoDao.findByInvitationCode(invitationCode); + } } diff --git a/luoo_user/src/main/java/com/luoo/user/vo/userinfo/UserInfoForInviteVO.java b/luoo_user/src/main/java/com/luoo/user/vo/userinfo/UserInfoForInviteVO.java new file mode 100644 index 0000000..be902cc --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/vo/userinfo/UserInfoForInviteVO.java @@ -0,0 +1,31 @@ +package com.luoo.user.vo.userinfo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * @program: luoo_parent + * @description: 邀请h5展示的对象信息 + * @author: yawei.huang + * @create: 2024-10-10 08:14 + **/ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class UserInfoForInviteVO implements Serializable { + + private static final long serialVersionUID = -3383281434773850094L; + + @ApiModelProperty(value = "用户昵称") + private String nickName; + + @ApiModelProperty(value = "用户头像") + private String avatar; + + @ApiModelProperty(value = "邀请码") + private String inviteCode; +}