修复Salon注册预约客户流程

This commit is contained in:
2026-10-30 15:13:38 +08:00
parent 53b6fcaa11
commit 7b9a5e4d1c
20 changed files with 748 additions and 67 deletions
@@ -110,10 +110,9 @@ public class PlanningServiceImpl implements PlanningService {
Long shopId = requirePlanningShopId(currentUser);
ShopDO shop = shopMapper.selectById(shopId);
PlanningCalendarSupport.BusinessHours businessHours = PlanningCalendarSupport.parseBusinessHours(
PlanningCalendarSupport.BusinessHours businessHours = parseConfiguredBusinessHours(
shop == null ? null : (StringUtils.hasText(shop.getAppointmentBusinessHours())
? shop.getAppointmentBusinessHours() : shop.getBusinessHours())
);
? shop.getAppointmentBusinessHours() : shop.getBusinessHours()));
List<PlanningArtistVO> artists = listArtists(shopId, artistId);
List<ArtistScheduleDO> schedules = listSchedules(shopId, start, end, artistId);
@@ -135,8 +134,8 @@ public class PlanningServiceImpl implements PlanningService {
artists.forEach(artist -> artist.setRangeCount(countByArtist.getOrDefault(artist.getId(), 0L).intValue()));
PlanningCalendarVO vo = new PlanningCalendarVO();
vo.setBusinessStartTime(businessHours.start().toString());
vo.setBusinessEndTime(businessHours.end().toString());
vo.setBusinessStartTime(businessHours == null ? null : businessHours.start().toString());
vo.setBusinessEndTime(businessHours == null ? null : businessHours.end().toString());
vo.setDefaultAppointmentDurationMinutes(shop == null || shop.getDefaultAppointmentDurationMinutes() == null
|| shop.getDefaultAppointmentDurationMinutes() <= 0 ? DEFAULT_DURATION_MINUTES : shop.getDefaultAppointmentDurationMinutes());
vo.setSlotMinutes(DEFAULT_SLOT_MINUTES);
@@ -862,7 +861,12 @@ public class PlanningServiceImpl implements PlanningService {
ShopDO shop = shopMapper.selectById(shopId);
String configuredHours = shop == null ? null : (StringUtils.hasText(shop.getAppointmentBusinessHours())
? shop.getAppointmentBusinessHours() : shop.getBusinessHours());
PlanningCalendarSupport.BusinessHours hours = PlanningCalendarSupport.parseBusinessHours(configuredHours);
PlanningCalendarSupport.BusinessHours hours = parseConfiguredBusinessHours(configuredHours);
if (hours == null) {
throw new RuntimeException(StringUtils.hasText(configuredHours)
? "门店营业时间格式无效,请先完成设置"
: "门店营业时间未设置,请先完成设置");
}
LocalTime start = startTime.toLocalTime();
LocalTime end = endTime.toLocalTime();
if (start.isBefore(hours.start()) || end.isAfter(hours.end()) || !startTime.toLocalDate().equals(endTime.toLocalDate())) {
@@ -870,6 +874,19 @@ public class PlanningServiceImpl implements PlanningService {
}
}
private PlanningCalendarSupport.BusinessHours parseConfiguredBusinessHours(String value) {
if (!StringUtils.hasText(value)) return null;
String[] parts = value.trim().split("-");
if (parts.length != 2) return null;
try {
LocalTime start = LocalTime.parse(parts[0].trim());
LocalTime end = LocalTime.parse(parts[1].trim());
return start.isBefore(end) ? new PlanningCalendarSupport.BusinessHours(start, end) : null;
} catch (RuntimeException ignored) {
return null;
}
}
private void ensureFutureAppointmentTime(LocalDateTime startTime) {
LocalDate today = LocalDate.now();
if (startTime.toLocalDate().isBefore(today)) {
@@ -227,7 +227,6 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopDO> implements
ContentModerationRecordDO latestReview = contentModerationRecordMapper.selectOne(Wrappers.lambdaQuery(ContentModerationRecordDO.class)
.eq(ContentModerationRecordDO::getContentType, "SHOP")
.eq(ContentModerationRecordDO::getBusinessId, id)
.eq(ContentModerationRecordDO::getIsDelete, 0)
.orderByDesc(ContentModerationRecordDO::getVersionNo)
.last("limit 1"));
result.setShopNameModerationStatus(latestReview == null ? shop.getModerationStatus() : latestReview.getStatus());
@@ -621,13 +621,12 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
return userMapper.selectList(wrapper).stream()
.filter(user -> Objects.equals(normalizedName, user.getNickname()))
.filter(user -> Objects.equals(normalizedWechatId, UserProfileFieldSupport.normalizeOptionalText(user.getWechatId())))
.filter(user -> Objects.equals(normalizedPhone, decryptPhone(user.getPhone())))
.filter(user -> Objects.equals(normalizedPhone, resolveCustomerPhone(user)))
.map(user -> {
AppointmentCustomerOptionVO customer = new AppointmentCustomerOptionVO();
customer.setId(user.getId());
customer.setName(user.getNickname());
String contactPhone = decryptPhone(user.getContactPhone());
customer.setPhone(StringUtils.hasText(contactPhone) ? contactPhone : decryptPhone(user.getPhone()));
customer.setPhone(resolveCustomerPhone(user));
customer.setAvatar(resolveAccessibleAvatar(user.getAvatar()));
customer.setCreatedAt(user.getCreateTime());
return customer;
@@ -656,9 +655,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
AppointmentCustomerOptionVO option = new AppointmentCustomerOptionVO();
option.setId(user.getId());
option.setName(user.getNickname());
String contactPhone = decryptPhone(user.getContactPhone());
String phone = StringUtils.hasText(contactPhone) ? contactPhone : decryptPhone(user.getPhone());
option.setPhone(phone);
option.setPhone(resolveCustomerPhone(user));
option.setAvatar(resolveAccessibleAvatar(user.getAvatar()));
option.setCreatedAt(user.getCreateTime());
return option;
@@ -676,6 +673,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
else wrapper.and(query -> query.eq(UserDO::getShopId, shopId).or().in(UserDO::getId, shopUserIds));
}
private String resolveCustomerPhone(UserDO customer) {
String contactPhone = decryptPhone(customer.getContactPhone());
return StringUtils.hasText(contactPhone) ? contactPhone : decryptPhone(customer.getPhone());
}
/**
* 分配默认权限
* @param userId 用户ID
@@ -102,6 +102,111 @@ class PlanningServiceImplTest {
verify(orderItemMapper, never()).insert(any(OrderItemDO.class));
}
@Test
void rejectsCreatingAppointmentForPastDate() {
UserDO operator = new UserDO();
operator.setType(2);
ShopDO shop = new ShopDO();
shop.setId(21L);
shop.setBusinessHours("10:00-22:00");
when(adminScopeHelper.resolveShopScope(operator, null)).thenReturn(21L);
when(shopMapper.selectById(21L)).thenReturn(shop);
PlanningAppointmentCreateDTO dto = new PlanningAppointmentCreateDTO();
dto.setAppointmentDate(java.time.LocalDate.now().minusDays(1).toString());
dto.setAppointmentTime("14:00");
RuntimeException error = assertThrows(RuntimeException.class, () -> service.createAppointment(operator, dto));
assertEquals("历史日期请使用历史补单", error.getMessage());
verify(orderMapper, never()).insert(any(OrderDO.class));
}
@Test
void rejectsAppointmentOutsideBusinessHours() {
UserDO operator = new UserDO();
operator.setType(2);
ShopDO shop = new ShopDO();
shop.setId(21L);
shop.setAppointmentBusinessHours("10:00-20:00");
when(adminScopeHelper.resolveShopScope(operator, null)).thenReturn(21L);
when(shopMapper.selectById(21L)).thenReturn(shop);
PlanningAppointmentCreateDTO dto = new PlanningAppointmentCreateDTO();
dto.setAppointmentDate(java.time.LocalDate.now().plusDays(2).toString());
dto.setAppointmentTime("19:30");
dto.setDurationMinutes(60);
RuntimeException error = assertThrows(RuntimeException.class, () -> service.createAppointment(operator, dto));
assertEquals("预约时间超出店铺营业时间", error.getMessage());
verify(orderMapper, never()).insert(any(OrderDO.class));
}
@Test
void rejectsAppointmentWhenShopBusinessHoursAreMissing() {
UserDO operator = new UserDO();
operator.setType(2);
ShopDO shop = new ShopDO();
shop.setId(21L);
when(adminScopeHelper.resolveShopScope(operator, null)).thenReturn(21L);
when(shopMapper.selectById(21L)).thenReturn(shop);
PlanningAppointmentCreateDTO dto = new PlanningAppointmentCreateDTO();
dto.setAppointmentDate(java.time.LocalDate.now().plusDays(2).toString());
dto.setAppointmentTime("14:00");
dto.setDurationMinutes(60);
RuntimeException error = assertThrows(RuntimeException.class, () -> service.createAppointment(operator, dto));
assertEquals("门店营业时间未设置,请先完成设置", error.getMessage());
verify(orderMapper, never()).insert(any(OrderDO.class));
}
@Test
void usesShopDefaultDurationWhenRequestOmitsDuration() {
UserDO operator = new UserDO();
operator.setType(2);
ShopDO shop = new ShopDO();
shop.setId(21L);
shop.setAppointmentBusinessHours("10:00-22:00");
shop.setDefaultAppointmentDurationMinutes(90);
when(adminScopeHelper.resolveShopScope(operator, null)).thenReturn(21L);
when(shopMapper.selectById(21L)).thenReturn(shop);
PlanningAppointmentCreateDTO dto = new PlanningAppointmentCreateDTO();
dto.setAppointmentDate(java.time.LocalDate.now().plusDays(2).toString());
dto.setAppointmentTime("21:00");
RuntimeException error = assertThrows(RuntimeException.class, () -> service.createAppointment(operator, dto));
assertEquals("预约时间超出店铺营业时间", error.getMessage());
verify(orderMapper, never()).insert(any(OrderDO.class));
}
@Test
void productDurationTakesPriorityOverShopDefaultWhenRequestOmitsDuration() {
UserDO operator = new UserDO();
operator.setType(2);
ShopDO shop = new ShopDO();
shop.setId(21L);
shop.setAppointmentBusinessHours("10:00-22:00");
shop.setDefaultAppointmentDurationMinutes(60);
ProductDO product = new ProductDO();
product.setId(41L);
product.setShopId(21L);
product.setIsDelete(0);
product.setApproximateDuration("120分钟");
when(adminScopeHelper.resolveShopScope(operator, null)).thenReturn(21L);
when(shopMapper.selectById(21L)).thenReturn(shop);
when(productMapper.selectById(41L)).thenReturn(product);
PlanningAppointmentCreateDTO dto = new PlanningAppointmentCreateDTO();
dto.setProductId(41L);
dto.setAppointmentDate(java.time.LocalDate.now().plusDays(2).toString());
dto.setAppointmentTime("21:00");
RuntimeException error = assertThrows(RuntimeException.class, () -> service.createAppointment(operator, dto));
assertEquals("预约时间超出店铺营业时间", error.getMessage());
verify(orderMapper, never()).insert(any(OrderDO.class));
}
@Test
void backfillOrderDoesNotCheckShopBusinessExpiry() {
service = spy(service);
@@ -0,0 +1,100 @@
package com.xiaowang.jayucloud.salon.core.modules.shop.service.impl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xiaowang.jayucloud.salon.core.config.AppCacheProperties;
import com.xiaowang.jayucloud.salon.core.modules.artist.service.NailArtistInfoService;
import com.xiaowang.jayucloud.salon.core.modules.content.mapper.CommentMapper;
import com.xiaowang.jayucloud.salon.core.modules.file.service.ObjectStorageFileService;
import com.xiaowang.jayucloud.salon.core.modules.file.support.ObjectStorageUrlSupport;
import com.xiaowang.jayucloud.salon.core.modules.integration.service.MapService;
import com.xiaowang.jayucloud.salon.core.modules.marketing.mapper.CouponMapper;
import com.xiaowang.jayucloud.salon.core.modules.marketing.mapper.UserCouponMapper;
import com.xiaowang.jayucloud.salon.core.modules.marketing.service.CouponService;
import com.xiaowang.jayucloud.salon.core.modules.order.mapper.OrderArtistReviewMapper;
import com.xiaowang.jayucloud.salon.core.modules.privacy.entity.ContentModerationRecordDO;
import com.xiaowang.jayucloud.salon.core.modules.privacy.mapper.ContentModerationRecordMapper;
import com.xiaowang.jayucloud.salon.core.modules.privacy.service.ContentModerationService;
import com.xiaowang.jayucloud.salon.core.modules.product.mapper.ProductMapper;
import com.xiaowang.jayucloud.salon.core.modules.product.mapper.TagMapper;
import com.xiaowang.jayucloud.salon.core.modules.shop.dto.ShopAppointmentSettingsDTO;
import com.xiaowang.jayucloud.salon.core.modules.shop.entity.ShopDO;
import com.xiaowang.jayucloud.salon.core.modules.shop.mapper.ShopMapper;
import com.xiaowang.jayucloud.salon.core.modules.shop.service.ShopBusinessExpiryService;
import com.xiaowang.jayucloud.salon.core.modules.shop.support.UserShopBindingSupport;
import com.xiaowang.jayucloud.salon.core.modules.shop.vo.ShopAppointmentSettingsVO;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class ShopAppointmentSettingsTest {
@Mock private ShopMapper shopMapper;
@Mock private ContentModerationRecordMapper contentModerationRecordMapper;
@Mock private ShopBusinessExpiryService shopBusinessExpiryService;
@Mock private CouponService couponService;
@Mock private CouponMapper couponMapper;
@Mock private ProductMapper productMapper;
@Mock private TagMapper tagMapper;
@Mock private CommentMapper commentMapper;
@Mock private UserCouponMapper userCouponMapper;
@Mock private OrderArtistReviewMapper orderArtistReviewMapper;
@Mock private ObjectStorageFileService objectStorageFileService;
@Mock private ObjectStorageUrlSupport objectStorageUrlSupport;
@Mock private UserShopBindingSupport userShopBindingSupport;
@Mock private NailArtistInfoService nailArtistInfoService;
@Mock private com.xiaowang.jayucloud.salon.core.support.cache.MultiLevelCacheService multiLevelCacheService;
@Mock private AppCacheProperties appCacheProperties;
@Mock private MapService mapService;
@Mock private ContentModerationService contentModerationService;
@Mock private ObjectMapper objectMapper;
@InjectMocks
private ShopServiceImpl shopService;
@Test
void savesAppointmentSettingsWithoutSubmittingPublicProfileForReview() {
ShopDO shop = new ShopDO();
shop.setId(21L);
shop.setBusinessHours("10:00-22:00");
when(shopMapper.selectById(21L)).thenReturn(shop);
when(shopMapper.updateById(any(ShopDO.class))).thenReturn(1);
ShopAppointmentSettingsDTO dto = new ShopAppointmentSettingsDTO();
dto.setBusinessHours("09:30-21:00");
dto.setDefaultAppointmentDurationMinutes(75);
assertTrue(shopService.updateAppointmentSettings(21L, dto));
ArgumentCaptor<ShopDO> saved = ArgumentCaptor.forClass(ShopDO.class);
verify(shopMapper).updateById(saved.capture());
assertEquals("09:30-21:00", saved.getValue().getAppointmentBusinessHours());
assertEquals(75, saved.getValue().getDefaultAppointmentDurationMinutes());
verifyNoInteractions(contentModerationService);
}
@Test
void returnsDefaultDurationForExistingShopWithoutConfiguredValue() {
ShopDO shop = new ShopDO();
shop.setId(21L);
shop.setShopName("薄荷美甲");
shop.setBusinessHours("09:00-21:00");
when(shopMapper.selectById(21L)).thenReturn(shop);
when(contentModerationRecordMapper.selectOne(any(Wrapper.class))).thenReturn(null);
ShopAppointmentSettingsVO settings = shopService.getAppointmentSettings(21L);
assertEquals("09:00-21:00", settings.getBusinessHours());
assertEquals(60, settings.getDefaultAppointmentDurationMinutes());
}
}
@@ -95,4 +95,23 @@ class UserServiceCustomerMatchingTest {
assertEquals("13800138000", matches.get(0).getPhone());
assertTrue(wrongWechat.isEmpty());
}
@Test
void appointmentIdentityLookupFallsBackToLegacyContactPhone() {
UserDO existing = new UserDO();
existing.setId(93L);
existing.setNickname("周女士");
existing.setWechatId("wx-zhou");
existing.setContactPhone("encrypted-contact-phone");
existing.setType(0);
existing.setIsDelete(0);
when(userMapper.selectList(any(Wrapper.class))).thenReturn(List.of(existing));
when(phoneCrypto.decrypt("encrypted-contact-phone")).thenReturn("13800138000");
List<com.xiaowang.jayucloud.salon.core.modules.manager.vo.AppointmentCustomerOptionVO> matches =
userService.findCustomerIdentityMatches("周女士", "wx-zhou", "13800138000", null);
assertEquals(1, matches.size());
assertEquals("13800138000", matches.get(0).getPhone());
}
}