From e8b51a5dbe0626a58196cee72e8eb3bcf64664e8 Mon Sep 17 00:00:00 2001 From: huangyw <1207046171@qq.com> Date: Wed, 24 Jul 2024 16:21:50 +0800 Subject: [PATCH] =?UTF-8?q?release:=20=E6=96=B0=E6=89=8B=E6=AC=A2=E8=BF=8E?= =?UTF-8?q?=E5=A5=96=E5=8A=B1=E7=A7=AF=E5=88=86=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/constants/TaskPointIdConstants.java | 51 ++++++++++++ .../luoo/user/service/UserInfoService.java | 77 ++++++++++++++----- 2 files changed, 108 insertions(+), 20 deletions(-) create mode 100644 luoo_common/src/main/java/constants/TaskPointIdConstants.java diff --git a/luoo_common/src/main/java/constants/TaskPointIdConstants.java b/luoo_common/src/main/java/constants/TaskPointIdConstants.java new file mode 100644 index 0000000..fdc64cf --- /dev/null +++ b/luoo_common/src/main/java/constants/TaskPointIdConstants.java @@ -0,0 +1,51 @@ +package constants; + +/** + * @program: luoo_parent + * @description: 任务积分id固定值 + * @author: yawei.huang + * @create: 2024-07-24 15:50 + **/ +public class TaskPointIdConstants { + + // 新手欢迎奖励 todo + public static final String NEW_USER_WELCOME_AWARD = "1"; + // 修改头像 todo + public static final String MODIFY_AVATAR = "2"; + // 修改昵称 todo + public static final String MODIFY_NICKNAME = "3"; + // 完善个人信息 todo + public static final String COMPLETE_PERSONAL_INFORMATION = "4"; + // 成功关注1位用户 todo + public static final String SUCCESS_FOLLOW_ONE_USER = "5"; + // 首次分享期刊 todo + public static final String FIRST_SHARE_JOURNAL = "6"; + // 首次收藏期刊 todo + public static final String FIRST_COLLECT_JOURNAL = "7"; + // 首次购物成功 todo + public static final String FIRST_SHOPPING_SUCCESS = "8"; + // 首次完成评价 todo + public static final String FIRST_COMPLETE_COMMENT = "9"; + // 开通会员 todo + public static final String OPEN_MEMBER = "10"; + + // 以下不需要校验是否已做过 + // 每日登录 todo + public static final String DAILY_LOGIN = "11"; + // 每日签到 todo + public static final String DAILY_SIGN = "12"; + // 分享期刊 todo + public static final String SHARE_JOURNAL = "13"; + // 邀请好友 todo + public static final String INVITE_FRIEND = "14"; + // 好友首次下单成功 todo + public static final String FRIEND_FIRST_ORDER_SUCCESS = "15"; + // 购买天数达标 todo + public static final String BUY_DAYS_REACHED = "16"; + // 积分抽奖 todo + public static final String POINT_LOTTERY = "17"; + // 积分商城 todo + public static final String POINT_SHOP = "18"; + + +} 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 ebb64aa..462bdeb 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 @@ -18,6 +18,7 @@ import com.luoo.user.util.NickNameUtil; import com.luoo.user.util.NickNameUtil2; import constants.Constants; import constants.ErrorConstants; +import constants.TaskPointIdConstants; import dto.UserLoginDto; import enums.UserBankStateEnum; import enums.UserRealNameStateEnum; @@ -55,34 +56,44 @@ import java.util.stream.Collectors; */ @Service public class UserInfoService { - @Autowired - private UserInfoDao userInfoDao; - @Autowired - private IdWorker idWorker; + private final UserInfoDao userInfoDao; - @Autowired - private RedisTemplate redisTemplate; + private final IdWorker idWorker; - @Autowired - private RabbitTemplate rabbitTemplate; + private final RedisTemplate redisTemplate; - @Autowired - private BCryptPasswordEncoder encoder; + private final RabbitTemplate rabbitTemplate; - @Autowired - private HttpServletRequest request; + private final BCryptPasswordEncoder encoder; - @Autowired - private JwtUtil jwtUtil; + private final HttpServletRequest request; - @Autowired - private UserRealNameDao userRealNameDao; + private final JwtUtil jwtUtil; - @Autowired - private UserBankDao userBankDao; + private final UserRealNameDao userRealNameDao; - @Autowired - private WithdrawDao withdrawDao; + private final UserBankDao userBankDao; + + private final WithdrawDao withdrawDao; + + private final UserPointLogService userPointLogService; + + public UserInfoService(UserInfoDao userInfoDao, IdWorker idWorker, RedisTemplate redisTemplate, + RabbitTemplate rabbitTemplate, BCryptPasswordEncoder encoder, HttpServletRequest request, + JwtUtil jwtUtil, UserRealNameDao userRealNameDao, UserBankDao userBankDao, + WithdrawDao withdrawDao, UserPointLogService userPointLogService) { + this.userInfoDao = userInfoDao; + this.idWorker = idWorker; + this.redisTemplate = redisTemplate; + this.rabbitTemplate = rabbitTemplate; + this.encoder = encoder; + this.request = request; + this.jwtUtil = jwtUtil; + this.userRealNameDao = userRealNameDao; + this.userBankDao = userBankDao; + this.withdrawDao = withdrawDao; + this.userPointLogService = userPointLogService; + } /** * token解析示例 @@ -215,6 +226,7 @@ public class UserInfoService { public String loginOrRegister(UserInfo loginUserInfo) { UserInfo userInfo = userInfoDao.findByMobile(loginUserInfo.getMobile()); + boolean isNewUser = false; if (null == userInfo) { userInfo = loginUserInfo; userInfo.setId(String.valueOf(idWorker.nextId())); @@ -228,6 +240,7 @@ public class UserInfoService { userInfo.setThumbnail(Constants.DEFAULT_USER_THUMBNAIL); userInfo.setSignature(Constants.DEFAULT_USER_SIGNATURE); + isNewUser = true; } else { // userInfo.setAppleId(loginUserInfo.getAppleId()); userInfo.setLastUseDeviceId(loginUserInfo.getLastUseDeviceId()); @@ -239,6 +252,12 @@ public class UserInfoService { } userInfo.setLastLoginTime(new Date()); userInfoDao.save(userInfo); + + if(isNewUser) { + // 只有新用户会获得积分 + userPointLogService.addByTaskNew(TaskPointIdConstants.NEW_USER_WELCOME_AWARD, userInfo.getId()); + } + return Constants.TOKEN_PREFIX + jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar()); } @@ -246,6 +265,7 @@ public class UserInfoService { public String appleLoginOrRegister(UserInfo loginUserInfo) { UserInfo userInfo = userInfoDao.findByAppleId(loginUserInfo.getAppleId()); + boolean isNewUser = false; if (null == userInfo) { // return "未注册"; userInfo = loginUserInfo; @@ -259,6 +279,8 @@ public class UserInfoService { userInfo.setAvatar(Constants.DEFAULT_USER_AVATAR); userInfo.setThumbnail(Constants.DEFAULT_USER_THUMBNAIL); userInfo.setSignature(Constants.DEFAULT_USER_SIGNATURE); + + isNewUser = true; } else { userInfo.setLastUseDeviceId(loginUserInfo.getLastUseDeviceId()); userInfo.setLastUseDeviceBrand(loginUserInfo.getLastUseDeviceBrand()); @@ -269,6 +291,11 @@ public class UserInfoService { } userInfo.setLastLoginTime(new Date()); userInfoDao.save(userInfo); + + if(isNewUser) { + // 只有新用户会获得积分 + userPointLogService.addByTaskNew(TaskPointIdConstants.NEW_USER_WELCOME_AWARD, userInfo.getId()); + } return Constants.TOKEN_PREFIX + jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar()); } @@ -318,6 +345,9 @@ public class UserInfoService { public String wechatRegister(UserInfo loginUserInfo) { UserInfo userInfo = userInfoDao.findByMobile(loginUserInfo.getMobile()); + + boolean isNewUser = false; + if (null == userInfo) { userInfo = loginUserInfo; userInfo.setId(String.valueOf(idWorker.nextId())); @@ -330,6 +360,8 @@ public class UserInfoService { userInfo.setAvatar(Constants.DEFAULT_USER_AVATAR); userInfo.setThumbnail(Constants.DEFAULT_USER_THUMBNAIL); userInfo.setSignature(Constants.DEFAULT_USER_SIGNATURE); + + isNewUser = true; } else { userInfo.setLastUseDeviceId(loginUserInfo.getLastUseDeviceId()); userInfo.setLastUseDeviceBrand(loginUserInfo.getLastUseDeviceBrand()); @@ -342,6 +374,11 @@ public class UserInfoService { } userInfo.setLastLoginTime(new Date()); userInfoDao.save(userInfo); + + if(isNewUser) { + // 只有新用户会获得积分 + userPointLogService.addByTaskNew(TaskPointIdConstants.NEW_USER_WELCOME_AWARD, userInfo.getId()); + } return Constants.TOKEN_PREFIX + jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar()); }