1. add user_market_info
This commit is contained in:
2026-02-05 18:30:40 +08:00
parent 2a73036bc1
commit 23e0017055
5 changed files with 43 additions and 27 deletions

View File

@@ -47,6 +47,7 @@ import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.utils.*; import org.springblade.core.tool.utils.*;
import org.springblade.modules.auth.provider.UserType; import org.springblade.modules.auth.provider.UserType;
import org.springblade.modules.auth.utils.CodeUtil; import org.springblade.modules.auth.utils.CodeUtil;
import org.springblade.modules.market.service.IMarketInfoService;
import org.springblade.modules.resource.utils.AliyunDynpsService; import org.springblade.modules.resource.utils.AliyunDynpsService;
import org.springblade.modules.system.pojo.entity.User; import org.springblade.modules.system.pojo.entity.User;
import org.springblade.modules.system.service.IUserService; import org.springblade.modules.system.service.IUserService;
@@ -69,11 +70,13 @@ public class AppRegisterTokenGranter extends PasswordTokenGranter {
private final IUserService service; private final IUserService service;
private final AliyunDynpsService dynpsService; private final AliyunDynpsService dynpsService;
private final IMarketInfoService marketInfoService;
public AppRegisterTokenGranter(OAuth2ClientService clientService, OAuth2UserService userService, PasswordHandler passwordHandler, IUserService service, AliyunDynpsService dynpsService) { public AppRegisterTokenGranter(OAuth2ClientService clientService, OAuth2UserService userService, PasswordHandler passwordHandler, IUserService service, AliyunDynpsService dynpsService, IMarketInfoService marketInfoService) {
super(clientService, userService, passwordHandler); super(clientService, userService, passwordHandler);
this.service = service; this.service = service;
this.dynpsService = dynpsService; this.dynpsService = dynpsService;
this.marketInfoService = marketInfoService;
} }
@Override @Override
@@ -114,35 +117,28 @@ public class AppRegisterTokenGranter extends PasswordTokenGranter {
if (StringUtil.isBlank(smsCode)) { if (StringUtil.isBlank(smsCode)) {
throw new UserInvalidException("无效验证码"); throw new UserInvalidException("无效验证码");
} }
Boolean verified; User invitor = null;
try {
verified = dynpsService.verifySms(request.getPhone(), smsCode);
} catch (Exception e) {
throw new UserInvalidException(e.getMessage());
}
if (verified) {
if (StringUtil.isNotBlank(invitationCode) && !StringUtil.equals(invitationCode, "0")) { if (StringUtil.isNotBlank(invitationCode) && !StringUtil.equals(invitationCode, "0")) {
if (!CodeUtil.isValidBase36Nullable(invitationCode)) { String invitorCode;
throw new UserInvalidException("无效邀请码"); try {
} invitorCode = String.valueOf(Long.parseLong(new StringBuilder(invitationCode).reverse().toString(), 36));
long invitorId = Long.parseLong(invitationCode, 36); } catch (Exception e) {
User invitor = service.getById(invitorId);
if (invitor != null) {
throw new UserInvalidException("无效邀请码"); throw new UserInvalidException("无效邀请码");
} }
//todo: 邀请人 invitor = service.getByPhone(invitorCode);
} Assert.notNull(invitor, "无效邀请码");
} else {
throw new UserInvalidException("验证码验证失败");
} }
Assert.isTrue(dynpsService.verifySms(request.getPhone(), smsCode), "验证码验证失败");
// 执行用户注册 // 执行用户注册
if (service.registerAppUser(user)) { if (service.registerAppUser(user)) {
if (marketInfoService.initInfo(user, invitor)) {
request.setUsername(user.getAccount()); request.setUsername(user.getAccount());
// 构建oauth2所需用户信息 // 构建oauth2所需用户信息
return super.user(request); return super.user(request);
} }
}
throw new UserInvalidException(ExceptionCode.INVALID_USER.getMessage()); throw new UserInvalidException(ExceptionCode.INVALID_USER.getMessage());
} }

