用户邀请码

邀请注册送湖分
This commit is contained in:
wuchunlei
2024-11-08 16:48:21 +08:00
parent a77ec18e38
commit c41fda16d8
12 changed files with 330 additions and 6 deletions

View File

@@ -15,10 +15,8 @@ import com.peanut.common.utils.MD5Utils;
import com.peanut.common.utils.MailUtil;
import com.peanut.modules.book.service.*;
import com.peanut.modules.book.to.PageIdDto;
import com.peanut.modules.common.entity.BookBuyConfigEntity;
import com.peanut.modules.common.entity.BookEntity;
import com.peanut.modules.common.entity.MyUserEntity;
import com.peanut.modules.common.entity.TransactionDetailsEntity;
import com.peanut.modules.common.entity.*;
import com.peanut.modules.common.service.UserInviteRegisterService;
import com.peanut.modules.sys.service.SysUserTokenService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -58,6 +56,8 @@ public class MyUserController {
private BookService bookService;
@Autowired
private TransactionDetailsService transactionDetailsService;
@Autowired
private UserInviteRegisterService inviteRegisterService;
/**
* 列表
@@ -79,7 +79,11 @@ public class MyUserController {
public R getUserList(@RequestBody PageIdDto p){
LambdaQueryWrapper<MyUserEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.and(p.getKey()!="",k->k.like(MyUserEntity::getName,p.getKey()).or().like(MyUserEntity::getTel,p.getKey()).or().like(MyUserEntity::getEmail,p.getKey()));
if (!StringUtils.isEmpty(p.getVipType())){
wrapper.eq(MyUserEntity::getVip,p.getVipType());
}
wrapper.orderByDesc(MyUserEntity::getCreateTime);
Page<MyUserEntity> myUserEntityPage = userService.getBaseMapper().selectPage(new Page<MyUserEntity>(p.getPage(), p.getLimit()), wrapper);
return R.ok().put("user",myUserEntityPage);
@@ -338,7 +342,8 @@ public class MyUserController {
* 常规注册 / 验证码 登录
*/
@RequestMapping("/registerOrLogin")
public R register(String tel, String code) {
@Transactional
public R registerOrLogin(String tel, String code,String inviteCode) {
String redisCode = redisTemplate.opsForValue().get("RegistCode" + tel);
System.out.println(redisCode);
if (StringUtils.isEmpty(redisCode)){
@@ -348,6 +353,15 @@ public class MyUserController {
if (!lcode.equals(code)) {
return R.error(500,"验证码不符!");
}
//校验邀请码
MyUserEntity inviteUser = null;
if (!StringUtils.isEmpty(inviteCode)) {
inviteUser = userService.getOne(new LambdaQueryWrapper<MyUserEntity>()
.eq(MyUserEntity::getInviteCode, inviteCode));
if (inviteUser == null) {
return R.error("邀请码有误");
}
}
//查询是否存在当前用户手机号
LambdaQueryWrapper<MyUserEntity> wrapper = new LambdaQueryWrapper();
if (tel.contains("@")){
@@ -366,7 +380,18 @@ public class MyUserController {
}else {
myUserEntity.setTel(tel);
}
myUserEntity.setInviteCode(inviteRegisterService.generateInviteCode());
userService.save(myUserEntity);
//添加邀请记录
if (!StringUtils.isEmpty(inviteCode)){
myUserEntity.setInviteCode(inviteCode);
userService.updateById(myUserEntity);
UserInviteRegister inviteRegister = new UserInviteRegister();
inviteRegister.setUserId(inviteUser.getId());
inviteRegister.setInvitedUserId(myUserEntity.getId());
inviteRegisterService.save(inviteRegister);
inviteRegisterService.checkInviteRegisterCount(inviteUser.getId());
}
R r = sysUserTokenService.createToken(myUserEntity.getId());
return R.ok("注册成功").put("userInfo",myUserEntity).put("token",r);
}else {