diff --git a/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/config/BrandProperties.java b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/config/BrandProperties.java index d44177dd..d9ce1166 100644 --- a/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/config/BrandProperties.java +++ b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/config/BrandProperties.java @@ -20,5 +20,5 @@ public class BrandProperties { /** * 管理师注册店铺的默认描述。 */ - private String managerRegisterShopDescription = "指尖管理师注册店铺"; + private String managerRegisterShopDescription = "甲屿店务注册店铺"; } diff --git a/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/config/JwtProperties.java b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/config/JwtProperties.java index a76f2903..75fdde5d 100644 --- a/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/config/JwtProperties.java +++ b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/config/JwtProperties.java @@ -27,6 +27,11 @@ public class JwtProperties { */ private long accessTokenExpirationSeconds = 2 * 60 * 60; + /** + * 记住登录 AccessToken 有效期,单位秒。 + */ + private long rememberMeAccessTokenExpirationSeconds = 60 * 60; + /** * RefreshToken 有效期,单位秒。 */ diff --git a/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/auth/dto/PhoneLoginRequestDTO.java b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/auth/dto/PhoneLoginRequestDTO.java index f2e55213..632f86c4 100644 --- a/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/auth/dto/PhoneLoginRequestDTO.java +++ b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/auth/dto/PhoneLoginRequestDTO.java @@ -34,6 +34,11 @@ public class PhoneLoginRequestDTO implements AgreementAwareRequest { */ private Long shopId; + /** + * 记住登录标志 + */ + private Boolean rememberMe; + /** * Purpose: agreementAccepted supports PhoneLoginRequestDTO.java by holding or executing the agreement accepted business role. * Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state. diff --git a/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/manager/controller/admin/AdminManagerController.java b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/manager/controller/admin/AdminManagerController.java index 43f592ff..e4d9ca4d 100644 --- a/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/manager/controller/admin/AdminManagerController.java +++ b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/manager/controller/admin/AdminManagerController.java @@ -9,6 +9,7 @@ import com.xiaowang.fingertipdesigner.core.modules.artist.dto.NailArtistInfoDTO; import com.xiaowang.fingertipdesigner.core.modules.artist.service.ArtistScheduleService; import com.xiaowang.fingertipdesigner.core.modules.artist.service.NailArtistInfoService; import com.xiaowang.fingertipdesigner.core.modules.artist.vo.ArtistScheduleVO; +import com.xiaowang.fingertipdesigner.core.modules.manager.dto.ManagerCustomerCreateDTO; import com.xiaowang.fingertipdesigner.core.modules.planning.dto.PlanningAppointmentCreateDTO; import com.xiaowang.fingertipdesigner.core.modules.planning.dto.PlanningAppointmentMoveDTO; import com.xiaowang.fingertipdesigner.core.modules.planning.dto.PlanningAppointmentStatusDTO; @@ -125,6 +126,28 @@ public class AdminManagerController { return Result.success(userService.getUserById(id)); } + @PostMapping("/customers") + @RequirePermission("user:create") + @OperationGuard(action = "manager-customer-create", ttlSeconds = 10, message = "客户创建处理中,请勿重复提交") + public Result createCustomer(HttpServletRequest request, + @Valid @RequestBody ManagerCustomerCreateDTO dto) { + UserDO currentUser = adminScopeHelper.getCurrentUser(request); + adminScopeHelper.requireShopContext(currentUser, "请先选择店铺后再新增客户"); + Long shopId = adminScopeHelper.resolveShopScope(currentUser, null); + String phone = dto.getPhone().trim(); + UserDTO userDTO = new UserDTO(); + userDTO.setNickname(dto.getNickname().trim()); + userDTO.setPhone(phone); + userDTO.setContactPhone(phone); + userDTO.setAccount(phone); + userDTO.setType(0); + userDTO.setShopId(shopId); + userDTO.setShopIds(List.of(shopId)); + userDTO.setLevel("普通"); + userDTO.setVipId(0L); + return Result.success(userService.createUser(userDTO)); + } + @GetMapping("/employees") @RequirePermission("nail_artist:view") public Result> employees(HttpServletRequest request) { @@ -164,6 +187,7 @@ public class AdminManagerController { public Result createEmployeeUser(HttpServletRequest request, @Valid @RequestBody UserDTO dto) { UserDO currentUser = adminScopeHelper.getCurrentUser(request); + dto.setType(3); adminScopeHelper.ensureAssignableUserType(currentUser, dto.getType()); if (!adminScopeHelper.isPlatformAdmin(currentUser)) { Long managedShopId = adminScopeHelper.getManagedShopId(currentUser); diff --git a/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/manager/dto/ManagerCustomerCreateDTO.java b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/manager/dto/ManagerCustomerCreateDTO.java new file mode 100644 index 00000000..cf9f02b8 --- /dev/null +++ b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/manager/dto/ManagerCustomerCreateDTO.java @@ -0,0 +1,17 @@ +package com.xiaowang.fingertipdesigner.core.modules.manager.dto; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Pattern; + +@Data +public class ManagerCustomerCreateDTO { + + @NotBlank(message = "客户姓名不能为空") + private String nickname; + + @NotBlank(message = "手机号不能为空") + @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确") + private String phone; +} diff --git a/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/planning/service/impl/PlanningServiceImpl.java b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/planning/service/impl/PlanningServiceImpl.java index 7cdccafc..39a182b8 100644 --- a/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/planning/service/impl/PlanningServiceImpl.java +++ b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/planning/service/impl/PlanningServiceImpl.java @@ -481,7 +481,7 @@ public class PlanningServiceImpl implements PlanningService { vo.setProductId(product == null ? item == null ? null : item.getProductId() : product.getId()); vo.setProductTitle(reservation != null && hasText(reservation.getProductTitle()) ? reservation.getProductTitle() - : product == null ? "预约项目" : product.getTitle()); + : product == null ? "预约作品" : product.getTitle()); vo.setArtistId(artistId); vo.setArtistName(artist == null ? "未分配" : artist.getName()); vo.setArtistColor(artist == null ? ARTIST_COLORS.get(0) : artist.getColor()); @@ -578,11 +578,11 @@ public class PlanningServiceImpl implements PlanningService { private ProductDO requireActiveProduct(Long productId, Long shopId) { if (productId == null) { - throw new RuntimeException("请选择预约项目"); + throw new RuntimeException("请选择预约作品"); } ProductDO product = productMapper.selectById(productId); if (product == null || Integer.valueOf(1).equals(product.getIsDelete()) || !shopId.equals(product.getShopId())) { - throw new RuntimeException("预约项目不存在或不属于当前店铺"); + throw new RuntimeException("预约作品不存在或不属于当前店铺"); } return product; } @@ -597,11 +597,11 @@ public class PlanningServiceImpl implements PlanningService { private ProductDO createManualAppointmentProduct(PlanningAppointmentCreateDTO dto, Long shopId) { String title = trimToNull(dto.getManualProductTitle()); if (!hasText(title)) { - throw new RuntimeException("请选择预约项目或填写手动项目名称"); + throw new RuntimeException("请选择预约作品或填写手动作品名称"); } BigDecimal price = dto.getManualProductPrice(); if (price == null || price.compareTo(BigDecimal.ZERO) < 0) { - throw new RuntimeException("手动项目价格不能小于0"); + throw new RuntimeException("手动作品价格不能小于0"); } int durationMinutes = dto.getDurationMinutes() == null || dto.getDurationMinutes() <= 0 ? DEFAULT_DURATION_MINUTES diff --git a/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/user/service/impl/UserServiceImpl.java b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/user/service/impl/UserServiceImpl.java index d6088343..cb67bd85 100644 --- a/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/user/service/impl/UserServiceImpl.java +++ b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/user/service/impl/UserServiceImpl.java @@ -1062,7 +1062,7 @@ public class UserServiceImpl extends ServiceImpl implements * @param false parameter `false` supplied by the caller * @return return result consumed by the caller or returned to the frontend */ - return buildLoginResponse(userDO, resolvedShopId, false); + return buildLoginResponse(userDO, resolvedShopId, false, Boolean.TRUE.equals(loginRequestDTO.getRememberMe())); } @Override @@ -1110,7 +1110,7 @@ public class UserServiceImpl extends ServiceImpl implements } Long resolvedShopId = resolveUserLoginShopId(userDO, phoneLoginRequestDTO.getShopId()); - return buildLoginResponse(userDO, resolvedShopId, ENCODED_UNSET_PASSWORD.equals(userDO.getPassword())); + return buildLoginResponse(userDO, resolvedShopId, ENCODED_UNSET_PASSWORD.equals(userDO.getPassword()), Boolean.TRUE.equals(phoneLoginRequestDTO.getRememberMe())); } // 未设置密码的特殊标识 @@ -1279,7 +1279,7 @@ public class UserServiceImpl extends ServiceImpl implements * @param false parameter `false` supplied by the caller * @return return result consumed by the caller or returned to the frontend */ - return buildLoginResponse(userDO, resolvedShopId, false); + return buildLoginResponse(userDO, resolvedShopId, false, Boolean.TRUE.equals(loginRequestDTO.getRememberMe())); } @Override @@ -2751,6 +2751,10 @@ public class UserServiceImpl extends ServiceImpl implements return buildLoginResponse(userDO, currentShopId, needSetPassword, null); } + private LoginResponseVO buildLoginResponse(UserDO userDO, Long currentShopId, boolean needSetPassword, boolean rememberMe) { + return buildLoginResponse(userDO, currentShopId, needSetPassword, null, rememberMe); + } + /** * Run business method `buildLoginResponse`. * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result. @@ -2761,6 +2765,10 @@ public class UserServiceImpl extends ServiceImpl implements * @return private LoginResponseVO result consumed by the caller or returned to the frontend */ private LoginResponseVO buildLoginResponse(UserDO userDO, Long currentShopId, boolean needSetPassword, String previousSessionId) { + return buildLoginResponse(userDO, currentShopId, needSetPassword, previousSessionId, false); + } + + private LoginResponseVO buildLoginResponse(UserDO userDO, Long currentShopId, boolean needSetPassword, String previousSessionId, boolean rememberMe) { UserSessionService.SessionIssueResult sessionIssueResult = StringUtils.hasText(previousSessionId) ? userSessionService.rotateSession(previousSessionId, userDO.getId(), userDO.getAccount(), currentShopId, userDO.getType()) : userSessionService.issueSession(userDO.getId(), userDO.getAccount(), currentShopId, userDO.getType()); @@ -2769,7 +2777,8 @@ public class UserServiceImpl extends ServiceImpl implements userDO.getAccount(), currentShopId, sessionIssueResult.sessionId(), - sessionIssueResult.accessJti() + sessionIssueResult.accessJti(), + jwtUtil.resolveAccessTokenExpirationSeconds(rememberMe) ); String refreshToken = jwtUtil.generateRefreshToken( userDO.getId(), diff --git a/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/utils/JwtUtil.java b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/utils/JwtUtil.java index 23d57893..7ab043e5 100644 --- a/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/utils/JwtUtil.java +++ b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/utils/JwtUtil.java @@ -41,6 +41,10 @@ public class JwtUtil { * Usage: reference this method from the owning layer and pass validated inputs before reading or updating related state. */ public String generateAccessToken(Long userId, String account, Long currentShopId, String sessionId, String jti) { + return generateAccessToken(userId, account, currentShopId, sessionId, jti, jwtProperties.getAccessTokenExpirationSeconds()); + } + + public String generateAccessToken(Long userId, String account, Long currentShopId, String sessionId, String jti, long expirationSeconds) { Map claims = new HashMap<>(); claims.put("userId", userId); claims.put("account", account); @@ -50,7 +54,13 @@ public class JwtUtil { if (currentShopId != null && currentShopId > 0) { claims.put("shopId", currentShopId); } - return createToken(claims, userId.toString(), jwtProperties.getAccessTokenExpirationSeconds() * 1000); + return createToken(claims, userId.toString(), expirationSeconds * 1000); + } + + public long resolveAccessTokenExpirationSeconds(boolean rememberMe) { + return rememberMe + ? jwtProperties.getRememberMeAccessTokenExpirationSeconds() + : jwtProperties.getAccessTokenExpirationSeconds(); } /** diff --git a/FD-Core/src/main/resources/application.yaml b/FD-Core/src/main/resources/application.yaml index ee810935..1dbaab81 100644 --- a/FD-Core/src/main/resources/application.yaml +++ b/FD-Core/src/main/resources/application.yaml @@ -28,11 +28,12 @@ mybatis: fingertip-designer: brand: message-template-name: ${PLATFORM_MESSAGE_TEMPLATE_NAME:FingertipDesigner} - manager-register-shop-description: ${PLATFORM_MANAGER_REGISTER_SHOP_DESCRIPTION:指尖管理师注册店铺} + manager-register-shop-description: ${PLATFORM_MANAGER_REGISTER_SHOP_DESCRIPTION:甲屿店务注册店铺} security: jwt: issuer: fingertip-designer access-token-expiration-seconds: 7200 + remember-me-access-token-expiration-seconds: 3600 refresh-token-expiration-seconds: 604800 clock-skew-seconds: 30 signature: diff --git a/FD-Core/src/test/java/com/xiaowang/fingertipdesigner/core/modules/manager/controller/admin/AdminManagerControllerTest.java b/FD-Core/src/test/java/com/xiaowang/fingertipdesigner/core/modules/manager/controller/admin/AdminManagerControllerTest.java index 2dab2c18..0470ad13 100644 --- a/FD-Core/src/test/java/com/xiaowang/fingertipdesigner/core/modules/manager/controller/admin/AdminManagerControllerTest.java +++ b/FD-Core/src/test/java/com/xiaowang/fingertipdesigner/core/modules/manager/controller/admin/AdminManagerControllerTest.java @@ -7,6 +7,7 @@ import com.xiaowang.fingertipdesigner.core.modules.artist.dto.NailArtistInfoDTO; import com.xiaowang.fingertipdesigner.core.modules.artist.service.ArtistScheduleService; import com.xiaowang.fingertipdesigner.core.modules.artist.service.NailArtistInfoService; import com.xiaowang.fingertipdesigner.core.modules.artist.vo.ArtistScheduleVO; +import com.xiaowang.fingertipdesigner.core.modules.manager.dto.ManagerCustomerCreateDTO; import com.xiaowang.fingertipdesigner.core.modules.planning.service.PlanningService; import com.xiaowang.fingertipdesigner.core.modules.product.service.ProductService; import com.xiaowang.fingertipdesigner.core.modules.product.vo.ProductVO; @@ -28,6 +29,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -109,6 +111,53 @@ class AdminManagerControllerTest { verify(adminScopeHelper).ensureAssignableUserType(manager, 3); } + @Test + void createEmployeeUserShouldForceNailArtistType() { + MockHttpServletRequest request = new MockHttpServletRequest(); + UserDO manager = new UserDO(); + manager.setType(2); + UserDTO dto = new UserDTO(); + dto.setType(0); + when(adminScopeHelper.getCurrentUser(request)).thenReturn(manager); + when(adminScopeHelper.isPlatformAdmin(manager)).thenReturn(true); + when(userService.createUser(dto)).thenReturn(102L); + + Result result = controller.createEmployeeUser(request, dto); + + assertThat(result.getData()).isEqualTo(102L); + assertThat(dto.getType()).isEqualTo(3); + verify(adminScopeHelper).ensureAssignableUserType(manager, 3); + } + + @Test + void createCustomerShouldForceNormalUserInCurrentShop() { + MockHttpServletRequest request = new MockHttpServletRequest(); + UserDO manager = new UserDO(); + manager.setType(2); + ManagerCustomerCreateDTO dto = new ManagerCustomerCreateDTO(); + dto.setNickname(" 小王客户 "); + dto.setPhone(" 13800138000 "); + when(adminScopeHelper.getCurrentUser(request)).thenReturn(manager); + when(adminScopeHelper.resolveShopScope(manager, null)).thenReturn(8L); + when(userService.createUser(any(UserDTO.class))).thenReturn(103L); + + Result result = controller.createCustomer(request, dto); + + assertThat(result.getData()).isEqualTo(103L); + verify(adminScopeHelper).requireShopContext(manager, "请先选择店铺后再新增客户"); + verify(userService).createUser(org.mockito.ArgumentMatchers.argThat(userDTO -> + "小王客户".equals(userDTO.getNickname()) + && "13800138000".equals(userDTO.getPhone()) + && "13800138000".equals(userDTO.getContactPhone()) + && "13800138000".equals(userDTO.getAccount()) + && Integer.valueOf(0).equals(userDTO.getType()) + && Long.valueOf(8L).equals(userDTO.getShopId()) + && userDTO.getShopIds().equals(List.of(8L)) + && "普通".equals(userDTO.getLevel()) + && Long.valueOf(0L).equals(userDTO.getVipId()) + )); + } + @Test void saveScheduleShouldResolveShopScopeBeforeSaving() { MockHttpServletRequest request = new MockHttpServletRequest(); diff --git a/FD-Core/src/test/java/com/xiaowang/fingertipdesigner/core/modules/planning/service/impl/PlanningServiceImplTest.java b/FD-Core/src/test/java/com/xiaowang/fingertipdesigner/core/modules/planning/service/impl/PlanningServiceImplTest.java new file mode 100644 index 00000000..fb70a733 --- /dev/null +++ b/FD-Core/src/test/java/com/xiaowang/fingertipdesigner/core/modules/planning/service/impl/PlanningServiceImplTest.java @@ -0,0 +1,197 @@ +package com.xiaowang.fingertipdesigner.core.modules.planning.service.impl; + +import com.xiaowang.fingertipdesigner.core.modules.artist.mapper.ArtistScheduleMapper; +import com.xiaowang.fingertipdesigner.core.modules.artist.mapper.NailArtistInfoMapper; +import com.xiaowang.fingertipdesigner.core.modules.order.entity.OrderDO; +import com.xiaowang.fingertipdesigner.core.modules.order.entity.OrderItemDO; +import com.xiaowang.fingertipdesigner.core.modules.order.mapper.OrderItemMapper; +import com.xiaowang.fingertipdesigner.core.modules.order.mapper.OrderMapper; +import com.xiaowang.fingertipdesigner.core.modules.order.service.OrderService; +import com.xiaowang.fingertipdesigner.core.modules.planning.dto.PlanningAppointmentCreateDTO; +import com.xiaowang.fingertipdesigner.core.modules.planning.entity.AppointmentReservationDO; +import com.xiaowang.fingertipdesigner.core.modules.planning.mapper.AppointmentReservationMapper; +import com.xiaowang.fingertipdesigner.core.modules.planning.service.AppointmentCapacityService; +import com.xiaowang.fingertipdesigner.core.modules.product.entity.ProductDO; +import com.xiaowang.fingertipdesigner.core.modules.product.mapper.ProductMapper; +import com.xiaowang.fingertipdesigner.core.modules.security.support.AdminScopeHelper; +import com.xiaowang.fingertipdesigner.core.modules.shop.entity.ShopDO; +import com.xiaowang.fingertipdesigner.core.modules.shop.mapper.ShopMapper; +import com.xiaowang.fingertipdesigner.core.modules.user.entity.UserDO; +import com.xiaowang.fingertipdesigner.core.modules.user.mapper.UserMapper; +import com.xiaowang.fingertipdesigner.core.support.id.TimeOrderedSnowflakeIdGenerator; +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 java.math.BigDecimal; +import java.time.LocalDateTime; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class PlanningServiceImplTest { + + @Mock + private AdminScopeHelper adminScopeHelper; + + @Mock + private UserMapper userMapper; + + @Mock + private NailArtistInfoMapper nailArtistInfoMapper; + + @Mock + private ArtistScheduleMapper artistScheduleMapper; + + @Mock + private AppointmentReservationMapper appointmentReservationMapper; + + @Mock + private OrderMapper orderMapper; + + @Mock + private OrderItemMapper orderItemMapper; + + @Mock + private ProductMapper productMapper; + + @Mock + private ShopMapper shopMapper; + + @Mock + private AppointmentCapacityService appointmentCapacityService; + + @Mock + private OrderService orderService; + + @Mock + private TimeOrderedSnowflakeIdGenerator snowflakeIdGenerator; + + private PlanningServiceImpl planningService; + + @BeforeEach + void setUp() { + planningService = new PlanningServiceImpl( + adminScopeHelper, + userMapper, + nailArtistInfoMapper, + artistScheduleMapper, + appointmentReservationMapper, + orderMapper, + orderItemMapper, + productMapper, + shopMapper, + appointmentCapacityService, + orderService, + snowflakeIdGenerator + ); + } + + @Test + void createAppointmentShouldHideManualProductFromFront() { + UserDO manager = user(2, 8L); + UserDO artist = user(3, 8L); + artist.setId(20L); + UserDO customer = user(0, 8L); + customer.setId(30L); + ShopDO shop = new ShopDO(); + shop.setBusinessHours("10:00-22:00"); + PlanningAppointmentCreateDTO dto = new PlanningAppointmentCreateDTO(); + dto.setCustomerUserId(30L); + dto.setArtistId(20L); + dto.setAppointmentDate("2026-06-26"); + dto.setAppointmentTime("13:00"); + dto.setDurationMinutes(90); + dto.setManualProductTitle(" 日落贝壳 "); + dto.setManualProductPrice(new BigDecimal("168.00")); + dto.setClientRequestId("manual-product-test"); + + when(adminScopeHelper.resolveShopScope(manager, null)).thenReturn(8L); + when(productMapper.insert(any(ProductDO.class))).thenAnswer(invocation -> { + ProductDO product = invocation.getArgument(0); + product.setId(100L); + return 1; + }); + when(userMapper.selectById(20L)).thenReturn(artist); + when(userMapper.selectById(30L)).thenReturn(customer); + when(shopMapper.selectById(8L)).thenReturn(shop); + when(snowflakeIdGenerator.nextIdString()).thenReturn("202606260001"); + when(orderMapper.insert(any(OrderDO.class))).thenAnswer(invocation -> { + OrderDO order = invocation.getArgument(0); + order.setId(200L); + return 1; + }); + when(orderItemMapper.insert(any(OrderItemDO.class))).thenAnswer(invocation -> { + OrderItemDO item = invocation.getArgument(0); + item.setId(300L); + return 1; + }); + when(orderItemMapper.selectById(300L)).thenAnswer(invocation -> { + OrderItemDO item = new OrderItemDO(); + item.setId(300L); + item.setOrderId(200L); + item.setProductId(100L); + item.setArtistId(20L); + item.setQuantity(1); + item.setAppointmentTime(LocalDateTime.of(2026, 6, 26, 13, 0)); + item.setIsDelete(0); + return item; + }); + when(orderMapper.selectById(200L)).thenAnswer(invocation -> { + OrderDO order = new OrderDO(); + order.setId(200L); + order.setUserId(30L); + order.setShopId(8L); + order.setStatus(1); + order.setIsDelete(0); + return order; + }); + when(productMapper.selectById(100L)).thenAnswer(invocation -> { + ProductDO product = new ProductDO(); + product.setId(100L); + product.setShopId(8L); + product.setTitle("日落贝壳"); + product.setPrice(new BigDecimal("168.00")); + product.setApproximateDuration("90分钟"); + product.setFrontVisible(0); + product.setSourceType("MANAGER_APPOINTMENT"); + product.setIsDelete(0); + return product; + }); + AppointmentReservationDO reservation = new AppointmentReservationDO(); + reservation.setOrderItemId(300L); + reservation.setArtistId(20L); + reservation.setProductTitle("日落贝壳"); + reservation.setAppointmentStartTime(LocalDateTime.of(2026, 6, 26, 13, 0)); + reservation.setAppointmentEndTime(LocalDateTime.of(2026, 6, 26, 14, 30)); + when(appointmentReservationMapper.selectOne(any())).thenReturn(reservation); + when(userMapper.selectBatchIds(any())).thenReturn(List.of(customer)); + + planningService.createAppointment(manager, dto); + + ArgumentCaptor captor = ArgumentCaptor.forClass(ProductDO.class); + org.mockito.Mockito.verify(productMapper).insert(captor.capture()); + ProductDO product = captor.getValue(); + assertThat(product.getTitle()).isEqualTo("日落贝壳"); + assertThat(product.getFrontVisible()).isZero(); + assertThat(product.getSourceType()).isEqualTo("MANAGER_APPOINTMENT"); + assertThat(product.getImageFileIds()).isNull(); + } + + private UserDO user(Integer type, Long shopId) { + UserDO user = new UserDO(); + user.setId(10L + type); + user.setType(type); + user.setShopId(shopId); + user.setIsDelete(0); + user.setNickname("测试用户"); + user.setPhone("13800138000"); + return user; + } +} diff --git a/FD-Core/src/test/java/com/xiaowang/fingertipdesigner/core/utils/JwtUtilTest.java b/FD-Core/src/test/java/com/xiaowang/fingertipdesigner/core/utils/JwtUtilTest.java new file mode 100644 index 00000000..643b40b2 --- /dev/null +++ b/FD-Core/src/test/java/com/xiaowang/fingertipdesigner/core/utils/JwtUtilTest.java @@ -0,0 +1,20 @@ +package com.xiaowang.fingertipdesigner.core.utils; + +import com.xiaowang.fingertipdesigner.core.config.JwtProperties; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class JwtUtilTest { + + @Test + void resolveAccessTokenExpirationSecondsShouldUseRememberMeSeconds() { + JwtProperties properties = new JwtProperties(); + properties.setAccessTokenExpirationSeconds(120L); + properties.setRememberMeAccessTokenExpirationSeconds(3600L); + JwtUtil jwtUtil = new JwtUtil(properties); + + assertThat(jwtUtil.resolveAccessTokenExpirationSeconds(false)).isEqualTo(120L); + assertThat(jwtUtil.resolveAccessTokenExpirationSeconds(true)).isEqualTo(3600L); + } +} diff --git a/FD-Frontend/src/config/brand.ts b/FD-Frontend/src/config/brand.ts index ba05a0a4..f595b4ad 100644 --- a/FD-Frontend/src/config/brand.ts +++ b/FD-Frontend/src/config/brand.ts @@ -4,9 +4,9 @@ function normalizeBrandValue(value: string | undefined, fallbackValue: string): } export const BRAND_CONFIG = { - appName: normalizeBrandValue(import.meta.env.VITE_APP_NAME, '指尖设计师'), - appNameEn: normalizeBrandValue(import.meta.env.VITE_APP_NAME_EN, 'Fingertip Designer'), - appTitle: normalizeBrandValue(import.meta.env.VITE_APP_TITLE, 'Fingertip Designer 指尖设计师'), - adminAppName: normalizeBrandValue(import.meta.env.VITE_ADMIN_APP_NAME, '指尖设计师管理台'), + appName: normalizeBrandValue(import.meta.env.VITE_APP_NAME, '甲屿设计师'), + appNameEn: normalizeBrandValue(import.meta.env.VITE_APP_NAME_EN, 'Jiayu Designer'), + appTitle: normalizeBrandValue(import.meta.env.VITE_APP_TITLE, '甲屿设计师'), + adminAppName: normalizeBrandValue(import.meta.env.VITE_ADMIN_APP_NAME, '甲屿设计师管理台'), appShortName: normalizeBrandValue(import.meta.env.VITE_APP_SHORT_NAME, 'YN') } diff --git a/FD-WeChat-Fronted/utils/config.js b/FD-WeChat-Fronted/utils/config.js index 583ac410..60785d4a 100644 --- a/FD-WeChat-Fronted/utils/config.js +++ b/FD-WeChat-Fronted/utils/config.js @@ -157,9 +157,9 @@ const API_DOMAIN = ensureHttps( ENV_VERSION ) const BRAND_CONFIG = { - appName: String(localOverride.appName || '指尖设计师'), - appNameEn: String(localOverride.appNameEn || 'Fingertip Designer'), - appTitle: String(localOverride.appTitle || 'Fingertip Designer 指尖设计师') + appName: String(localOverride.appName || '甲屿设计师'), + appNameEn: String(localOverride.appNameEn || 'Jiayu Designer'), + appTitle: String(localOverride.appTitle || '甲屿设计师') } module.exports = { diff --git a/FD-WeChat-Fronted/utils/config.local.example.js b/FD-WeChat-Fronted/utils/config.local.example.js index 31a7d16d..14b0cd41 100644 --- a/FD-WeChat-Fronted/utils/config.local.example.js +++ b/FD-WeChat-Fronted/utils/config.local.example.js @@ -1,8 +1,8 @@ module.exports = { developTarget: 'local', - appName: '指尖设计师', - appNameEn: 'Fingertip Designer', - appTitle: 'Fingertip Designer 指尖设计师', + appName: '甲屿设计师', + appNameEn: 'Jiayu Designer', + appTitle: '甲屿设计师', requestTimeout: 10000, enableRequestSigning: true, domains: { diff --git a/FM-Wechat-Fronted/api/customers.js b/FM-Wechat-Fronted/api/customers.js index 819dfde5..d6a2b36b 100644 --- a/FM-Wechat-Fronted/api/customers.js +++ b/FM-Wechat-Fronted/api/customers.js @@ -4,10 +4,7 @@ module.exports = { list(params) { return request({ url: '/manager/customers', - params: { - hasOrder: true, - ...params - } + params }) }, @@ -15,5 +12,13 @@ module.exports = { return request({ url: `/manager/customers/${id}` }) + }, + + create(data) { + return request({ + url: '/manager/customers', + method: 'POST', + data + }) } } diff --git a/FM-Wechat-Fronted/app.json b/FM-Wechat-Fronted/app.json index ee0dbed0..bd9553f0 100644 --- a/FM-Wechat-Fronted/app.json +++ b/FM-Wechat-Fronted/app.json @@ -21,7 +21,7 @@ "pages/about/index" ], "window": { - "navigationBarTitleText": "指尖管理师", + "navigationBarTitleText": "甲屿店务", "navigationBarBackgroundColor": "#F8F5EF", "navigationBarTextStyle": "black", "backgroundColor": "#F8F5EF", diff --git a/FM-Wechat-Fronted/app.wxss b/FM-Wechat-Fronted/app.wxss index 9402c400..1dce276a 100644 --- a/FM-Wechat-Fronted/app.wxss +++ b/FM-Wechat-Fronted/app.wxss @@ -193,6 +193,13 @@ button::after { font-weight: 600; } +.field-label.required::after, +.required-label::after { + content: " *"; + color: #c56f36; + font-weight: 900; +} + .field input, .field textarea, .field-value { diff --git a/FM-Wechat-Fronted/pages/appointment-detail/index.js b/FM-Wechat-Fronted/pages/appointment-detail/index.js index 10ad3fda..d5cb4cd1 100644 --- a/FM-Wechat-Fronted/pages/appointment-detail/index.js +++ b/FM-Wechat-Fronted/pages/appointment-detail/index.js @@ -1,12 +1,12 @@ const planningApi = require('../../api/planning') -const mock = require('../../utils/mock') Page({ data: { id: '', appointment: {}, avatarText: '', - timeText: '' + timeText: '', + loadError: '' }, onLoad(options) { @@ -19,8 +19,12 @@ Page({ const appointment = await planningApi.appointment(this.data.id) this.applyAppointment(appointment) } catch (error) { - const demo = mock.buildCalendar(new Date()).appointments[0] - this.applyAppointment(demo) + this.setData({ + appointment: {}, + avatarText: '', + timeText: '', + loadError: error.message || '预约详情加载失败' + }) } }, @@ -28,7 +32,8 @@ Page({ this.setData({ appointment, avatarText: String(appointment.customerName || '客').slice(0, 1), - timeText: `${(appointment.startTime || '').slice(0, 16)} - ${(appointment.endTime || '').slice(11, 16)}` + timeText: `${(appointment.startTime || '').slice(0, 16)} - ${(appointment.endTime || '').slice(11, 16)}`, + loadError: '' }) }, diff --git a/FM-Wechat-Fronted/pages/appointment-detail/index.wxml b/FM-Wechat-Fronted/pages/appointment-detail/index.wxml index b1725e46..7b21f317 100644 --- a/FM-Wechat-Fronted/pages/appointment-detail/index.wxml +++ b/FM-Wechat-Fronted/pages/appointment-detail/index.wxml @@ -1,5 +1,10 @@ - + + {{loadError}} + + + + {{avatarText}} @@ -33,12 +38,12 @@ - + 备注 {{appointment.remark || '暂无备注'}} - + diff --git a/FM-Wechat-Fronted/pages/appointment-detail/index.wxss b/FM-Wechat-Fronted/pages/appointment-detail/index.wxss index 6f074c89..00b7edcd 100644 --- a/FM-Wechat-Fronted/pages/appointment-detail/index.wxss +++ b/FM-Wechat-Fronted/pages/appointment-detail/index.wxss @@ -2,6 +2,17 @@ padding: 24rpx; } +.detail-error { + margin-top: 24rpx; +} + +.retry-btn { + width: 180rpx; + min-width: 180rpx; + max-width: 180rpx; + margin: 24rpx auto 0; +} + .detail-head { display: flex; align-items: center; diff --git a/FM-Wechat-Fronted/pages/appointment-form/index.js b/FM-Wechat-Fronted/pages/appointment-form/index.js index 83daf58f..f05e6099 100644 --- a/FM-Wechat-Fronted/pages/appointment-form/index.js +++ b/FM-Wechat-Fronted/pages/appointment-form/index.js @@ -86,6 +86,7 @@ Page({ selectedArtist: {}, productModalVisible: false, productKeyword: '', + productError: '', conflictTip: '', conflictLevel: 'free', canCreateAppointment: true, @@ -96,6 +97,8 @@ Page({ const creatable = canCreateAppointment() this.setData({ canCreateAppointment: creatable, + 'form.customerName': options.customerName ? decodeURIComponent(options.customerName) : '', + 'form.phone': options.phone ? decodeURIComponent(options.phone) : '', 'form.appointmentDate': options.date || dateUtil.formatDate(new Date()), 'form.artistId': options.artistId || '' }) @@ -107,17 +110,16 @@ Page({ }, async loadOptions() { - const fallbackProducts = [ - { id: 1, title: '纯色美甲', approximateDuration: '90分钟' }, - { id: 2, title: '猫眼延长', approximateDuration: '120分钟' }, - { id: 3, title: '手部护理', approximateDuration: '60分钟' } - ] try { const productsData = await productsApi.list({ page: 1, size: 100 }) - const products = productsData.list || productsData || fallbackProducts - this.setData({ products }) + const products = productsData.list || productsData || [] + this.setData({ products, productError: '' }) } catch (error) { - this.setData({ products: fallbackProducts }) + this.setData({ + products: [], + filteredProducts: [], + productError: error.message || '作品列表加载失败' + }) } await this.loadArtists() this.refreshProductCards() @@ -125,14 +127,24 @@ Page({ }, async loadArtists() { - const calendar = await planningApi.calendar({ - startDate: this.data.form.appointmentDate, - endDate: this.data.form.appointmentDate - }) - const artists = getCalendarArtists(calendar) - const selectedArtist = this.data.form.artistId ? findArtist(artists, this.data.form.artistId) : {} - this.setData({ artists, selectedArtist }) - this.refreshProductCards() + try { + const calendar = await planningApi.calendar({ + startDate: this.data.form.appointmentDate, + endDate: this.data.form.appointmentDate + }) + const artists = getCalendarArtists(calendar) + const selectedArtist = this.data.form.artistId ? findArtist(artists, this.data.form.artistId) : {} + this.setData({ artists, selectedArtist }) + this.refreshProductCards() + } catch (error) { + this.setData({ + artists: [], + selectedArtist: {}, + 'form.artistId': '', + conflictTip: error.message || '美甲师列表加载失败', + conflictLevel: 'danger' + }) + } }, onInput(event) { @@ -198,7 +210,7 @@ Page({ const title = String(this.data.form.manualProductTitle || '').trim() const price = Number(this.data.form.manualProductPrice) if (!title || Number.isNaN(price) || price < 0) { - wx.showToast({ title: '请填写手动项目名称和价格', icon: 'none' }) + wx.showToast({ title: '请填写手动预约作品名称和价格', icon: 'none' }) return } this.setData({ @@ -265,9 +277,9 @@ Page({ this.setData({ conflictTip: tip, conflictLevel: 'free' }) return { ok: true, tip } } catch (error) { - const tip = '暂未获取到排班,请保存时以系统校验为准' - this.setData({ conflictTip: tip, conflictLevel: 'warn' }) - return { ok: true, tip } + const tip = error.message || '排班校验失败,请稍后重试' + this.setData({ conflictTip: tip, conflictLevel: 'danger' }) + return { ok: false, tip } } }, diff --git a/FM-Wechat-Fronted/pages/appointment-form/index.wxml b/FM-Wechat-Fronted/pages/appointment-form/index.wxml index 101b8cb8..39c514ae 100644 --- a/FM-Wechat-Fronted/pages/appointment-form/index.wxml +++ b/FM-Wechat-Fronted/pages/appointment-form/index.wxml @@ -1,39 +1,39 @@ - 客户姓名 + 客户姓名 - 手机号 + 手机号 - 预约日期 + 预约日期 {{form.appointmentDate}} - 预约时间 + 预约时间 {{form.appointmentTime}} - 项目内容 + 预约作品 - {{selectedProduct.title || form.manualProductTitle || '请选择项目'}} + {{selectedProduct.title || form.manualProductTitle || '请选择预约作品'}} 手动 预计时长 - + 分钟 - 指定员工 + 指定员工 {{selectedArtist.name || '请选择美甲师'}} @@ -58,12 +58,13 @@ - 选择项目内容 + 选择预约作品 × + {{productError}} 图 @@ -78,15 +79,15 @@ - 暂无匹配作品 + 暂无匹配作品 - 手动新增项目 + 手动新增预约作品 - + - + diff --git a/FM-Wechat-Fronted/pages/appointment-form/index.wxss b/FM-Wechat-Fronted/pages/appointment-form/index.wxss index 87c14707..be4121de 100644 --- a/FM-Wechat-Fronted/pages/appointment-form/index.wxss +++ b/FM-Wechat-Fronted/pages/appointment-form/index.wxss @@ -114,18 +114,37 @@ } .modal-close { + position: relative; display: flex; align-items: center; justify-content: center; - width: 56rpx; - min-width: 56rpx; - height: 56rpx; + width: 48rpx; + min-width: 48rpx; + height: 48rpx; border-radius: 50%; - background: #f2e7da; - color: #61554c; - font-size: 32rpx; - font-weight: 800; - line-height: 1; + border: 1rpx solid #e4d8ca; + background: #fffaf4; + color: transparent; + font-size: 0; + line-height: 0; +} + +.modal-close::before, +.modal-close::after { + content: ""; + position: absolute; + width: 22rpx; + height: 3rpx; + border-radius: 999rpx; + background: #61554c; +} + +.modal-close::before { + transform: rotate(45deg); +} + +.modal-close::after { + transform: rotate(-45deg); } .product-search { diff --git a/FM-Wechat-Fronted/pages/artist-transfer/index.js b/FM-Wechat-Fronted/pages/artist-transfer/index.js index eab5face..1f0beeb7 100644 --- a/FM-Wechat-Fronted/pages/artist-transfer/index.js +++ b/FM-Wechat-Fronted/pages/artist-transfer/index.js @@ -1,5 +1,4 @@ const planningApi = require('../../api/planning') -const mock = require('../../utils/mock') const dateUtil = require('../../utils/date') Page({ @@ -9,26 +8,49 @@ Page({ selectedArtistId: '', date: dateUtil.formatDate(new Date()), time: '13:00', + loadError: '', loading: false }, onLoad(options) { this.setData({ - id: options.id || '', - artists: mock.artists.map((item, index) => ({ - ...item, - availableStatus: index === 1 ? 'busy' : index === 2 ? 'full' : 'free', - availableText: index === 1 ? '有冲突' : index === 2 ? '已满' : '可接' - })) + id: options.id || '' }) + this.loadArtists() + }, + + async loadArtists() { + try { + const calendar = await planningApi.calendar({ + startDate: this.data.date, + endDate: this.data.date + }) + const artists = Array.isArray(calendar.artists) ? calendar.artists : [] + this.setData({ + artists: artists.map(item => ({ + ...item, + availableStatus: 'free', + availableText: '可选择' + })), + selectedArtistId: '', + loadError: '' + }) + } catch (error) { + this.setData({ + artists: [], + selectedArtistId: '', + loadError: error.message || '美甲师列表加载失败' + }) + } }, selectArtist(event) { this.setData({ selectedArtistId: event.currentTarget.dataset.id }) }, - onDateChange(event) { + async onDateChange(event) { this.setData({ date: event.detail.value }) + await this.loadArtists() }, onTimeChange(event) { diff --git a/FM-Wechat-Fronted/pages/artist-transfer/index.wxml b/FM-Wechat-Fronted/pages/artist-transfer/index.wxml index 52b46cd4..5c56893e 100644 --- a/FM-Wechat-Fronted/pages/artist-transfer/index.wxml +++ b/FM-Wechat-Fronted/pages/artist-transfer/index.wxml @@ -1,5 +1,10 @@ + + {{loadError}} + + + 暂无可选美甲师 @@ -14,22 +19,22 @@ - + - 新日期 + 新日期 {{date}} - 新时间 + 新时间 {{time}} - + diff --git a/FM-Wechat-Fronted/pages/artist-transfer/index.wxss b/FM-Wechat-Fronted/pages/artist-transfer/index.wxss index 670c34df..0fe4bd23 100644 --- a/FM-Wechat-Fronted/pages/artist-transfer/index.wxss +++ b/FM-Wechat-Fronted/pages/artist-transfer/index.wxss @@ -2,6 +2,13 @@ padding: 24rpx; } +.retry-btn { + width: 180rpx; + min-width: 180rpx; + max-width: 180rpx; + margin: 24rpx auto 0; +} + .transfer-card.active { outline: 3rpx solid #8fb89a; } diff --git a/FM-Wechat-Fronted/pages/customer-detail/index.js b/FM-Wechat-Fronted/pages/customer-detail/index.js index 24702ef1..c41e227b 100644 --- a/FM-Wechat-Fronted/pages/customer-detail/index.js +++ b/FM-Wechat-Fronted/pages/customer-detail/index.js @@ -1,3 +1,5 @@ +const customersApi = require('../../api/customers') + function canCreateAppointment() { const app = getApp() const userInfo = app.globalData.userInfo || {} @@ -9,13 +11,10 @@ Page({ id: '', canCreateAppointment: true, avatarText: '客', - customer: { name: '王女士', phone: '138****1201' }, - stats: { orderCount: 12, amount: 2860, lastTime: '06-01' }, - orders: [ - { id: 1, date: '2026-06-01', project: '纯色美甲', amount: 168, artist: '小王' }, - { id: 2, date: '2026-05-18', project: '猫眼延长', amount: 268, artist: '小李' }, - { id: 3, date: '2026-05-02', project: '手部护理', amount: 98, artist: '小张' } - ] + customer: {}, + stats: { orderCount: 0, amount: 0, lastTime: '-' }, + orders: [], + loadError: '' }, onLoad(options) { @@ -23,6 +22,48 @@ Page({ id: options.id || '', canCreateAppointment: canCreateAppointment() }) + this.loadCustomer() + }, + + async loadCustomer() { + if (!this.data.id) { + this.setData({ + customer: {}, + stats: { orderCount: 0, amount: 0, lastTime: '-' }, + orders: [], + loadError: '缺少客户 ID' + }) + return + } + try { + const detail = await customersApi.detail(this.data.id) + if (!detail) { + throw new Error('客户详情不存在') + } + const customer = { + id: detail.id, + name: detail.nickname || detail.name || detail.account || '客户', + phone: detail.contactPhone || detail.phone || '未填写' + } + this.setData({ + customer, + avatarText: String(customer.name || '客').slice(-1), + stats: { + orderCount: detail.orderCount || detail.totalOrderCount || 0, + amount: detail.totalAmount || detail.consumeAmount || 0, + lastTime: detail.lastOrderTime || detail.lastConsumeTime || '-' + }, + orders: Array.isArray(detail.orders) ? detail.orders : [], + loadError: '' + }) + } catch (error) { + this.setData({ + customer: {}, + stats: { orderCount: 0, amount: 0, lastTime: '-' }, + orders: [], + loadError: error.message || '客户详情加载失败' + }) + } }, createAppointment() { @@ -30,7 +71,10 @@ Page({ wx.showToast({ title: '美甲师账号只能查看预约', icon: 'none' }) return } - wx.navigateTo({ url: '/pages/appointment-form/index' }) + const customer = this.data.customer || {} + wx.navigateTo({ + url: `/pages/appointment-form/index?customerName=${encodeURIComponent(customer.name || '')}&phone=${encodeURIComponent(customer.phone || '')}` + }) }, back() { diff --git a/FM-Wechat-Fronted/pages/customer-detail/index.wxml b/FM-Wechat-Fronted/pages/customer-detail/index.wxml index 4cc65201..b9f9a2a5 100644 --- a/FM-Wechat-Fronted/pages/customer-detail/index.wxml +++ b/FM-Wechat-Fronted/pages/customer-detail/index.wxml @@ -1,4 +1,10 @@ + + {{loadError}} + + + + {{avatarText}} @@ -28,13 +34,15 @@ 历史订单 + 暂无历史订单 - {{item.project}} - {{item.date}} · {{item.artist}} + {{item.project || item.productTitle || '预约作品'}} + {{item.date || item.appointmentDate || '-'}} · {{item.artist || item.artistName || '-'}} - ¥{{item.amount}} + ¥{{item.amount || item.payAmount || 0}} + diff --git a/FM-Wechat-Fronted/pages/customer-detail/index.wxss b/FM-Wechat-Fronted/pages/customer-detail/index.wxss index 21633e1b..5ab302ec 100644 --- a/FM-Wechat-Fronted/pages/customer-detail/index.wxss +++ b/FM-Wechat-Fronted/pages/customer-detail/index.wxss @@ -87,3 +87,10 @@ color: #6f8f83; font-weight: 900; } + +.retry-btn { + width: 180rpx; + min-width: 180rpx; + max-width: 180rpx; + margin: 24rpx auto 0; +} diff --git a/FM-Wechat-Fronted/pages/customers/index.js b/FM-Wechat-Fronted/pages/customers/index.js index 2e020c9b..cb5468c5 100644 --- a/FM-Wechat-Fronted/pages/customers/index.js +++ b/FM-Wechat-Fronted/pages/customers/index.js @@ -3,7 +3,14 @@ const customersApi = require('../../api/customers') Page({ data: { keyword: '', - customers: [] + customers: [], + loadError: '', + createModalVisible: false, + creating: false, + createForm: { + nickname: '', + phone: '' + } }, onLoad() { @@ -17,15 +24,11 @@ Page({ }, async loadCustomers() { - const fallback = [ - { id: 1, name: '王女士', phone: '138****1201', lastTime: '2026-06-01' }, - { id: 2, name: '陈女士', phone: '136****8842', lastTime: '2026-05-29' }, - { id: 3, name: '林女士', phone: '159****6671', lastTime: '2026-05-27' } - ] try { const data = await customersApi.list({ keyword: this.data.keyword, page: 1, size: 30 }) const list = data.list || data || [] this.setData({ + loadError: '', customers: list.map(item => ({ id: item.id, name: item.nickname || item.name || item.account || '客户', @@ -34,11 +37,65 @@ Page({ })) }) } catch (error) { - this.setData({ customers: fallback }) + this.setData({ + customers: [], + loadError: error.message || '客户列表加载失败' + }) } }, openDetail(event) { wx.navigateTo({ url: `/pages/customer-detail/index?id=${event.currentTarget.dataset.id}` }) + }, + + addCustomer() { + this.setData({ createModalVisible: true }) + }, + + closeCreateModal() { + if (this.data.creating) { + return + } + this.setData({ createModalVisible: false }) + }, + + stopTap() { + }, + + onCreateInput(event) { + this.setData({ + [`createForm.${event.currentTarget.dataset.field}`]: event.detail.value + }) + }, + + resetCreateForm() { + this.setData({ + createForm: { + nickname: '', + phone: '' + } + }) + }, + + async submitCustomer() { + const form = this.data.createForm + const nickname = String(form.nickname || '').trim() + const phone = String(form.phone || '').trim() + if (!nickname || !phone) { + wx.showToast({ title: '请填写客户姓名和手机号', icon: 'none' }) + return + } + this.setData({ creating: true }) + try { + await customersApi.create({ nickname, phone }) + wx.showToast({ title: '客户已新增', icon: 'success' }) + this.resetCreateForm() + this.setData({ createModalVisible: false }) + await this.loadCustomers() + } catch (error) { + wx.showToast({ title: error.message || '新增失败', icon: 'none' }) + } finally { + this.setData({ creating: false }) + } } }) diff --git a/FM-Wechat-Fronted/pages/customers/index.wxml b/FM-Wechat-Fronted/pages/customers/index.wxml index 00dbc320..c853c402 100644 --- a/FM-Wechat-Fronted/pages/customers/index.wxml +++ b/FM-Wechat-Fronted/pages/customers/index.wxml @@ -1,9 +1,17 @@ - - + + + + + + + {{loadError}} + + + 暂无客户 {{item.name}} @@ -13,4 +21,24 @@ › + + + + + 新增客户 + × + + + + 客户姓名 + + + + 手机号 + + + + + + diff --git a/FM-Wechat-Fronted/pages/customers/index.wxss b/FM-Wechat-Fronted/pages/customers/index.wxss index 29be2353..daf5bcf7 100644 --- a/FM-Wechat-Fronted/pages/customers/index.wxss +++ b/FM-Wechat-Fronted/pages/customers/index.wxss @@ -1,4 +1,11 @@ +.customer-toolbar { + display: flex; + align-items: center; + gap: 14rpx; +} + .search-card { + flex: 1; padding: 0 24rpx; height: 84rpx; display: flex; @@ -37,3 +44,106 @@ color: #b0a79e; font-size: 48rpx; } + +.retry-btn { + width: 180rpx; + min-width: 180rpx; + max-width: 180rpx; + margin: 24rpx auto 0; +} + +.modal-mask { + position: fixed; + inset: 0; + z-index: 80; + display: flex; + align-items: flex-end; + justify-content: center; + background: rgba(18, 15, 12, 0.48); +} + +.customer-modal { + width: 100%; + padding: 28rpx 28rpx calc(28rpx + env(safe-area-inset-bottom)); + border-radius: 28rpx 28rpx 0 0; + background: #fffaf4; + box-shadow: 0 -18rpx 40rpx rgba(41, 31, 23, 0.16); +} + +.modal-head { + display: flex; + align-items: center; + justify-content: space-between; + gap: 20rpx; + margin-bottom: 20rpx; +} + +.modal-title { + color: #27211d; + font-size: 34rpx; + font-weight: 900; +} + +.modal-close { + position: relative; + display: flex; + align-items: center; + justify-content: center; + width: 48rpx; + min-width: 48rpx; + height: 48rpx; + border: 1rpx solid #e4d8ca; + border-radius: 50%; + background: #fffaf4; + color: transparent; + font-size: 0; + line-height: 0; +} + +.modal-close::before, +.modal-close::after { + content: ""; + position: absolute; + width: 22rpx; + height: 3rpx; + border-radius: 999rpx; + background: #61554c; +} + +.modal-close::before { + transform: rotate(45deg); +} + +.modal-close::after { + transform: rotate(-45deg); +} + +.form-grid { + display: grid; + grid-template-columns: 1fr; + gap: 16rpx; +} + +.modal-field { + padding: 16rpx 18rpx; + border-radius: 18rpx; + background: #f7efe7; +} + +.modal-field text { + display: block; + margin-bottom: 8rpx; + color: #6c5f54; + font-size: 24rpx; + font-weight: 800; +} + +.modal-field input { + height: 58rpx; + color: #2c2722; + font-size: 28rpx; +} + +.modal-submit { + margin-top: 22rpx; +} diff --git a/FM-Wechat-Fronted/pages/employee-detail/index.js b/FM-Wechat-Fronted/pages/employee-detail/index.js index f00a3f7e..62831a66 100644 --- a/FM-Wechat-Fronted/pages/employee-detail/index.js +++ b/FM-Wechat-Fronted/pages/employee-detail/index.js @@ -1,23 +1,43 @@ -const mock = require('../../utils/mock') +const employeesApi = require('../../api/employees') + +const EMPLOYEE_COLORS = ['#7AA9C2', '#8EB99B', '#BDA7D8', '#D7B17D', '#D98D8D'] Page({ data: { id: '', - employee: {} + employee: {}, + loadError: '' }, onLoad(options) { - const id = options.id || mock.artists[0].id - const artist = mock.artists.find(item => String(item.id) === String(id)) || mock.artists[0] - this.setData({ - id, - employee: { - ...artist, - monthOrders: 32, - monthAmount: 5800, - avgAmount: 181 - } - }) + this.setData({ id: options.id || '' }) + this.loadDetail() + }, + + async loadDetail() { + try { + const data = await employeesApi.detail(this.data.id) + const name = data.nickname || data.name || data.artistName || '美甲师' + const monthOrders = data.monthOrders || data.orderCount || 0 + const monthAmount = data.monthAmount || data.turnover || 0 + this.setData({ + loadError: '', + employee: { + ...data, + name, + shortName: name.slice(-1), + color: data.color || EMPLOYEE_COLORS[0], + monthOrders, + monthAmount, + avgAmount: monthOrders > 0 ? Math.round(monthAmount / monthOrders) : 0 + } + }) + } catch (error) { + this.setData({ + employee: {}, + loadError: error.message || '美甲师详情加载失败' + }) + } }, go(event) { diff --git a/FM-Wechat-Fronted/pages/employee-detail/index.wxml b/FM-Wechat-Fronted/pages/employee-detail/index.wxml index ec050539..663ced2a 100644 --- a/FM-Wechat-Fronted/pages/employee-detail/index.wxml +++ b/FM-Wechat-Fronted/pages/employee-detail/index.wxml @@ -1,5 +1,10 @@ - + + {{loadError}} + + + + {{employee.shortName}} {{employee.name}} @@ -7,7 +12,7 @@ - + {{employee.monthOrders}} 本月订单 @@ -22,7 +27,7 @@ - + 排班设置 请假管理 diff --git a/FM-Wechat-Fronted/pages/employee-detail/index.wxss b/FM-Wechat-Fronted/pages/employee-detail/index.wxss index 077627b5..8c25beb1 100644 --- a/FM-Wechat-Fronted/pages/employee-detail/index.wxss +++ b/FM-Wechat-Fronted/pages/employee-detail/index.wxss @@ -5,6 +5,17 @@ padding: 28rpx; } +.detail-error { + margin-top: 24rpx; +} + +.retry-btn { + width: 180rpx; + min-width: 180rpx; + max-width: 180rpx; + margin: 24rpx auto 0; +} + .avatar { display: flex; align-items: center; diff --git a/FM-Wechat-Fronted/pages/employees/index.js b/FM-Wechat-Fronted/pages/employees/index.js index 0aac0929..c46f74be 100644 --- a/FM-Wechat-Fronted/pages/employees/index.js +++ b/FM-Wechat-Fronted/pages/employees/index.js @@ -1,16 +1,19 @@ const employeesApi = require('../../api/employees') -const mock = require('../../utils/mock') + +const EMPLOYEE_COLORS = ['#7AA9C2', '#8EB99B', '#BDA7D8', '#D7B17D', '#D98D8D'] +const DEFAULT_EMPLOYEE_PASSWORD = 'Fingertip@123' Page({ data: { employees: [], + loadError: '', createModalVisible: false, creating: false, createForm: { nickname: '', phone: '', account: '', - password: '888888', + password: DEFAULT_EMPLOYEE_PASSWORD, wechatId: '' } }, @@ -20,26 +23,25 @@ Page({ }, async loadEmployees() { - const fallback = mock.artists.map((item, index) => ({ - ...item, - monthOrders: 32 - index * 5, - monthAmount: 5800 - index * 760 - })) try { const data = await employeesApi.list({ page: 1, size: 50 }) const list = data.list || data || [] this.setData({ + loadError: '', employees: list.map((item, index) => ({ id: item.userId || item.id, name: item.nickname || item.name || item.artistName || `美甲师${index + 1}`, shortName: (item.nickname || item.name || '师').slice(-1), - color: mock.artists[index % mock.artists.length].color, + color: EMPLOYEE_COLORS[index % EMPLOYEE_COLORS.length], monthOrders: item.monthOrders || item.orderCount || 0, monthAmount: item.monthAmount || item.turnover || 0 })) }) } catch (error) { - this.setData({ employees: fallback }) + this.setData({ + employees: [], + loadError: error.message || '美甲师列表加载失败' + }) } }, @@ -79,7 +81,7 @@ Page({ nickname: '', phone: '', account: '', - password: '888888', + password: DEFAULT_EMPLOYEE_PASSWORD, wechatId: '' } }) diff --git a/FM-Wechat-Fronted/pages/employees/index.wxml b/FM-Wechat-Fronted/pages/employees/index.wxml index 4fd1a7e4..44e07b54 100644 --- a/FM-Wechat-Fronted/pages/employees/index.wxml +++ b/FM-Wechat-Fronted/pages/employees/index.wxml @@ -5,6 +5,11 @@ + + {{loadError}} + + + 暂无美甲师 {{item.shortName}} @@ -27,23 +32,23 @@ - 姓名 + 姓名 - 手机号 + 手机号 - 登录账号 + 登录账号 - 初始密码 + 初始密码 - 微信号 + 微信号 diff --git a/FM-Wechat-Fronted/pages/employees/index.wxss b/FM-Wechat-Fronted/pages/employees/index.wxss index 51399d20..b796a5d3 100644 --- a/FM-Wechat-Fronted/pages/employees/index.wxss +++ b/FM-Wechat-Fronted/pages/employees/index.wxss @@ -65,6 +65,13 @@ border-radius: 999rpx; } +.retry-btn { + width: 180rpx; + min-width: 180rpx; + max-width: 180rpx; + margin: 24rpx auto 0; +} + .modal-mask { position: fixed; inset: 0; @@ -102,18 +109,37 @@ } .modal-close { + position: relative; display: flex; align-items: center; justify-content: center; - width: 56rpx; - min-width: 56rpx; - height: 56rpx; + width: 48rpx; + min-width: 48rpx; + height: 48rpx; border-radius: 50%; - background: #f2e7da; - color: #61554c; - font-size: 32rpx; - font-weight: 800; - line-height: 1; + border: 1rpx solid #e4d8ca; + background: #fffaf4; + color: transparent; + font-size: 0; + line-height: 0; +} + +.modal-close::before, +.modal-close::after { + content: ""; + position: absolute; + width: 22rpx; + height: 3rpx; + border-radius: 999rpx; + background: #61554c; +} + +.modal-close::before { + transform: rotate(45deg); +} + +.modal-close::after { + transform: rotate(-45deg); } .form-grid { diff --git a/FM-Wechat-Fronted/pages/login/index.js b/FM-Wechat-Fronted/pages/login/index.js index 556e20c5..9819ff80 100644 --- a/FM-Wechat-Fronted/pages/login/index.js +++ b/FM-Wechat-Fronted/pages/login/index.js @@ -4,11 +4,12 @@ const { BRAND_CONFIG } = require('../../utils/config') const PHONE_REGEX = /^1[3-9]\d{9}$/ function buildSession(data) { + const userInfo = data.userInfo || data.user || {} return { ...data, accessToken: data.accessToken || data.token, - userInfo: data.userInfo || data.user || {}, - shopName: data.shopName || (data.shop && data.shop.shopName) + userInfo, + shopName: data.shopName || userInfo.shopName || (data.shop && data.shop.shopName) } } @@ -41,12 +42,22 @@ function buildShopOptionsFromSelection(selection) { const shops = selection && Array.isArray(selection.shops) ? selection.shops : [] return shops.map(shop => ({ id: shop.id, - name: shop.shopName || shop.name || `店铺 ${shop.id}` + name: shop.shopName || shop.name || `店铺 ${shop.id}`, + description: selection && selection.message ? selection.message : '' })) } function isShopSelectionRequiredError(error) { - return !!(error && error.message && error.message.indexOf('请选择登录店铺') !== -1) + const message = error && error.message ? error.message : '' + return message.indexOf('选择店铺') !== -1 || message.indexOf('请选择店铺') !== -1 || message.indexOf('请选择登录店铺') !== -1 +} + +function assertShopSession(session) { + const userInfo = session.userInfo || {} + if (!userInfo.shopId) { + throw new Error('请选择店铺后再进入管理师端') + } + return session } Page({ @@ -63,6 +74,7 @@ Page({ countdown: 0, countdownTimer: null, agreementAccepted: false, + rememberMe: false, agreements: [], appName: BRAND_CONFIG.appName, shopSelectVisible: false, @@ -125,6 +137,12 @@ Page({ }) }, + toggleRememberMe() { + this.setData({ + rememberMe: !this.data.rememberMe + }) + }, + buildAgreementPayload() { const agreementVersions = {} ;(this.data.agreements || []).forEach(item => { @@ -162,15 +180,13 @@ Page({ if (!shopOptions.length) { throw new Error('当前账号没有可用店铺,无法进入管理师端') } - const app = getApp() - app.setSession(session) if (shopOptions.length === 1) { - return buildSession(await authApi.switchShop(shopOptions[0].id)) + return this.loginForShop(shopOptions[0].id) } this.setData({ shopOptions, shopSelectVisible: true, - shopSelectMode: 'switch' + shopSelectMode: 'login' }) return null }, @@ -181,6 +197,7 @@ Page({ return { phone: String(form.phone || '').trim(), verificationCode: String(form.code || '').trim(), + rememberMe: !!this.data.rememberMe, ...this.buildAgreementPayload(), ...(shopId ? { shopId } : {}) } @@ -188,6 +205,7 @@ Page({ return { account: form.account, password: form.password, + rememberMe: !!this.data.rememberMe, ...(shopId ? { shopId } : {}) } }, @@ -199,6 +217,10 @@ Page({ : authApi.login(data) }, + async loginForShop(shopId) { + return assertShopSession(buildSession(await this.requestLogin(shopId))) + }, + async loadLoginShopOptions() { const form = this.data.form const selection = this.data.loginMode === 'phone' @@ -228,6 +250,15 @@ Page({ }) }, + async tryOpenLoginShopSelector() { + try { + await this.openLoginShopSelector() + return true + } catch (error) { + return false + } + }, + async selectLoginShop(event) { if (this.data.switchingShop) { return @@ -252,10 +283,7 @@ Page({ }, async loginWithSelectedShop(shopId) { - const session = await this.resolveLoginSession(await this.requestLogin(shopId)) - if (!session) { - return - } + const session = await this.loginForShop(shopId) const app = getApp() app.setSession(session) this.closeShopSelector() @@ -296,7 +324,7 @@ Page({ async submit() { const form = this.data.form if (this.data.loginMode === 'password' && (!form.account || !form.password)) { - wx.showToast({ title: '请填写手机号和密码', icon: 'none' }) + wx.showToast({ title: '请填写账号和密码', icon: 'none' }) return } if (this.data.loginMode === 'phone' && (!PHONE_REGEX.test(String(form.phone || '').trim()) || !String(form.code || '').trim())) { @@ -311,18 +339,20 @@ Page({ } this.setData({ loading: true }) try { - const data = await this.requestLogin('') const app = getApp() + const data = await this.requestLogin('') const session = await this.resolveLoginSession(data) if (!session) { return } - app.setSession(session) + app.setSession(assertShopSession(session)) wx.reLaunch({ url: '/pages/planning/index' }) } catch (error) { - if (isShopSelectionRequiredError(error)) { + if (isShopSelectionRequiredError(error) || await this.tryOpenLoginShopSelector()) { try { - await this.openLoginShopSelector() + if (!this.data.shopSelectVisible) { + await this.openLoginShopSelector() + } } catch (shopError) { wx.showToast({ title: shopError.message || '店铺列表加载失败', icon: 'none' }) } diff --git a/FM-Wechat-Fronted/pages/login/index.wxml b/FM-Wechat-Fronted/pages/login/index.wxml index d2cbc161..47b1538d 100644 --- a/FM-Wechat-Fronted/pages/login/index.wxml +++ b/FM-Wechat-Fronted/pages/login/index.wxml @@ -12,8 +12,8 @@ - 手机号 - + 账号 + 密码 @@ -36,6 +36,10 @@ {{agreementAccepted ? '✓' : ''}} 我已阅读并同意用户协议和隐私政策 + + {{rememberMe ? '✓' : ''}} + 记住登录 1 小时 + @@ -62,7 +66,7 @@ 店 {{item.name}} - ID {{item.id}} + {{item.description || ('ID ' + item.id)}} diff --git a/FM-Wechat-Fronted/pages/login/index.wxss b/FM-Wechat-Fronted/pages/login/index.wxss index f54f5531..7de65eb8 100644 --- a/FM-Wechat-Fronted/pages/login/index.wxss +++ b/FM-Wechat-Fronted/pages/login/index.wxss @@ -93,7 +93,8 @@ text-align: right; } -.agreement-row { +.agreement-row, +.remember-row { display: flex; align-items: center; gap: 14rpx; @@ -102,6 +103,10 @@ font-size: 24rpx; } +.remember-row { + margin-top: 18rpx; +} + .agreement-check { display: flex; align-items: center; diff --git a/FM-Wechat-Fronted/pages/planning/index.js b/FM-Wechat-Fronted/pages/planning/index.js index 2aea242b..d0822a98 100644 --- a/FM-Wechat-Fronted/pages/planning/index.js +++ b/FM-Wechat-Fronted/pages/planning/index.js @@ -7,14 +7,6 @@ function canCreateAppointment() { return Number(userInfo.type) !== 3 } -function buildEmptyCalendar() { - return { - artists: [], - appointments: [], - daySummaries: [] - } -} - function resolveCalendarErrorMessage(error) { return error && error.message ? error.message : '规划数据加载失败' } @@ -153,7 +145,7 @@ Page({ this.applyCalendar(data) this.setData({ calendarError: '' }) } catch (error) { - this.applyCalendar(buildEmptyCalendar()) + this.clearCalendarView() this.setData({ calendarError: resolveCalendarErrorMessage(error), selectedArtistId: '', @@ -168,6 +160,23 @@ Page({ } }, + clearCalendarView() { + this.setData({ + businessStartTime: '10:00', + businessEndTime: '22:00', + artists: [], + appointments: [], + daySummaries: [], + monthDays: [], + weekDays: [], + dayLanes: [], + hours: [], + dayTotal: 0, + freeArtistCount: 0, + pendingCount: 0 + }) + }, + resolveRange() { const current = this.data.currentDateText if (this.data.viewMode === 'week') { diff --git a/FM-Wechat-Fronted/pages/planning/index.wxml b/FM-Wechat-Fronted/pages/planning/index.wxml index 81ad7f86..ad66aec2 100644 --- a/FM-Wechat-Fronted/pages/planning/index.wxml +++ b/FM-Wechat-Fronted/pages/planning/index.wxml @@ -34,6 +34,7 @@ + @@ -146,6 +147,7 @@ + - + diff --git a/FM-Wechat-Fronted/utils/config.js b/FM-Wechat-Fronted/utils/config.js index a35b4ef7..ce4f386a 100644 --- a/FM-Wechat-Fronted/utils/config.js +++ b/FM-Wechat-Fronted/utils/config.js @@ -139,10 +139,10 @@ const DEVELOP_TARGET = Object.prototype.hasOwnProperty.call(localOverride, 'deve const BASE_DOMAIN = resolveDomain(DOMAIN_MAP, ENV_VERSION, DEVELOP_TARGET) const brandOverride = localOverride.brand || {} const BRAND_CONFIG = { - appName: String(brandOverride.appName || '指尖管理师'), - productName: String(brandOverride.productName || 'Fingertip Designer'), - defaultShopName: String(brandOverride.defaultShopName || 'Fingertip Designer'), - registerShopPlaceholder: String(brandOverride.registerShopPlaceholder || '例如:Fingertip Designer') + appName: String(brandOverride.appName || '甲屿店务'), + productName: String(brandOverride.productName || '甲屿设计师'), + defaultShopName: String(brandOverride.defaultShopName || '甲屿设计师'), + registerShopPlaceholder: String(brandOverride.registerShopPlaceholder || '例如:甲屿设计师') } module.exports = { diff --git a/FM-Wechat-Fronted/utils/config.local.example.js b/FM-Wechat-Fronted/utils/config.local.example.js index fb8172ef..e5a6b276 100644 --- a/FM-Wechat-Fronted/utils/config.local.example.js +++ b/FM-Wechat-Fronted/utils/config.local.example.js @@ -3,10 +3,10 @@ module.exports = { requestTimeout: 10000, enableRequestSigning: true, brand: { - appName: '指尖管理师', - productName: 'Fingertip Designer', - defaultShopName: 'Fingertip Designer', - registerShopPlaceholder: '例如:Fingertip Designer' + appName: '甲屿店务', + productName: '甲屿设计师', + defaultShopName: '甲屿设计师', + registerShopPlaceholder: '例如:甲屿设计师' }, domains: { local: 'http://127.0.0.1:80', diff --git a/FM-Wechat-Fronted/utils/mock.js b/FM-Wechat-Fronted/utils/mock.js deleted file mode 100644 index cfb18671..00000000 --- a/FM-Wechat-Fronted/utils/mock.js +++ /dev/null @@ -1,87 +0,0 @@ -const date = require('./date') - -const artists = [ - { id: 101, name: '小王', shortName: '王', color: '#7BA7C7', status: 1, statusText: '可预约', rangeCount: 0 }, - { id: 102, name: '小李', shortName: '李', color: '#8FB89A', status: 1, statusText: '可预约', rangeCount: 0 }, - { id: 103, name: '小张', shortName: '张', color: '#A894C7', status: 1, statusText: '可预约', rangeCount: 0 } -] - -function countFor(day, index) { - const seed = day.getDate() + index * 2 + day.getMonth() - if (seed % 7 === 0) return 0 - return (seed % 4) + 1 -} - -function buildCalendar(currentDate) { - const start = date.startOfMonth(currentDate) - const end = date.endOfMonth(currentDate) - const daySummaries = [] - const appointments = [] - let cursor = new Date(start.getTime()) - let orderItemId = 1 - while (cursor <= end) { - const dateText = date.formatDate(cursor) - const artistCounts = artists.map((artist, index) => { - const count = countFor(cursor, index) - return { - artistId: artist.id, - artistName: artist.name, - shortName: artist.shortName, - color: artist.color, - count, - status: count >= 4 ? 'full' : count > 0 ? 'working' : 'free' - } - }) - const totalCount = artistCounts.reduce((sum, item) => sum + item.count, 0) - daySummaries.push({ - date: dateText, - totalCount, - artistCounts, - dayStatus: totalCount >= 8 ? 'full' : totalCount > 0 ? 'working' : 'free' - }) - artistCounts.forEach((count, artistIndex) => { - for (let i = 0; i < Math.min(count.count, 3); i += 1) { - const startMinute = 10 * 60 + ((artistIndex * 90 + i * 110 + cursor.getDate() * 5) % 620) - const duration = i % 2 === 0 ? 90 : 60 - const artist = artists[artistIndex] - appointments.push({ - orderId: 9000 + orderItemId, - orderItemId, - customerName: ['王女士', '陈女士', '林女士', '赵女士'][i % 4], - customerPhone: '138****' + String(1000 + orderItemId).slice(-4), - productTitle: ['纯色美甲', '猫眼延长', '手部护理', '法式款'][i % 4], - artistId: artist.id, - artistName: artist.name, - artistColor: artist.color, - date: dateText, - startTime: `${dateText} ${date.timeFromMinutes(startMinute)}:00`, - endTime: `${dateText} ${date.timeFromMinutes(startMinute + duration)}:00`, - startMinute, - durationMinutes: duration, - status: i === 2 ? 0 : 1, - statusText: i === 2 ? '待确认' : '已确认', - remark: '' - }) - orderItemId += 1 - } - }) - cursor = date.addDays(cursor, 1) - } - artists.forEach(artist => { - artist.rangeCount = appointments.filter(item => item.artistId === artist.id).length - }) - return { - businessStartTime: '10:00', - businessEndTime: '22:00', - slotMinutes: 30, - artists, - schedules: [], - appointments, - daySummaries - } -} - -module.exports = { - artists, - buildCalendar -} diff --git a/FM-Wechat-Fronted/utils/request.js b/FM-Wechat-Fronted/utils/request.js index 714653c0..611ade8d 100644 --- a/FM-Wechat-Fronted/utils/request.js +++ b/FM-Wechat-Fronted/utils/request.js @@ -9,6 +9,8 @@ const HEADER_NONCE = 'X-Nonce' const HEADER_SIGNATURE = 'X-Signature' const HEADER_SIGNATURE_VERSION = 'X-Sign-Version' +let sessionExpiredHandling = false + function buildUrl(url, params) { const sourceParams = params || {} const baseUrl = sourceParams.__baseUrl ? sourceParams.__baseUrl : ADMIN_API_BASE_URL @@ -27,6 +29,47 @@ function normalizeError(message, raw) { return error } +function resolveResponseMessage(response, fallbackMessage) { + const data = response && response.data ? response.data : {} + return data.message || fallbackMessage +} + +function clearRuntimeSession() { + const app = getApp() + if (app && typeof app.clearSession === 'function') { + app.clearSession() + return + } + auth.clearSession() +} + +function redirectToLoginAfterExpired(message) { + if (sessionExpiredHandling) { + return + } + sessionExpiredHandling = true + clearRuntimeSession() + wx.showToast({ + title: message, + icon: 'none', + duration: 1200 + }) + setTimeout(() => { + wx.reLaunch({ + url: '/pages/login/index', + complete() { + sessionExpiredHandling = false + } + }) + }, 700) +} + +function handleUnauthorized(response) { + const message = resolveResponseMessage(response, '登录已过期,请重新登录') + redirectToLoginAfterExpired(message) + return normalizeError(message, response) +} + function extractPath(value) { const target = String(value || '') if (!target) { @@ -71,6 +114,7 @@ function isAuthFreePath(url) { '/auth/register', '/user/send-verification-code', '/user/phone-login', + '/user/check/login-shops/', '/legal-agreement/current' ].some(path => String(url || '').includes(path)) } @@ -134,9 +178,7 @@ function request(options) { }, success(response) { if (response.statusCode === 401) { - auth.clearSession() - wx.reLaunch({ url: '/pages/login/index' }) - reject(normalizeError('登录已失效,请重新登录', response)) + reject(handleUnauthorized(response)) return } if (response.statusCode >= 400) { @@ -149,6 +191,10 @@ function request(options) { resolve(payload.data) return } + if (payload.code === 401) { + reject(handleUnauthorized({ data: payload })) + return + } reject(normalizeError(payload.message || '请求失败', payload)) return }