From 7d7d23a3d29aff89e17a5b3bdca21e533e01185d Mon Sep 17 00:00:00 2001
From: xiaowang <2161656029@qq.com>
Date: Mon, 6 Jul 2026 17:35:12 +0800
Subject: [PATCH] =?UTF-8?q?=E6=94=B6=E7=B4=A7=E5=BA=97=E5=8A=A1=E7=AB=AF?=
=?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=A0=81=E7=99=BB=E5=BD=95=E5=87=86=E5=85=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
JY-Artist-Frontend/src/views/AuthView.vue | 4 +-
.../user/controller/front/UserController.java | 5 ++
.../modules/user/service/UserService.java | 8 +++
.../user/service/impl/UserServiceImpl.java | 50 ++++++++++++++++++-
...erServiceImplPermissionAssignmentTest.java | 44 ++++++++++++++++
JY-Salon-Front/src/api/auth-free-paths.ts | 1 +
JY-Salon-Front/src/api/auth.ts | 3 ++
JY-Salon-Front/src/views/LoginView.vue | 15 ++++--
8 files changed, 124 insertions(+), 6 deletions(-)
diff --git a/JY-Artist-Frontend/src/views/AuthView.vue b/JY-Artist-Frontend/src/views/AuthView.vue
index 7f7c68eb..42d371c4 100644
--- a/JY-Artist-Frontend/src/views/AuthView.vue
+++ b/JY-Artist-Frontend/src/views/AuthView.vue
@@ -26,8 +26,8 @@
- 账号密码登录
手机号验证码登录
+ 账号密码登录
@@ -479,7 +479,7 @@ const activeTab = ref<'login' | 'register'>('login')
* Purpose: loginType supports AuthView.vue by holding or executing the login type page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
-const loginType = ref<'password' | 'phone'>('password')
+const loginType = ref<'password' | 'phone'>('phone')
/** loading is a reactive state variable used by the template and event handlers. */
const loading = ref(false)
/** loadingShops is a reactive state variable used by the template and event handlers. */
diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/controller/front/UserController.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/controller/front/UserController.java
index 531d50b8..1921979f 100644
--- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/controller/front/UserController.java
+++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/controller/front/UserController.java
@@ -410,6 +410,11 @@ public class UserController {
return Result.success(userService.getLoginShopSelectionByPhone(phone));
}
+ @GetMapping("/check/manager-login-shops/phone/{phone}")
+ public Result getManagerLoginShopsByPhone(@PathVariable String phone) {
+ return Result.success(userService.getManagerLoginShopSelectionByPhone(phone));
+ }
+
@GetMapping("/check/phone/{phone}")
/**
* Run business method `checkPhoneAvailability`.
diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/service/UserService.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/service/UserService.java
index a8651ecd..f8f20835 100644
--- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/service/UserService.java
+++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/service/UserService.java
@@ -148,6 +148,14 @@ public interface UserService extends IService {
*/
LoginShopSelectionVO getLoginShopSelectionByPhone(String phone);
+ /**
+ * 查询店务端手机号验证码登录可选店铺。
+ *
+ * @param phone 手机号
+ * @return 可登录店铺选择结果
+ */
+ LoginShopSelectionVO getManagerLoginShopSelectionByPhone(String phone);
+
/**
* Load data by the supplied parameter.
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/service/impl/UserServiceImpl.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/service/impl/UserServiceImpl.java
index 395c4300..5aaf2df5 100644
--- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/service/impl/UserServiceImpl.java
+++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/service/impl/UserServiceImpl.java
@@ -956,6 +956,33 @@ public class UserServiceImpl extends ServiceImpl implements
return buildLoginShopSelection(List.of(), false, "当前账号没有可登录的店铺,请联系门店处理");
}
+ @Override
+ public LoginShopSelectionVO getManagerLoginShopSelectionByPhone(String phone) {
+ String normalizedPhone = phone == null ? "" : phone.trim();
+ if (!StringUtils.hasText(normalizedPhone)) {
+ return buildLoginShopSelection(List.of(), false, "请输入手机号后再选择店铺");
+ }
+
+ UserDO userDO = userMapper.selectOne(
+ Wrappers.lambdaQuery(UserDO.class)
+ .eq(UserDO::getPhone, normalizedPhone)
+ .eq(UserDO::getIsDelete, 0)
+ .last("limit 1")
+ );
+ if (userDO == null || !isManagerLoginUser(userDO)) {
+ return buildLoginShopSelection(List.of(), false, "仅店长或美甲师可登录店务端");
+ }
+ if (userDO.getStatus() != null && !Integer.valueOf(1).equals(userDO.getStatus())) {
+ return buildLoginShopSelection(List.of(), false, "该账号已被禁用");
+ }
+
+ List shops = listEnabledShopOptionsForUser(userDO.getId());
+ if (!shops.isEmpty()) {
+ return buildLoginShopSelection(shops, false, buildLoginShopMessage(shops));
+ }
+ return buildLoginShopSelection(List.of(), false, "当前账号没有可登录的店铺,请联系平台管理员");
+ }
+
@Override
/**
* Load data by the supplied parameter.
@@ -1086,6 +1113,9 @@ public class UserServiceImpl extends ServiceImpl implements
);
if (userDO == null) {
+ if (isManagerWebClient(phoneLoginRequestDTO.getClientType())) {
+ throw new RuntimeException("仅店长或美甲师可登录店务端");
+ }
if (phoneLoginRequestDTO.getShopId() == null || phoneLoginRequestDTO.getShopId() == 0) {
/**
* Run business method `RuntimeException`.
@@ -1103,10 +1133,15 @@ public class UserServiceImpl extends ServiceImpl implements
* @return result consumed by the caller or returned to the frontend
*/
assertUserAvailable(userDO);
+ if (isManagerWebClient(phoneLoginRequestDTO.getClientType()) && !isManagerLoginUser(userDO)) {
+ throw new RuntimeException("仅店长或美甲师可登录店务端");
+ }
clearLoginFailureCount(userDO.getAccount());
}
- Long resolvedShopId = resolveUserLoginShopId(userDO, phoneLoginRequestDTO.getShopId());
+ Long resolvedShopId = isManagerWebClient(phoneLoginRequestDTO.getClientType())
+ ? resolveAdminLoginShopId(userDO, phoneLoginRequestDTO.getShopId())
+ : resolveUserLoginShopId(userDO, phoneLoginRequestDTO.getShopId());
return buildLoginResponse(userDO, resolvedShopId, ENCODED_UNSET_PASSWORD.equals(userDO.getPassword()), Boolean.TRUE.equals(phoneLoginRequestDTO.getRememberMe()));
}
@@ -1184,6 +1219,7 @@ public class UserServiceImpl extends ServiceImpl implements
* Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state.
*/
private static final String ENCODED_UNSET_PASSWORD = "$2a$10$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW"; // 加密后的特殊标识
+ private static final String MANAGER_WEB_CLIENT_TYPE = "MANAGER_WEB";
/**
* Run the registration flow.
@@ -1423,6 +1459,18 @@ public class UserServiceImpl extends ServiceImpl implements
return shopId != null && shopId > 0 ? shopId : null;
}
+ private boolean isManagerWebClient(String clientType) {
+ return MANAGER_WEB_CLIENT_TYPE.equalsIgnoreCase(clientType == null ? "" : clientType.trim());
+ }
+
+ private boolean isManagerLoginUser(UserDO userDO) {
+ if (userDO == null) {
+ return false;
+ }
+ Integer userType = userDO.getType();
+ return Integer.valueOf(2).equals(userType) || Integer.valueOf(3).equals(userType);
+ }
+
@Override
/**
* Run the registration flow.
diff --git a/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/user/service/impl/UserServiceImplPermissionAssignmentTest.java b/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/user/service/impl/UserServiceImplPermissionAssignmentTest.java
index 62f4aaad..e8ff18fc 100644
--- a/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/user/service/impl/UserServiceImplPermissionAssignmentTest.java
+++ b/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/user/service/impl/UserServiceImplPermissionAssignmentTest.java
@@ -9,8 +9,10 @@ import com.xiaowang.jayucloud.core.modules.user.mapper.UserMapper;
import com.xiaowang.jayucloud.core.modules.security.mapper.UserPermissionMapper;
import com.xiaowang.jayucloud.core.modules.user.mapper.UserRelationMapper;
import com.xiaowang.jayucloud.core.modules.security.mapper.UserShopRoleMapper;
+import com.xiaowang.jayucloud.core.modules.auth.dto.PhoneLoginRequestDTO;
import com.xiaowang.jayucloud.core.modules.integration.mapper.WechatMiniBindingMapper;
import com.xiaowang.jayucloud.core.modules.auth.dto.RegisterRequestDTO;
+import com.xiaowang.jayucloud.core.modules.auth.vo.LoginShopSelectionVO;
import com.xiaowang.jayucloud.core.modules.security.entity.PermissionDO;
import com.xiaowang.jayucloud.core.modules.user.entity.UserDO;
import com.xiaowang.jayucloud.core.modules.artist.service.NailArtistInfoService;
@@ -40,6 +42,7 @@ import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.doAnswer;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
class UserServiceImplPermissionAssignmentTest {
@@ -183,6 +186,47 @@ class UserServiceImplPermissionAssignmentTest {
verifyNoInteractions(permissionMapper, userPermissionMapper);
}
+ @Test
+ void managerWebPhoneLoginRejectsPlainCustomer() {
+ PhoneLoginRequestDTO request = new PhoneLoginRequestDTO();
+ request.setPhone("13900000002");
+ request.setVerificationCode("123456");
+ request.setClientType("MANAGER_WEB");
+
+ UserDO customer = new UserDO();
+ customer.setId(1002L);
+ customer.setAccount("plaincustomer");
+ customer.setPhone("13900000002");
+ customer.setType(0);
+ customer.setStatus(1);
+ customer.setIsDelete(0);
+
+ when(verificationCodeService.verifyCode("13900000002", "123456")).thenReturn(true);
+ when(userMapper.selectOne(org.mockito.ArgumentMatchers.any())).thenReturn(customer);
+
+ assertThatThrownBy(() -> service.phoneLogin(request))
+ .isInstanceOf(RuntimeException.class)
+ .hasMessageContaining("仅店长或美甲师可登录店务端");
+ }
+
+ @Test
+ void managerLoginShopSelectionRejectsPlainCustomerPhone() {
+ UserDO customer = new UserDO();
+ customer.setId(1003L);
+ customer.setPhone("13900000003");
+ customer.setType(0);
+ customer.setStatus(1);
+ customer.setIsDelete(0);
+
+ when(userMapper.selectOne(org.mockito.ArgumentMatchers.any())).thenReturn(customer);
+
+ LoginShopSelectionVO selection = service.getManagerLoginShopSelectionByPhone("13900000003");
+
+ assertThat(selection.isAllowShoplessLogin()).isFalse();
+ assertThat(selection.getShops()).isEmpty();
+ assertThat(selection.getMessage()).contains("仅店长或美甲师");
+ }
+
@Test
@SuppressWarnings("unchecked")
void exactAccountQueryUsesCaseSensitiveComparison() throws Exception {
diff --git a/JY-Salon-Front/src/api/auth-free-paths.ts b/JY-Salon-Front/src/api/auth-free-paths.ts
index bed18145..72cc119d 100644
--- a/JY-Salon-Front/src/api/auth-free-paths.ts
+++ b/JY-Salon-Front/src/api/auth-free-paths.ts
@@ -2,6 +2,7 @@ const API_AUTH_FREE_PATHS = [
'/user/send-verification-code',
'/user/phone-login',
'/user/check/login-shops/phone/',
+ '/user/check/manager-login-shops/phone/',
'/legal-agreement/current'
]
diff --git a/JY-Salon-Front/src/api/auth.ts b/JY-Salon-Front/src/api/auth.ts
index f9265af0..34f2f0bf 100644
--- a/JY-Salon-Front/src/api/auth.ts
+++ b/JY-Salon-Front/src/api/auth.ts
@@ -50,6 +50,9 @@ export const authApi = {
getPhoneLoginShops(phone: string): Promise {
return api.get(`/user/check/login-shops/phone/${encodeURIComponent(phone)}`)
},
+ getManagerPhoneLoginShops(phone: string): Promise {
+ return api.get(`/user/check/manager-login-shops/phone/${encodeURIComponent(phone)}`)
+ },
getCurrentAgreements(): Promise {
return api.get('/legal-agreement/current')
},
diff --git a/JY-Salon-Front/src/views/LoginView.vue b/JY-Salon-Front/src/views/LoginView.vue
index 518c5487..c1ab38fd 100644
--- a/JY-Salon-Front/src/views/LoginView.vue
+++ b/JY-Salon-Front/src/views/LoginView.vue
@@ -9,8 +9,8 @@
-
+
@@ -117,7 +117,7 @@ const session = useSessionStore()
const toast = useToastStore()
const appIconUrl = `${import.meta.env.BASE_URL}assets/images/app-icon.png`
const preference = readJson(LOGIN_PREFERENCE_KEY, {})
-const loginMode = ref(preference.loginMode || 'password')
+const loginMode = ref(preference.loginMode || 'phone')
const form = reactive({
account: preference.account || '',
password: '',
@@ -213,6 +213,12 @@ const sendLoginCode = async (): Promise => {
}
codeLoading.value = true
try {
+ const selection = await authApi.getManagerPhoneLoginShops(form.phone)
+ const shops = Array.isArray(selection.shops) ? selection.shops : []
+ if (!selection.allowShoplessLogin && shops.length === 0) {
+ toast.error(selection.message || '仅店长或美甲师可登录店务端')
+ return
+ }
await authApi.sendLoginCode(form.phone)
toast.success('验证码已发送')
startCountdown()
@@ -259,8 +265,11 @@ const showLoginError = (error: unknown): void => {
const openShopSelector = async (): Promise => {
const selection = loginMode.value === 'password'
? await authApi.getPasswordLoginShops(form.account)
- : await authApi.getPhoneLoginShops(form.phone)
+ : await authApi.getManagerPhoneLoginShops(form.phone)
const shops = Array.isArray(selection.shops) ? selection.shops : []
+ if (!selection.allowShoplessLogin && shops.length === 0) {
+ throw new Error(selection.message || '仅店长或美甲师可登录店务端')
+ }
if (shops.length <= 1) {
return false
}