This commit is contained in:
@@ -55,8 +55,10 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
||||
"/user/reset-password-by-phone",
|
||||
"/legal-agreement/current",
|
||||
"/legal-agreement/current/**",
|
||||
"/legal-agreement/pending",
|
||||
"/api/legal-agreement/current",
|
||||
"/api/legal-agreement/current/**",
|
||||
"/api/legal-agreement/pending",
|
||||
"/product/get/**",
|
||||
"/product/list/**",
|
||||
"/comment/list/product/**",
|
||||
|
||||
+15
-2
@@ -188,10 +188,23 @@ public class AdminManagerController {
|
||||
public Result<CustomerDialVO> dialCustomer(HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
@PathVariable Long customerId,
|
||||
@RequestParam Long orderId) {
|
||||
@RequestParam(required = false) Long appointmentId,
|
||||
@RequestParam(required = false) Long orderId) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
response.setHeader("Cache-Control", "no-store");
|
||||
return Result.success(customerDialService.dial(currentUser, customerId, orderId, request));
|
||||
return Result.success(customerDialService.dial(currentUser, customerId, appointmentId, orderId, request));
|
||||
}
|
||||
|
||||
@PostMapping("/customers/dial")
|
||||
@RequirePermission("user:view")
|
||||
public Result<CustomerDialVO> dialCustomerForGuest(HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
@RequestParam(required = false) Long customerId,
|
||||
@RequestParam(required = false) Long appointmentId,
|
||||
@RequestParam(required = false) Long orderId) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
response.setHeader("Cache-Control", "no-store");
|
||||
return Result.success(customerDialService.dial(currentUser, customerId, appointmentId, orderId, request));
|
||||
}
|
||||
|
||||
@GetMapping("/customers/{id}")
|
||||
|
||||
+15
-4
@@ -15,6 +15,10 @@ import org.springframework.util.StringUtils;
|
||||
@RequiredArgsConstructor
|
||||
public class DirectDialTargetProvider implements DialTargetProvider {
|
||||
|
||||
public static final int NUMBER_UNAVAILABLE_CODE = 422;
|
||||
|
||||
public static final String NUMBER_UNAVAILABLE_BUSINESS_CODE = "DIAL_NUMBER_UNAVAILABLE";
|
||||
|
||||
private final PhoneCrypto phoneCrypto;
|
||||
|
||||
@Override
|
||||
@@ -26,12 +30,22 @@ public class DirectDialTargetProvider implements DialTargetProvider {
|
||||
public DialTarget resolve(UserDO customer, OrderDO order) {
|
||||
String plainPhone = resolvePlainPhone(customer, order);
|
||||
if (!StringUtils.hasText(plainPhone) || plainPhone.contains("*")) {
|
||||
throw new BusinessException(422, "该客户未登记可拨打的手机号");
|
||||
throw new BusinessException(NUMBER_UNAVAILABLE_CODE,
|
||||
"该预约/订单未登记可拨打的手机号(" + NUMBER_UNAVAILABLE_BUSINESS_CODE + ")");
|
||||
}
|
||||
return new DialTarget(DialMode.DIRECT, plainPhone.trim(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 号码来源优先级:订单/预约上的客户手机号快照优先,其次客户档案。
|
||||
*/
|
||||
private String resolvePlainPhone(UserDO customer, OrderDO order) {
|
||||
if (order != null && StringUtils.hasText(order.getCustomerPhoneSnapshot())) {
|
||||
String snapshot = phoneCrypto.decrypt(order.getCustomerPhoneSnapshot());
|
||||
if (StringUtils.hasText(snapshot)) {
|
||||
return snapshot;
|
||||
}
|
||||
}
|
||||
if (customer != null) {
|
||||
if (StringUtils.hasText(customer.getContactPhone())) {
|
||||
String contactPhone = phoneCrypto.decrypt(customer.getContactPhone());
|
||||
@@ -46,9 +60,6 @@ public class DirectDialTargetProvider implements DialTargetProvider {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (order != null && StringUtils.hasText(order.getCustomerPhoneSnapshot())) {
|
||||
return phoneCrypto.decrypt(order.getCustomerPhoneSnapshot());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -10,5 +10,5 @@ import javax.servlet.http.HttpServletRequest;
|
||||
*/
|
||||
public interface CustomerDialService {
|
||||
|
||||
CustomerDialVO dial(UserDO currentUser, Long customerId, Long orderId, HttpServletRequest request);
|
||||
CustomerDialVO dial(UserDO currentUser, Long customerId, Long appointmentId, Long orderId, HttpServletRequest request);
|
||||
}
|
||||
|
||||
+58
-11
@@ -2,6 +2,8 @@ package com.xiaowang.jayucloud.salon.core.modules.privacy.service.impl;
|
||||
|
||||
import com.xiaowang.jayucloud.salon.core.common.BusinessException;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.entity.OrderDO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.entity.OrderItemDO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.mapper.OrderItemMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.mapper.OrderMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.privacy.config.DialProperties;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.privacy.dial.DialTarget;
|
||||
@@ -34,33 +36,56 @@ public class CustomerDialServiceImpl implements CustomerDialService {
|
||||
private final AdminScopeHelper adminScopeHelper;
|
||||
private final UserService userService;
|
||||
private final OrderMapper orderMapper;
|
||||
private final OrderItemMapper orderItemMapper;
|
||||
private final RequestThrottleService requestThrottleService;
|
||||
private final SecurityAuditSupport securityAuditSupport;
|
||||
private final DialProperties dialProperties;
|
||||
private final List<DialTargetProvider> providers;
|
||||
|
||||
@Override
|
||||
public CustomerDialVO dial(UserDO currentUser, Long customerId, Long orderId, HttpServletRequest request) {
|
||||
public CustomerDialVO dial(UserDO currentUser, Long customerId, Long appointmentId, Long orderId, HttpServletRequest request) {
|
||||
adminScopeHelper.requireShopContext(currentUser, "请先选择店铺后再拨号");
|
||||
Long currentShopId = currentUser.getShopId();
|
||||
requestThrottleService.checkCustomerDial(request, currentUser.getId());
|
||||
|
||||
UserDO customer = userService.getById(customerId);
|
||||
if (customer == null || Objects.equals(1, customer.getIsDelete()) || !Objects.equals(0, customer.getType())) {
|
||||
throw new BusinessException(404, "客户不存在");
|
||||
if (customerId == null && appointmentId == null && orderId == null) {
|
||||
throw new BusinessException(400, "请提供预约或订单信息后再拨号(DIAL_TARGET_REQUIRED)");
|
||||
}
|
||||
adminScopeHelper.ensureUserAccessibleInCurrentShop(currentUser, customerId, "无权拨打其他店铺客户");
|
||||
|
||||
OrderDO order = orderMapper.selectById(orderId);
|
||||
if (order == null || Objects.equals(1, order.getIsDelete()) || !Objects.equals(customerId, order.getUserId())) {
|
||||
throw new BusinessException(403, "该客户与订单不匹配,或无权拨打");
|
||||
OrderDO order = null;
|
||||
if (appointmentId != null) {
|
||||
OrderItemDO item = orderItemMapper.selectById(appointmentId);
|
||||
if (item == null || Objects.equals(1, item.getIsDelete())) {
|
||||
throw new BusinessException(404, "预约不存在");
|
||||
}
|
||||
order = orderMapper.selectById(item.getOrderId());
|
||||
if (order == null || Objects.equals(1, order.getIsDelete())) {
|
||||
throw new BusinessException(404, "预约关联订单不存在");
|
||||
}
|
||||
}
|
||||
if (!Objects.equals(currentShopId, order.getShopId())) {
|
||||
throw new BusinessException(403, "无权拨打其他店铺订单客户");
|
||||
if (orderId != null) {
|
||||
if (order != null && !Objects.equals(orderId, order.getId())) {
|
||||
throw new BusinessException(403, "预约与订单不匹配,或无权拨打");
|
||||
}
|
||||
if (order == null) {
|
||||
order = orderMapper.selectById(orderId);
|
||||
if (order == null || Objects.equals(1, order.getIsDelete())) {
|
||||
throw new BusinessException(404, "订单不存在");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (order != null && !Objects.equals(currentShopId, order.getShopId())) {
|
||||
throw new BusinessException(403, "无权拨打其他店铺预约/订单客户");
|
||||
}
|
||||
|
||||
UserDO customer = resolveCustomer(currentUser, customerId, order);
|
||||
Long auditCustomerId = customer == null ? null : customer.getId();
|
||||
|
||||
DialTargetProvider provider = resolveProvider();
|
||||
String reason = "customerId=" + customerId + ";orderId=" + orderId + ";provider=" + provider.providerKey();
|
||||
String reason = "customerId=" + auditCustomerId
|
||||
+ ";appointmentId=" + appointmentId
|
||||
+ ";orderId=" + (order == null ? null : order.getId())
|
||||
+ ";provider=" + provider.providerKey();
|
||||
try {
|
||||
DialTarget target = provider.resolve(customer, order);
|
||||
securityAuditSupport.success(request, AUDIT_ACTION, reason + ";mode=" + target.getMode() + ";result=SUCCESS");
|
||||
@@ -80,6 +105,28 @@ public class CustomerDialServiceImpl implements CustomerDialService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析目标客户:优先使用显式 customerId,其次订单关联客户;散客预约返回 null,不要求客户有账号。
|
||||
*/
|
||||
private UserDO resolveCustomer(UserDO currentUser, Long customerId, OrderDO order) {
|
||||
Long targetCustomerId = customerId;
|
||||
if (targetCustomerId == null && order != null) {
|
||||
targetCustomerId = order.getUserId();
|
||||
}
|
||||
if (targetCustomerId == null) {
|
||||
return null;
|
||||
}
|
||||
if (order != null && !Objects.equals(targetCustomerId, order.getUserId())) {
|
||||
throw new BusinessException(403, "该客户与预约/订单不匹配,或无权拨打");
|
||||
}
|
||||
UserDO customer = userService.getById(targetCustomerId);
|
||||
if (customer == null || Objects.equals(1, customer.getIsDelete()) || !Objects.equals(0, customer.getType())) {
|
||||
throw new BusinessException(404, "客户不存在");
|
||||
}
|
||||
adminScopeHelper.ensureUserAccessibleInCurrentShop(currentUser, targetCustomerId, "无权拨打其他店铺客户");
|
||||
return customer;
|
||||
}
|
||||
|
||||
private DialTargetProvider resolveProvider() {
|
||||
String configured = StringUtils.hasText(dialProperties.getProvider())
|
||||
? dialProperties.getProvider().trim()
|
||||
|
||||
+22
@@ -9,6 +9,7 @@ import com.xiaowang.jayucloud.salon.core.modules.system.service.LegalAgreementSe
|
||||
import com.xiaowang.jayucloud.salon.core.modules.security.service.SecurityAuditLogService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.security.support.AdminScopeHelper;
|
||||
import com.xiaowang.jayucloud.salon.core.support.security.RequestThrottleService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.vo.AgreementPendingVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.vo.LegalAgreementVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.user.vo.UserAgreementConsentVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -68,6 +69,27 @@ public class LegalAgreementController {
|
||||
return Result.success(legalAgreementService.getCurrentAgreement(type));
|
||||
}
|
||||
|
||||
@GetMapping("/pending")
|
||||
/**
|
||||
* Purpose: pending 返回当前协议版本;登录用户额外返回是否已同意新版本。免登录只返回当前版本。
|
||||
*/
|
||||
public Result<AgreementPendingVO> pending(HttpServletRequest request) {
|
||||
requestThrottleService.checkAgreementRead(request, "PENDING");
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
return Result.success(legalAgreementService.getPendingAgreements(userId));
|
||||
}
|
||||
|
||||
@PostMapping("/accept")
|
||||
/**
|
||||
* Purpose: accept 记录登录用户对当前发布协议版本的同意。
|
||||
*/
|
||||
public Result<AgreementPendingVO> accept(HttpServletRequest request,
|
||||
@RequestParam(required = false) String clientType) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
legalAgreementService.acceptCurrentAgreements(userId, clientType, request);
|
||||
return Result.success(legalAgreementService.getPendingAgreements(userId));
|
||||
}
|
||||
|
||||
@GetMapping("/admin/list")
|
||||
@RequirePermission("legal_agreement:manage")
|
||||
/**
|
||||
|
||||
+5
@@ -3,6 +3,7 @@ package com.xiaowang.jayucloud.salon.core.modules.system.service;
|
||||
import com.xiaowang.jayucloud.salon.core.common.dto.AgreementAwareRequest;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.dto.LegalAgreementDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.user.entity.UserDO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.vo.AgreementPendingVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.vo.LegalAgreementVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.user.vo.UserAgreementConsentVO;
|
||||
|
||||
@@ -31,6 +32,10 @@ public interface LegalAgreementService {
|
||||
|
||||
UserAgreementConsentVO getMyConsent(Long userId);
|
||||
|
||||
AgreementPendingVO getPendingAgreements(Long userId);
|
||||
|
||||
void acceptCurrentAgreements(Long userId, String clientType, HttpServletRequest httpRequest);
|
||||
|
||||
void requireAccepted(AgreementAwareRequest request);
|
||||
|
||||
void recordConsent(Long userId, AgreementAwareRequest request, String entry, HttpServletRequest httpRequest);
|
||||
|
||||
+54
@@ -11,6 +11,7 @@ import com.xiaowang.jayucloud.salon.core.modules.system.mapper.LegalAgreementMap
|
||||
import com.xiaowang.jayucloud.salon.core.modules.user.mapper.UserAgreementConsentMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.service.LegalAgreementService;
|
||||
import com.xiaowang.jayucloud.salon.core.support.security.RequestThrottleService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.vo.AgreementPendingVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.vo.LegalAgreementVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.user.vo.UserAgreementConsentVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -20,6 +21,8 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -170,6 +173,57 @@ public class LegalAgreementServiceImpl implements LegalAgreementService {
|
||||
return new UserAgreementConsentVO(versions);
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Purpose: getPendingAgreements 返回当前协议版本与该用户的同意状态;未登录时只返回当前版本。
|
||||
*/
|
||||
public AgreementPendingVO getPendingAgreements(Long userId) {
|
||||
Map<String, String> currentVersions = new LinkedHashMap<>();
|
||||
Map<String, String> acceptedVersions = new LinkedHashMap<>();
|
||||
List<String> pendingTypes = new ArrayList<>();
|
||||
Map<String, String> accepted = userId == null
|
||||
? Collections.emptyMap()
|
||||
: getMyConsent(userId).getConsentVersions();
|
||||
for (String type : List.of(USER_TERMS, PRIVACY_POLICY)) {
|
||||
LegalAgreementDO current = findCurrentAgreement(type);
|
||||
if (current == null) {
|
||||
continue;
|
||||
}
|
||||
currentVersions.put(type, current.getVersion());
|
||||
String acceptedVersion = accepted == null ? null : accepted.get(type);
|
||||
if (StringUtils.hasText(acceptedVersion)) {
|
||||
acceptedVersions.put(type, acceptedVersion);
|
||||
}
|
||||
if (!StringUtils.hasText(acceptedVersion) || !current.getVersion().equals(acceptedVersion)) {
|
||||
pendingTypes.add(type);
|
||||
}
|
||||
}
|
||||
Boolean pending = userId == null ? null : !pendingTypes.isEmpty();
|
||||
return new AgreementPendingVO(pending, currentVersions, acceptedVersions, pendingTypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
/**
|
||||
* Purpose: acceptCurrentAgreements 记录用户对当前发布版本的同意,不依赖客户端上报版本。
|
||||
*/
|
||||
public void acceptCurrentAgreements(Long userId, String clientType, HttpServletRequest httpRequest) {
|
||||
if (userId == null) {
|
||||
throw new RuntimeException("请先登录后再同意协议");
|
||||
}
|
||||
String normalizedClientType = StringUtils.hasText(clientType)
|
||||
? clientType.trim().toUpperCase()
|
||||
: "WEB";
|
||||
String ip = resolveClientIp(httpRequest);
|
||||
for (String type : List.of(USER_TERMS, PRIVACY_POLICY)) {
|
||||
LegalAgreementDO current = findCurrentAgreement(type);
|
||||
if (current == null) {
|
||||
throw new RuntimeException("当前协议未配置,请联系管理员");
|
||||
}
|
||||
upsertConsent(userId, type, current.getVersion(), "agreement-gate", normalizedClientType, ip);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Purpose: requireAccepted supports LegalAgreementServiceImpl.java by holding or executing the require accepted business role.
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package com.xiaowang.jayucloud.salon.core.modules.system.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 协议重新同意状态:未登录时只返回当前版本,登录后额外返回已同意版本与待同意类型。
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class AgreementPendingVO {
|
||||
|
||||
private Boolean pending;
|
||||
|
||||
private Map<String, String> currentVersions;
|
||||
|
||||
private Map<String, String> acceptedVersions;
|
||||
|
||||
private List<String> pendingTypes;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
-- 隐私政策与用户协议新版本发布:停用当前生效版本,并从停用前正文复制新版本
|
||||
-- 版本:2026.11.04-R2
|
||||
-- 说明:正文通过 INSERT ... SELECT 复制 V18 已修订的当前生效文本,不在 SQL 中重复维护长文本;
|
||||
-- V18 已在任一环境执行后不得修改,本文件仅新增版本。
|
||||
|
||||
UPDATE t_legal_agreement
|
||||
SET status = 0, update_time = NOW()
|
||||
WHERE agreement_type IN ('USER_TERMS', 'PRIVACY_POLICY')
|
||||
AND is_delete = 0
|
||||
AND status = 1;
|
||||
|
||||
INSERT INTO t_legal_agreement
|
||||
(id, agreement_type, title, version, content, status, effective_time, create_time, update_time, is_delete)
|
||||
SELECT 313931273555140005, 'USER_TERMS', title, '2026.11.04-R2', content, 1,
|
||||
'2026-11-04 00:00:00', NOW(), NOW(), 0
|
||||
FROM t_legal_agreement
|
||||
WHERE agreement_type = 'USER_TERMS'
|
||||
AND is_delete = 0
|
||||
ORDER BY effective_time DESC, create_time DESC
|
||||
LIMIT 1;
|
||||
|
||||
INSERT INTO t_legal_agreement
|
||||
(id, agreement_type, title, version, content, status, effective_time, create_time, update_time, is_delete)
|
||||
SELECT 313931273555140006, 'PRIVACY_POLICY', title, '2026.11.04-R2', content, 1,
|
||||
'2026-11-04 00:00:00', NOW(), NOW(), 0
|
||||
FROM t_legal_agreement
|
||||
WHERE agreement_type = 'PRIVACY_POLICY'
|
||||
AND is_delete = 0
|
||||
ORDER BY effective_time DESC, create_time DESC
|
||||
LIMIT 1;
|
||||
+93
-10
@@ -2,6 +2,8 @@ package com.xiaowang.jayucloud.salon.core.modules.privacy.service.impl;
|
||||
|
||||
import com.xiaowang.jayucloud.salon.core.common.BusinessException;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.entity.OrderDO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.entity.OrderItemDO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.mapper.OrderItemMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.mapper.OrderMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.privacy.config.DialProperties;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.privacy.dial.DialMode;
|
||||
@@ -26,7 +28,7 @@ import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -38,6 +40,7 @@ class CustomerDialServiceImplTest {
|
||||
@Mock private AdminScopeHelper adminScopeHelper;
|
||||
@Mock private UserService userService;
|
||||
@Mock private OrderMapper orderMapper;
|
||||
@Mock private OrderItemMapper orderItemMapper;
|
||||
@Mock private RequestThrottleService requestThrottleService;
|
||||
@Mock private SecurityAuditSupport securityAuditSupport;
|
||||
@Mock private PhoneCrypto phoneCrypto;
|
||||
@@ -54,7 +57,7 @@ class CustomerDialServiceImplTest {
|
||||
List<DialTargetProvider> providers = List.of(
|
||||
new DirectDialTargetProvider(phoneCrypto),
|
||||
new PlaceholderPrivacyNumberProvider());
|
||||
service = new CustomerDialServiceImpl(adminScopeHelper, userService, orderMapper,
|
||||
service = new CustomerDialServiceImpl(adminScopeHelper, userService, orderMapper, orderItemMapper,
|
||||
requestThrottleService, securityAuditSupport, properties, providers);
|
||||
|
||||
currentUser = new UserDO();
|
||||
@@ -81,7 +84,7 @@ class CustomerDialServiceImplTest {
|
||||
when(userService.getById(100L)).thenReturn(customer);
|
||||
when(orderMapper.selectById(10L)).thenReturn(order);
|
||||
|
||||
CustomerDialVO result = service.dial(currentUser, 100L, 10L, request);
|
||||
CustomerDialVO result = service.dial(currentUser, 100L, null, 10L, request);
|
||||
|
||||
assertEquals(DialMode.DIRECT, result.getMode());
|
||||
assertEquals("13800138000", result.getDialNumber());
|
||||
@@ -90,13 +93,94 @@ class CustomerDialServiceImplTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsOrderOfAnotherShop() {
|
||||
order.setShopId(2L);
|
||||
void guestOrderUsesSnapshotWithoutRequiringCustomerAccount() {
|
||||
order.setUserId(null);
|
||||
order.setCustomerPhoneSnapshot("encrypted-snapshot");
|
||||
when(phoneCrypto.decrypt("encrypted-snapshot")).thenReturn("13900139000");
|
||||
when(orderMapper.selectById(10L)).thenReturn(order);
|
||||
|
||||
CustomerDialVO result = service.dial(currentUser, null, null, 10L, request);
|
||||
|
||||
assertEquals("13900139000", result.getDialNumber());
|
||||
assertEquals(DialMode.DIRECT, result.getMode());
|
||||
verify(securityAuditSupport).success(eq(request), anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void orderSnapshotTakesPriorityOverCustomerProfile() {
|
||||
order.setCustomerPhoneSnapshot("encrypted-snapshot");
|
||||
customer.setPhone("encrypted-customer-phone");
|
||||
when(phoneCrypto.decrypt("encrypted-snapshot")).thenReturn("13900139000");
|
||||
when(userService.getById(100L)).thenReturn(customer);
|
||||
when(orderMapper.selectById(10L)).thenReturn(order);
|
||||
|
||||
CustomerDialVO result = service.dial(currentUser, 100L, null, 10L, request);
|
||||
|
||||
assertEquals("13900139000", result.getDialNumber());
|
||||
}
|
||||
|
||||
@Test
|
||||
void appointmentLocatorResolvesOrderItemThenOrder() {
|
||||
OrderItemDO item = new OrderItemDO();
|
||||
item.setId(5L);
|
||||
item.setOrderId(10L);
|
||||
item.setIsDelete(0);
|
||||
when(orderItemMapper.selectById(5L)).thenReturn(item);
|
||||
when(orderMapper.selectById(10L)).thenReturn(order);
|
||||
when(userService.getById(100L)).thenReturn(customer);
|
||||
customer.setPhone("encrypted-phone");
|
||||
when(phoneCrypto.decrypt("encrypted-phone")).thenReturn("13800138000");
|
||||
|
||||
CustomerDialVO result = service.dial(currentUser, null, 5L, null, request);
|
||||
|
||||
assertEquals("13800138000", result.getDialNumber());
|
||||
verify(securityAuditSupport).success(eq(request), anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsWhenAppointmentAndOrderDoNotMatch() {
|
||||
OrderItemDO item = new OrderItemDO();
|
||||
item.setId(5L);
|
||||
item.setOrderId(10L);
|
||||
item.setIsDelete(0);
|
||||
when(orderItemMapper.selectById(5L)).thenReturn(item);
|
||||
when(orderMapper.selectById(10L)).thenReturn(order);
|
||||
|
||||
BusinessException error = assertThrows(BusinessException.class,
|
||||
() -> service.dial(currentUser, 100L, 10L, request));
|
||||
() -> service.dial(currentUser, null, 5L, 11L, request));
|
||||
|
||||
assertEquals(403, error.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void guestOrderWithoutAnyPhoneReturnsExplicitBusinessCode() {
|
||||
order.setUserId(null);
|
||||
order.setCustomerPhoneSnapshot(null);
|
||||
when(orderMapper.selectById(10L)).thenReturn(order);
|
||||
|
||||
BusinessException error = assertThrows(BusinessException.class,
|
||||
() -> service.dial(currentUser, null, null, 10L, request));
|
||||
|
||||
assertEquals(DirectDialTargetProvider.NUMBER_UNAVAILABLE_CODE, error.getCode());
|
||||
assertTrue(error.getMessage().contains(DirectDialTargetProvider.NUMBER_UNAVAILABLE_BUSINESS_CODE));
|
||||
verify(securityAuditSupport).fail(eq(request), anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsWhenNoLocatorProvided() {
|
||||
BusinessException error = assertThrows(BusinessException.class,
|
||||
() -> service.dial(currentUser, null, null, null, request));
|
||||
|
||||
assertEquals(400, error.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsOrderOfAnotherShop() {
|
||||
order.setShopId(2L);
|
||||
when(orderMapper.selectById(10L)).thenReturn(order);
|
||||
|
||||
BusinessException error = assertThrows(BusinessException.class,
|
||||
() -> service.dial(currentUser, 100L, null, 10L, request));
|
||||
|
||||
assertEquals(403, error.getCode());
|
||||
}
|
||||
@@ -104,18 +188,17 @@ class CustomerDialServiceImplTest {
|
||||
@Test
|
||||
void rejectsOrderThatDoesNotBelongToCustomer() {
|
||||
order.setUserId(101L);
|
||||
when(userService.getById(100L)).thenReturn(customer);
|
||||
when(orderMapper.selectById(10L)).thenReturn(order);
|
||||
|
||||
BusinessException error = assertThrows(BusinessException.class,
|
||||
() -> service.dial(currentUser, 100L, 10L, request));
|
||||
() -> service.dial(currentUser, 100L, null, 10L, request));
|
||||
|
||||
assertEquals(403, error.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void privacyNumberProviderReportsNotConfiguredWithoutFallingBackToRealNumber() {
|
||||
service = new CustomerDialServiceImpl(adminScopeHelper, userService, orderMapper,
|
||||
service = new CustomerDialServiceImpl(adminScopeHelper, userService, orderMapper, orderItemMapper,
|
||||
requestThrottleService, securityAuditSupport, privacyProperties(), List.of(
|
||||
new DirectDialTargetProvider(phoneCrypto),
|
||||
new PlaceholderPrivacyNumberProvider()));
|
||||
@@ -124,7 +207,7 @@ class CustomerDialServiceImplTest {
|
||||
when(orderMapper.selectById(10L)).thenReturn(order);
|
||||
|
||||
BusinessException error = assertThrows(BusinessException.class,
|
||||
() -> service.dial(currentUser, 100L, 10L, request));
|
||||
() -> service.dial(currentUser, 100L, null, 10L, request));
|
||||
|
||||
assertEquals(PlaceholderPrivacyNumberProvider.NOT_CONFIGURED_CODE, error.getCode());
|
||||
verify(securityAuditSupport).fail(eq(request), anyString(), anyString());
|
||||
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
package com.xiaowang.jayucloud.salon.core.modules.system.service.impl;
|
||||
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.entity.LegalAgreementDO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.mapper.LegalAgreementMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.vo.AgreementPendingVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.user.entity.UserAgreementConsentDO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.user.mapper.UserAgreementConsentMapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class LegalAgreementServiceImplTest {
|
||||
|
||||
private static final String CURRENT_VERSION = "2026.11.04-R2";
|
||||
|
||||
@Mock private LegalAgreementMapper agreementMapper;
|
||||
@Mock private UserAgreementConsentMapper consentMapper;
|
||||
@Mock private HttpServletRequest request;
|
||||
|
||||
private LegalAgreementServiceImpl service;
|
||||
private LegalAgreementDO userTerms;
|
||||
private LegalAgreementDO privacyPolicy;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = new LegalAgreementServiceImpl(agreementMapper, consentMapper);
|
||||
userTerms = currentAgreement(LegalAgreementServiceImpl.USER_TERMS);
|
||||
privacyPolicy = currentAgreement(LegalAgreementServiceImpl.PRIVACY_POLICY);
|
||||
}
|
||||
|
||||
@Test
|
||||
void anonymousPendingReturnsCurrentVersionsOnly() {
|
||||
when(agreementMapper.selectOne(any())).thenReturn(userTerms, privacyPolicy);
|
||||
|
||||
AgreementPendingVO result = service.getPendingAgreements(null);
|
||||
|
||||
assertEquals(CURRENT_VERSION, result.getCurrentVersions().get(LegalAgreementServiceImpl.USER_TERMS));
|
||||
assertEquals(CURRENT_VERSION, result.getCurrentVersions().get(LegalAgreementServiceImpl.PRIVACY_POLICY));
|
||||
assertTrue(result.getAcceptedVersions().isEmpty());
|
||||
assertNull(result.getPending());
|
||||
}
|
||||
|
||||
@Test
|
||||
void loggedInUserWithoutConsentIsPending() {
|
||||
when(agreementMapper.selectOne(any())).thenReturn(userTerms, privacyPolicy);
|
||||
when(consentMapper.selectList(any())).thenReturn(new ArrayList<>());
|
||||
|
||||
AgreementPendingVO result = service.getPendingAgreements(8L);
|
||||
|
||||
assertEquals(Boolean.TRUE, result.getPending());
|
||||
assertEquals(List.of(LegalAgreementServiceImpl.USER_TERMS, LegalAgreementServiceImpl.PRIVACY_POLICY),
|
||||
result.getPendingTypes());
|
||||
}
|
||||
|
||||
@Test
|
||||
void oldVersionConsentIsPending() {
|
||||
when(agreementMapper.selectOne(any())).thenReturn(userTerms, privacyPolicy);
|
||||
when(consentMapper.selectList(any())).thenReturn(List.of(
|
||||
consent(LegalAgreementServiceImpl.USER_TERMS, "2026.11.04"),
|
||||
consent(LegalAgreementServiceImpl.PRIVACY_POLICY, "2026.11.04")));
|
||||
|
||||
AgreementPendingVO result = service.getPendingAgreements(8L);
|
||||
|
||||
assertEquals(Boolean.TRUE, result.getPending());
|
||||
assertEquals("2026.11.04", result.getAcceptedVersions().get(LegalAgreementServiceImpl.USER_TERMS));
|
||||
assertEquals(2, result.getPendingTypes().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void acceptedCurrentVersionsAreNotPending() {
|
||||
when(agreementMapper.selectOne(any())).thenReturn(userTerms, privacyPolicy);
|
||||
when(consentMapper.selectList(any())).thenReturn(List.of(
|
||||
consent(LegalAgreementServiceImpl.USER_TERMS, CURRENT_VERSION),
|
||||
consent(LegalAgreementServiceImpl.PRIVACY_POLICY, CURRENT_VERSION)));
|
||||
|
||||
AgreementPendingVO result = service.getPendingAgreements(8L);
|
||||
|
||||
assertEquals(Boolean.FALSE, result.getPending());
|
||||
assertTrue(result.getPendingTypes().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void acceptRecordsBothCurrentVersions() {
|
||||
when(agreementMapper.selectOne(any())).thenReturn(userTerms, privacyPolicy);
|
||||
when(consentMapper.selectOne(any())).thenReturn(null);
|
||||
|
||||
service.acceptCurrentAgreements(8L, "WECHAT_MINI", request);
|
||||
|
||||
ArgumentCaptor<UserAgreementConsentDO> captor = ArgumentCaptor.forClass(UserAgreementConsentDO.class);
|
||||
verify(consentMapper, times(2)).insert(captor.capture());
|
||||
assertEquals(8L, captor.getAllValues().get(0).getUserId());
|
||||
assertEquals(CURRENT_VERSION, captor.getAllValues().get(0).getVersion());
|
||||
assertEquals(CURRENT_VERSION, captor.getAllValues().get(1).getVersion());
|
||||
assertEquals("WECHAT_MINI", captor.getAllValues().get(0).getClientType());
|
||||
assertEquals("agreement-gate", captor.getAllValues().get(0).getEntry());
|
||||
}
|
||||
|
||||
private LegalAgreementDO currentAgreement(String type) {
|
||||
LegalAgreementDO agreement = new LegalAgreementDO();
|
||||
agreement.setAgreementType(type);
|
||||
agreement.setVersion(CURRENT_VERSION);
|
||||
agreement.setStatus(1);
|
||||
agreement.setIsDelete(0);
|
||||
return agreement;
|
||||
}
|
||||
|
||||
private UserAgreementConsentDO consent(String type, String version) {
|
||||
UserAgreementConsentDO consent = new UserAgreementConsentDO();
|
||||
consent.setUserId(8L);
|
||||
consent.setAgreementType(type);
|
||||
consent.setVersion(version);
|
||||
return consent;
|
||||
}
|
||||
}
|
||||
@@ -234,6 +234,13 @@ export const authApi = {
|
||||
}
|
||||
}
|
||||
|
||||
export interface AgreementPending {
|
||||
pending: boolean | null
|
||||
currentVersions: Record<string, string>
|
||||
acceptedVersions: Record<string, string>
|
||||
pendingTypes: string[]
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: legalAgreementApi supports auth.ts by holding or executing the legal agreement api 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.
|
||||
@@ -247,5 +254,13 @@ export const legalAgreementApi = {
|
||||
},
|
||||
getMyConsent: () => {
|
||||
return api.get<{ consentVersions: Record<string, string> }>('/user/agreement-consent/me')
|
||||
},
|
||||
getPending: () => {
|
||||
return api.get<AgreementPending>('/legal-agreement/pending')
|
||||
},
|
||||
accept: (clientType = 'WEB') => {
|
||||
return api.post<AgreementPending>('/legal-agreement/accept', null, {
|
||||
params: { clientType }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import type { IdType } from '@/utils/id'
|
||||
import { clearAdminSessionStorage } from '@/utils/admin-session'
|
||||
import { attachRequestSignature } from '@/utils/request-signature'
|
||||
import { isApiAuthFreePath } from './auth-free-paths'
|
||||
import { isAgreementPending } from '../utils/agreement-gate'
|
||||
import {
|
||||
getApiResponseMessage,
|
||||
isPermissionErrorMessage,
|
||||
@@ -77,6 +78,18 @@ const getStoredAccessToken = (isAdmin = false) => {
|
||||
: (localStorage.getItem('accessToken') || sessionStorage.getItem('accessToken'))
|
||||
}
|
||||
|
||||
/**
|
||||
* 协议门禁接口在后台登录态下也需要使用管理员 token;其余沿用原有 admin 路径判断。
|
||||
*/
|
||||
const isAdminScopedUrl = (url?: string) => {
|
||||
if (!url) return false
|
||||
if (url.includes('/admin/') || url.includes('/order/admin/')) return true
|
||||
const hasAdminToken = Boolean(localStorage.getItem('adminAccessToken') || sessionStorage.getItem('adminAccessToken'))
|
||||
return hasAdminToken && (url.includes('/legal-agreement/pending') || url.includes('/legal-agreement/accept'))
|
||||
}
|
||||
|
||||
const AGREEMENT_GATE_ALLOWLIST = ['/legal-agreement/', '/admin/auth/', '/user/logout', '/user/info']
|
||||
|
||||
/**
|
||||
* Purpose: getStoredRefreshToken supports index.ts by holding or executing the get stored refresh token 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.
|
||||
@@ -238,7 +251,11 @@ const handleTokenExpired = (isAdmin = false, failedToken: string | null = null)
|
||||
|
||||
api.interceptors.request.use(
|
||||
async config => {
|
||||
const isAdminRequest = config.url?.includes('/admin/') || config.url?.includes('/order/admin/')
|
||||
if (isAgreementPending() && !AGREEMENT_GATE_ALLOWLIST.some(path => config.url?.includes(path))) {
|
||||
return Promise.reject(new Error('请先阅读并同意最新版用户协议与隐私政策'))
|
||||
}
|
||||
|
||||
const isAdminRequest = isAdminScopedUrl(config.url)
|
||||
let token = isAdminRequest
|
||||
? (localStorage.getItem('adminAccessToken') || sessionStorage.getItem('adminAccessToken'))
|
||||
: (localStorage.getItem('accessToken') || sessionStorage.getItem('accessToken'))
|
||||
@@ -286,7 +303,7 @@ api.interceptors.response.use(
|
||||
|
||||
if (error.response?.status === 401) {
|
||||
// 检查是否是后台管理的API请求
|
||||
const isAdminRequest = originalRequest.url?.includes('/admin/') || originalRequest.url?.includes('/order/admin/')
|
||||
const isAdminRequest = isAdminScopedUrl(originalRequest.url)
|
||||
const requestToken = getRequestToken(originalRequest)
|
||||
const isRealTokenExpired = isTokenExpiredResponse(error, requestToken)
|
||||
|
||||
|
||||
@@ -278,9 +278,13 @@ export const userApi = {
|
||||
/**
|
||||
* 后台管理员按预约/订单上下文单次取号,号码不入库、不缓存。
|
||||
*/
|
||||
dialCustomer: async (customerId: IdType, orderId: IdType): Promise<CustomerDialResult> => {
|
||||
return await api.post<CustomerDialResult>(`/manager/customers/${customerId}/dial`, null, {
|
||||
params: { orderId }
|
||||
dialCustomer: async (params: { customerId?: IdType; appointmentId?: IdType; orderId?: IdType }): Promise<CustomerDialResult> => {
|
||||
return await api.post<CustomerDialResult>('/manager/customers/dial', null, {
|
||||
params: {
|
||||
customerId: params.customerId || undefined,
|
||||
appointmentId: params.appointmentId || undefined,
|
||||
orderId: params.orderId || undefined
|
||||
}
|
||||
}) as unknown as CustomerDialResult
|
||||
},
|
||||
getUserInfo: async (): Promise<UserVO> => {
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* 协议同意门禁状态:登录后检测到未同意的新版本时置位,
|
||||
* 请求层据此拦截非协议类业务请求,避免用户绕过弹层继续操作。
|
||||
*/
|
||||
let agreementPending = false
|
||||
|
||||
export const setAgreementPending = (value: boolean) => {
|
||||
agreementPending = value
|
||||
}
|
||||
|
||||
export const isAgreementPending = () => agreementPending
|
||||
@@ -68,7 +68,7 @@
|
||||
<span>预约用户:{{ order.customerNickname || '用户' }}</span>
|
||||
<span v-if="order.customerPhoneMasked">联系电话:{{ order.customerPhoneMasked }}</span>
|
||||
<a-button
|
||||
v-if="order.customerPhoneMasked && order.userId"
|
||||
v-if="order.customerPhoneMasked"
|
||||
size="small"
|
||||
type="link"
|
||||
:loading="dialingOrderId === order.id"
|
||||
@@ -667,15 +667,18 @@ const confirmQuote = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** 按订单上下文单次取号后发起拨号,号码不落库、不缓存。 */
|
||||
/** 按订单上下文单次取号后发起拨号,号码不落库、不缓存;散客无 userId 时仅用订单定位。 */
|
||||
const dialCustomer = async (order: any) => {
|
||||
if (!order?.userId || !order?.id) {
|
||||
if (!order?.id) {
|
||||
message.warning('缺少订单上下文,无法取号')
|
||||
return
|
||||
}
|
||||
dialingOrderId.value = order.id
|
||||
try {
|
||||
const result = await userApi.dialCustomer(order.userId, order.id)
|
||||
const result = await userApi.dialCustomer({
|
||||
customerId: order.userId || undefined,
|
||||
orderId: order.id
|
||||
})
|
||||
if (!result?.dialNumber) {
|
||||
throw new Error('未获取到可拨打号码')
|
||||
}
|
||||
|
||||
@@ -70,6 +70,25 @@
|
||||
</a-button>
|
||||
</div>
|
||||
</a-drawer>
|
||||
|
||||
<a-modal
|
||||
v-model:open="agreementModalOpen"
|
||||
title="用户协议与隐私政策已更新"
|
||||
:closable="false"
|
||||
:maskClosable="false"
|
||||
:keyboard="false"
|
||||
:footer="null"
|
||||
>
|
||||
<div class="agreement-gate">
|
||||
<p>新版本{{ agreementVersionText ? `(${agreementVersionText})` : '' }}已发布,请阅读并同意后继续使用后台。</p>
|
||||
<p class="agreement-gate__links">
|
||||
<a href="/legal/user-terms.html" target="_blank" rel="noopener">查看用户协议</a>
|
||||
<span> · </span>
|
||||
<a href="/legal/privacy-policy.html" target="_blank" rel="noopener">查看隐私政策</a>
|
||||
</p>
|
||||
<a-button type="primary" block :loading="agreementAccepting" @click="acceptAgreements">同意并继续</a-button>
|
||||
</div>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -84,6 +103,8 @@ import { DEFAULT_AVATAR } from '@/constants'
|
||||
import { completeAdminLogout } from '@/utils/admin-logout'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
import { useAdminViewport } from '@/composables/useAdminViewport'
|
||||
import { legalAgreementApi, type AgreementPending } from '@/api/auth'
|
||||
import { setAgreementPending } from '@/utils/agreement-gate'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
@@ -92,6 +113,9 @@ const collapsed = ref(false)
|
||||
const mobileDrawerOpen = ref(false)
|
||||
const selectedKeys = ref<string[]>([route.path])
|
||||
const userInfo = ref<any>(null)
|
||||
const agreementModalOpen = ref(false)
|
||||
const agreementAccepting = ref(false)
|
||||
const agreementVersionText = ref('')
|
||||
const iconMap: Record<AdminNavIconKey, Component> = { home: HomeOutlined, user: UserOutlined, shop: HomeOutlined, security: SafetyCertificateOutlined, tool: ToolOutlined, team: TeamOutlined, dashboard: HomeOutlined, gift: HomeOutlined, message: HomeOutlined, tag: HomeOutlined, shopping: HomeOutlined, calendar: HomeOutlined }
|
||||
const menuItems = adminNavigationItems.map(item => ({ key: item.path, label: item.label, icon: iconMap[item.iconKey] }))
|
||||
|
||||
@@ -99,9 +123,43 @@ const handleMenuClick = ({ key }: { key: string | number }) => router.push(Strin
|
||||
const openMobileMenu = ({ key }: { key: string | number }) => { mobileDrawerOpen.value = false; router.push(String(key)) }
|
||||
const handleLogout = () => Modal.confirm({ title: '确认退出登录', content: '退出后需要重新登录后台。', okText: '确认', cancelText: '取消', onOk: async () => { await runWithGlobalLoading(() => completeAdminLogout(router)); message.success('已退出登录') } })
|
||||
|
||||
const checkAgreementGate = async () => {
|
||||
try {
|
||||
const result = await legalAgreementApi.getPending() as unknown as AgreementPending
|
||||
if (result?.pending) {
|
||||
agreementVersionText.value = result.currentVersions?.USER_TERMS || ''
|
||||
setAgreementPending(true)
|
||||
agreementModalOpen.value = true
|
||||
} else {
|
||||
setAgreementPending(false)
|
||||
}
|
||||
} catch (error) {
|
||||
// 查询失败不阻塞后台使用,协议接口仍由服务端登录态校验保护
|
||||
}
|
||||
}
|
||||
|
||||
const acceptAgreements = async () => {
|
||||
if (agreementAccepting.value) return
|
||||
agreementAccepting.value = true
|
||||
try {
|
||||
const result = await legalAgreementApi.accept('WEB') as unknown as AgreementPending
|
||||
if (result?.pending === true) {
|
||||
throw new Error('协议同意状态未更新,请稍后重试')
|
||||
}
|
||||
setAgreementPending(false)
|
||||
agreementModalOpen.value = false
|
||||
message.success('已同意最新版协议')
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '同意协议失败')
|
||||
} finally {
|
||||
agreementAccepting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
watch(() => route.path, path => { selectedKeys.value = [path] }, { immediate: true })
|
||||
onMounted(() => {
|
||||
try { userInfo.value = JSON.parse(localStorage.getItem('adminUserInfo') || 'null') } catch { userInfo.value = null }
|
||||
checkAgreementGate()
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -419,6 +477,22 @@ onMounted(() => {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.agreement-gate {
|
||||
display: grid;
|
||||
gap: 14px;
|
||||
color: #315650;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.agreement-gate p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.agreement-gate__links a {
|
||||
color: var(--theme-primary-action);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
@media (max-width: 960px) {
|
||||
.header,
|
||||
.content {
|
||||
|
||||
@@ -47,14 +47,19 @@ module.exports = {
|
||||
},
|
||||
|
||||
/**
|
||||
* 后台按预约/订单上下文单次取号,号码不入库、不缓存。
|
||||
* 后台按预约/订单上下文单次取号,号码不入库、不缓存;散客可不传 customerId。
|
||||
*/
|
||||
dialCustomer(customerId, orderId) {
|
||||
dialCustomer(params) {
|
||||
const source = params || {}
|
||||
const query = {}
|
||||
if (source.customerId) query.customerId = source.customerId
|
||||
if (source.appointmentId) query.appointmentId = source.appointmentId
|
||||
if (source.orderId) query.orderId = source.orderId
|
||||
return request({
|
||||
url: `/manager/customers/${customerId}/dial`,
|
||||
url: '/manager/customers/dial',
|
||||
method: 'POST',
|
||||
data: {},
|
||||
params: { orderId }
|
||||
params: query
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
@@ -135,13 +135,17 @@ Page({
|
||||
async dialCustomer() {
|
||||
const appointment = this.data.appointment || {}
|
||||
if (this.data.dialing) return
|
||||
if (!appointment.customerPhoneAvailable || !appointment.customerId || !appointment.orderId) {
|
||||
if (!appointment.customerPhoneAvailable || !appointment.orderId) {
|
||||
wx.showToast({ title: '该客户暂无可拨打的手机号', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.setData({ dialing: true })
|
||||
try {
|
||||
const result = await customersApi.dialCustomer(appointment.customerId, appointment.orderId)
|
||||
const result = await customersApi.dialCustomer({
|
||||
customerId: appointment.customerId,
|
||||
appointmentId: appointment.orderItemId,
|
||||
orderId: appointment.orderId
|
||||
})
|
||||
if (!result || !result.dialNumber) {
|
||||
throw new Error('未获取到可拨打号码')
|
||||
}
|
||||
|
||||
@@ -95,4 +95,7 @@ const styles = fs.readFileSync(path.join(__dirname, 'index.wxss'), 'utf8')
|
||||
;['订单编号', '服务项目', '美甲师', '时长', '成交金额', '取消原因', 'remarkText', 'customerPhoneText'].forEach(text => assert(markup.includes(text)))
|
||||
assert.match(markup, /class="primary-btn transfer-action"/)
|
||||
assert.match(markup, /class="danger-btn"/)
|
||||
assert.match(markup, /appointment\.customerPhoneAvailable && appointment\.orderId/)
|
||||
assert.strictEqual(markup.includes('appointment.customerId && appointment.orderId'), false)
|
||||
assert.match(styles, /\.transfer-action\s*\{[^}]*box-shadow/)
|
||||
assert.match(styles, /\.call-btn\s*\{/)
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<view class="phone-row">
|
||||
<text class="phone">{{appointment.customerPhoneText}}</text>
|
||||
<button
|
||||
wx:if="{{appointment.customerPhoneAvailable && appointment.customerId && appointment.orderId}}"
|
||||
wx:if="{{appointment.customerPhoneAvailable && appointment.orderId}}"
|
||||
class="call-btn"
|
||||
size="mini"
|
||||
loading="{{dialing}}"
|
||||
|
||||
Reference in New Issue
Block a user