release- 拉新逻辑

release-2024-08-08
huangyawei 4 months ago
parent 9e7f41f5c0
commit 8ba3025ddf

@ -34,7 +34,7 @@ public class TaskPointIdConstants {
public static final String DAILY_SIGN = "11";
// 分享期刊
public static final String SHARE_JOURNAL = "12";
// 新用户邀请 todo
// 新用户邀请
public static final String NEW_USER_INVITE = "13";
// 每日评论
public static final String DAILY_COMMENT = "14";
@ -47,13 +47,13 @@ public class TaskPointIdConstants {
public static final String DAILY_SIGN_7 = "17";
// 连续签到30天
public static final String DAILY_SIGN_30 = "18";
// 邀请用户3人 todo
// 邀请用户3人
public static final String INVITE_USER_3 = "19";
// 邀请用户6人 todo
// 邀请用户6人
public static final String INVITE_USER_6 = "20";
// 邀请用户10人 todo
// 邀请用户10人
public static final String INVITE_USER_10 = "21";
// 邀请用户20人 todo
// 邀请用户20人
public static final String INVITE_USER_20 = "22";

@ -144,7 +144,7 @@ public class LoginController extends BaseController {
loginUserInfo.setLastUseDeviceId(loginReq.getDeviceId());
loginUserInfo.setLastUseDeviceBrand(loginReq.getDeviceBrand());
loginUserInfo.setLastLoginIp(getIpAddr(request));
String token = userInfoService.loginOrRegister(loginUserInfo);
String token = userInfoService.loginOrRegisterWithInvite(loginUserInfo, loginReq);
redisTemplate.delete(redisMobileCheckCodeKey);
return Result.success(token);
}

@ -699,5 +699,12 @@ public class MyController extends BaseController {
return Result.success(userInfoService.withdrawPageResult(authorization, pageNum, pageSize));
}
@ApiOperation(value = "18 用户生成邀请码")
@PostMapping("/invitation/code")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<String> createInvitationCode(@ApiParam(value = "用户token", required = true) @RequestHeader(value = "Authorization", required = true) String authorization) {
return Result.success(userInfoService.createInvitationCode(authorization));
}
}

@ -48,4 +48,6 @@ public interface UserInfoDao extends JpaRepository<UserInfo, String>, JpaSpecifi
public Integer countByUserNameAndUserNameNotNull(String userName);
public List<UserInfo> findAllByIsAuthor(int isAuthor);
public UserInfo findByInvitationCode(String invitationCode);
}

@ -21,4 +21,6 @@ public interface UserPointLogDao extends JpaRepository<UserPointLog, String>, Jp
@Query(value = "select * from tb_user_point_log where user_id = ?1 and task_point_id = ?2 and Date(create_time) BETWEEN DATE_SUB(CURDATE(), INTERVAL ?3 DAY) AND DATE_SUB(CURDATE(), INTERVAL 1 DAY)", nativeQuery = true)
public List<UserPointLog> findDaysByUserIdAndTaskPointId(String userId, String pointId, Integer days);
public List<UserPointLog> findUserPointLogsByUserIdAndTaskPointId(String userId, String taskPointId);
}

@ -31,4 +31,7 @@ public class LoginReq implements Serializable {
@ApiModelProperty(name = "deviceBrand", value = "设备品牌", required = false)
String deviceBrand;
@ApiModelProperty(name = "invitationCode", value = "邀请码", required = false)
String invitationCode;
}

@ -212,5 +212,15 @@ public class UserInfo implements Serializable {
*/
private Integer isAuthor;
/**
*
*/
private String invitationCode;
/**
*
*/
private String invitationUserId;
}

@ -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;
}
}

@ -111,6 +111,22 @@ public class UserPointLogService {
addByTask(taskPointId, userLoginDto);
}
/**
* 使userId
*
*/
public void addByTaskDailyAndUserId(String taskPointId, String userId) {
UserPointLog userPointLog = UserPointLog.builder()
.id(String.valueOf(idWorker.nextId()))
.type(PointEnums.TASK_POINT_TYPE_ADD.getCode())
.createUser(userId)
.taskPointId(taskPointId)
.userId(userId)
.build();
rabbitTemplate.convertAndSend("pointLog", userPointLog);
}
private void addByTask(String taskPointId, UserLoginDto userLoginDto) {
UserPointLog userPointLog = UserPointLog.builder()

@ -1,2 +1,9 @@
alter table tb_lottery
add draw_time datetime null comment '开奖时间' after apply_end_time;
alter table tb_user_info
add invitation_code varchar(20) null comment '邀请码';
alter table tb_user_info
add invitation_user_id varchar(20) null comment '邀请人';

Loading…
Cancel
Save