|
@@ -12,7 +12,9 @@ import com.etotem.cfc.mapper.ChildMapper;
|
|
|
import com.etotem.cfc.mapper.FamilyMapper;
|
|
import com.etotem.cfc.mapper.FamilyMapper;
|
|
|
import com.etotem.cfc.mapper.UserMapper;
|
|
import com.etotem.cfc.mapper.UserMapper;
|
|
|
import com.etotem.cfc.service.VerificationCodeService;
|
|
import com.etotem.cfc.service.VerificationCodeService;
|
|
|
-import com.etotem.cfc.service.WechatService;
|
|
|
|
|
|
|
+import com.etotem.cfc.entity.DistributionRelation;
|
|
|
|
|
+import com.etotem.cfc.service.DistributionService;
|
|
|
|
|
+import com.etotem.cfc.common.Result;
|
|
|
import com.etotem.cfc.service.api.UserServiceInterface;
|
|
import com.etotem.cfc.service.api.UserServiceInterface;
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -43,6 +45,12 @@ private VerificationCodeService verificationCodeService;
|
|
|
@Resource
|
|
@Resource
|
|
|
private WechatService wechatService;
|
|
private WechatService wechatService;
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private DanshopSyncService danshopSyncService;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private DistributionService distributionService;
|
|
|
|
|
+
|
|
|
@Resource
|
|
@Resource
|
|
|
private OnboardingService onboardingService;
|
|
private OnboardingService onboardingService;
|
|
|
|
|
|
|
@@ -1086,22 +1094,58 @@ private WechatService wechatService;
|
|
|
String inviteCode = dto.getInviteCode();
|
|
String inviteCode = dto.getInviteCode();
|
|
|
String role = dto.getRole() != null ? dto.getRole() : "parent";
|
|
String role = dto.getRole() != null ? dto.getRole() : "parent";
|
|
|
String nickname = dto.getNickname() != null ? dto.getNickname() : "用户" + phone.substring(7);
|
|
String nickname = dto.getNickname() != null ? dto.getNickname() : "用户" + phone.substring(7);
|
|
|
-
|
|
|
|
|
- // 查找家庭
|
|
|
|
|
|
|
+
|
|
|
|
|
+ Result<DistributionRelation> distResult = distributionService.findByInviteCode(inviteCode);
|
|
|
|
|
+ if (distResult.getCode() == 200 && distResult.getData() != null) {
|
|
|
|
|
+ Family family = new Family();
|
|
|
|
|
+ family.setName("我的家庭");
|
|
|
|
|
+ family.setInviteCode(generateInviteCode());
|
|
|
|
|
+ family.setCreatedAt(new Date());
|
|
|
|
|
+ family.setUpdatedAt(new Date());
|
|
|
|
|
+ familyMapper.insert(family);
|
|
|
|
|
+
|
|
|
|
|
+ User user = new User();
|
|
|
|
|
+ user.setOpenid("phone:" + phone);
|
|
|
|
|
+ user.setUnionid("");
|
|
|
|
|
+ user.setFamilyId(family.getId());
|
|
|
|
|
+ user.setRole(role);
|
|
|
|
|
+ user.setNickname(nickname);
|
|
|
|
|
+ user.setPhone(phone);
|
|
|
|
|
+ user.setPassword("");
|
|
|
|
|
+ user.setCreatedAt(new Date());
|
|
|
|
|
+ user.setUpdatedAt(new Date());
|
|
|
|
|
+ userMapper.insert(user);
|
|
|
|
|
+
|
|
|
|
|
+ distributionService.registerByInviteCode(inviteCode, user.getId());
|
|
|
|
|
+
|
|
|
|
|
+ String token = jwtConfig.generateToken(user.getId(), user.getRole());
|
|
|
|
|
+
|
|
|
|
|
+ LoginResultDTO result = new LoginResultDTO();
|
|
|
|
|
+ result.setToken(token);
|
|
|
|
|
+ result.setUserId(user.getId());
|
|
|
|
|
+ result.setRole(user.getRole());
|
|
|
|
|
+ result.setRoles(user.getRoles());
|
|
|
|
|
+ result.setFamilyId(user.getFamilyId());
|
|
|
|
|
+ result.setNickname(user.getNickname());
|
|
|
|
|
+ result.setIsNewUser(true);
|
|
|
|
|
+ populateTeacherFields(result, user);
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
Family family = familyMapper.selectOne(new LambdaQueryWrapper<Family>()
|
|
Family family = familyMapper.selectOne(new LambdaQueryWrapper<Family>()
|
|
|
.eq(Family::getInviteCode, inviteCode));
|
|
.eq(Family::getInviteCode, inviteCode));
|
|
|
-
|
|
|
|
|
- User user;
|
|
|
|
|
- boolean isNewUser = false;
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (family == null) {
|
|
if (family == null) {
|
|
|
throw new RuntimeException("邀请码无效");
|
|
throw new RuntimeException("邀请码无效");
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ User user;
|
|
|
|
|
+ boolean isNewUser = false;
|
|
|
|
|
+
|
|
|
// 检查手机号是否已注册
|
|
// 检查手机号是否已注册
|
|
|
User existingUser = userMapper.selectOne(new LambdaQueryWrapper<User>()
|
|
User existingUser = userMapper.selectOne(new LambdaQueryWrapper<User>()
|
|
|
.eq(User::getPhone, phone));
|
|
.eq(User::getPhone, phone));
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (existingUser != null) {
|
|
if (existingUser != null) {
|
|
|
// 管理员不能登录小程序
|
|
// 管理员不能登录小程序
|
|
|
if ("admin".equals(existingUser.getRole())) {
|
|
if ("admin".equals(existingUser.getRole())) {
|
|
@@ -1128,7 +1172,7 @@ private WechatService wechatService;
|
|
|
user.setUpdatedAt(new Date());
|
|
user.setUpdatedAt(new Date());
|
|
|
userMapper.insert(user);
|
|
userMapper.insert(user);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 如果家庭绑定了成长规划师,自动将家庭ID添加到成长规划师的 teacherFamilyIds
|
|
// 如果家庭绑定了成长规划师,自动将家庭ID添加到成长规划师的 teacherFamilyIds
|
|
|
if (family.getTeacherId() != null) {
|
|
if (family.getTeacherId() != null) {
|
|
|
User teacher = userMapper.selectById(family.getTeacherId());
|
|
User teacher = userMapper.selectById(family.getTeacherId());
|
|
@@ -1143,10 +1187,10 @@ private WechatService wechatService;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 生成token
|
|
// 生成token
|
|
|
String token = jwtConfig.generateToken(user.getId(), user.getRole());
|
|
String token = jwtConfig.generateToken(user.getId(), user.getRole());
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
LoginResultDTO result = new LoginResultDTO();
|
|
LoginResultDTO result = new LoginResultDTO();
|
|
|
result.setToken(token);
|
|
result.setToken(token);
|
|
|
result.setUserId(user.getId());
|
|
result.setUserId(user.getId());
|
|
@@ -1156,7 +1200,7 @@ private WechatService wechatService;
|
|
|
result.setNickname(user.getNickname());
|
|
result.setNickname(user.getNickname());
|
|
|
result.setIsNewUser(isNewUser);
|
|
result.setIsNewUser(isNewUser);
|
|
|
populateTeacherFields(result, user);
|
|
populateTeacherFields(result, user);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|