用户邀请码
邀请注册送湖分
This commit is contained in:
@@ -8,14 +8,17 @@ import com.peanut.common.utils.R;
|
||||
import com.peanut.common.utils.ShiroUtils;
|
||||
import com.peanut.modules.common.entity.ClassUser;
|
||||
import com.peanut.modules.common.entity.MyUserEntity;
|
||||
import com.peanut.modules.common.entity.UserInviteRegister;
|
||||
import com.peanut.modules.common.entity.UserVip;
|
||||
import com.peanut.modules.common.service.ClassEntityService;
|
||||
import com.peanut.modules.common.service.MyUserService;
|
||||
import com.peanut.modules.common.service.UserInviteRegisterService;
|
||||
import com.peanut.modules.common.service.UserVipService;
|
||||
import com.peanut.modules.sys.service.SysUserTokenService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
@@ -42,6 +45,8 @@ public class UserController {
|
||||
private SysUserTokenService sysUserTokenService;
|
||||
@Autowired
|
||||
private UserVipService userVipService;
|
||||
@Autowired
|
||||
private UserInviteRegisterService inviteRegisterService;
|
||||
|
||||
/**
|
||||
* 常规注册 发短信验证码
|
||||
@@ -197,7 +202,8 @@ public class UserController {
|
||||
* 验证码注册或登录
|
||||
*/
|
||||
@RequestMapping("/registerOrLogin")
|
||||
public R register(String tel, String code) {
|
||||
@Transactional
|
||||
public R register(String tel, String code,String inviteCode) {
|
||||
String redisCode = redisTemplate.opsForValue().get("RegistCode" + tel);
|
||||
System.out.println(redisCode);
|
||||
if (StringUtils.isEmpty(redisCode)){
|
||||
@@ -207,6 +213,15 @@ public class UserController {
|
||||
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("@")){
|
||||
@@ -224,6 +239,16 @@ public class UserController {
|
||||
myUserEntity.setTel(tel);
|
||||
}
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user