支持管理账号手机号选填
This commit is contained in:
+1
-4
@@ -260,7 +260,7 @@ public class AdminManagerController {
|
||||
dto.setShopId(managedShopId);
|
||||
dto.setShopIds(List.of(managedShopId));
|
||||
}
|
||||
if (!StringUtils.hasText(dto.getWechatId())) {
|
||||
if (!StringUtils.hasText(dto.getWechatId()) && StringUtils.hasText(dto.getPhone())) {
|
||||
dto.setWechatId(dto.getPhone());
|
||||
}
|
||||
return Result.success(userService.createUser(dto));
|
||||
@@ -418,9 +418,6 @@ public class AdminManagerController {
|
||||
userDTO.setAvatar(dto.getAvatar().trim());
|
||||
}
|
||||
if (dto.getPhone() != null) {
|
||||
if (!StringUtils.hasText(dto.getPhone())) {
|
||||
throw new RuntimeException("登录手机号不能为空");
|
||||
}
|
||||
userDTO.setPhone(dto.getPhone().trim());
|
||||
}
|
||||
if (dto.getContactPhone() != null) {
|
||||
|
||||
+50
-4
@@ -384,9 +384,14 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
|
||||
List<Long> validatedShopIds = resolveValidatedShopIds(userDTO.getShopIds(), userDTO.getShopId());
|
||||
Long validatedShopId = pickPrimaryShopId(validatedShopIds);
|
||||
String validatedPhone = validateUserPhone(userDTO.getPhone(), null, true);
|
||||
String validatedPhone = validateUserPhone(userDTO.getPhone(), null, false);
|
||||
Integer userType = userDTO.getType();
|
||||
String validatedWechatId = UserProfileFieldSupport.normalizeOptionalText(userDTO.getWechatId());
|
||||
String validatedWechatId = normalizeServiceUserWechatId(
|
||||
userType,
|
||||
userDTO.getWechatId(),
|
||||
validatedPhone,
|
||||
validatedAccount
|
||||
);
|
||||
UserProfileFieldSupport.requireWechatIdForServiceUser(userType, validatedWechatId);
|
||||
|
||||
/**
|
||||
@@ -559,8 +564,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
validatePasswordStrength(userDTO.getPassword());
|
||||
userDO.setPassword(passwordEncoder.encode(userDTO.getPassword()));
|
||||
}
|
||||
if (userDTO.getPhone() != null) {
|
||||
userDO.setPhone(validateUserPhone(userDTO.getPhone(), id, true));
|
||||
boolean phoneUpdateRequested = userDTO.getPhone() != null;
|
||||
String validatedPhone = null;
|
||||
if (phoneUpdateRequested) {
|
||||
validatedPhone = validateUserPhone(userDTO.getPhone(), id, false);
|
||||
userDO.setPhone(validatedPhone);
|
||||
}
|
||||
if (userDTO.getContactPhone() != null) {
|
||||
userDO.setContactPhone(UserProfileFieldSupport.normalizeOptionalText(userDTO.getContactPhone()));
|
||||
@@ -594,6 +602,12 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
userDO.setVipId(userDTO.getVipId());
|
||||
}
|
||||
Integer targetUserType = userDO.getType();
|
||||
userDO.setWechatId(normalizeServiceUserWechatId(
|
||||
targetUserType,
|
||||
userDO.getWechatId(),
|
||||
userDO.getPhone(),
|
||||
userDO.getAccount()
|
||||
));
|
||||
UserProfileFieldSupport.requireWechatIdForServiceUser(targetUserType, userDO.getWechatId());
|
||||
List<Long> validatedShopIds = null;
|
||||
boolean shopBindingChanged = userDTO.getShopIds() != null || userDTO.getShopId() != null;
|
||||
@@ -612,6 +626,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
userDO.setUpdateTime(LocalDateTime.now());
|
||||
boolean updated = userMapper.updateById(userDO) > 0;
|
||||
if (updated) {
|
||||
if (phoneUpdateRequested && validatedPhone == null) {
|
||||
clearUserPhone(id);
|
||||
}
|
||||
if (shopBindingChanged) {
|
||||
userShopBindingSupport.syncUserShopBindings(id, validatedShopIds);
|
||||
}
|
||||
@@ -630,6 +647,35 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
return updated;
|
||||
}
|
||||
|
||||
private String normalizeServiceUserWechatId(Integer userType, String wechatId, String phone, String account) {
|
||||
String normalizedWechatId = UserProfileFieldSupport.normalizeOptionalText(wechatId);
|
||||
if (!Integer.valueOf(2).equals(userType) && !Integer.valueOf(3).equals(userType)) {
|
||||
return normalizedWechatId;
|
||||
}
|
||||
if (StringUtils.hasText(normalizedWechatId)) {
|
||||
return normalizedWechatId;
|
||||
}
|
||||
String normalizedPhone = UserProfileFieldSupport.normalizeOptionalText(phone);
|
||||
if (StringUtils.hasText(normalizedPhone)) {
|
||||
return normalizedPhone;
|
||||
}
|
||||
return UserProfileFieldSupport.normalizeOptionalText(account);
|
||||
}
|
||||
|
||||
private void clearUserPhone(Long userId) {
|
||||
int updatedRows = userMapper.update(
|
||||
null,
|
||||
new LambdaUpdateWrapper<UserDO>()
|
||||
.eq(UserDO::getId, userId)
|
||||
.eq(UserDO::getIsDelete, 0)
|
||||
.set(UserDO::getPhone, null)
|
||||
.set(UserDO::getPhoneVerified, 0)
|
||||
);
|
||||
if (updatedRows <= 0) {
|
||||
throw new RuntimeException("手机号清空失败,用户ID:" + userId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
* @param id 用户ID
|
||||
|
||||
Reference in New Issue
Block a user