View File

@@ -29,6 +29,7 @@ import org.springblade.modules.market.pojo.entity.MarketInfoEntity;
import org.springblade.modules.market.pojo.vo.MarketInfoVO; import org.springblade.modules.market.pojo.vo.MarketInfoVO;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseService; import org.springblade.core.mp.base.BaseService;
import org.springblade.modules.system.pojo.entity.User;
/** /**
* 用户拓展信息表 服务类 * 用户拓展信息表 服务类
@@ -46,4 +47,5 @@ public interface IMarketInfoService extends BaseService<MarketInfoEntity> {
*/ */
IPage<MarketInfoVO> selectMarketInfoPage(IPage<MarketInfoVO> page, MarketInfoVO marketInfo); IPage<MarketInfoVO> selectMarketInfoPage(IPage<MarketInfoVO> page, MarketInfoVO marketInfo);
boolean initInfo(User user, User invitor);
} }

View File

@@ -29,10 +29,13 @@ import org.springblade.modules.market.pojo.entity.MarketInfoEntity;
import org.springblade.modules.market.pojo.vo.MarketInfoVO; import org.springblade.modules.market.pojo.vo.MarketInfoVO;
import org.springblade.modules.market.mapper.MarketInfoMapper; import org.springblade.modules.market.mapper.MarketInfoMapper;
import org.springblade.modules.market.service.IMarketInfoService; import org.springblade.modules.market.service.IMarketInfoService;
import org.springblade.modules.system.pojo.entity.User;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.mp.base.BaseServiceImpl;
import java.util.Optional;
/** /**
* 用户拓展信息表 服务实现类 * 用户拓展信息表 服务实现类
* *
@@ -47,4 +50,12 @@ public class MarketInfoServiceImpl extends BaseServiceImpl<MarketInfoMapper, Mar
return page.setRecords(baseMapper.selectMarketInfoPage(page, marketInfo)); return page.setRecords(baseMapper.selectMarketInfoPage(page, marketInfo));
} }
@Override
public boolean initInfo(User user, User invitor) {
MarketInfoEntity info = new MarketInfoEntity();
info.setId(user.getId());
Optional.ofNullable(invitor).map(User::getId).ifPresent(info::setPid);
return save(info);
}
} }

View File

@@ -232,7 +232,7 @@ public interface IUserService extends BaseService<User> {
*/ */
boolean registerUser(User user); boolean registerUser(User user);
boolean registerAppUser(User user,User invitor); boolean registerAppUser(User user);
/** /**
* 配置用户平台 * 配置用户平台
* *
@@ -306,4 +306,5 @@ public interface IUserService extends BaseService<User> {
String inviteCode(); String inviteCode();
User getByPhone(String phoneNumber);
} }

View File

@@ -451,7 +451,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implement
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public boolean registerAppUser(User user, User invitor) { public boolean registerAppUser(User user) {
Tenant tenant = SysCache.getTenant(user.getTenantId()); Tenant tenant = SysCache.getTenant(user.getTenantId());
if (tenant == null || tenant.getId() == null) { if (tenant == null || tenant.getId() == null) {
throw new OAuth2Exception("租户信息错误!"); throw new OAuth2Exception("租户信息错误!");
@@ -611,6 +611,12 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implement
@Override @Override
public String inviteCode() { public String inviteCode() {
return Long.toString(Long.parseLong(AuthUtil.getUserAccount()), 36).toUpperCase(); String upperCaseCode = Long.toString(Long.parseLong(AuthUtil.getUserAccount()), 36).toUpperCase();
return new StringBuilder(upperCaseCode).reverse().toString();
}
@Override
public User getByPhone(String phoneNumber) {
return getOne(Wrappers.<User>lambdaQuery().eq(User::getAccount, phoneNumber).eq(User::getIsDeleted, 0).eq(User::getStatus, 1));
} }
} }