diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/manager/controller/admin/AdminManagerController.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/manager/controller/admin/AdminManagerController.java index 8f28f65c..08a60a94 100644 --- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/manager/controller/admin/AdminManagerController.java +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/manager/controller/admin/AdminManagerController.java @@ -25,7 +25,9 @@ import com.xiaowang.jayucloud.core.modules.product.service.ProductService; import com.xiaowang.jayucloud.core.modules.product.vo.ProductVO; import com.xiaowang.jayucloud.core.modules.security.support.AdminScopeHelper; import com.xiaowang.jayucloud.core.modules.shop.dto.ShopDTO; +import com.xiaowang.jayucloud.core.modules.shop.dto.ShopScheduleExceptionDTO; import com.xiaowang.jayucloud.core.modules.shop.service.ShopService; +import com.xiaowang.jayucloud.core.modules.shop.vo.ShopScheduleExceptionVO; import com.xiaowang.jayucloud.core.modules.shop.vo.ShopVO; import com.xiaowang.jayucloud.core.modules.user.dto.UserDTO; import com.xiaowang.jayucloud.core.modules.user.entity.UserDO; @@ -294,4 +296,26 @@ public class AdminManagerController { } return Result.success(shopService.updateShop(shopId, dto)); } + + @GetMapping("/shop/schedule-exceptions") + @RequirePermission("shop:view") + public Result> shopScheduleExceptions(HttpServletRequest request, + @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate, + @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate) { + UserDO currentUser = adminScopeHelper.getCurrentUser(request); + Long shopId = adminScopeHelper.resolveShopScope(currentUser, null); + adminScopeHelper.requireShopContext(currentUser); + return Result.success(shopService.listScheduleExceptions(shopId, startDate, endDate)); + } + + @PostMapping("/shop/schedule-exceptions") + @RequirePermission("shop:edit") + @OperationGuard(action = "manager-shop-schedule-exception-save", ttlSeconds = 10, message = "店铺特殊日期保存处理中,请勿重复提交") + public Result saveShopScheduleException(HttpServletRequest request, + @RequestBody ShopScheduleExceptionDTO dto) { + UserDO currentUser = adminScopeHelper.getCurrentUser(request); + dto.setShopId(adminScopeHelper.resolveShopScope(currentUser, dto.getShopId())); + adminScopeHelper.requireShopContext(currentUser); + return Result.success(shopService.saveScheduleException(dto)); + } } 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 65117b9e..ab74c47d 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 @@ -11,6 +11,7 @@ import com.xiaowang.jayucloud.core.modules.order.entity.OrderDO; import com.xiaowang.jayucloud.core.modules.order.entity.OrderItemDO; import com.xiaowang.jayucloud.core.modules.product.entity.ProductDO; import com.xiaowang.jayucloud.core.modules.shop.entity.ShopDO; +import com.xiaowang.jayucloud.core.modules.shop.entity.ShopScheduleExceptionDO; import com.xiaowang.jayucloud.core.modules.user.entity.UserDO; import com.xiaowang.jayucloud.core.modules.planning.mapper.AppointmentReservationMapper; import com.xiaowang.jayucloud.core.modules.artist.mapper.ArtistScheduleMapper; @@ -19,6 +20,7 @@ import com.xiaowang.jayucloud.core.modules.order.mapper.OrderItemMapper; import com.xiaowang.jayucloud.core.modules.order.mapper.OrderMapper; import com.xiaowang.jayucloud.core.modules.product.mapper.ProductMapper; import com.xiaowang.jayucloud.core.modules.shop.mapper.ShopMapper; +import com.xiaowang.jayucloud.core.modules.shop.mapper.ShopScheduleExceptionMapper; import com.xiaowang.jayucloud.core.modules.user.mapper.UserMapper; import com.xiaowang.jayucloud.core.modules.planning.service.AppointmentCapacityService; import com.xiaowang.jayucloud.core.modules.order.service.OrderService; @@ -26,6 +28,7 @@ import com.xiaowang.jayucloud.core.modules.planning.service.PlanningService; import com.xiaowang.jayucloud.core.modules.security.support.AdminScopeHelper; import com.xiaowang.jayucloud.core.modules.order.support.OrderStatus; import com.xiaowang.jayucloud.core.modules.planning.support.PlanningCalendarSupport; +import com.xiaowang.jayucloud.core.modules.shop.support.ShopScheduleSupport; import com.xiaowang.jayucloud.core.support.id.TimeOrderedSnowflakeIdGenerator; import com.xiaowang.jayucloud.core.modules.planning.vo.PlanningAppointmentVO; import com.xiaowang.jayucloud.core.modules.planning.vo.PlanningArtistCountVO; @@ -83,6 +86,7 @@ public class PlanningServiceImpl implements PlanningService { private final OrderItemMapper orderItemMapper; private final ProductMapper productMapper; private final ShopMapper shopMapper; + private final ShopScheduleExceptionMapper shopScheduleExceptionMapper; private final AppointmentCapacityService appointmentCapacityService; private final OrderService orderService; private final TimeOrderedSnowflakeIdGenerator snowflakeIdGenerator; @@ -103,6 +107,7 @@ public class PlanningServiceImpl implements PlanningService { PlanningCalendarSupport.BusinessHours businessHours = PlanningCalendarSupport.parseBusinessHours( shop == null ? null : shop.getBusinessHours() ); + Map shopExceptionByDate = listShopScheduleExceptions(shopId, start, end); List artists = listArtists(shopId, artistId); List schedules = listSchedules(shopId, start, end, artistId); @@ -128,7 +133,7 @@ public class PlanningServiceImpl implements PlanningService { vo.setArtists(artists); vo.setSchedules(scheduleVos); vo.setAppointments(appointments); - vo.setDaySummaries(buildDaySummaries(start, end, artists, schedules, appointments)); + vo.setDaySummaries(buildDaySummaries(start, end, artists, schedules, appointments, shop, shopExceptionByDate)); return vo; } @@ -505,7 +510,8 @@ public class PlanningServiceImpl implements PlanningService { } private List buildDaySummaries(LocalDate start, LocalDate end, List artists, - List schedules, List appointments) { + List schedules, List appointments, + ShopDO shop, Map shopExceptionByDate) { Map> appointmentsByDate = appointments.stream() .filter(appointment -> appointment.getDate() != null) .collect(Collectors.groupingBy(PlanningAppointmentVO::getDate)); @@ -558,13 +564,27 @@ public class PlanningServiceImpl implements PlanningService { summary.setDate(date); summary.setTotalCount(total); summary.setArtistCounts(artistCounts); - summary.setDayStatus(PlanningCalendarSupport.resolveDayStatus(total, hasWorkingSchedule, allFull)); + 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"); summaries.add(summary); cursor = cursor.plusDays(1); } return summaries; } + private Map listShopScheduleExceptions(Long shopId, LocalDate start, LocalDate end) { + return shopScheduleExceptionMapper.selectList(new QueryWrapper() + .eq("shop_id", shopId) + .eq("is_delete", 0) + .between("work_date", start, end)) + .stream() + .collect(Collectors.toMap(ShopScheduleExceptionDO::getWorkDate, Function.identity(), (a, b) -> a)); + } + private String resolveArtistDayStatus(PlanningArtistVO artist, ArtistScheduleDO schedule, List appointments) { if (schedule != null && !Integer.valueOf(1).equals(schedule.getStatus())) { return "rest"; @@ -740,14 +760,26 @@ public class PlanningServiceImpl implements PlanningService { private void ensureWithinBusinessHours(Long shopId, LocalDateTime startTime, LocalDateTime endTime) { ShopDO shop = shopMapper.selectById(shopId); - PlanningCalendarSupport.BusinessHours hours = PlanningCalendarSupport.parseBusinessHours(shop == null ? null : shop.getBusinessHours()); + LocalDate workDate = startTime.toLocalDate(); + ShopScheduleSupport.LocalTimeRange hours = ShopScheduleSupport.resolveOpenRange(shop, selectShopScheduleException(shopId, workDate), workDate); + if (!hours.open()) { + throw new RuntimeException("当前日期为店铺休息日,不能预约:" + workDate); + } LocalTime start = startTime.toLocalTime(); LocalTime end = endTime.toLocalTime(); - if (start.isBefore(hours.start()) || end.isAfter(hours.end()) || !startTime.toLocalDate().equals(endTime.toLocalDate())) { + if (start.isBefore(hours.startTime()) || end.isAfter(hours.endTime()) || !startTime.toLocalDate().equals(endTime.toLocalDate())) { throw new RuntimeException("预约时间超出店铺营业时间"); } } + private ShopScheduleExceptionDO selectShopScheduleException(Long shopId, LocalDate workDate) { + return shopScheduleExceptionMapper.selectOne(new QueryWrapper() + .eq("shop_id", shopId) + .eq("work_date", workDate) + .eq("is_delete", 0) + .last("LIMIT 1")); + } + private LocalDateTime parseAppointmentStart(String appointmentStartTime, String appointmentDate, String appointmentTime) { if (hasText(appointmentStartTime)) { String normalized = appointmentStartTime.trim().replace('T', ' '); diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/vo/PlanningDaySummaryVO.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/vo/PlanningDaySummaryVO.java index 7ad0dba6..0e7240df 100644 --- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/vo/PlanningDaySummaryVO.java +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/vo/PlanningDaySummaryVO.java @@ -10,4 +10,6 @@ public class PlanningDaySummaryVO { private Integer totalCount; private List artistCounts; private String dayStatus; + private String businessStartTime; + private String businessEndTime; } diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/dto/ShopDTO.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/dto/ShopDTO.java index fcbc5be9..2129a4e2 100644 --- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/dto/ShopDTO.java +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/dto/ShopDTO.java @@ -54,6 +54,12 @@ public class ShopDTO { */ private String businessHours; + private String schedulePresetType; + + private String scheduleWorkDays; + + private String scheduleRemark; + /** * 店铺封面图文件ID集合(Banner图),多个ID以逗号分隔 */ diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/dto/ShopScheduleExceptionDTO.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/dto/ShopScheduleExceptionDTO.java new file mode 100644 index 00000000..5fa7aea4 --- /dev/null +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/dto/ShopScheduleExceptionDTO.java @@ -0,0 +1,16 @@ +package com.xiaowang.jayucloud.core.modules.shop.dto; + +import lombok.Data; + +import java.time.LocalDate; +import java.time.LocalTime; + +@Data +public class ShopScheduleExceptionDTO { + private Long shopId; + private LocalDate workDate; + private String exceptionType; + private LocalTime startTime; + private LocalTime endTime; + private String remark; +} diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/entity/ShopDO.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/entity/ShopDO.java index 9047f4d0..40e54de5 100644 --- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/entity/ShopDO.java +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/entity/ShopDO.java @@ -76,6 +76,15 @@ public class ShopDO extends BaseEntity { @TableField("business_hours") private String businessHours; + @TableField("schedule_preset_type") + private String schedulePresetType; + + @TableField("schedule_work_days") + private String scheduleWorkDays; + + @TableField("schedule_remark") + private String scheduleRemark; + /** * 店铺封面图文件ID集合(Banner图),多个ID以逗号分隔 */ diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/entity/ShopScheduleExceptionDO.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/entity/ShopScheduleExceptionDO.java new file mode 100644 index 00000000..9ce104fd --- /dev/null +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/entity/ShopScheduleExceptionDO.java @@ -0,0 +1,32 @@ +package com.xiaowang.jayucloud.core.modules.shop.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableLogic; +import com.baomidou.mybatisplus.annotation.TableName; +import com.xiaowang.jayucloud.core.common.entity.BaseEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.time.LocalDate; +import java.time.LocalTime; + +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("t_shop_schedule_exception") +public class ShopScheduleExceptionDO extends BaseEntity { + @TableField("shop_id") + private Long shopId; + @TableField("work_date") + private LocalDate workDate; + @TableField("exception_type") + private String exceptionType; + @TableField("start_time") + private LocalTime startTime; + @TableField("end_time") + private LocalTime endTime; + @TableField("remark") + private String remark; + @TableField("is_delete") + @TableLogic + private Integer isDelete; +} diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/mapper/ShopScheduleExceptionMapper.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/mapper/ShopScheduleExceptionMapper.java new file mode 100644 index 00000000..c5b6210a --- /dev/null +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/mapper/ShopScheduleExceptionMapper.java @@ -0,0 +1,9 @@ +package com.xiaowang.jayucloud.core.modules.shop.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.xiaowang.jayucloud.core.modules.shop.entity.ShopScheduleExceptionDO; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface ShopScheduleExceptionMapper extends BaseMapper { +} diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/service/ShopService.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/service/ShopService.java index 6d80350c..895ed867 100644 --- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/service/ShopService.java +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/service/ShopService.java @@ -3,10 +3,13 @@ package com.xiaowang.jayucloud.core.modules.shop.service; import com.baomidou.mybatisplus.extension.service.IService; import com.xiaowang.jayucloud.core.modules.shop.entity.ShopDO; import com.xiaowang.jayucloud.core.modules.shop.dto.ShopDTO; +import com.xiaowang.jayucloud.core.modules.shop.dto.ShopScheduleExceptionDTO; import com.xiaowang.jayucloud.core.common.vo.PageResultVO; +import com.xiaowang.jayucloud.core.modules.shop.vo.ShopScheduleExceptionVO; import com.xiaowang.jayucloud.core.modules.shop.vo.ShopTrustProfileVO; import com.xiaowang.jayucloud.core.modules.shop.vo.ShopVO; +import java.time.LocalDate; import java.util.List; /** @@ -110,4 +113,8 @@ public interface ShopService extends IService { * 前台可用:未删除、启用、且授权未到期。 */ boolean isFrontendAvailable(Long shopId); + + List listScheduleExceptions(Long shopId, LocalDate startDate, LocalDate endDate); + + ShopScheduleExceptionVO saveScheduleException(ShopScheduleExceptionDTO dto); } diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/service/impl/ShopServiceImpl.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/service/impl/ShopServiceImpl.java index c2b57239..c7788b82 100644 --- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/service/impl/ShopServiceImpl.java +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/service/impl/ShopServiceImpl.java @@ -7,11 +7,13 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.fasterxml.jackson.core.type.TypeReference; import com.xiaowang.jayucloud.core.config.AppCacheProperties; import com.xiaowang.jayucloud.core.modules.shop.dto.ShopDTO; +import com.xiaowang.jayucloud.core.modules.shop.dto.ShopScheduleExceptionDTO; import com.xiaowang.jayucloud.core.modules.marketing.entity.CouponDO; import com.xiaowang.jayucloud.core.modules.content.entity.CommentDO; import com.xiaowang.jayucloud.core.modules.order.entity.OrderArtistReviewDO; import com.xiaowang.jayucloud.core.modules.product.entity.ProductDO; import com.xiaowang.jayucloud.core.modules.shop.entity.ShopDO; +import com.xiaowang.jayucloud.core.modules.shop.entity.ShopScheduleExceptionDO; import com.xiaowang.jayucloud.core.modules.product.entity.TagDO; import com.xiaowang.jayucloud.core.modules.marketing.entity.UserCouponDO; import com.xiaowang.jayucloud.core.modules.content.mapper.CommentMapper; @@ -19,6 +21,7 @@ import com.xiaowang.jayucloud.core.modules.marketing.mapper.CouponMapper; import com.xiaowang.jayucloud.core.modules.order.mapper.OrderArtistReviewMapper; import com.xiaowang.jayucloud.core.modules.product.mapper.ProductMapper; import com.xiaowang.jayucloud.core.modules.shop.mapper.ShopMapper; +import com.xiaowang.jayucloud.core.modules.shop.mapper.ShopScheduleExceptionMapper; import com.xiaowang.jayucloud.core.modules.product.mapper.TagMapper; import com.xiaowang.jayucloud.core.modules.marketing.mapper.UserCouponMapper; import com.xiaowang.jayucloud.core.modules.marketing.service.CouponService; @@ -27,11 +30,13 @@ import com.xiaowang.jayucloud.core.modules.artist.service.NailArtistInfoService; import com.xiaowang.jayucloud.core.modules.file.service.ObjectStorageFileService; import com.xiaowang.jayucloud.core.modules.shop.service.ShopService; import com.xiaowang.jayucloud.core.modules.file.support.ObjectStorageUrlSupport; +import com.xiaowang.jayucloud.core.modules.shop.support.ShopScheduleSupport; import com.xiaowang.jayucloud.core.modules.shop.support.ShopThemeSupport; import com.xiaowang.jayucloud.core.modules.shop.support.UserShopBindingSupport; import com.xiaowang.jayucloud.core.support.cache.MultiLevelCacheService; import com.xiaowang.jayucloud.core.modules.file.vo.ObjectStorageFileVO; import com.xiaowang.jayucloud.core.common.vo.PageResultVO; +import com.xiaowang.jayucloud.core.modules.shop.vo.ShopScheduleExceptionVO; import com.xiaowang.jayucloud.core.modules.shop.vo.ShopTrustProfileVO; import com.xiaowang.jayucloud.core.modules.shop.vo.ShopVO; import lombok.RequiredArgsConstructor; @@ -89,6 +94,7 @@ public class ShopServiceImpl extends ServiceImpl implements * Variable `shopMapper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls. */ private final ShopMapper shopMapper; + private final ShopScheduleExceptionMapper shopScheduleExceptionMapper; /** * Variable `couponService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls. */ @@ -161,6 +167,7 @@ public class ShopServiceImpl extends ServiceImpl implements shopDO.setLongitude(shopDTO.getLongitude()); shopDO.setLatitude(shopDTO.getLatitude()); shopDO.setBusinessHours(shopDTO.getBusinessHours()); + applyScheduleRule(shopDO, shopDTO); shopDO.setCoverImageFileId(shopDTO.getCoverImageFileId()); shopDO.setImageFileIds(shopDTO.getImageFileIds()); applyTheme(shopDO, shopDTO); @@ -196,6 +203,7 @@ public class ShopServiceImpl extends ServiceImpl implements shopDO.setLongitude(shopDTO.getLongitude()); shopDO.setLatitude(shopDTO.getLatitude()); shopDO.setBusinessHours(shopDTO.getBusinessHours()); + applyScheduleRule(shopDO, shopDTO); shopDO.setCoverImageFileId(shopDTO.getCoverImageFileId()); shopDO.setImageFileIds(shopDTO.getImageFileIds()); applyTheme(shopDO, shopDTO); @@ -453,6 +461,45 @@ public class ShopServiceImpl extends ServiceImpl implements return result; } + @Override + public List listScheduleExceptions(Long shopId, LocalDate startDate, LocalDate endDate) { + if (shopId == null) { + throw new RuntimeException("店铺ID不能为空"); + } + LocalDate start = startDate == null ? LocalDate.now() : startDate; + LocalDate end = endDate == null ? start.plusDays(60L) : endDate; + if (end.isBefore(start)) { + end = start; + } + return shopScheduleExceptionMapper.selectList(Wrappers.lambdaQuery(ShopScheduleExceptionDO.class) + .eq(ShopScheduleExceptionDO::getShopId, shopId) + .eq(ShopScheduleExceptionDO::getIsDelete, 0) + .between(ShopScheduleExceptionDO::getWorkDate, start, end) + .orderByAsc(ShopScheduleExceptionDO::getWorkDate)) + .stream() + .map(this::toScheduleExceptionVO) + .toList(); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public ShopScheduleExceptionVO saveScheduleException(ShopScheduleExceptionDTO dto) { + ShopScheduleExceptionDO normalized = normalizeScheduleException(dto); + ShopScheduleExceptionDO existing = shopScheduleExceptionMapper.selectOne(Wrappers.lambdaQuery(ShopScheduleExceptionDO.class) + .eq(ShopScheduleExceptionDO::getShopId, normalized.getShopId()) + .eq(ShopScheduleExceptionDO::getWorkDate, normalized.getWorkDate()) + .eq(ShopScheduleExceptionDO::getIsDelete, 0) + .last("LIMIT 1")); + if (existing == null) { + shopScheduleExceptionMapper.insert(normalized); + } else { + normalized.setId(existing.getId()); + shopScheduleExceptionMapper.updateById(normalized); + } + evictShopCaches(normalized.getShopId()); + return toScheduleExceptionVO(normalized); + } + /** * Purpose: countActiveProducts counts products that can contribute to a public shop trust profile. * Usage: call it with a valid shop id before rendering product trust metrics. @@ -768,6 +815,9 @@ public class ShopServiceImpl extends ServiceImpl implements shopVO.setLatitude(shopDO.getLatitude()); shopVO.setNavigationUrls(mapService.buildNavigationUrls(shopDO.getShopName(), shopDO.getAddress(), shopDO.getLongitude(), shopDO.getLatitude())); shopVO.setBusinessHours(shopDO.getBusinessHours()); + shopVO.setSchedulePresetType(ShopScheduleSupport.normalizePresetType(shopDO.getSchedulePresetType())); + shopVO.setScheduleWorkDays(ShopScheduleSupport.normalizeWorkDays(shopDO.getScheduleWorkDays(), shopDO.getSchedulePresetType())); + shopVO.setScheduleRemark(shopDO.getScheduleRemark()); shopVO.setCoverImageFileId(shopDO.getCoverImageFileId()); shopVO.setCoverImageUrls(new java.util.ArrayList<>()); shopVO.setImageFileIds(shopDO.getImageFileIds()); @@ -870,6 +920,50 @@ public class ShopServiceImpl extends ServiceImpl implements shopDO.setAuthorizationExpireTime(shopDTO.getAuthorizationExpireTime()); } + private void applyScheduleRule(ShopDO shopDO, ShopDTO shopDTO) { + if (shopDO.getId() != null && !StringUtils.hasText(shopDTO.getSchedulePresetType()) + && !StringUtils.hasText(shopDTO.getScheduleWorkDays()) && !StringUtils.hasText(shopDTO.getScheduleRemark())) { + return; + } + String presetType = ShopScheduleSupport.normalizePresetType(shopDTO.getSchedulePresetType()); + shopDO.setSchedulePresetType(presetType); + shopDO.setScheduleWorkDays(ShopScheduleSupport.normalizeWorkDays(shopDTO.getScheduleWorkDays(), presetType)); + shopDO.setScheduleRemark(StringUtils.hasText(shopDTO.getScheduleRemark()) ? shopDTO.getScheduleRemark().trim() : null); + } + + private ShopScheduleExceptionDO normalizeScheduleException(ShopScheduleExceptionDTO dto) { + if (dto == null || dto.getShopId() == null || dto.getWorkDate() == null) { + throw new RuntimeException("店铺特殊日期信息不完整"); + } + String exceptionType = ShopScheduleSupport.normalizeExceptionType(dto.getExceptionType()); + if (!ShopScheduleSupport.EXCEPTION_REST.equals(exceptionType) + && (dto.getStartTime() == null || dto.getEndTime() == null || !dto.getStartTime().isBefore(dto.getEndTime()))) { + throw new RuntimeException("临时营业或改班必须填写正确的开始和结束时间"); + } + ShopScheduleExceptionDO exception = new ShopScheduleExceptionDO(); + exception.setShopId(dto.getShopId()); + exception.setWorkDate(dto.getWorkDate()); + exception.setExceptionType(exceptionType); + exception.setStartTime(ShopScheduleSupport.EXCEPTION_REST.equals(exceptionType) ? null : dto.getStartTime()); + exception.setEndTime(ShopScheduleSupport.EXCEPTION_REST.equals(exceptionType) ? null : dto.getEndTime()); + exception.setRemark(StringUtils.hasText(dto.getRemark()) ? dto.getRemark().trim() : null); + exception.setIsDelete(0); + return exception; + } + + private ShopScheduleExceptionVO toScheduleExceptionVO(ShopScheduleExceptionDO exception) { + ShopScheduleExceptionVO vo = new ShopScheduleExceptionVO(); + vo.setId(exception.getId()); + vo.setShopId(exception.getShopId()); + vo.setWorkDate(exception.getWorkDate()); + vo.setExceptionType(exception.getExceptionType()); + vo.setStartTime(exception.getStartTime()); + vo.setEndTime(exception.getEndTime()); + vo.setRemark(exception.getRemark()); + vo.setCreateTime(exception.getCreateTime()); + return vo; + } + /** * Purpose: applyTheme supports ShopServiceImpl.java by holding or executing the apply theme business role. * Usage: reference this method from the owning layer and pass validated inputs before reading or updating related state. diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/support/ShopScheduleSupport.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/support/ShopScheduleSupport.java new file mode 100644 index 00000000..3dd16c51 --- /dev/null +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/support/ShopScheduleSupport.java @@ -0,0 +1,127 @@ +package com.xiaowang.jayucloud.core.modules.shop.support; + +import com.xiaowang.jayucloud.core.modules.planning.support.PlanningCalendarSupport; +import com.xiaowang.jayucloud.core.modules.shop.entity.ShopDO; +import com.xiaowang.jayucloud.core.modules.shop.entity.ShopScheduleExceptionDO; + +import java.time.DayOfWeek; +import java.time.LocalDate; +import java.time.LocalTime; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +public final class ShopScheduleSupport { + public static final String PRESET_EVERYDAY = "EVERYDAY"; + public static final String PRESET_DOUBLE_REST = "DOUBLE_REST"; + public static final String PRESET_SINGLE_REST = "SINGLE_REST"; + public static final String PRESET_CUSTOM = "CUSTOM"; + public static final String EXCEPTION_REST = "REST"; + public static final String EXCEPTION_EXTRA_WORK = "EXTRA_WORK"; + public static final String EXCEPTION_CHANGE_SHIFT = "CHANGE_SHIFT"; + private static final List EVERYDAY_WORK_DAYS = List.of(1, 2, 3, 4, 5, 6, 7); + + private ShopScheduleSupport() { + } + + public static String normalizePresetType(String presetType) { + if (presetType == null || presetType.trim().isEmpty()) { + return PRESET_EVERYDAY; + } + String value = presetType.trim(); + if (PRESET_EVERYDAY.equals(value) || PRESET_DOUBLE_REST.equals(value) + || PRESET_SINGLE_REST.equals(value) || PRESET_CUSTOM.equals(value)) { + return value; + } + throw new RuntimeException("不支持的店铺排班预设:" + value); + } + + public static List resolveWorkDays(String workDays, String presetType) { + String normalizedPreset = normalizePresetType(presetType); + List presetDays = switch (normalizedPreset) { + case PRESET_DOUBLE_REST -> List.of(1, 2, 3, 4, 5); + case PRESET_SINGLE_REST -> List.of(1, 2, 3, 4, 5, 6); + case PRESET_EVERYDAY -> EVERYDAY_WORK_DAYS; + default -> workDays == null ? List.of() : decodeWorkDays(workDays); + }; + List normalized = normalizeWorkDays(presetDays); + if (normalized.isEmpty()) { + throw new RuntimeException("请至少选择一个店铺营业日"); + } + return normalized; + } + + public static String normalizeWorkDays(String workDays, String presetType) { + return encodeWorkDays(resolveWorkDays(workDays, presetType)); + } + + public static List decodeWorkDays(String workDays) { + if (workDays == null) { + return EVERYDAY_WORK_DAYS; + } + if (workDays.trim().isEmpty()) { + return List.of(); + } + return List.of(workDays.split(",")).stream() + .map(String::trim) + .filter(value -> !value.isEmpty()) + .map(Integer::valueOf) + .toList(); + } + + public static String encodeWorkDays(List workDays) { + return normalizeWorkDays(workDays).stream() + .map(String::valueOf) + .collect(Collectors.joining(",")); + } + + public static String normalizeExceptionType(String exceptionType) { + if (exceptionType == null || exceptionType.trim().isEmpty()) { + throw new RuntimeException("特殊日期类型不能为空"); + } + String value = exceptionType.trim(); + if (EXCEPTION_REST.equals(value) || EXCEPTION_EXTRA_WORK.equals(value) || EXCEPTION_CHANGE_SHIFT.equals(value)) { + return value; + } + throw new RuntimeException("不支持的店铺特殊日期类型:" + value); + } + + public static LocalTimeRange resolveOpenRange(ShopDO shop, ShopScheduleExceptionDO exception, LocalDate workDate) { + PlanningCalendarSupport.BusinessHours businessHours = PlanningCalendarSupport.parseBusinessHours(shop == null ? null : shop.getBusinessHours()); + if (exception != null) { + if (EXCEPTION_REST.equals(exception.getExceptionType())) { + return new LocalTimeRange(false, businessHours.start(), businessHours.end(), exceptionRemark(exception)); + } + if (EXCEPTION_EXTRA_WORK.equals(exception.getExceptionType()) || EXCEPTION_CHANGE_SHIFT.equals(exception.getExceptionType())) { + if (exception.getStartTime() == null || exception.getEndTime() == null) { + throw new RuntimeException("店铺特殊日期营业时间不完整:" + exception.getWorkDate()); + } + return new LocalTimeRange(true, exception.getStartTime(), exception.getEndTime(), exceptionRemark(exception)); + } + } + List workDays = resolveWorkDays(shop == null ? null : shop.getScheduleWorkDays(), shop == null ? null : shop.getSchedulePresetType()); + boolean open = workDays.contains(workDate.getDayOfWeek().getValue()); + return new LocalTimeRange(open, businessHours.start(), businessHours.end(), "店铺常规营业"); + } + + private static List normalizeWorkDays(List workDays) { + Set normalized = new LinkedHashSet<>(); + for (Integer day : workDays == null ? List.of() : workDays) { + if (day != null && day >= DayOfWeek.MONDAY.getValue() && day <= DayOfWeek.SUNDAY.getValue()) { + normalized.add(day); + } + } + return normalized.stream().sorted().toList(); + } + + private static String exceptionRemark(ShopScheduleExceptionDO exception) { + if (exception.getRemark() != null && !exception.getRemark().isBlank()) { + return exception.getRemark(); + } + return "店铺特殊日期:" + exception.getExceptionType(); + } + + public record LocalTimeRange(boolean open, LocalTime startTime, LocalTime endTime, String remark) { + } +} diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/vo/ShopScheduleExceptionVO.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/vo/ShopScheduleExceptionVO.java new file mode 100644 index 00000000..470f093e --- /dev/null +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/vo/ShopScheduleExceptionVO.java @@ -0,0 +1,19 @@ +package com.xiaowang.jayucloud.core.modules.shop.vo; + +import lombok.Data; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; + +@Data +public class ShopScheduleExceptionVO { + private Long id; + private Long shopId; + private LocalDate workDate; + private String exceptionType; + private LocalTime startTime; + private LocalTime endTime; + private String remark; + private LocalDateTime createTime; +} diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/vo/ShopVO.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/vo/ShopVO.java index 7279b1c7..8dffa79d 100644 --- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/vo/ShopVO.java +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/vo/ShopVO.java @@ -70,6 +70,12 @@ public class ShopVO { */ private String businessHours; + private String schedulePresetType; + + private String scheduleWorkDays; + + private String scheduleRemark; + /** * 店铺封面图文件ID集合(Banner图),多个ID以逗号分隔 */ diff --git a/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/manager/controller/admin/AdminManagerControllerTest.java b/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/manager/controller/admin/AdminManagerControllerTest.java index 31bab44d..d1da0d9e 100644 --- a/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/manager/controller/admin/AdminManagerControllerTest.java +++ b/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/manager/controller/admin/AdminManagerControllerTest.java @@ -18,7 +18,9 @@ import com.xiaowang.jayucloud.core.modules.product.service.ProductService; import com.xiaowang.jayucloud.core.modules.product.vo.ProductVO; import com.xiaowang.jayucloud.core.modules.security.support.AdminScopeHelper; import com.xiaowang.jayucloud.core.modules.shop.dto.ShopDTO; +import com.xiaowang.jayucloud.core.modules.shop.dto.ShopScheduleExceptionDTO; import com.xiaowang.jayucloud.core.modules.shop.service.ShopService; +import com.xiaowang.jayucloud.core.modules.shop.vo.ShopScheduleExceptionVO; import com.xiaowang.jayucloud.core.modules.shop.vo.ShopVO; import com.xiaowang.jayucloud.core.modules.user.dto.UserDTO; import com.xiaowang.jayucloud.core.modules.user.entity.UserDO; @@ -248,6 +250,24 @@ class AdminManagerControllerTest { verify(shopService).updateShop(8L, dto); } + @Test + void saveShopScheduleExceptionShouldResolveShopScopeBeforeSaving() { + MockHttpServletRequest request = new MockHttpServletRequest(); + UserDO manager = new UserDO(); + ShopScheduleExceptionDTO dto = new ShopScheduleExceptionDTO(); + dto.setShopId(99L); + ShopScheduleExceptionVO vo = new ShopScheduleExceptionVO(); + when(adminScopeHelper.getCurrentUser(request)).thenReturn(manager); + when(adminScopeHelper.resolveShopScope(manager, 99L)).thenReturn(8L); + when(shopService.saveScheduleException(dto)).thenReturn(vo); + + Result result = controller.saveShopScheduleException(request, dto); + + assertThat(result.getData()).isSameAs(vo); + assertThat(dto.getShopId()).isEqualTo(8L); + verify(adminScopeHelper).requireShopContext(manager); + } + @Test void employeesShouldReturnScopedArtistsForNonPlatformUser() { MockHttpServletRequest request = new MockHttpServletRequest(); 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 56ec586e..2ce09c72 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 @@ -17,6 +17,7 @@ import com.xiaowang.jayucloud.core.modules.product.mapper.ProductMapper; import com.xiaowang.jayucloud.core.modules.security.support.AdminScopeHelper; import com.xiaowang.jayucloud.core.modules.shop.entity.ShopDO; import com.xiaowang.jayucloud.core.modules.shop.mapper.ShopMapper; +import com.xiaowang.jayucloud.core.modules.shop.mapper.ShopScheduleExceptionMapper; import com.xiaowang.jayucloud.core.modules.user.entity.UserDO; import com.xiaowang.jayucloud.core.modules.user.mapper.UserMapper; import com.xiaowang.jayucloud.core.support.id.TimeOrderedSnowflakeIdGenerator; @@ -34,6 +35,7 @@ import java.time.LocalTime; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -67,6 +69,9 @@ class PlanningServiceImplTest { @Mock private ShopMapper shopMapper; + @Mock + private ShopScheduleExceptionMapper shopScheduleExceptionMapper; + @Mock private AppointmentCapacityService appointmentCapacityService; @@ -90,6 +95,7 @@ class PlanningServiceImplTest { orderItemMapper, productMapper, shopMapper, + shopScheduleExceptionMapper, appointmentCapacityService, orderService, snowflakeIdGenerator @@ -187,6 +193,41 @@ class PlanningServiceImplTest { assertThat(product.getImageFileIds()).isNull(); } + @Test + void createAppointmentRejectsStoreRestDay() { + 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"); + shop.setSchedulePresetType("DOUBLE_REST"); + shop.setScheduleWorkDays("1,2,3,4,5"); + PlanningAppointmentCreateDTO dto = new PlanningAppointmentCreateDTO(); + dto.setCustomerUserId(30L); + dto.setArtistId(20L); + dto.setAppointmentDate("2026-07-04"); + dto.setAppointmentTime("13:00"); + dto.setDurationMinutes(60); + dto.setManualProductTitle("周末测试"); + dto.setManualProductPrice(new BigDecimal("100.00")); + + 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(shopScheduleExceptionMapper.selectOne(any())).thenReturn(null); + + assertThatThrownBy(() -> planningService.createAppointment(manager, dto)) + .hasMessageContaining("当前日期为店铺休息日"); + } + @Test void calendarMarksMonthAvailabilityByContinuousNinetyMinuteWindow() { UserDO manager = user(2, 8L); @@ -211,6 +252,7 @@ class PlanningServiceImplTest { 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(freeArtist, shortShiftArtist)); when(nailArtistInfoMapper.selectList(any())).thenReturn(List.of()); when(artistScheduleMapper.selectList(any())).thenReturn(List.of(freeSchedule, shortSchedule)); diff --git a/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/shop/service/impl/ShopServiceImplTest.java b/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/shop/service/impl/ShopServiceImplTest.java index f3b04e24..3a43d875 100644 --- a/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/shop/service/impl/ShopServiceImplTest.java +++ b/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/shop/service/impl/ShopServiceImplTest.java @@ -10,6 +10,7 @@ import com.xiaowang.jayucloud.core.modules.marketing.mapper.CouponMapper; import com.xiaowang.jayucloud.core.modules.order.mapper.OrderArtistReviewMapper; import com.xiaowang.jayucloud.core.modules.product.mapper.ProductMapper; import com.xiaowang.jayucloud.core.modules.shop.mapper.ShopMapper; +import com.xiaowang.jayucloud.core.modules.shop.mapper.ShopScheduleExceptionMapper; import com.xiaowang.jayucloud.core.modules.product.mapper.TagMapper; import com.xiaowang.jayucloud.core.modules.marketing.mapper.UserCouponMapper; import com.xiaowang.jayucloud.core.modules.marketing.service.CouponService; @@ -44,6 +45,8 @@ class ShopServiceImplTest { @Mock private ShopMapper shopMapper; @Mock + private ShopScheduleExceptionMapper shopScheduleExceptionMapper; + @Mock private CouponService couponService; @Mock private CouponMapper couponMapper; @@ -79,6 +82,7 @@ class ShopServiceImplTest { MockitoAnnotations.openMocks(this); service = new ShopServiceImpl( shopMapper, + shopScheduleExceptionMapper, couponService, couponMapper, productMapper, diff --git a/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/shop/support/ShopScheduleSupportTest.java b/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/shop/support/ShopScheduleSupportTest.java new file mode 100644 index 00000000..de461d80 --- /dev/null +++ b/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/shop/support/ShopScheduleSupportTest.java @@ -0,0 +1,52 @@ +package com.xiaowang.jayucloud.core.modules.shop.support; + +import com.xiaowang.jayucloud.core.modules.shop.entity.ShopDO; +import com.xiaowang.jayucloud.core.modules.shop.entity.ShopScheduleExceptionDO; +import org.junit.jupiter.api.Test; + +import java.time.LocalDate; +import java.time.LocalTime; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +class ShopScheduleSupportTest { + + @Test + void defaultScheduleKeepsExistingStoresOpenEveryDay() { + ShopDO shop = new ShopDO(); + shop.setBusinessHours("10:00-22:00"); + + ShopScheduleSupport.LocalTimeRange range = ShopScheduleSupport.resolveOpenRange(shop, null, LocalDate.of(2026, 7, 5)); + + assertThat(range.open()).isTrue(); + assertThat(range.startTime()).isEqualTo(LocalTime.of(10, 0)); + assertThat(range.endTime()).isEqualTo(LocalTime.of(22, 0)); + } + + @Test + void doubleRestClosesWeekendAndSpecialDateCanOpenTemporarily() { + ShopDO shop = new ShopDO(); + shop.setSchedulePresetType(ShopScheduleSupport.PRESET_DOUBLE_REST); + shop.setScheduleWorkDays("1,2,3,4,5"); + shop.setBusinessHours("09:00-18:00"); + ShopScheduleExceptionDO exception = new ShopScheduleExceptionDO(); + exception.setExceptionType(ShopScheduleSupport.EXCEPTION_EXTRA_WORK); + exception.setStartTime(LocalTime.of(10, 0)); + exception.setEndTime(LocalTime.of(16, 0)); + + ShopScheduleSupport.LocalTimeRange closedRange = ShopScheduleSupport.resolveOpenRange(shop, null, LocalDate.of(2026, 7, 4)); + ShopScheduleSupport.LocalTimeRange openRange = ShopScheduleSupport.resolveOpenRange(shop, exception, LocalDate.of(2026, 7, 4)); + + assertThat(closedRange.open()).isFalse(); + assertThat(openRange.open()).isTrue(); + assertThat(openRange.startTime()).isEqualTo(LocalTime.of(10, 0)); + assertThat(openRange.endTime()).isEqualTo(LocalTime.of(16, 0)); + } + + @Test + void rejectsEmptyCustomWorkDays() { + assertThatThrownBy(() -> ShopScheduleSupport.resolveWorkDays("", ShopScheduleSupport.PRESET_CUSTOM)) + .hasMessageContaining("请至少选择一个店铺营业日"); + } +} diff --git a/JY-Salon-Front/src/api/managerShop.ts b/JY-Salon-Front/src/api/managerShop.ts index aa092e6a..48a12dda 100644 --- a/JY-Salon-Front/src/api/managerShop.ts +++ b/JY-Salon-Front/src/api/managerShop.ts @@ -1,5 +1,5 @@ import { adminApi } from '@/api/client' -import type { ShopInfo } from '@/types/manager' +import type { ShopInfo, ShopScheduleException } from '@/types/manager' export const managerShopApi = { info(): Promise { @@ -8,6 +8,12 @@ export const managerShopApi = { update(data: Partial): Promise { return adminApi.put('/manager/shop', data) }, + scheduleExceptions(params?: { startDate?: string; endDate?: string }): Promise { + return adminApi.get('/manager/shop/schedule-exceptions', { params }) + }, + saveScheduleException(data: ShopScheduleException): Promise { + return adminApi.post('/manager/shop/schedule-exceptions', data) + }, exportPreview(params: { type: string; startDate: string; endDate: string }): Promise { return adminApi.get('/export', { params }) } diff --git a/JY-Salon-Front/src/types/manager.ts b/JY-Salon-Front/src/types/manager.ts index 5744caf3..65edb8c3 100644 --- a/JY-Salon-Front/src/types/manager.ts +++ b/JY-Salon-Front/src/types/manager.ts @@ -86,16 +86,20 @@ export interface ArtistScheduleException { artistId: IdType shopId?: IdType workDate: string + exceptionType?: string startTime?: string endTime?: string status: number reason?: string + remark?: string } export interface DaySummary { date: string totalCount: number dayStatus?: string + businessStartTime?: string + businessEndTime?: string artistCounts?: Array<{ artistId: IdType artistName?: string @@ -153,12 +157,25 @@ export interface ShopInfo { businessHours?: string startTime?: string endTime?: string + schedulePresetType?: string + scheduleWorkDays?: string + scheduleRemark?: string description?: string logo?: string imageUrl?: string authorizationExpireTime?: string } +export interface ShopScheduleException { + id?: IdType + shopId?: IdType + workDate: string + exceptionType: string + startTime?: string + endTime?: string + remark?: string +} + export interface CustomerCreateRequest { nickname: string phone: string diff --git a/JY-Salon-Front/src/utils/available-times.test.ts b/JY-Salon-Front/src/utils/available-times.test.ts index 4cee3f0f..47065cf0 100644 --- a/JY-Salon-Front/src/utils/available-times.test.ts +++ b/JY-Salon-Front/src/utils/available-times.test.ts @@ -52,4 +52,28 @@ describe('available time groups', () => { expect(groups[0]?.times.map(item => item.value)).toEqual(['10:00']) }) + + it('returns no slots when the store day is closed', () => { + const calendar: PlanningCalendar = { + daySummaries: [{ date: '2026-06-29', totalCount: 0, dayStatus: 'rest' }], + schedules: [{ artistId: 1, date: '2026-06-29', startTime: '10:00', endTime: '12:00', status: 1 }] + } + + const groups = buildAvailableTimeGroups(calendar, buildForm()) + + expect(groups).toEqual([]) + }) + + it('clamps slots to store business hours from day summary', () => { + const calendar: PlanningCalendar = { + daySummaries: [{ date: '2026-06-29', totalCount: 0, dayStatus: 'free', businessStartTime: '09:00', businessEndTime: '10:30' }], + schedules: [{ artistId: 1, date: '2026-06-29', startTime: '08:00', endTime: '12:00', status: 1 }] + } + const form = buildForm() + form.durationMinutes = '60' + + const groups = buildAvailableTimeGroups(calendar, form) + + expect(groups[0]?.times.map(item => item.value)).toEqual(['09:00', '09:15', '09:30']) + }) }) diff --git a/JY-Salon-Front/src/utils/available-times.ts b/JY-Salon-Front/src/utils/available-times.ts index e35fce98..9c5299b1 100644 --- a/JY-Salon-Front/src/utils/available-times.ts +++ b/JY-Salon-Front/src/utils/available-times.ts @@ -46,11 +46,24 @@ const hasBusyConflict = (startMinute: number, endMinute: number, ranges: Array<{ return ranges.some(range => startMinute < range.endMinute && endMinute > range.startMinute) } +const clampToBusinessHours = (startMinute: number, endMinute: number, businessStartTime?: string, businessEndTime?: string): { startMinute: number; endMinute: number } => { + const businessStartMinute = businessStartTime ? minutesOfDay(businessStartTime) : startMinute + const businessEndMinute = businessEndTime ? minutesOfDay(businessEndTime) : endMinute + return { + startMinute: Math.max(startMinute, businessStartMinute), + endMinute: Math.min(endMinute, businessEndMinute) + } +} + export const buildAvailableTimeGroups = (calendar: PlanningCalendar, form: AppointmentForm): AvailableTimeGroup[] => { const durationMinutes = normalizeDuration(form.durationMinutes) if (!durationMinutes) { return [] } + const daySummary = (calendar.daySummaries || []).find(item => item.date === form.appointmentDate) + if (daySummary?.dayStatus === 'rest') { + return [] + } const schedules = (calendar.schedules || []) .filter((item: ArtistSchedule) => String(item.artistId) === String(form.artistId)) .filter(item => item.date === form.appointmentDate) @@ -62,8 +75,14 @@ export const buildAvailableTimeGroups = (calendar: PlanningCalendar, form: Appoi evening: { key: 'evening', title: '晚上', times: [] } } schedules.forEach(schedule => { - const scheduleStart = minutesOfDay(extractTimeText(schedule.startTime)) - const scheduleEnd = minutesOfDay(extractTimeText(schedule.endTime)) + const range = clampToBusinessHours( + minutesOfDay(extractTimeText(schedule.startTime)), + minutesOfDay(extractTimeText(schedule.endTime)), + daySummary?.businessStartTime, + daySummary?.businessEndTime + ) + const scheduleStart = range.startMinute + const scheduleEnd = range.endMinute for (let minute = scheduleStart; minute + durationMinutes <= scheduleEnd; minute += TIME_SLOT_MINUTES) { const endMinute = minute + durationMinutes if (!hasBusyConflict(minute, endMinute, busyRanges)) { diff --git a/JY-Salon-Front/src/views/AppointmentFormView.vue b/JY-Salon-Front/src/views/AppointmentFormView.vue index aaa60bcb..56b4890d 100644 --- a/JY-Salon-Front/src/views/AppointmentFormView.vue +++ b/JY-Salon-Front/src/views/AppointmentFormView.vue @@ -278,8 +278,17 @@ const checkAvailability = async (): Promise<{ ok: boolean; tip?: string }> => { } const startMinute = minutesOfDay(form.appointmentTime) const endMinute = startMinute + normalizeDuration(form.durationMinutes) - if (startMinute < minutesOfDay('10:00') || endMinute > minutesOfDay('22:00')) { - conflictTip.value = '该时间超出营业时间 10:00-22:00' + const calendar = await managerPlanningApi.calendar({ startDate: form.appointmentDate, endDate: form.appointmentDate, artistId: form.artistId }) + const daySummary = (calendar.daySummaries || []).find(item => item.date === form.appointmentDate) + const businessStartTime = String(daySummary?.businessStartTime || calendar.businessStartTime || '10:00').slice(0, 5) + const businessEndTime = String(daySummary?.businessEndTime || calendar.businessEndTime || '22:00').slice(0, 5) + if (daySummary?.dayStatus === 'rest') { + conflictTip.value = '当前日期为店铺休息日' + conflictLevel.value = 'danger' + return { ok: false, tip: conflictTip.value } + } + if (startMinute < minutesOfDay(businessStartTime) || endMinute > minutesOfDay(businessEndTime)) { + conflictTip.value = `该时间超出营业时间 ${businessStartTime}-${businessEndTime}` conflictLevel.value = 'danger' return { ok: false, tip: conflictTip.value } } diff --git a/JY-Salon-Front/src/views/ShopSettingsView.vue b/JY-Salon-Front/src/views/ShopSettingsView.vue index ab003726..a3a9a594 100644 --- a/JY-Salon-Front/src/views/ShopSettingsView.vue +++ b/JY-Salon-Front/src/views/ShopSettingsView.vue @@ -2,35 +2,116 @@
-
- - - - - -
+

{{ helpModal.content }}

@@ -51,22 +132,60 @@ @@ -150,4 +379,72 @@ onMounted(loadInfo) color: #504a43; line-height: 1.7; } + +.preset-grid, +.weekday-grid { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 10px; +} + +.weekday-grid { + grid-template-columns: repeat(4, minmax(0, 1fr)); +} + +.preset-chip, +.weekday-chip { + min-height: 38px; + border: 1px solid #e3ddd2; + border-radius: 8px; + background: #fffaf2; + color: #5f564c; + font-weight: 700; +} + +.preset-chip.active, +.weekday-chip.active { + border-color: #75a78e; + background: #e5f2eb; + color: #2f6b55; +} + +.field-block { + display: grid; + gap: 10px; +} + +.field-title { + color: #6f665c; + font-size: 13px; + font-weight: 800; +} + +.section-action { + width: 100%; + margin: 12px 0; +} + +.exception-list { + display: grid; + gap: 12px; +} + +.exception-card__title { + margin: 0; + color: #2f2a25; + font-size: 16px; +} + +.exception-card__subtitle, +.exception-card__remark { + margin: 4px 0 0; + color: #7b7167; + font-size: 13px; +} + +@media (min-width: 768px) { + .preset-grid { + grid-template-columns: repeat(4, minmax(0, 1fr)); + } +} diff --git a/JY-Salon-WeChat/api/shop.js b/JY-Salon-WeChat/api/shop.js index 52a8542f..0caa3b87 100644 --- a/JY-Salon-WeChat/api/shop.js +++ b/JY-Salon-WeChat/api/shop.js @@ -15,6 +15,21 @@ module.exports = { }) }, + scheduleExceptions(params) { + return request({ + url: '/manager/shop/schedule-exceptions', + params + }) + }, + + saveScheduleException(data) { + return request({ + url: '/manager/shop/schedule-exceptions', + method: 'POST', + data + }) + }, + exportData(params) { return request({ url: '/export', diff --git a/JY-Salon-WeChat/pages/appointment-form/index.js b/JY-Salon-WeChat/pages/appointment-form/index.js index 532588c0..872ddec6 100644 --- a/JY-Salon-WeChat/pages/appointment-form/index.js +++ b/JY-Salon-WeChat/pages/appointment-form/index.js @@ -137,7 +137,20 @@ function hasBusyConflict(startMinute, endMinute, ranges) { return ranges.some(range => startMinute < range.endMinute && endMinute > range.startMinute) } +function clampToBusinessHours(startMinute, endMinute, businessStartTime, businessEndTime) { + const businessStartMinute = businessStartTime ? dateUtil.minutesOfDay(businessStartTime) : startMinute + const businessEndMinute = businessEndTime ? dateUtil.minutesOfDay(businessEndTime) : endMinute + return { + startMinute: Math.max(startMinute, businessStartMinute), + endMinute: Math.min(endMinute, businessEndMinute) + } +} + function buildAvailableTimeGroups(calendar, form, durationMinutes) { + const daySummary = (calendar.daySummaries || []).find(item => item.date === form.appointmentDate) + if (daySummary && daySummary.dayStatus === 'rest') { + return [] + } const schedules = (calendar.schedules || []) .filter(item => String(item.artistId) === String(form.artistId)) .filter(item => item.date === form.appointmentDate) @@ -149,8 +162,14 @@ function buildAvailableTimeGroups(calendar, form, durationMinutes) { evening: { key: 'evening', title: '晚上', times: [] } } schedules.forEach(schedule => { - const scheduleStart = dateUtil.minutesOfDay(extractTimeText(schedule.startTime)) - const scheduleEnd = dateUtil.minutesOfDay(extractTimeText(schedule.endTime)) + const range = clampToBusinessHours( + dateUtil.minutesOfDay(extractTimeText(schedule.startTime)), + dateUtil.minutesOfDay(extractTimeText(schedule.endTime)), + daySummary && daySummary.businessStartTime, + daySummary && daySummary.businessEndTime + ) + const scheduleStart = range.startMinute + const scheduleEnd = range.endMinute for (let minute = scheduleStart; minute + durationMinutes <= scheduleEnd; minute += TIME_SLOT_MINUTES) { const endMinute = minute + durationMinutes if (!hasBusyConflict(minute, endMinute, busyRanges)) { @@ -639,17 +658,25 @@ Page({ } const startMinute = dateUtil.minutesOfDay(form.appointmentTime) const endMinute = startMinute + durationMinutes - if (startMinute < dateUtil.minutesOfDay('10:00') || endMinute > dateUtil.minutesOfDay('22:00')) { - const tip = '该时间超出营业时间 10:00-22:00' - this.setData({ conflictTip: tip, conflictLevel: 'danger' }) - return { ok: false, tip } - } try { const calendar = await planningApi.calendar({ startDate: form.appointmentDate, endDate: form.appointmentDate, artistId: form.artistId }) + const daySummary = (calendar.daySummaries || []).find(item => item.date === form.appointmentDate) + const businessStartTime = String((daySummary && daySummary.businessStartTime) || calendar.businessStartTime || '10:00').slice(0, 5) + const businessEndTime = String((daySummary && daySummary.businessEndTime) || calendar.businessEndTime || '22:00').slice(0, 5) + if (daySummary && daySummary.dayStatus === 'rest') { + const tip = '当前日期为店铺休息日' + this.setData({ conflictTip: tip, conflictLevel: 'danger' }) + return { ok: false, tip } + } + if (startMinute < dateUtil.minutesOfDay(businessStartTime) || endMinute > dateUtil.minutesOfDay(businessEndTime)) { + const tip = `该时间超出营业时间 ${businessStartTime}-${businessEndTime}` + this.setData({ conflictTip: tip, conflictLevel: 'danger' }) + return { ok: false, tip } + } const schedule = (calendar.schedules || []).find(item => isScheduleCoveringTime(item, form, startMinute, endMinute)) if (!schedule) { const tip = `${this.data.selectedArtist.name || '该美甲师'} 当前时段无可预约排班` diff --git a/JY-Salon-WeChat/pages/shop-settings/index.js b/JY-Salon-WeChat/pages/shop-settings/index.js index 07fde0e0..8d070e37 100644 --- a/JY-Salon-WeChat/pages/shop-settings/index.js +++ b/JY-Salon-WeChat/pages/shop-settings/index.js @@ -1,12 +1,218 @@ +const shopApi = require('../../api/shop') +const dateUtil = require('../../utils/date') const { BRAND_CONFIG } = require('../../utils/config') +const { markPlanningRefresh } = require('../../utils/planning-refresh') + +const PRESETS = [ + { value: 'EVERYDAY', label: '全周营业', workDays: [1, 2, 3, 4, 5, 6, 7], startTime: '10:00', endTime: '22:00' }, + { value: 'DOUBLE_REST', label: '双休', workDays: [1, 2, 3, 4, 5], startTime: '09:00', endTime: '18:00' }, + { value: 'SINGLE_REST', label: '单休', workDays: [1, 2, 3, 4, 5, 6], startTime: '10:00', endTime: '22:00' }, + { value: 'CUSTOM', label: '自定义', workDays: [1, 2, 3, 4, 5], startTime: '10:00', endTime: '22:00' } +] + +const WEEKDAYS = [ + { value: 1, label: '周一' }, + { value: 2, label: '周二' }, + { value: 3, label: '周三' }, + { value: 4, label: '周四' }, + { value: 5, label: '周五' }, + { value: 6, label: '周六' }, + { value: 7, label: '周日' } +] + +const EXCEPTION_TYPES = [ + { value: 'REST', label: '休息' }, + { value: 'EXTRA_WORK', label: '临时营业' }, + { value: 'CHANGE_SHIFT', label: '临时改班' } +] + +function copyWorkDays(days) { + if (Array.isArray(days)) { + return days.map(day => Number(day)).filter(day => day >= 1 && day <= 7).sort() + } + return String(days || '') + .split(',') + .map(day => Number(String(day).trim())) + .filter(day => day >= 1 && day <= 7) + .sort() +} + +function encodeWorkDays(days) { + return Array.from(new Set(copyWorkDays(days))).join(',') +} + +function buildPreset(value) { + return PRESETS.find(item => item.value === value) || PRESETS[0] +} + +function buildPresetOptions(presetType) { + return PRESETS.map(item => ({ ...item, active: item.value === presetType })) +} + +function buildWeekdayOptions(workDays) { + const selected = copyWorkDays(workDays) + return WEEKDAYS.map(item => ({ ...item, active: selected.includes(item.value) })) +} + +function exceptionTypeLabel(value) { + const option = EXCEPTION_TYPES.find(item => item.value === value) + return option ? option.label : '特殊日期' +} + +function buildExceptionSummary(item) { + if (item.exceptionType === 'REST') { + return `${item.workDate} 店铺休息` + } + return `${item.workDate} ${exceptionTypeLabel(item.exceptionType)} ${String(item.startTime || '').slice(0, 5)}-${String(item.endTime || '').slice(0, 5)}` +} Page({ data: { - form: { shopName: BRAND_CONFIG.defaultShopName, startTime: '10:00', endTime: '22:00', defaultDuration: 60, rule: '必须选择已有作品作为项目来源' } + presets: PRESETS, + presetOptions: buildPresetOptions('EVERYDAY'), + weekdays: WEEKDAYS, + weekdayOptions: buildWeekdayOptions([1, 2, 3, 4, 5, 6, 7]), + exceptionTypes: EXCEPTION_TYPES, + exceptionTypeIndex: 0, + exceptionTypeLabel: '休息', + exceptions: [], + loading: false, + saving: false, + form: { + shopName: BRAND_CONFIG.defaultShopName, + startTime: '10:00', + endTime: '22:00', + defaultDuration: 60, + rule: '必须选择已有作品作为项目来源', + schedulePresetType: 'EVERYDAY', + scheduleWorkDays: [1, 2, 3, 4, 5, 6, 7], + scheduleRemark: '' + }, + exceptionForm: { + workDate: dateUtil.formatDate(new Date()), + exceptionType: 'REST', + startTime: '10:00', + endTime: '18:00', + remark: '' + } }, - onInput(event) { this.setData({ [`form.${event.currentTarget.dataset.field}`]: event.detail.value }) }, - onStartChange(event) { this.setData({ 'form.startTime': event.detail.value }) }, - onEndChange(event) { this.setData({ 'form.endTime': event.detail.value }) }, + + onLoad() { + this.loadSettings() + }, + + async loadSettings() { + this.setData({ loading: true }) + try { + const [settings, exceptions] = await Promise.all([ + shopApi.settings(), + shopApi.scheduleExceptions() + ]) + const hours = String(settings.businessHours || '').split('-') + const preset = buildPreset(settings.schedulePresetType || 'EVERYDAY') + const form = { + ...this.data.form, + shopName: settings.shopName || settings.name || this.data.form.shopName, + startTime: String(settings.startTime || hours[0] || preset.startTime).slice(0, 5), + endTime: String(settings.endTime || hours[1] || preset.endTime).slice(0, 5), + rule: settings.description || this.data.form.rule, + schedulePresetType: settings.schedulePresetType || preset.value, + scheduleWorkDays: copyWorkDays(settings.scheduleWorkDays || preset.workDays), + scheduleRemark: settings.scheduleRemark || '' + } + this.setData({ + form, + presetOptions: buildPresetOptions(form.schedulePresetType), + weekdayOptions: buildWeekdayOptions(form.scheduleWorkDays), + exceptions: (exceptions || []).map(item => ({ + ...item, + startTime: item.startTime ? String(item.startTime).slice(0, 5) : '', + endTime: item.endTime ? String(item.endTime).slice(0, 5) : '', + summary: buildExceptionSummary(item) + })) + }) + } catch (error) { + wx.showToast({ title: error.message || '店铺设置加载失败', icon: 'none' }) + } finally { + this.setData({ loading: false }) + } + }, + + onInput(event) { + this.setData({ [`form.${event.currentTarget.dataset.field}`]: event.detail.value }) + }, + + onExceptionInput(event) { + this.setData({ [`exceptionForm.${event.currentTarget.dataset.field}`]: event.detail.value }) + }, + + selectPreset(event) { + const preset = buildPreset(event.currentTarget.dataset.value) + const form = { + ...this.data.form, + schedulePresetType: preset.value, + scheduleWorkDays: copyWorkDays(preset.workDays), + startTime: preset.startTime, + endTime: preset.endTime + } + this.setData({ + form, + presetOptions: buildPresetOptions(form.schedulePresetType), + weekdayOptions: buildWeekdayOptions(form.scheduleWorkDays) + }) + }, + + toggleWeekday(event) { + const day = Number(event.currentTarget.dataset.value) + const workDays = copyWorkDays(this.data.form.scheduleWorkDays) + const exists = workDays.includes(day) + const nextDays = exists ? workDays.filter(item => item !== day) : [...workDays, day].sort() + this.setData({ + 'form.schedulePresetType': 'CUSTOM', + 'form.scheduleWorkDays': nextDays, + presetOptions: buildPresetOptions('CUSTOM'), + weekdayOptions: buildWeekdayOptions(nextDays) + }) + }, + + onStartChange(event) { + this.setData({ + 'form.startTime': event.detail.value, + 'form.schedulePresetType': 'CUSTOM', + presetOptions: buildPresetOptions('CUSTOM') + }) + }, + + onEndChange(event) { + this.setData({ + 'form.endTime': event.detail.value, + 'form.schedulePresetType': 'CUSTOM', + presetOptions: buildPresetOptions('CUSTOM') + }) + }, + + onExceptionDateChange(event) { + this.setData({ 'exceptionForm.workDate': event.detail.value }) + }, + + onExceptionStartChange(event) { + this.setData({ 'exceptionForm.startTime': event.detail.value }) + }, + + onExceptionEndChange(event) { + this.setData({ 'exceptionForm.endTime': event.detail.value }) + }, + + onExceptionTypeChange(event) { + const index = Number(event.detail.value) + const option = this.data.exceptionTypes[index] || this.data.exceptionTypes[0] + this.setData({ + exceptionTypeIndex: index, + exceptionTypeLabel: exceptionTypeLabel(option.value), + 'exceptionForm.exceptionType': option.value + }) + }, + explainDefaultDuration() { wx.showModal({ title: '默认时长', @@ -15,6 +221,7 @@ Page({ confirmText: '知道了' }) }, + explainBookingRule() { wx.showModal({ title: '预约规则', @@ -23,6 +230,75 @@ Page({ confirmText: '知道了' }) }, - save() { wx.showToast({ title: '已保存' }) }, - back() { wx.navigateBack() } + + async save() { + const form = this.data.form + const workDays = copyWorkDays(form.scheduleWorkDays) + if (!form.shopName) { + wx.showToast({ title: '请填写店铺名称', icon: 'none' }) + return + } + if (!workDays.length) { + wx.showToast({ title: '请选择营业日', icon: 'none' }) + return + } + if (!form.startTime || !form.endTime || form.startTime >= form.endTime) { + wx.showToast({ title: '请填写正确的营业时间', icon: 'none' }) + return + } + this.setData({ saving: true }) + try { + await shopApi.saveSettings({ + shopName: form.shopName, + name: form.shopName, + startTime: form.startTime, + endTime: form.endTime, + businessHours: `${form.startTime}-${form.endTime}`, + description: form.rule, + schedulePresetType: form.schedulePresetType, + scheduleWorkDays: encodeWorkDays(workDays), + scheduleRemark: String(form.scheduleRemark || '').trim() + }) + markPlanningRefresh() + wx.showToast({ title: '已保存', icon: 'success' }) + await this.loadSettings() + } catch (error) { + wx.showToast({ title: error.message || '保存失败', icon: 'none' }) + } finally { + this.setData({ saving: false }) + } + }, + + async saveException() { + const form = this.data.exceptionForm + if (!form.workDate || !form.exceptionType) { + wx.showToast({ title: '请补全特殊日期', icon: 'none' }) + return + } + if (form.exceptionType !== 'REST' && (!form.startTime || !form.endTime || form.startTime >= form.endTime)) { + wx.showToast({ title: '请填写正确的特殊日期时间', icon: 'none' }) + return + } + this.setData({ saving: true }) + try { + await shopApi.saveScheduleException({ + workDate: form.workDate, + exceptionType: form.exceptionType, + startTime: form.exceptionType === 'REST' ? null : form.startTime, + endTime: form.exceptionType === 'REST' ? null : form.endTime, + remark: String(form.remark || '').trim() + }) + markPlanningRefresh() + wx.showToast({ title: '特殊日期已保存', icon: 'success' }) + await this.loadSettings() + } catch (error) { + wx.showToast({ title: error.message || '特殊日期保存失败', icon: 'none' }) + } finally { + this.setData({ saving: false }) + } + }, + + back() { + wx.navigateBack() + } }) diff --git a/JY-Salon-WeChat/pages/shop-settings/index.wxml b/JY-Salon-WeChat/pages/shop-settings/index.wxml index b34e416f..a709d751 100644 --- a/JY-Salon-WeChat/pages/shop-settings/index.wxml +++ b/JY-Salon-WeChat/pages/shop-settings/index.wxml @@ -1,23 +1,64 @@ - - 店铺名称 - 营业开始{{form.startTime}} - 营业结束{{form.endTime}} - - - 默认时长 - ? + 店铺设置加载中 + + + 店铺名称 + + + 默认时长 + ? + + + 分钟 - - 分钟 - - - - 预约规则 - ? + + + 预约规则 + ? + + - - - + + + 店铺排班 + + + {{item.label}} + + + + 营业日 + + {{item.label}} + + + + 营业开始{{form.startTime}} + 营业结束{{form.endTime}} + 排班备注 + + + + + 特殊日期 + + 日期{{exceptionForm.workDate}} + 类型{{exceptionTypeLabel}} + 开始时间{{exceptionForm.startTime}} + 结束时间{{exceptionForm.endTime}} + 备注 + + + + + + {{item.summary}} + {{item.remark}} + + + + + + diff --git a/JY-Salon-WeChat/pages/shop-settings/index.wxss b/JY-Salon-WeChat/pages/shop-settings/index.wxss index cc5adf95..be32704a 100644 --- a/JY-Salon-WeChat/pages/shop-settings/index.wxss +++ b/JY-Salon-WeChat/pages/shop-settings/index.wxss @@ -23,3 +23,95 @@ font-weight: 800; line-height: 28rpx; } + +.loading-state { + padding: 48rpx 24rpx; + color: #7b7167; + text-align: center; +} + +.section { + margin-top: 24rpx; +} + +.section-title { + margin: 0 0 16rpx; + color: #3f382f; + font-size: 30rpx; + font-weight: 800; +} + +.rule-card { + display: flex; + flex-direction: column; + gap: 18rpx; +} + +.preset-grid, +.weekday-grid { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 16rpx; +} + +.weekday-grid { + grid-template-columns: repeat(4, minmax(0, 1fr)); +} + +.preset-chip, +.weekday-chip { + min-height: 72rpx; + display: flex; + align-items: center; + justify-content: center; + border: 2rpx solid #e3ddd2; + border-radius: 12rpx; + background: #fffaf2; + color: #5f564c; + font-size: 24rpx; + font-weight: 700; +} + +.preset-chip.active, +.weekday-chip.active { + border-color: #75a78e; + background: #e5f2eb; + color: #2f6b55; +} + +.field-block { + display: flex; + flex-direction: column; + gap: 12rpx; +} + +.field-title { + color: #6f665c; + font-size: 24rpx; + font-weight: 800; +} + +.exception-btn { + width: 100%; + margin-top: 8rpx; +} + +.exception-list { + display: flex; + flex-direction: column; + gap: 16rpx; + margin-top: 16rpx; +} + +.exception-card { + display: flex; + flex-direction: column; + gap: 8rpx; + color: #3f382f; + font-size: 26rpx; +} + +.exception-remark { + color: #7b7167; + font-size: 24rpx; +} diff --git a/scripts/sql/migrations/店铺排班规则和特殊日期_20260701.sql b/scripts/sql/migrations/店铺排班规则和特殊日期_20260701.sql new file mode 100644 index 00000000..80bfd7d4 --- /dev/null +++ b/scripts/sql/migrations/店铺排班规则和特殊日期_20260701.sql @@ -0,0 +1,96 @@ +use jayucloud; + +DROP PROCEDURE IF EXISTS sp_fd_add_column_if_not_exists; +DELIMITER $$ +CREATE PROCEDURE sp_fd_add_column_if_not_exists( + IN p_table_name varchar(128), + IN p_column_name varchar(128), + IN p_column_sql varchar(1000) +) +BEGIN + IF NOT EXISTS ( + SELECT 1 + FROM information_schema.columns + WHERE table_schema = DATABASE() + AND table_name = p_table_name + AND column_name = p_column_name + ) THEN + SET @fd_sql = CONCAT('ALTER TABLE ', p_table_name, ' ADD COLUMN ', p_column_sql); + PREPARE fd_stmt FROM @fd_sql; + EXECUTE fd_stmt; + DEALLOCATE PREPARE fd_stmt; + END IF; +END$$ +DELIMITER ; + +DROP PROCEDURE IF EXISTS sp_fd_add_index_if_not_exists; +DELIMITER $$ +CREATE PROCEDURE sp_fd_add_index_if_not_exists( + IN p_table_name varchar(128), + IN p_index_name varchar(128), + IN p_index_sql varchar(1000) +) +BEGIN + IF NOT EXISTS ( + SELECT 1 + FROM information_schema.statistics + WHERE table_schema = DATABASE() + AND table_name = p_table_name + AND index_name = p_index_name + ) THEN + SET @fd_sql = CONCAT('ALTER TABLE ', p_table_name, ' ADD INDEX ', p_index_name, ' ', p_index_sql); + PREPARE fd_stmt FROM @fd_sql; + EXECUTE fd_stmt; + DEALLOCATE PREPARE fd_stmt; + END IF; +END$$ +DELIMITER ; + +DROP PROCEDURE IF EXISTS sp_fd_add_unique_index_if_not_exists; +DELIMITER $$ +CREATE PROCEDURE sp_fd_add_unique_index_if_not_exists( + IN p_table_name varchar(128), + IN p_index_name varchar(128), + IN p_index_sql varchar(1000) +) +BEGIN + IF NOT EXISTS ( + SELECT 1 + FROM information_schema.statistics + WHERE table_schema = DATABASE() + AND table_name = p_table_name + AND index_name = p_index_name + ) THEN + SET @fd_sql = CONCAT('ALTER TABLE ', p_table_name, ' ADD UNIQUE INDEX ', p_index_name, ' ', p_index_sql); + PREPARE fd_stmt FROM @fd_sql; + EXECUTE fd_stmt; + DEALLOCATE PREPARE fd_stmt; + END IF; +END$$ +DELIMITER ; + +CALL sp_fd_add_column_if_not_exists('t_shop', 'schedule_preset_type', '`schedule_preset_type` varchar(32) NOT NULL DEFAULT ''EVERYDAY'' COMMENT ''店铺排班预设类型'''); +CALL sp_fd_add_column_if_not_exists('t_shop', 'schedule_work_days', '`schedule_work_days` varchar(32) NOT NULL DEFAULT ''1,2,3,4,5,6,7'' COMMENT ''店铺营业星期,1-7逗号分隔'''); +CALL sp_fd_add_column_if_not_exists('t_shop', 'schedule_remark', '`schedule_remark` varchar(255) NULL COMMENT ''店铺排班备注'''); + +CREATE TABLE IF NOT EXISTS t_shop_schedule_exception +( + id bigint unsigned NOT NULL COMMENT '店铺特殊日期ID', + shop_id bigint unsigned NOT NULL COMMENT '店铺ID', + work_date date NOT NULL COMMENT '特殊日期', + exception_type varchar(32) NOT NULL COMMENT '特殊日期类型:REST/EXTRA_WORK/CHANGE_SHIFT', + start_time time NULL COMMENT '特殊开始时间', + end_time time NULL COMMENT '特殊结束时间', + remark varchar(255) NULL COMMENT '备注', + create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + is_delete tinyint NOT NULL DEFAULT 0 COMMENT '逻辑删除', + PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='店铺特殊日期表'; + +CALL sp_fd_add_unique_index_if_not_exists('t_shop_schedule_exception', 'uk_shop_schedule_exception_date', '(`shop_id`, `work_date`, `is_delete`)'); +CALL sp_fd_add_index_if_not_exists('t_shop_schedule_exception', 'idx_shop_schedule_exception_date', '(`work_date`, `is_delete`)'); + +DROP PROCEDURE IF EXISTS sp_fd_add_column_if_not_exists; +DROP PROCEDURE IF EXISTS sp_fd_add_index_if_not_exists; +DROP PROCEDURE IF EXISTS sp_fd_add_unique_index_if_not_exists;