@ -4,14 +4,17 @@ import api.PageResult;
import client.vo.SimpleUser ;
import com.luoo.user.dao.UserBankDao ;
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.UserQueryReq ;
import com.luoo.user.dto.UserRealNameCheckDto ;
import com.luoo.user.dto.UserRealNameFormDto ;
import com.luoo.user.dto.bank.UserBankAddDto ;
import com.luoo.user.dto.request.LoginReq ;
import com.luoo.user.pojo.UserBank ;
import com.luoo.user.pojo.UserInfo ;
import com.luoo.user.pojo.UserPointLog ;
import com.luoo.user.pojo.UserRealName ;
import com.luoo.user.pojo.Withdraw ;
import com.luoo.user.util.NickNameUtil ;
@ -78,10 +81,13 @@ public class UserInfoService {
private final UserPointLogService userPointLogService ;
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 ) {
WithdrawDao withdrawDao , UserPointLogService userPointLogService ,
UserPointLogDao userPointLogDao ) {
this . userInfoDao = userInfoDao ;
this . idWorker = idWorker ;
this . redisTemplate = redisTemplate ;
@ -93,6 +99,7 @@ public class UserInfoService {
this . userBankDao = userBankDao ;
this . withdrawDao = withdrawDao ;
this . userPointLogService = userPointLogService ;
this . userPointLogDao = userPointLogDao ;
}
/ * *
@ -224,7 +231,14 @@ public class UserInfoService {
return userInfoDao . countByNickName ( nickName ) ;
}
public String loginOrRegister ( UserInfo loginUserInfo ) {
/ * *
* 注 册 判 断 是 否 有 邀 请 码
*
* @param loginUserInfo 登 录 用 户
* @param loginReq 邀 请 码
* @return token
* /
public String loginOrRegisterWithInvite ( UserInfo loginUserInfo , LoginReq loginReq ) {
UserInfo userInfo = userInfoDao . findByMobile ( loginUserInfo . getMobile ( ) ) ;
boolean isNewUser = false ;
if ( null = = userInfo ) {
@ -256,12 +270,73 @@ 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 < UserPointLog > 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 ( ) ) ;
}
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 ( ) ) ) ;
// userInfo.setNickName("雀乐-" + NickNameUtil.getRandomNickName());
userInfo . setNickName ( NickNameUtil2 . generateRandomString ( ) ) ;
Date curDate = new Date ( ) ;
userInfo . setJoinTime ( curDate ) ;
userInfo . setLastLoginTime ( curDate ) ;
userInfo . setStatus ( UserStatusEnum . ENABLE . getStatus ( ) ) ;
userInfo . setAvatar ( Constants . DEFAULT_USER_AVATAR ) ;
userInfo . setThumbnail ( Constants . DEFAULT_USER_THUMBNAIL ) ;
userInfo . setSignature ( Constants . DEFAULT_USER_SIGNATURE ) ;
isNewUser = true ;
} else {
// userInfo.setAppleId(loginUserInfo.getAppleId());
userInfo . setLastUseDeviceId ( loginUserInfo . getLastUseDeviceId ( ) ) ;
userInfo . setLastUseDeviceBrand ( loginUserInfo . getLastUseDeviceBrand ( ) ) ;
userInfo . setLastLoginIp ( loginUserInfo . getLastLoginIp ( ) ) ;
}
if ( ! UserStatusEnum . ENABLE . getStatus ( ) . equals ( userInfo . getStatus ( ) ) ) {
return null ;
}
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 ( ) ) ;
}
public String appleLoginOrRegister ( UserInfo loginUserInfo ) {
UserInfo userInfo = userInfoDao . findByAppleId ( loginUserInfo . getAppleId ( ) ) ;
@ -778,4 +853,23 @@ public class UserInfoService {
public List < UserInfo > getAuthors ( ) {
return userInfoDao . findAllByIsAuthor ( 1 ) ;
}
@Transactional ( rollbackFor = Exception . class )
public String createInvitationCode ( String token ) {
UserLoginDto user = jwtUtil . getUserLoginDto ( token ) ;
UserInfo byId = userInfoDao . getById ( user . getUserId ( ) ) ;
if ( StringUtils . isNotBlank ( byId . getInvitationCode ( ) ) ) {
return byId . getInvitationCode ( ) ;
}
String invitationCode = RandomStringUtils . randomNumeric ( 6 ) ;
while ( userInfoDao . findByInvitationCode ( invitationCode ) ! = null ) {
invitationCode = RandomStringUtils . randomNumeric ( 6 ) ;
}
byId . setInvitationCode ( invitationCode ) ;
userInfoDao . save ( byId ) ;
return invitationCode ;
}
}