diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/order/entity/OrderItemDO.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/order/entity/OrderItemDO.java index f0f63135..c53f72df 100644 --- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/order/entity/OrderItemDO.java +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/order/entity/OrderItemDO.java @@ -34,6 +34,9 @@ public class OrderItemDO extends BaseEntity { private BigDecimal referencePrice; private BigDecimal quotedPrice; private BigDecimal confirmedPrice; + private Boolean depositPaid; + private Boolean needRemoval; + private Boolean fromMeituan; /** * Field `artistId` (Long): data variable carried by this DTO/VO/entity. Check controller/service usage to see when it is filled. */ diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/dto/PlanningAppointmentCreateDTO.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/dto/PlanningAppointmentCreateDTO.java index 792db1f3..d48927c9 100644 --- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/dto/PlanningAppointmentCreateDTO.java +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/dto/PlanningAppointmentCreateDTO.java @@ -9,6 +9,9 @@ public class PlanningAppointmentCreateDTO { private Long customerUserId; private String customerName; private String phone; + private Boolean depositPaid; + private Boolean needRemoval; + private Boolean fromMeituan; private Long productId; private Integer quantity; private Long artistId; diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImpl.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImpl.java index 040b8189..71fdc64b 100644 --- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImpl.java +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImpl.java @@ -117,8 +117,9 @@ public class PlanningServiceImpl implements PlanningService { ); Map shopExceptionByDate = listShopScheduleExceptions(shopId, start, end); - List artists = listArtists(shopId, artistId); - List schedules = listSchedules(shopId, start, end, artists, artistId); + List artists = listArtists(shopId, null); + List selectedArtists = selectCalendarArtists(artists, artistId); + List schedules = listSchedules(shopId, start, end, selectedArtists, artistId); List scheduleVos = schedules.stream() .map(schedule -> toScheduleVO(schedule, artists)) .sorted(Comparator.comparing(PlanningScheduleVO::getDate) @@ -141,7 +142,8 @@ public class PlanningServiceImpl implements PlanningService { vo.setArtists(artists); vo.setSchedules(scheduleVos); vo.setAppointments(appointments); - vo.setDaySummaries(buildDaySummaries(start, end, artists, schedules, appointments, shop, shopExceptionByDate)); + vo.setDaySummaries(buildDaySummaries(start, end, selectedArtists, schedules, appointments, shop, shopExceptionByDate, + artistId != null && artistId > 0)); return vo; } @@ -195,6 +197,9 @@ public class PlanningServiceImpl implements PlanningService { item.setPrice(unitPrice); item.setArtistId(artist.getId()); item.setAppointmentTime(startTime); + item.setDepositPaid(Boolean.TRUE.equals(dto.getDepositPaid())); + item.setNeedRemoval(Boolean.TRUE.equals(dto.getNeedRemoval())); + item.setFromMeituan(Boolean.TRUE.equals(dto.getFromMeituan())); item.setIsDelete(0); orderItemMapper.insert(item); @@ -282,6 +287,15 @@ public class PlanningServiceImpl implements PlanningService { item.setPrice(unitPrice); item.setArtistId(artist.getId()); item.setAppointmentTime(startTime); + if (dto.getDepositPaid() != null) { + item.setDepositPaid(dto.getDepositPaid()); + } + if (dto.getNeedRemoval() != null) { + item.setNeedRemoval(dto.getNeedRemoval()); + } + if (dto.getFromMeituan() != null) { + item.setFromMeituan(dto.getFromMeituan()); + } orderItemMapper.updateById(item); return getAppointment(currentUser, item.getId()); } @@ -662,6 +676,9 @@ public class PlanningServiceImpl implements PlanningService { vo.setArtistId(artistId); vo.setArtistName(artist == null ? "未分配" : artist.getName()); vo.setArtistColor(artist == null ? ARTIST_COLORS.get(0) : artist.getColor()); + vo.setDepositPaid(item != null && Boolean.TRUE.equals(item.getDepositPaid())); + vo.setNeedRemoval(item != null && Boolean.TRUE.equals(item.getNeedRemoval())); + vo.setFromMeituan(item != null && Boolean.TRUE.equals(item.getFromMeituan())); vo.setDate(start == null ? null : start.toLocalDate().toString()); vo.setStartTime(start == null ? null : DATE_TIME_FORMATTER.format(start)); vo.setEndTime(end == null ? null : DATE_TIME_FORMATTER.format(end)); @@ -681,7 +698,8 @@ public class PlanningServiceImpl implements PlanningService { private List buildDaySummaries(LocalDate start, LocalDate end, List artists, List schedules, List appointments, - ShopDO shop, Map shopExceptionByDate) { + ShopDO shop, Map shopExceptionByDate, + boolean artistScoped) { Map> appointmentsByDate = appointments.stream() .filter(appointment -> appointment.getDate() != null) .collect(Collectors.groupingBy(PlanningAppointmentVO::getDate)); @@ -737,15 +755,30 @@ public class PlanningServiceImpl implements PlanningService { ShopScheduleSupport.LocalTimeRange openRange = ShopScheduleSupport.resolveOpenRange(shop, shopExceptionByDate.get(cursor), cursor); summary.setBusinessStartTime(openRange.startTime() == null ? null : openRange.startTime().toString()); summary.setBusinessEndTime(openRange.endTime() == null ? null : openRange.endTime().toString()); - summary.setDayStatus(openRange.open() - ? PlanningCalendarSupport.resolveDayStatus(total, hasWorkingSchedule, allFull) - : "rest"); + summary.setDayStatus(resolveDaySummaryStatus(openRange, total, hasWorkingSchedule, allFull, artistScoped)); summaries.add(summary); cursor = cursor.plusDays(1); } return summaries; } + private String resolveDaySummaryStatus(ShopScheduleSupport.LocalTimeRange openRange, int totalCount, + boolean hasWorkingSchedule, boolean allFull, boolean artistScoped) { + if (!openRange.open()) { + return "rest"; + } + if (artistScoped) { + return PlanningCalendarSupport.resolveDayStatus(totalCount, hasWorkingSchedule, allFull); + } + if (hasWorkingSchedule && allFull) { + return "full"; + } + if (totalCount <= 0) { + return "free"; + } + return "working"; + } + private Map listShopScheduleExceptions(Long shopId, LocalDate start, LocalDate end) { return shopScheduleExceptionMapper.selectList(new QueryWrapper() .eq("shop_id", shopId) @@ -884,23 +917,27 @@ public class PlanningServiceImpl implements PlanningService { } return customer; } - if (!hasText(dto.getPhone())) { - throw new RuntimeException("客户手机号不能为空"); + String customerName = trimToNull(dto.getCustomerName()); + String phone = trimToNull(dto.getPhone()); + if (hasText(phone)) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("is_delete", 0) + .and(query -> query.eq("phone", phone).or().eq("contact_phone", phone)) + .last("LIMIT 1"); + UserDO existing = userMapper.selectOne(wrapper); + if (existing != null) { + return existing; + } } - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("is_delete", 0) - .and(query -> query.eq("phone", dto.getPhone()).or().eq("contact_phone", dto.getPhone())) - .last("LIMIT 1"); - UserDO existing = userMapper.selectOne(wrapper); - if (existing != null) { - return existing; + if (!hasText(customerName)) { + throw new RuntimeException("客户姓名不能为空"); } UserDO customer = new UserDO(); customer.setShopId(shopId); - customer.setNickname(firstNonBlank(dto.getCustomerName(), dto.getPhone())); - customer.setPhone(dto.getPhone()); - customer.setContactPhone(dto.getPhone()); - customer.setAccount(dto.getPhone()); + customer.setNickname(firstNonBlank(customerName, phone, "到店客户")); + customer.setPhone(phone); + customer.setContactPhone(phone); + customer.setAccount("guest" + snowflakeIdGenerator.nextIdString()); customer.setPassword(ENCODED_UNSET_PASSWORD); customer.setType(0); customer.setStatus(1); @@ -909,6 +946,15 @@ public class PlanningServiceImpl implements PlanningService { return customer; } + private List selectCalendarArtists(List artists, Long artistId) { + if (artistId == null || artistId <= 0) { + return artists; + } + return artists.stream() + .filter(artist -> Objects.equals(artist.getId(), artistId)) + .toList(); + } + private String buildOrderCustomerNameSnapshot(PlanningAppointmentCreateDTO dto, UserDO customer) { return firstNonBlank( dto.getCustomerName(), diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/vo/PlanningAppointmentVO.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/vo/PlanningAppointmentVO.java index bf73cb8b..38bd39b1 100644 --- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/vo/PlanningAppointmentVO.java +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/vo/PlanningAppointmentVO.java @@ -25,6 +25,9 @@ public class PlanningAppointmentVO { private Integer status; private String statusText; private String occupancyStatus; + private Boolean depositPaid; + private Boolean needRemoval; + private Boolean fromMeituan; private Boolean canEdit; private Boolean canCancel; private String conflictReason; diff --git a/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImplTest.java b/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImplTest.java index 7b1be303..9c7719e6 100644 --- a/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImplTest.java +++ b/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImplTest.java @@ -211,6 +211,83 @@ class PlanningServiceImplTest { assertThat(appointment.getCustomerName()).isEqualTo("王女士"); } + @Test + void createAppointmentShouldCreateWalkInCustomerWithoutPhoneAndStoreFlags() { + UserDO manager = user(2, 8L); + UserDO artist = user(3, 8L); + artist.setId(20L); + ShopDO shop = new ShopDO(); + shop.setBusinessHours("10:00-22:00"); + PlanningAppointmentCreateDTO dto = new PlanningAppointmentCreateDTO(); + dto.setCustomerName(" 到店王女士 "); + dto.setArtistId(20L); + dto.setAppointmentDate("2026-07-20"); + dto.setAppointmentTime("15:00"); + dto.setDurationMinutes(60); + dto.setManualProductTitle("净色护理"); + dto.setManualProductPrice(new BigDecimal("128.00")); + dto.setDepositPaid(true); + dto.setNeedRemoval(true); + dto.setFromMeituan(true); + + ProductDO[] storedProduct = new ProductDO[1]; + UserDO[] storedCustomer = new UserDO[1]; + OrderDO[] storedOrder = new OrderDO[1]; + OrderItemDO[] storedItem = new OrderItemDO[1]; + when(adminScopeHelper.resolveShopScope(manager, null)).thenReturn(8L); + when(productMapper.insert(any(ProductDO.class))).thenAnswer(invocation -> { + ProductDO product = invocation.getArgument(0); + product.setId(100L); + storedProduct[0] = product; + return 1; + }); + when(userMapper.selectById(20L)).thenReturn(artist); + when(shopMapper.selectById(8L)).thenReturn(shop); + when(snowflakeIdGenerator.nextIdString()).thenReturn("202607200001", "202607200002"); + when(userMapper.insert(any(UserDO.class))).thenAnswer(invocation -> { + UserDO customer = invocation.getArgument(0); + customer.setId(30L); + storedCustomer[0] = customer; + return 1; + }); + when(orderMapper.insert(any(OrderDO.class))).thenAnswer(invocation -> { + OrderDO order = invocation.getArgument(0); + order.setId(200L); + storedOrder[0] = order; + return 1; + }); + when(orderItemMapper.insert(any(OrderItemDO.class))).thenAnswer(invocation -> { + OrderItemDO item = invocation.getArgument(0); + item.setId(300L); + storedItem[0] = item; + return 1; + }); + when(orderItemMapper.selectById(300L)).thenAnswer(invocation -> storedItem[0]); + when(orderMapper.selectById(200L)).thenAnswer(invocation -> storedOrder[0]); + when(productMapper.selectById(100L)).thenAnswer(invocation -> storedProduct[0]); + AppointmentReservationDO reservation = reservation(20L, 200L, 300L, + LocalDateTime.of(2026, 7, 20, 15, 0), + LocalDateTime.of(2026, 7, 20, 16, 0)); + when(appointmentReservationMapper.selectOne(any())).thenReturn(reservation); + when(userMapper.selectBatchIds(any())).thenAnswer(invocation -> List.of(storedCustomer[0])); + + var appointment = planningService.createAppointment(manager, dto); + + ArgumentCaptor customerCaptor = ArgumentCaptor.forClass(UserDO.class); + org.mockito.Mockito.verify(userMapper).insert(customerCaptor.capture()); + assertThat(customerCaptor.getValue().getNickname()).isEqualTo("到店王女士"); + assertThat(customerCaptor.getValue().getPhone()).isNull(); + assertThat(customerCaptor.getValue().getContactPhone()).isNull(); + assertThat(customerCaptor.getValue().getAccount()).isEqualTo("guest202607200001"); + assertThat(storedItem[0].getDepositPaid()).isTrue(); + assertThat(storedItem[0].getNeedRemoval()).isTrue(); + assertThat(storedItem[0].getFromMeituan()).isTrue(); + assertThat(appointment.getCustomerName()).isEqualTo("到店王女士"); + assertThat(appointment.getDepositPaid()).isTrue(); + assertThat(appointment.getNeedRemoval()).isTrue(); + assertThat(appointment.getFromMeituan()).isTrue(); + } + @Test void createAppointmentRejectsStoreRestDay() { UserDO manager = user(2, 8L); @@ -316,6 +393,73 @@ class PlanningServiceImplTest { assertThat(calendar.getAppointments().get(0).getCustomerName()).isEqualTo("预约王女士"); } + @Test + void calendarUsesShopStatusWhenNoEmployeeScheduleInShopView() { + UserDO manager = user(2, 8L); + UserDO firstArtist = user(3, 8L); + firstArtist.setId(20L); + firstArtist.setNickname("小王"); + UserDO secondArtist = user(3, 8L); + secondArtist.setId(21L); + secondArtist.setNickname("小李"); + LocalDate date = LocalDate.of(2026, 7, 20); + ShopDO shop = new ShopDO(); + shop.setBusinessHours("09:00-18:00"); + shop.setSchedulePresetType("EVERYDAY"); + + when(adminScopeHelper.resolveShopScope(manager, null)).thenReturn(8L); + when(shopMapper.selectById(8L)).thenReturn(shop); + when(shopScheduleExceptionMapper.selectList(any())).thenReturn(List.of()); + when(userMapper.selectList(any())).thenReturn(List.of(firstArtist, secondArtist)); + when(nailArtistInfoMapper.selectList(any())).thenReturn(List.of()); + when(artistScheduleMapper.selectList(any())).thenReturn(List.of()); + when(artistScheduleRuleMapper.selectList(any())).thenReturn(List.of()); + when(appointmentReservationMapper.selectList(any())).thenReturn(List.of()); + when(orderItemMapper.selectList(any())).thenReturn(List.of()); + + var calendar = planningService.getCalendar(manager, date, date, null); + + var summary = calendar.getDaySummaries().get(0); + assertThat(summary.getDayStatus()).isEqualTo("free"); + assertThat(summary.getArtistCounts()) + .extracting(count -> count.getArtistId() + ":" + count.getStatus()) + .containsExactly("20:rest", "21:rest"); + } + + @Test + void calendarUsesEmployeeStatusWhenSingleArtistHasNoSchedule() { + UserDO manager = user(2, 8L); + UserDO firstArtist = user(3, 8L); + firstArtist.setId(20L); + firstArtist.setNickname("小王"); + UserDO secondArtist = user(3, 8L); + secondArtist.setId(21L); + secondArtist.setNickname("小李"); + LocalDate date = LocalDate.of(2026, 7, 20); + ShopDO shop = new ShopDO(); + shop.setBusinessHours("09:00-18:00"); + shop.setSchedulePresetType("EVERYDAY"); + + when(adminScopeHelper.resolveShopScope(manager, null)).thenReturn(8L); + when(shopMapper.selectById(8L)).thenReturn(shop); + when(shopScheduleExceptionMapper.selectList(any())).thenReturn(List.of()); + when(userMapper.selectList(any())).thenReturn(List.of(firstArtist, secondArtist)); + when(nailArtistInfoMapper.selectList(any())).thenReturn(List.of()); + when(artistScheduleMapper.selectList(any())).thenReturn(List.of()); + when(artistScheduleRuleMapper.selectList(any())).thenReturn(List.of()); + when(appointmentReservationMapper.selectList(any())).thenReturn(List.of()); + when(orderItemMapper.selectList(any())).thenReturn(List.of()); + + var calendar = planningService.getCalendar(manager, date, date, 20L); + + assertThat(calendar.getArtists()).hasSize(2); + var summary = calendar.getDaySummaries().get(0); + assertThat(summary.getDayStatus()).isEqualTo("rest"); + assertThat(summary.getArtistCounts()) + .extracting(count -> count.getArtistId() + ":" + count.getStatus()) + .containsExactly("20:rest"); + } + @Test void calendarUsesRuleWhenDailyScheduleMissing() { UserDO manager = user(2, 8L); diff --git a/JY-Salon-WeChat/pages/appointment-form/index.js b/JY-Salon-WeChat/pages/appointment-form/index.js index 872ddec6..22aa37fb 100644 --- a/JY-Salon-WeChat/pages/appointment-form/index.js +++ b/JY-Salon-WeChat/pages/appointment-form/index.js @@ -269,6 +269,9 @@ Page({ manualProductImageUrl: '', durationMinutes: '', artistId: '', + depositPaid: false, + needRemoval: false, + fromMeituan: false, remark: '' }, customerOptions: [], @@ -378,6 +381,13 @@ Page({ } }, + onToggleChange(event) { + const field = event.currentTarget.dataset.field + this.setData({ + [`form.${field}`]: !!event.detail.value + }) + }, + onCustomerFocus(event) { const field = event.currentTarget.dataset.field this.setData({ customerDropdownVisible: true }) @@ -715,8 +725,10 @@ Page({ } const form = this.data.form const hasManualProduct = String(form.manualProductTitle || '').trim() && String(form.manualProductPrice || '').trim() + const customerName = String(form.customerName || '').trim() + const phone = String(form.phone || '').trim() const durationMinutes = normalizeDuration(form.durationMinutes) - if (!form.customerName || !form.phone || (!form.productId && !hasManualProduct) || !form.artistId) { + if (!customerName || (!form.productId && !hasManualProduct) || !form.artistId) { wx.showToast({ title: '请补全预约信息', icon: 'none' }) return } @@ -733,8 +745,13 @@ Page({ try { const payload = { ...form, + customerName, + phone: phone || undefined, customerUserId: form.customerUserId ? String(form.customerUserId) : undefined, artistId: String(form.artistId), + depositPaid: !!form.depositPaid, + needRemoval: !!form.needRemoval, + fromMeituan: !!form.fromMeituan, durationMinutes, clientRequestId: buildClientRequestId('manager-appointment') } diff --git a/JY-Salon-WeChat/pages/appointment-form/index.wxml b/JY-Salon-WeChat/pages/appointment-form/index.wxml index a725d8fe..e7047965 100644 --- a/JY-Salon-WeChat/pages/appointment-form/index.wxml +++ b/JY-Salon-WeChat/pages/appointment-form/index.wxml @@ -6,8 +6,8 @@ - 手机号 - + 手机号 + 正在搜索客户... @@ -58,6 +58,26 @@ › + + + + 是否交定金 + + + + + + 是否需要卸甲 + + + + + + 是否来自美团 + + + + 备注