给店铺增加排班规则
This commit is contained in:
+24
@@ -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<List<ShopScheduleExceptionVO>> 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<ShopScheduleExceptionVO> 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));
|
||||
}
|
||||
}
|
||||
|
||||
+37
-5
@@ -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<LocalDate, ShopScheduleExceptionDO> shopExceptionByDate = listShopScheduleExceptions(shopId, start, end);
|
||||
|
||||
List<PlanningArtistVO> artists = listArtists(shopId, artistId);
|
||||
List<ArtistScheduleDO> 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<PlanningDaySummaryVO> buildDaySummaries(LocalDate start, LocalDate end, List<PlanningArtistVO> artists,
|
||||
List<ArtistScheduleDO> schedules, List<PlanningAppointmentVO> appointments) {
|
||||
List<ArtistScheduleDO> schedules, List<PlanningAppointmentVO> appointments,
|
||||
ShopDO shop, Map<LocalDate, ShopScheduleExceptionDO> shopExceptionByDate) {
|
||||
Map<String, List<PlanningAppointmentVO>> 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<LocalDate, ShopScheduleExceptionDO> listShopScheduleExceptions(Long shopId, LocalDate start, LocalDate end) {
|
||||
return shopScheduleExceptionMapper.selectList(new QueryWrapper<ShopScheduleExceptionDO>()
|
||||
.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<PlanningAppointmentVO> 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<ShopScheduleExceptionDO>()
|
||||
.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', ' ');
|
||||
|
||||
+2
@@ -10,4 +10,6 @@ public class PlanningDaySummaryVO {
|
||||
private Integer totalCount;
|
||||
private List<PlanningArtistCountVO> artistCounts;
|
||||
private String dayStatus;
|
||||
private String businessStartTime;
|
||||
private String businessEndTime;
|
||||
}
|
||||
|
||||
@@ -54,6 +54,12 @@ public class ShopDTO {
|
||||
*/
|
||||
private String businessHours;
|
||||
|
||||
private String schedulePresetType;
|
||||
|
||||
private String scheduleWorkDays;
|
||||
|
||||
private String scheduleRemark;
|
||||
|
||||
/**
|
||||
* 店铺封面图文件ID集合(Banner图),多个ID以逗号分隔
|
||||
*/
|
||||
|
||||
+16
@@ -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;
|
||||
}
|
||||
@@ -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以逗号分隔
|
||||
*/
|
||||
|
||||
+32
@@ -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;
|
||||
}
|
||||
+9
@@ -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<ShopScheduleExceptionDO> {
|
||||
}
|
||||
+7
@@ -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<ShopDO> {
|
||||
* 前台可用:未删除、启用、且授权未到期。
|
||||
*/
|
||||
boolean isFrontendAvailable(Long shopId);
|
||||
|
||||
List<ShopScheduleExceptionVO> listScheduleExceptions(Long shopId, LocalDate startDate, LocalDate endDate);
|
||||
|
||||
ShopScheduleExceptionVO saveScheduleException(ShopScheduleExceptionDTO dto);
|
||||
}
|
||||
|
||||
+94
@@ -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<ShopMapper, ShopDO> 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<ShopMapper, ShopDO> 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<ShopMapper, ShopDO> 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<ShopMapper, ShopDO> implements
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ShopScheduleExceptionVO> 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<ShopMapper, ShopDO> 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<ShopMapper, ShopDO> 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.
|
||||
|
||||
+127
@@ -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<Integer> 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<Integer> resolveWorkDays(String workDays, String presetType) {
|
||||
String normalizedPreset = normalizePresetType(presetType);
|
||||
List<Integer> 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<Integer> 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<Integer> 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<Integer> 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<Integer> 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<Integer> normalizeWorkDays(List<Integer> workDays) {
|
||||
Set<Integer> normalized = new LinkedHashSet<>();
|
||||
for (Integer day : workDays == null ? List.<Integer>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) {
|
||||
}
|
||||
}
|
||||
+19
@@ -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;
|
||||
}
|
||||
@@ -70,6 +70,12 @@ public class ShopVO {
|
||||
*/
|
||||
private String businessHours;
|
||||
|
||||
private String schedulePresetType;
|
||||
|
||||
private String scheduleWorkDays;
|
||||
|
||||
private String scheduleRemark;
|
||||
|
||||
/**
|
||||
* 店铺封面图文件ID集合(Banner图),多个ID以逗号分隔
|
||||
*/
|
||||
|
||||
+20
@@ -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<ShopScheduleExceptionVO> 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();
|
||||
|
||||
+42
@@ -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));
|
||||
|
||||
+4
@@ -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,
|
||||
|
||||
+52
@@ -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("请至少选择一个店铺营业日");
|
||||
}
|
||||
}
|
||||
@@ -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<ShopInfo> {
|
||||
@@ -8,6 +8,12 @@ export const managerShopApi = {
|
||||
update(data: Partial<ShopInfo>): Promise<boolean> {
|
||||
return adminApi.put('/manager/shop', data)
|
||||
},
|
||||
scheduleExceptions(params?: { startDate?: string; endDate?: string }): Promise<ShopScheduleException[]> {
|
||||
return adminApi.get('/manager/shop/schedule-exceptions', { params })
|
||||
},
|
||||
saveScheduleException(data: ShopScheduleException): Promise<ShopScheduleException> {
|
||||
return adminApi.post('/manager/shop/schedule-exceptions', data)
|
||||
},
|
||||
exportPreview(params: { type: string; startDate: string; endDate: string }): Promise<unknown> {
|
||||
return adminApi.get('/export', { params })
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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'])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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 }
|
||||
}
|
||||
|
||||
@@ -2,35 +2,116 @@
|
||||
<MobileShell title="店铺设置">
|
||||
<div class="settings-view">
|
||||
<LoadingState v-if="loading" text="店铺信息加载中" />
|
||||
<section v-else class="card form-card">
|
||||
<label class="field">
|
||||
<span class="field-label">店铺名称</span>
|
||||
<input v-model.trim="form.shopName" placeholder="请输入店铺名称" />
|
||||
</label>
|
||||
<label class="field">
|
||||
<span class="field-label">营业开始</span>
|
||||
<input v-model="form.startTime" class="field-value" type="time" />
|
||||
</label>
|
||||
<label class="field">
|
||||
<span class="field-label">营业结束</span>
|
||||
<input v-model="form.endTime" class="field-value" type="time" />
|
||||
</label>
|
||||
<label class="field">
|
||||
<span class="label-with-help">
|
||||
<span class="field-label">默认时长</span>
|
||||
<button class="help-badge" type="button" aria-label="默认时长说明" @click.stop.prevent="showDurationHelp">?</button>
|
||||
</span>
|
||||
<input v-model.trim="form.defaultDuration" inputmode="numeric" placeholder="60" />
|
||||
<span class="muted">分钟</span>
|
||||
</label>
|
||||
<label class="field field--stack">
|
||||
<span class="label-with-help">
|
||||
<span class="field-label">预约规则</span>
|
||||
<button class="help-badge" type="button" aria-label="预约规则说明" @click.stop.prevent="showRuleHelp">?</button>
|
||||
</span>
|
||||
<textarea v-model.trim="form.rule" placeholder="例如:必须选择已有作品作为项目来源"></textarea>
|
||||
</label>
|
||||
</section>
|
||||
<template v-else>
|
||||
<section class="card form-card">
|
||||
<label class="field">
|
||||
<span class="field-label">店铺名称</span>
|
||||
<input v-model.trim="form.shopName" placeholder="请输入店铺名称" />
|
||||
</label>
|
||||
<label class="field">
|
||||
<span class="label-with-help">
|
||||
<span class="field-label">默认时长</span>
|
||||
<button class="help-badge" type="button" aria-label="默认时长说明" @click.stop.prevent="showDurationHelp">?</button>
|
||||
</span>
|
||||
<input v-model.trim="form.defaultDuration" inputmode="numeric" placeholder="60" />
|
||||
<span class="muted">分钟</span>
|
||||
</label>
|
||||
<label class="field field--stack">
|
||||
<span class="label-with-help">
|
||||
<span class="field-label">预约规则</span>
|
||||
<button class="help-badge" type="button" aria-label="预约规则说明" @click.stop.prevent="showRuleHelp">?</button>
|
||||
</span>
|
||||
<textarea v-model.trim="form.rule" placeholder="例如:必须选择已有作品作为项目来源"></textarea>
|
||||
</label>
|
||||
</section>
|
||||
|
||||
<PageSection title="店铺排班">
|
||||
<section class="card form-card">
|
||||
<div class="preset-grid">
|
||||
<button
|
||||
v-for="item in presets"
|
||||
:key="item.value"
|
||||
class="preset-chip"
|
||||
:class="{ active: form.schedulePresetType === item.value }"
|
||||
type="button"
|
||||
@click="selectPreset(item.value)"
|
||||
>
|
||||
{{ item.label }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="field-block">
|
||||
<div class="field-title">营业日</div>
|
||||
<div class="weekday-grid">
|
||||
<button
|
||||
v-for="item in weekdays"
|
||||
:key="item.value"
|
||||
class="weekday-chip"
|
||||
:class="{ active: workDays.includes(item.value) }"
|
||||
type="button"
|
||||
@click="toggleWeekday(item.value)"
|
||||
>
|
||||
{{ item.label }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label class="field">
|
||||
<span class="field-label">营业开始</span>
|
||||
<input v-model="form.startTime" class="field-value" type="time" @change="markCustom" />
|
||||
</label>
|
||||
<label class="field">
|
||||
<span class="field-label">营业结束</span>
|
||||
<input v-model="form.endTime" class="field-value" type="time" @change="markCustom" />
|
||||
</label>
|
||||
<label class="field">
|
||||
<span class="field-label">排班备注</span>
|
||||
<input v-model.trim="form.scheduleRemark" placeholder="可选" />
|
||||
</label>
|
||||
</section>
|
||||
</PageSection>
|
||||
|
||||
<PageSection title="特殊日期">
|
||||
<section class="card form-card">
|
||||
<label class="field">
|
||||
<span class="field-label">日期</span>
|
||||
<input v-model="exceptionForm.workDate" type="date" />
|
||||
</label>
|
||||
<label class="field">
|
||||
<span class="field-label">类型</span>
|
||||
<select v-model="exceptionForm.exceptionType">
|
||||
<option v-for="item in exceptionTypes" :key="item.value" :value="item.value">{{ item.label }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label v-if="exceptionForm.exceptionType !== 'REST'" class="field">
|
||||
<span class="field-label">开始时间</span>
|
||||
<input v-model="exceptionForm.startTime" type="time" />
|
||||
</label>
|
||||
<label v-if="exceptionForm.exceptionType !== 'REST'" class="field">
|
||||
<span class="field-label">结束时间</span>
|
||||
<input v-model="exceptionForm.endTime" type="time" />
|
||||
</label>
|
||||
<label class="field">
|
||||
<span class="field-label">备注</span>
|
||||
<input v-model.trim="exceptionForm.remark" placeholder="可选" />
|
||||
</label>
|
||||
</section>
|
||||
<button class="secondary-btn section-action" type="button" :disabled="saving" @click="saveException">保存特殊日期</button>
|
||||
<EmptyState v-if="exceptions.length === 0" title="暂无特殊日期" />
|
||||
<section v-else class="exception-list">
|
||||
<article v-for="item in exceptions" :key="String(item.id || item.workDate)" class="card exception-card">
|
||||
<div class="row-between">
|
||||
<div>
|
||||
<h2 class="exception-card__title">{{ item.workDate }}</h2>
|
||||
<div class="exception-card__subtitle">{{ exceptionSummary(item) }}</div>
|
||||
</div>
|
||||
<span class="tag">{{ exceptionTypeLabel(item.exceptionType) }}</span>
|
||||
</div>
|
||||
<p v-if="item.remark" class="exception-card__remark">{{ item.remark }}</p>
|
||||
</article>
|
||||
</section>
|
||||
</PageSection>
|
||||
</template>
|
||||
|
||||
<BaseModal v-model="helpModal.visible" :title="helpModal.title">
|
||||
<p class="help-content">{{ helpModal.content }}</p>
|
||||
@@ -51,22 +132,60 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import BaseModal from '@/components/BaseModal.vue'
|
||||
import EmptyState from '@/components/EmptyState.vue'
|
||||
import LoadingState from '@/components/LoadingState.vue'
|
||||
import MobileShell from '@/components/MobileShell.vue'
|
||||
import PageSection from '@/components/PageSection.vue'
|
||||
import { managerShopApi } from '@/api/managerShop'
|
||||
import type { ShopScheduleException } from '@/types/manager'
|
||||
import { formatDate } from '@/utils/date'
|
||||
import { useToastStore } from '@/stores/toast'
|
||||
|
||||
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 exceptionTypes = [
|
||||
{ value: 'REST', label: '休息' },
|
||||
{ value: 'EXTRA_WORK', label: '临时营业' },
|
||||
{ value: 'CHANGE_SHIFT', label: '临时改班' }
|
||||
]
|
||||
|
||||
const toast = useToastStore()
|
||||
const loading = ref(false)
|
||||
const saving = ref(false)
|
||||
const exceptions = ref<ShopScheduleException[]>([])
|
||||
const form = reactive({
|
||||
shopName: '甲屿云',
|
||||
shopName: '甲屿店务',
|
||||
startTime: '10:00',
|
||||
endTime: '22:00',
|
||||
defaultDuration: '60',
|
||||
rule: '必须选择已有作品作为项目来源'
|
||||
rule: '必须选择已有作品作为项目来源',
|
||||
schedulePresetType: 'EVERYDAY',
|
||||
scheduleWorkDays: '1,2,3,4,5,6,7',
|
||||
scheduleRemark: ''
|
||||
})
|
||||
const exceptionForm = reactive({
|
||||
workDate: formatDate(new Date()),
|
||||
exceptionType: 'REST',
|
||||
startTime: '10:00',
|
||||
endTime: '18:00',
|
||||
remark: ''
|
||||
})
|
||||
const helpModal = reactive({
|
||||
visible: false,
|
||||
@@ -74,19 +193,79 @@ const helpModal = reactive({
|
||||
content: ''
|
||||
})
|
||||
|
||||
const workDays = computed(() => parseWorkDays(form.scheduleWorkDays))
|
||||
|
||||
const parseWorkDays = (value: string): number[] => {
|
||||
return value.split(',')
|
||||
.map(item => Number(item.trim()))
|
||||
.filter(item => item >= 1 && item <= 7)
|
||||
.sort((a, b) => a - b)
|
||||
}
|
||||
|
||||
const encodeWorkDays = (days: number[]): string => {
|
||||
return [...new Set(days)].sort((a, b) => a - b).join(',')
|
||||
}
|
||||
|
||||
const selectedPreset = (value: string) => presets.find(item => item.value === value) ?? presets[0]!
|
||||
|
||||
const loadInfo = async (): Promise<void> => {
|
||||
loading.value = true
|
||||
try {
|
||||
const info = await managerShopApi.info()
|
||||
const [info, exceptionList] = await Promise.all([
|
||||
managerShopApi.info(),
|
||||
managerShopApi.scheduleExceptions()
|
||||
])
|
||||
form.shopName = info.shopName || info.name || form.shopName
|
||||
form.startTime = info.startTime || form.startTime
|
||||
form.endTime = info.endTime || form.endTime
|
||||
const hours = String(info.businessHours || '').split('-')
|
||||
form.startTime = String(info.startTime || hours[0] || form.startTime).slice(0, 5)
|
||||
form.endTime = String(info.endTime || hours[1] || form.endTime).slice(0, 5)
|
||||
form.rule = info.description || form.rule
|
||||
form.schedulePresetType = info.schedulePresetType || 'EVERYDAY'
|
||||
form.scheduleWorkDays = info.scheduleWorkDays || selectedPreset(form.schedulePresetType).workDays.join(',')
|
||||
form.scheduleRemark = info.scheduleRemark || ''
|
||||
exceptions.value = (exceptionList || []).map(normalizeException)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const normalizeException = (item: ShopScheduleException): ShopScheduleException => ({
|
||||
...item,
|
||||
startTime: item.startTime ? String(item.startTime).slice(0, 5) : '',
|
||||
endTime: item.endTime ? String(item.endTime).slice(0, 5) : ''
|
||||
})
|
||||
|
||||
const selectPreset = (value: string): void => {
|
||||
const preset = selectedPreset(value)
|
||||
form.schedulePresetType = preset.value
|
||||
form.scheduleWorkDays = preset.workDays.join(',')
|
||||
form.startTime = preset.startTime
|
||||
form.endTime = preset.endTime
|
||||
}
|
||||
|
||||
const toggleWeekday = (day: number): void => {
|
||||
const days = workDays.value.includes(day)
|
||||
? workDays.value.filter(item => item !== day)
|
||||
: [...workDays.value, day]
|
||||
form.schedulePresetType = 'CUSTOM'
|
||||
form.scheduleWorkDays = encodeWorkDays(days)
|
||||
}
|
||||
|
||||
const markCustom = (): void => {
|
||||
form.schedulePresetType = 'CUSTOM'
|
||||
}
|
||||
|
||||
const exceptionTypeLabel = (value: string): string => {
|
||||
return exceptionTypes.find(item => item.value === value)?.label || '特殊日期'
|
||||
}
|
||||
|
||||
const exceptionSummary = (item: ShopScheduleException): string => {
|
||||
if (item.exceptionType === 'REST') {
|
||||
return '店铺休息'
|
||||
}
|
||||
return `${String(item.startTime || '').slice(0, 5)} - ${String(item.endTime || '').slice(0, 5)}`
|
||||
}
|
||||
|
||||
const showDurationHelp = (): void => {
|
||||
helpModal.title = '默认时长'
|
||||
helpModal.content = '用于手动创建预约或未选择作品时的默认服务时长,会影响可约时间校验和预约结束时间估算。'
|
||||
@@ -99,7 +278,26 @@ const showRuleHelp = (): void => {
|
||||
helpModal.visible = true
|
||||
}
|
||||
|
||||
const validateRule = (): boolean => {
|
||||
if (!form.shopName) {
|
||||
toast.error('请填写店铺名称')
|
||||
return false
|
||||
}
|
||||
if (workDays.value.length === 0) {
|
||||
toast.error('请选择店铺营业日')
|
||||
return false
|
||||
}
|
||||
if (!form.startTime || !form.endTime || form.startTime >= form.endTime) {
|
||||
toast.error('请填写正确的营业时间')
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
const save = async (): Promise<void> => {
|
||||
if (!validateRule()) {
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
await managerShopApi.update({
|
||||
@@ -108,7 +306,10 @@ const save = async (): Promise<void> => {
|
||||
startTime: form.startTime,
|
||||
endTime: form.endTime,
|
||||
businessHours: `${form.startTime}-${form.endTime}`,
|
||||
description: form.rule
|
||||
description: form.rule,
|
||||
schedulePresetType: form.schedulePresetType,
|
||||
scheduleWorkDays: form.scheduleWorkDays,
|
||||
scheduleRemark: form.scheduleRemark
|
||||
})
|
||||
toast.success('已保存')
|
||||
} finally {
|
||||
@@ -116,6 +317,34 @@ const save = async (): Promise<void> => {
|
||||
}
|
||||
}
|
||||
|
||||
const saveException = async (): Promise<void> => {
|
||||
if (!exceptionForm.workDate) {
|
||||
toast.error('请选择特殊日期')
|
||||
return
|
||||
}
|
||||
if (exceptionForm.exceptionType !== 'REST' && (!exceptionForm.startTime || !exceptionForm.endTime || exceptionForm.startTime >= exceptionForm.endTime)) {
|
||||
toast.error('请填写正确的特殊日期时间')
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
const payload: ShopScheduleException = {
|
||||
workDate: exceptionForm.workDate,
|
||||
exceptionType: exceptionForm.exceptionType,
|
||||
remark: exceptionForm.remark
|
||||
}
|
||||
if (exceptionForm.exceptionType !== 'REST') {
|
||||
payload.startTime = exceptionForm.startTime
|
||||
payload.endTime = exceptionForm.endTime
|
||||
}
|
||||
await managerShopApi.saveScheduleException(payload)
|
||||
exceptions.value = (await managerShopApi.scheduleExceptions()).map(normalizeException)
|
||||
toast.success('特殊日期已保存')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(loadInfo)
|
||||
</script>
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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 || '该美甲师'} 当前时段无可预约排班`
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,23 +1,64 @@
|
||||
<view class="page no-tab">
|
||||
<view class="card form-card">
|
||||
<view class="field"><text class="field-label">店铺名称</text><input value="{{form.shopName}}" data-field="shopName" bindinput="onInput" /></view>
|
||||
<view class="field"><text class="field-label">营业开始</text><picker mode="time" value="{{form.startTime}}" bindchange="onStartChange"><view class="field-value">{{form.startTime}}</view></picker></view>
|
||||
<view class="field"><text class="field-label">营业结束</text><picker mode="time" value="{{form.endTime}}" bindchange="onEndChange"><view class="field-value">{{form.endTime}}</view></picker></view>
|
||||
<view class="field">
|
||||
<view class="label-with-help">
|
||||
<text class="field-label">默认时长</text>
|
||||
<text class="help-badge" catchtap="explainDefaultDuration">?</text>
|
||||
<view wx:if="{{loading}}" class="loading-state">店铺设置加载中</view>
|
||||
<block wx:else>
|
||||
<view class="card form-card">
|
||||
<view class="field"><text class="field-label">店铺名称</text><input value="{{form.shopName}}" data-field="shopName" bindinput="onInput" /></view>
|
||||
<view class="field">
|
||||
<view class="label-with-help">
|
||||
<text class="field-label">默认时长</text>
|
||||
<text class="help-badge" catchtap="explainDefaultDuration">?</text>
|
||||
</view>
|
||||
<input type="number" value="{{form.defaultDuration}}" data-field="defaultDuration" bindinput="onInput" />
|
||||
<text class="muted">分钟</text>
|
||||
</view>
|
||||
<input type="number" value="{{form.defaultDuration}}" data-field="defaultDuration" bindinput="onInput" />
|
||||
<text class="muted">分钟</text>
|
||||
</view>
|
||||
<view class="field">
|
||||
<view class="label-with-help">
|
||||
<text class="field-label">预约规则</text>
|
||||
<text class="help-badge" catchtap="explainBookingRule">?</text>
|
||||
<view class="field">
|
||||
<view class="label-with-help">
|
||||
<text class="field-label">预约规则</text>
|
||||
<text class="help-badge" catchtap="explainBookingRule">?</text>
|
||||
</view>
|
||||
<input value="{{form.rule}}" data-field="rule" bindinput="onInput" placeholder="例如:必须选择已有作品作为项目来源" />
|
||||
</view>
|
||||
<input value="{{form.rule}}" data-field="rule" bindinput="onInput" placeholder="例如:必须选择已有作品作为项目来源" />
|
||||
</view>
|
||||
</view>
|
||||
<view class="fixed-bottom"><button class="primary-btn" bindtap="save">保存设置</button></view>
|
||||
|
||||
<view class="section">
|
||||
<view class="section-title">店铺排班</view>
|
||||
<view class="card rule-card">
|
||||
<view class="preset-grid">
|
||||
<view wx:for="{{presetOptions}}" wx:key="value" class="preset-chip {{item.active ? 'active' : ''}}" data-value="{{item.value}}" bindtap="selectPreset">{{item.label}}</view>
|
||||
</view>
|
||||
|
||||
<view class="field-block">
|
||||
<view class="field-title">营业日</view>
|
||||
<view class="weekday-grid">
|
||||
<view wx:for="{{weekdayOptions}}" wx:key="value" class="weekday-chip {{item.active ? 'active' : ''}}" data-value="{{item.value}}" bindtap="toggleWeekday">{{item.label}}</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="field"><text class="field-label">营业开始</text><picker mode="time" value="{{form.startTime}}" bindchange="onStartChange"><view class="field-value">{{form.startTime}}</view></picker></view>
|
||||
<view class="field"><text class="field-label">营业结束</text><picker mode="time" value="{{form.endTime}}" bindchange="onEndChange"><view class="field-value">{{form.endTime}}</view></picker></view>
|
||||
<view class="field"><text class="field-label">排班备注</text><input value="{{form.scheduleRemark}}" data-field="scheduleRemark" bindinput="onInput" placeholder="可选" /></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<view class="section-title">特殊日期</view>
|
||||
<view class="card rule-card">
|
||||
<view class="field"><text class="field-label">日期</text><picker mode="date" value="{{exceptionForm.workDate}}" bindchange="onExceptionDateChange"><view class="field-value">{{exceptionForm.workDate}}</view></picker></view>
|
||||
<view class="field"><text class="field-label">类型</text><picker range="{{exceptionTypes}}" range-key="label" value="{{exceptionTypeIndex}}" bindchange="onExceptionTypeChange"><view class="field-value">{{exceptionTypeLabel}}</view></picker></view>
|
||||
<view wx:if="{{exceptionForm.exceptionType !== 'REST'}}" class="field"><text class="field-label">开始时间</text><picker mode="time" value="{{exceptionForm.startTime}}" bindchange="onExceptionStartChange"><view class="field-value">{{exceptionForm.startTime}}</view></picker></view>
|
||||
<view wx:if="{{exceptionForm.exceptionType !== 'REST'}}" class="field"><text class="field-label">结束时间</text><picker mode="time" value="{{exceptionForm.endTime}}" bindchange="onExceptionEndChange"><view class="field-value">{{exceptionForm.endTime}}</view></picker></view>
|
||||
<view class="field"><text class="field-label">备注</text><input value="{{exceptionForm.remark}}" data-field="remark" bindinput="onExceptionInput" placeholder="可选" /></view>
|
||||
<button class="secondary-btn exception-btn" loading="{{saving}}" bindtap="saveException">保存特殊日期</button>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{exceptions.length}}" class="exception-list">
|
||||
<view wx:for="{{exceptions}}" wx:key="id" class="card exception-card">
|
||||
<text>{{item.summary}}</text>
|
||||
<text wx:if="{{item.remark}}" class="exception-remark">{{item.remark}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
|
||||
<view class="fixed-bottom"><button class="primary-btn" loading="{{saving}}" bindtap="save">保存设置</button></view>
|
||||
</view>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user