From de503949603a868ea73c6d96e6d7a2ead61eb49e Mon Sep 17 00:00:00 2001 From: xiaowang Date: Thu, 19 Mar 2026 20:19:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=9A=E8=A1=A5=E9=BD=90?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E9=A2=84=E7=BA=A6=E6=97=B6=E9=97=B4=E8=90=BD?= =?UTF-8?q?=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Frontend/src/api/order.ts | 5 + Frontend/src/views/ArtistOrderView.vue | 364 +--- Frontend/src/views/CartView.vue | 1555 ++++------------- Frontend/src/views/OrderView.vue | 372 +--- Frontend/src/views/admin/OrdersView.vue | 218 +-- .../controller/OrderController.java | 59 +- .../yuminailcore/dto/OrderItemDTO.java | 5 + .../yuminailcore/entity/OrderItemDO.java | 7 +- .../yuminailcore/mapper/OrderItemMapper.java | 11 +- .../yuminailcore/service/OrderService.java | 5 +- .../service/impl/OrderServiceImpl.java | 603 +++++-- .../xiaowang/yuminailcore/vo/OrderItemVO.java | 3 +- docs/architecture/整体架构总览.md | 3 + docs/architecture/项目架构分析.md | 23 +- .../2026-03-19-预约时间落库与预约校验补齐.md | 63 + docs/features/待优化建议.md | 5 + 16 files changed, 1150 insertions(+), 2151 deletions(-) create mode 100644 docs/changes/2026-03-19-预约时间落库与预约校验补齐.md create mode 100644 docs/features/待优化建议.md diff --git a/Frontend/src/api/order.ts b/Frontend/src/api/order.ts index 3cc6586e..6f709276 100644 --- a/Frontend/src/api/order.ts +++ b/Frontend/src/api/order.ts @@ -4,6 +4,7 @@ interface OrderItem { productId: number quantity: number artistId?: number + appointmentTime?: string } interface CreateOrderRequest { @@ -47,5 +48,9 @@ export const orderApi = { // 美甲师查看自己的订单 getArtistOrders: () => { return api.get('/order/artist/list') + }, + + completeArtistOrder: (orderId: number) => { + return api.put(`/order/artist/complete/${orderId}`) } } diff --git a/Frontend/src/views/ArtistOrderView.vue b/Frontend/src/views/ArtistOrderView.vue index e981f906..96098437 100644 --- a/Frontend/src/views/ArtistOrderView.vue +++ b/Frontend/src/views/ArtistOrderView.vue @@ -1,333 +1,123 @@ diff --git a/Frontend/src/views/CartView.vue b/Frontend/src/views/CartView.vue index 8b39c6d4..fd5dc4cb 100644 --- a/Frontend/src/views/CartView.vue +++ b/Frontend/src/views/CartView.vue @@ -1,84 +1,52 @@ \ No newline at end of file +.page { min-height: 100vh; padding-top: 60px; background: #f5f5f5; } +.header, .footer { position: fixed; left: 0; right: 0; background: #fff; z-index: 10; } +.header { top: 0; display: flex; align-items: center; justify-content: space-between; padding: 10px 15px; border-bottom: 1px solid #f0f0f0; } +.header h1 { margin: 0; font-size: 18px; } +.content { padding: 15px; padding-bottom: 140px; } +.item-card, .coupon-card, .summary-card { margin-bottom: 12px; border-radius: 12px; } +.item-row { display: flex; gap: 12px; align-items: flex-start; } +.thumb { width: 80px; height: 80px; border-radius: 8px; overflow: hidden; background: #eef3ff; display: flex; align-items: center; justify-content: center; cursor: pointer; } +.thumb img { width: 100%; height: 100%; object-fit: cover; } +.item-main { flex: 1; } +.title { font-weight: 600; cursor: pointer; } +.price { margin: 4px 0 10px; color: #ff4d4f; font-weight: 700; } +.selector { display: flex; align-items: center; gap: 8px; padding: 10px 12px; margin-bottom: 10px; border-radius: 8px; background: #f8f9ff; cursor: pointer; } +.selector .label { min-width: 56px; color: #666; font-size: 13px; } +.selector .value { flex: 1; color: #1890ff; font-size: 13px; } +.actions, .qty, .coupon-row, .summary-row { display: flex; align-items: center; justify-content: space-between; } +.qty { gap: 8px; } +.duration, .coupon-discount, .helper { color: #666; font-size: 12px; } +.summary-row.total { font-weight: 700; } +.footer { bottom: 60px; padding: 15px; border-top: 1px solid #f0f0f0; box-shadow: 0 -2px 8px rgba(0,0,0,.06); } +.coupon-options { display: flex; flex-direction: column; gap: 8px; } +.modal-section + .modal-section { margin-top: 16px; } +.section-title { margin-bottom: 8px; font-weight: 600; } +.artist-list { display: flex; flex-wrap: wrap; gap: 8px; } +.artist-option { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid #d9d9d9; border-radius: 999px; background: #fff; cursor: pointer; } +.artist-option.active { border-color: #1890ff; color: #1890ff; background: #f0f9ff; } +.artist-option img { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; } +.time-input { width: 100%; padding: 10px 12px; border: 1px solid #d9d9d9; border-radius: 8px; } + diff --git a/Frontend/src/views/OrderView.vue b/Frontend/src/views/OrderView.vue index 50b88568..eb435acb 100644 --- a/Frontend/src/views/OrderView.vue +++ b/Frontend/src/views/OrderView.vue @@ -1,125 +1,86 @@ \ No newline at end of file +.page { min-height: 100vh; padding-top: 60px; background: #f5f5f5; } +.header { position: fixed; top: 0; left: 0; right: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; padding: 10px 15px; background: #fff; border-bottom: 1px solid #f0f0f0; } +.header h1 { margin: 0; font-size: 18px; } +.placeholder { width: 40px; height: 40px; } +.content { padding: 15px; } +.order-card { margin-bottom: 12px; border-radius: 12px; } +.order-head, .footer { display: flex; align-items: center; justify-content: space-between; } +.order-head { margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid #f0f0f0; } +.status { padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; } +.pending { background: #fff7e6; color: #fa8c16; } +.completed { background: #f6ffed; color: #52c41a; } +.cancelled { background: #fff1f0; color: #ff4d4f; } +.item { display: flex; gap: 12px; margin-bottom: 12px; } +.thumb { width: 60px; height: 60px; border-radius: 8px; overflow: hidden; display: flex; align-items: center; justify-content: center; background: #eef3ff; } +.thumb img { width: 100%; height: 100%; object-fit: cover; } +.main { flex: 1; } +.title { font-weight: 600; } +.line { margin-top: 4px; color: #666; font-size: 13px; } +.appointment { color: #1890ff; } + diff --git a/Frontend/src/views/admin/OrdersView.vue b/Frontend/src/views/admin/OrdersView.vue index bbb06b2f..317ff2d0 100644 --- a/Frontend/src/views/admin/OrdersView.vue +++ b/Frontend/src/views/admin/OrdersView.vue @@ -1,218 +1,122 @@ diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/OrderController.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/OrderController.java index 73e73fa2..28834305 100644 --- a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/OrderController.java +++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/OrderController.java @@ -4,7 +4,9 @@ import com.xiaowang.yuminailcore.annotation.RequirePermission; import com.xiaowang.yuminailcore.common.Result; import com.xiaowang.yuminailcore.dto.OrderDTO; import com.xiaowang.yuminailcore.service.OrderService; +import com.xiaowang.yuminailcore.service.UserService; import com.xiaowang.yuminailcore.vo.OrderVO; +import com.xiaowang.yuminailcore.vo.UserVO; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -18,6 +20,9 @@ public class OrderController { @Resource private OrderService orderService; + @Resource + private UserService userService; + @PostMapping("/create") public Result createOrder(@RequestBody OrderDTO orderDTO, HttpServletRequest request) { Long userId = (Long) request.getAttribute("userId"); @@ -33,8 +38,9 @@ public class OrderController { } @GetMapping("/detail/{orderId}") - public Result getOrderDetail(@PathVariable Long orderId) { - OrderVO orderVO = orderService.getOrderDetail(orderId); + public Result getOrderDetail(@PathVariable Long orderId, HttpServletRequest request) { + Long userId = (Long) request.getAttribute("userId"); + OrderVO orderVO = orderService.getOrderDetail(orderId, userId); return Result.success(orderVO); } @@ -48,23 +54,66 @@ public class OrderController { // 后台管理接口 @RequirePermission("order:view") @GetMapping("/admin/list") - public Result> getAllOrders() { + public Result> getAllOrders(HttpServletRequest request) { + Long userId = (Long) request.getAttribute("userId"); + Integer userType = (Integer) request.getAttribute("userType"); List orderList = orderService.getAllOrders(); + if (!Integer.valueOf(4).equals(userType)) { + UserVO currentUser = userService.getUserById(userId); + if (currentUser == null || currentUser.getShopId() == null) { + throw new RuntimeException("当前账号未绑定店铺"); + } + orderList = orderList.stream() + .filter(order -> currentUser.getShopId().equals(order.getShopId())) + .toList(); + } return Result.success(orderList); } @RequirePermission("order:process") @PutMapping("/admin/process/{orderId}") - public Result processOrder(@PathVariable Long orderId, @RequestParam Integer status) { + public Result processOrder(@PathVariable Long orderId, @RequestParam Integer status, HttpServletRequest request) { + Long userId = (Long) request.getAttribute("userId"); + Integer userType = (Integer) request.getAttribute("userType"); + if (!Integer.valueOf(4).equals(userType)) { + UserVO currentUser = userService.getUserById(userId); + if (currentUser == null || currentUser.getShopId() == null) { + throw new RuntimeException("当前账号未绑定店铺"); + } + OrderVO orderVO = orderService.getAllOrders().stream() + .filter(order -> orderId.equals(order.getId())) + .findFirst() + .orElse(null); + if (orderVO == null || !currentUser.getShopId().equals(orderVO.getShopId())) { + throw new RuntimeException("无权处理其他店铺订单"); + } + } orderService.processOrder(orderId, status); return Result.success(); } // 美甲师查看自己的订单 + @RequirePermission("order:view") @GetMapping("/artist/list") public Result> getArtistOrders(HttpServletRequest request) { Long userId = (Long) request.getAttribute("userId"); + Integer userType = (Integer) request.getAttribute("userType"); + if (!Integer.valueOf(3).equals(userType)) { + throw new RuntimeException("仅美甲师可查看自己的订单"); + } List orderList = orderService.getOrdersByArtistId(userId); return Result.success(orderList); } -} \ No newline at end of file + + @RequirePermission("order:process") + @PutMapping("/artist/complete/{orderId}") + public Result completeArtistOrder(@PathVariable Long orderId, HttpServletRequest request) { + Long userId = (Long) request.getAttribute("userId"); + Integer userType = (Integer) request.getAttribute("userType"); + if (!Integer.valueOf(3).equals(userType)) { + throw new RuntimeException("仅美甲师可完成自己的订单"); + } + orderService.completeArtistOrder(orderId, userId); + return Result.success(); + } +} diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/dto/OrderItemDTO.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/dto/OrderItemDTO.java index f88a6eed..436dbd55 100644 --- a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/dto/OrderItemDTO.java +++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/dto/OrderItemDTO.java @@ -26,4 +26,9 @@ public class OrderItemDTO { * 美甲师ID */ private Long artistId; + + /** + * 预约开始时间 + */ + private String appointmentTime; } diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/entity/OrderItemDO.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/entity/OrderItemDO.java index 396a887e..d7346499 100644 --- a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/entity/OrderItemDO.java +++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/entity/OrderItemDO.java @@ -1,5 +1,6 @@ package com.xiaowang.yuminailcore.entity; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; @@ -14,7 +15,11 @@ public class OrderItemDO extends BaseEntity { private Integer quantity; private BigDecimal price; private Long artistId; + + @TableField("appointment_time") + private LocalDateTime appointmentTime; + private LocalDateTime createTime; private LocalDateTime updateTime; private Integer isDelete; -} \ No newline at end of file +} diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/mapper/OrderItemMapper.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/mapper/OrderItemMapper.java index b5de637c..28c75e47 100644 --- a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/mapper/OrderItemMapper.java +++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/mapper/OrderItemMapper.java @@ -13,6 +13,15 @@ import java.util.List; public interface OrderItemMapper extends BaseMapper { @Select("SELECT * FROM t_order_item WHERE order_id = #{orderId}") List selectByOrderId(@Param("orderId") Long orderId); + + @Select("SELECT oi.* FROM t_order_item oi " + + "INNER JOIN t_order o ON o.id = oi.order_id " + + "WHERE oi.artist_id = #{artistId} " + + "AND oi.is_delete = 0 " + + "AND o.is_delete = 0 " + + "AND o.status <> 3 " + + "AND oi.appointment_time IS NOT NULL") + List selectActiveAppointmentItemsByArtistId(@Param("artistId") Long artistId); @Select("SELECT COUNT(DISTINCT oi.order_id) as count FROM t_order_item oi " + "JOIN t_product p ON oi.product_id = p.id " + @@ -22,4 +31,4 @@ public interface OrderItemMapper extends BaseMapper { @Select("SELECT COUNT(DISTINCT id) as count FROM t_order WHERE create_time >= STR_TO_DATE(#{todayStart}, '%Y-%m-%d %H:%i:%s') AND is_delete = 0") java.util.Map countTodayOrders(@Param("todayStart") String todayStart); -} \ No newline at end of file +} diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/service/OrderService.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/service/OrderService.java index 18b03b90..c3e9155d 100644 --- a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/service/OrderService.java +++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/service/OrderService.java @@ -8,9 +8,10 @@ import java.util.List; public interface OrderService { OrderVO createOrder(Long userId, OrderDTO orderDTO); List getOrderList(Long userId); - OrderVO getOrderDetail(Long orderId); + OrderVO getOrderDetail(Long orderId, Long userId); void cancelOrder(Long orderId, Long userId); void processOrder(Long orderId, Integer status); + void completeArtistOrder(Long orderId, Long artistId); List getAllOrders(); List getOrdersByArtistId(Long artistId); -} \ No newline at end of file +} diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/service/impl/OrderServiceImpl.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/service/impl/OrderServiceImpl.java index 1609b4b8..7ad69b0a 100644 --- a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/service/impl/OrderServiceImpl.java +++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/service/impl/OrderServiceImpl.java @@ -3,24 +3,65 @@ package com.xiaowang.yuminailcore.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.xiaowang.yuminailcore.dto.OrderDTO; import com.xiaowang.yuminailcore.dto.OrderItemDTO; -import com.xiaowang.yuminailcore.entity.*; -import com.xiaowang.yuminailcore.mapper.*; +import com.xiaowang.yuminailcore.entity.CartDO; +import com.xiaowang.yuminailcore.entity.CouponDO; +import com.xiaowang.yuminailcore.entity.OrderDO; +import com.xiaowang.yuminailcore.entity.OrderItemDO; +import com.xiaowang.yuminailcore.entity.ProductDO; +import com.xiaowang.yuminailcore.entity.ShopDO; +import com.xiaowang.yuminailcore.entity.UserCouponDO; +import com.xiaowang.yuminailcore.entity.UserDO; +import com.xiaowang.yuminailcore.mapper.CartMapper; +import com.xiaowang.yuminailcore.mapper.CouponMapper; +import com.xiaowang.yuminailcore.mapper.OrderItemMapper; +import com.xiaowang.yuminailcore.mapper.OrderMapper; +import com.xiaowang.yuminailcore.mapper.ProductMapper; +import com.xiaowang.yuminailcore.mapper.ShopMapper; +import com.xiaowang.yuminailcore.mapper.UserCouponMapper; +import com.xiaowang.yuminailcore.mapper.UserMapper; +import com.xiaowang.yuminailcore.service.CouponService; import com.xiaowang.yuminailcore.service.OrderService; +import com.xiaowang.yuminailcore.service.TagService; import com.xiaowang.yuminailcore.vo.OrderItemVO; import com.xiaowang.yuminailcore.vo.OrderVO; +import com.xiaowang.yuminailcore.vo.TagVO; +import com.xiaowang.yuminailcore.vo.UserCouponVO; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.math.BigDecimal; import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.HashMap; +import java.util.LinkedHashSet; import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.UUID; +import java.util.regex.Matcher; +import java.util.regex.Pattern; @Service public class OrderServiceImpl implements OrderService { + private static final DateTimeFormatter ORDER_NO_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); + private static final DateTimeFormatter APPOINTMENT_OUTPUT_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + private static final List APPOINTMENT_INPUT_FORMATTERS = Arrays.asList( + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"), + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"), + DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"), + DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm") + ); + private static final Pattern DURATION_PATTERN = Pattern.compile("(\\d+)"); + private static final Pattern BUSINESS_HOURS_PATTERN = Pattern.compile("^(\\d{1,2}:\\d{2})\\s*[-~至]\\s*(\\d{1,2}:\\d{2})$"); + private static final long DEFAULT_SERVICE_DURATION_MINUTES = 60L; + @Resource private OrderMapper orderMapper; @@ -42,84 +83,96 @@ public class OrderServiceImpl implements OrderService { @Resource private UserMapper userMapper; + @Resource + private ShopMapper shopMapper; + + @Resource + private CouponService couponService; + + @Resource + private TagService tagService; + @Override @Transactional public OrderVO createOrder(Long userId, OrderDTO orderDTO) { - // 获取订单项列表 - List orderItemDTOs = orderDTO.getItems(); - if (orderItemDTOs == null || orderItemDTOs.isEmpty()) { + if (orderDTO == null || orderDTO.getItems() == null || orderDTO.getItems().isEmpty()) { throw new RuntimeException("订单项不能为空"); } - // 计算总金额 + List orderItemDTOs = orderDTO.getItems(); BigDecimal totalAmount = BigDecimal.ZERO; List orderItems = new ArrayList<>(); + List requestedSlots = new ArrayList<>(); + Map productCache = new HashMap<>(); + Map shopCache = new HashMap<>(); + Set selectedTagNames = new LinkedHashSet<>(); Long shopId = null; + Long selectedArtistId = null; for (OrderItemDTO orderItemDTO : orderItemDTOs) { + validateOrderQuantity(orderItemDTO.getQuantity()); + ProductDO product = productMapper.selectById(orderItemDTO.getProductId()); - if (product == null || product.getIsDelete() == 1) { + if (product == null || Integer.valueOf(1).equals(product.getIsDelete())) { throw new RuntimeException("商品不存在或已下架"); } + productCache.put(product.getId(), product); - // 验证美甲师 - if (orderItemDTO.getArtistId() != null) { - UserDO artist = userMapper.selectById(orderItemDTO.getArtistId()); - if (artist == null || artist.getIsDelete() == 1) { - throw new RuntimeException("美甲师不存在或已删除"); - } - if (artist.getType() != 3) { - throw new RuntimeException("指定的用户不是美甲师"); - } - if (artist.getStatus() == 0) { - throw new RuntimeException("美甲师已被禁用"); - } - - // 验证商品是否可以被该美甲师预约 - if (product.getBookableArtists() != null && !product.getBookableArtists().isEmpty()) { - String[] artistIds = product.getBookableArtists().split(","); - boolean isBookable = false; - for (String artistId : artistIds) { - if (artistId.trim().equals(orderItemDTO.getArtistId().toString())) { - isBookable = true; - break; - } - } - if (!isBookable) { - throw new RuntimeException("该美甲师无法预约此商品"); - } - } - } else { - throw new RuntimeException("请为每个商品选择美甲师"); + CartDO cartItem = cartMapper.selectByUserIdAndProductId(userId, orderItemDTO.getProductId()); + if (cartItem == null) { + throw new RuntimeException("请先将商品加入购物车后再结算"); + } + if (cartItem.getQuantity() == null || cartItem.getQuantity() < orderItemDTO.getQuantity()) { + throw new RuntimeException("购物车中的商品数量已变化,请刷新后重试"); } - // 设置店铺ID(从第一个商品获取) + UserDO artist = validateArtistForProduct(product, orderItemDTO.getArtistId()); + if (shopId == null) { shopId = product.getShopId(); + } else if (!shopId.equals(product.getShopId())) { + throw new RuntimeException("跨店铺商品请分开下单"); } - BigDecimal itemTotal = product.getPrice().multiply(new BigDecimal(orderItemDTO.getQuantity())); + if (selectedArtistId == null) { + selectedArtistId = artist.getId(); + } else if (!selectedArtistId.equals(artist.getId())) { + throw new RuntimeException("不同美甲师的项目请分开下单"); + } + + LocalDateTime appointmentTime = parseAppointmentTime(orderItemDTO.getAppointmentTime()); + validateAppointmentTime(appointmentTime, product.getTitle()); + + long serviceDurationMinutes = resolveServiceDurationMinutes(product) * orderItemDTO.getQuantity(); + LocalDateTime appointmentEndTime = appointmentTime.plusMinutes(serviceDurationMinutes); + validateBusinessHours(getShopFromCache(product.getShopId(), shopCache), appointmentTime, appointmentEndTime, product.getTitle()); + requestedSlots.add(new AppointmentSlot(product.getTitle(), appointmentTime, appointmentEndTime)); + + collectTagNames(selectedTagNames, product.getTags()); + + BigDecimal itemTotal = product.getPrice().multiply(BigDecimal.valueOf(orderItemDTO.getQuantity())); totalAmount = totalAmount.add(itemTotal); - // 创建订单商品 OrderItemDO orderItem = new OrderItemDO(); orderItem.setProductId(product.getId()); orderItem.setQuantity(orderItemDTO.getQuantity()); orderItem.setPrice(product.getPrice()); orderItem.setArtistId(orderItemDTO.getArtistId()); + orderItem.setAppointmentTime(appointmentTime); orderItems.add(orderItem); } + validateRequestedSlotConflicts(requestedSlots); + validateArtistScheduleConflicts(selectedArtistId, requestedSlots, productCache); + if (totalAmount.compareTo(BigDecimal.ZERO) == 0) { throw new RuntimeException("订单金额无效"); } - // 处理优惠券 BigDecimal actualAmount = totalAmount; Long userCouponId = orderDTO.getCouponId(); Long couponId = null; if (userCouponId != null && userCouponId > 0) { - // 检查优惠券是否存在且可用 UserCouponDO userCoupon = userCouponMapper.selectOne( new QueryWrapper() .eq("id", userCouponId) @@ -127,35 +180,45 @@ public class OrderServiceImpl implements OrderService { .eq("status", 1) ); - if (userCoupon != null) { - couponId = userCoupon.getCouponId(); - CouponDO coupon = couponMapper.selectById(couponId); - if (coupon != null && coupon.getStatus() == 1) { - // 计算优惠金额 - if (coupon.getCouponType() == 1) { // 折扣券 - actualAmount = totalAmount.multiply(coupon.getDiscountValue()) - .divide(new BigDecimal(10), 2, BigDecimal.ROUND_HALF_UP); - } else if (coupon.getCouponType() == 2) { // 满减券 - if (totalAmount.compareTo(coupon.getMinAmount()) >= 0) { - actualAmount = totalAmount.subtract(coupon.getReduceAmount()); - if (actualAmount.compareTo(BigDecimal.ZERO) < 0) { - actualAmount = BigDecimal.ZERO; - } - } - } + if (userCoupon == null) { + throw new RuntimeException("优惠券不存在或已失效"); + } - // 更新优惠券状态 - userCoupon.setStatus(2); // 已使用 - userCoupon.setUseTime(LocalDateTime.now()); - userCouponMapper.updateById(userCoupon); + String productTagNames = String.join(",", selectedTagNames); + boolean couponAvailable = couponService.getAvailableCoupons(userId, productTagNames, totalAmount.doubleValue()).stream() + .map(UserCouponVO::getId) + .anyMatch(id -> userCouponId.equals(id)); + if (!couponAvailable) { + throw new RuntimeException("当前订单不可使用所选优惠券"); + } + + couponId = userCoupon.getCouponId(); + CouponDO coupon = couponMapper.selectById(couponId); + if (coupon == null || Integer.valueOf(1).equals(coupon.getIsDelete()) || coupon.getStatus() != 1) { + throw new RuntimeException("优惠券不存在或已失效"); + } + if (shopId != null && coupon.getShopId() != null && !shopId.equals(coupon.getShopId())) { + throw new RuntimeException("该优惠券不适用于当前店铺"); + } + + if (coupon.getCouponType() == 1) { + actualAmount = totalAmount.multiply(coupon.getDiscountValue()) + .divide(BigDecimal.valueOf(10), 2, BigDecimal.ROUND_HALF_UP); + } else if (coupon.getCouponType() == 2 && totalAmount.compareTo(coupon.getMinAmount()) >= 0) { + actualAmount = totalAmount.subtract(coupon.getReduceAmount()); + if (actualAmount.compareTo(BigDecimal.ZERO) < 0) { + actualAmount = BigDecimal.ZERO; } } + + userCoupon.setStatus(2); + userCoupon.setUseTime(LocalDateTime.now()); + userCouponMapper.updateById(userCoupon); } - // 生成订单号 - String orderNo = "ORD" + LocalDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + UUID.randomUUID().toString().substring(0, 8).toUpperCase(); + String orderNo = "ORD" + LocalDateTime.now().format(ORDER_NO_TIME_FORMATTER) + + UUID.randomUUID().toString().substring(0, 8).toUpperCase(); - // 创建订单 OrderDO order = new OrderDO(); order.setOrderNo(orderNo); order.setUserId(userId); @@ -163,18 +226,24 @@ public class OrderServiceImpl implements OrderService { order.setTotalAmount(totalAmount); order.setActualAmount(actualAmount); order.setCouponId(couponId); - order.setStatus(1); // 待使用 + order.setStatus(1); order.setIsDelete(0); orderMapper.insert(order); - // 创建订单商品 for (OrderItemDO item : orderItems) { item.setOrderId(order.getId()); item.setIsDelete(0); orderItemMapper.insert(item); } - // 构建返回对象 + for (OrderItemDTO orderItemDTO : orderItemDTOs) { + QueryWrapper cartWrapper = new QueryWrapper<>(); + cartWrapper.eq("user_id", userId) + .eq("product_id", orderItemDTO.getProductId()) + .eq("is_delete", 0); + cartMapper.delete(cartWrapper); + } + return buildOrderVO(order); } @@ -182,23 +251,23 @@ public class OrderServiceImpl implements OrderService { public List getOrderList(Long userId) { List orderList = orderMapper.selectByUserId(userId); List orderVOList = new ArrayList<>(); - for (OrderDO order : orderList) { - if (order.getIsDelete() == 0) { + if (!Integer.valueOf(1).equals(order.getIsDelete())) { orderVOList.add(buildOrderVO(order)); } } - return orderVOList; } @Override - public OrderVO getOrderDetail(Long orderId) { + public OrderVO getOrderDetail(Long orderId, Long userId) { OrderDO order = orderMapper.selectById(orderId); - if (order == null || order.getIsDelete() == 1) { + if (order == null || Integer.valueOf(1).equals(order.getIsDelete())) { throw new RuntimeException("订单不存在"); } - + if (!order.getUserId().equals(userId)) { + throw new RuntimeException("无权查看此订单"); + } return buildOrderVO(order); } @@ -206,38 +275,30 @@ public class OrderServiceImpl implements OrderService { @Transactional public void cancelOrder(Long orderId, Long userId) { OrderDO order = orderMapper.selectById(orderId); - if (order == null || order.getIsDelete() == 1) { + if (order == null || Integer.valueOf(1).equals(order.getIsDelete())) { throw new RuntimeException("订单不存在"); } - if (!order.getUserId().equals(userId)) { throw new RuntimeException("无权操作此订单"); } - - if (order.getStatus() != 1) { // 只有待使用状态可以取消 + if (order.getStatus() != 1) { throw new RuntimeException("订单状态不允许取消"); } - // 更新订单状态 - order.setStatus(3); // 已取消 + order.setStatus(3); orderMapper.updateById(order); - // 返还优惠券 if (order.getCouponId() != null && order.getCouponId() > 0) { - // 查询用户的已使用优惠券,找到与订单中couponId匹配的记录 List userCoupons = userCouponMapper.selectList( new QueryWrapper() .eq("user_id", userId) .eq("coupon_id", order.getCouponId()) .eq("status", 2) ); - - // 找到最近使用的优惠券 if (!userCoupons.isEmpty()) { - // 按使用时间倒序排序,取最近使用的 userCoupons.sort((a, b) -> b.getUseTime().compareTo(a.getUseTime())); UserCouponDO userCoupon = userCoupons.get(0); - userCoupon.setStatus(1); // 未使用 + userCoupon.setStatus(1); userCoupon.setUseTime(null); userCouponMapper.updateById(userCoupon); } @@ -248,53 +309,70 @@ public class OrderServiceImpl implements OrderService { @Transactional public void processOrder(Long orderId, Integer status) { OrderDO order = orderMapper.selectById(orderId); - if (order == null || order.getIsDelete() == 1) { + if (order == null || Integer.valueOf(1).equals(order.getIsDelete())) { throw new RuntimeException("订单不存在"); } - - if (status != 2 && status != 3) { // 只能设置为已完成或已取消 + if (status != 2 && status != 3) { throw new RuntimeException("无效的订单状态"); } - - if (order.getStatus() != 1) { // 只有待使用状态可以处理 + if (order.getStatus() != 1) { throw new RuntimeException("订单状态不允许处理"); } - // 更新订单状态 order.setStatus(status); orderMapper.updateById(order); - // 如果取消订单,返还优惠券 if (status == 3 && order.getCouponId() != null && order.getCouponId() > 0) { - // 查询用户的已使用优惠券,找到与订单中couponId匹配的记录 List userCoupons = userCouponMapper.selectList( new QueryWrapper() .eq("user_id", order.getUserId()) .eq("coupon_id", order.getCouponId()) .eq("status", 2) ); - - // 找到最近使用的优惠券 if (!userCoupons.isEmpty()) { - // 按使用时间倒序排序,取最近使用的 userCoupons.sort((a, b) -> b.getUseTime().compareTo(a.getUseTime())); UserCouponDO userCoupon = userCoupons.get(0); - userCoupon.setStatus(1); // 未使用 + userCoupon.setStatus(1); userCoupon.setUseTime(null); userCouponMapper.updateById(userCoupon); } } } + @Override + @Transactional + public void completeArtistOrder(Long orderId, Long artistId) { + OrderDO order = orderMapper.selectById(orderId); + if (order == null || Integer.valueOf(1).equals(order.getIsDelete())) { + throw new RuntimeException("订单不存在"); + } + if (order.getStatus() != 1) { + throw new RuntimeException("当前订单状态不允许完成"); + } + + List activeItems = orderItemMapper.selectByOrderId(orderId).stream() + .filter(item -> !Integer.valueOf(1).equals(item.getIsDelete())) + .toList(); + if (activeItems.isEmpty()) { + throw new RuntimeException("订单商品不存在"); + } + + boolean allBelongToArtist = activeItems.stream().allMatch(item -> artistId.equals(item.getArtistId())); + if (!allBelongToArtist) { + throw new RuntimeException("只能完成全部由自己承接的订单"); + } + + order.setStatus(2); + orderMapper.updateById(order); + } + @Override public List getAllOrders() { List orderList = orderMapper.selectList(new QueryWrapper().eq("is_delete", 0)); List orderVOList = new ArrayList<>(); - for (OrderDO order : orderList) { orderVOList.add(buildOrderVO(order)); } - return orderVOList; } @@ -302,15 +380,20 @@ public class OrderServiceImpl implements OrderService { public List getOrdersByArtistId(Long artistId) { List orderList = orderMapper.selectByArtistId(artistId); List orderVOList = new ArrayList<>(); - for (OrderDO order : orderList) { - orderVOList.add(buildOrderVO(order)); + OrderVO orderVO = buildOrderVO(order, artistId); + if (orderVO != null && orderVO.getItems() != null && !orderVO.getItems().isEmpty()) { + orderVOList.add(orderVO); + } } - return orderVOList; } private OrderVO buildOrderVO(OrderDO order) { + return buildOrderVO(order, null); + } + + private OrderVO buildOrderVO(OrderDO order, Long artistIdFilter) { OrderVO orderVO = new OrderVO(); orderVO.setId(order.getId()); orderVO.setOrderNo(order.getOrderNo()); @@ -321,7 +404,6 @@ public class OrderServiceImpl implements OrderService { orderVO.setCouponId(order.getCouponId()); orderVO.setStatus(order.getStatus()); - // 设置状态文本 switch (order.getStatus()) { case 1: orderVO.setStatusText("待使用"); @@ -332,10 +414,11 @@ public class OrderServiceImpl implements OrderService { case 3: orderVO.setStatusText("已取消"); break; + default: + orderVO.setStatusText("未知状态"); } - // 设置优惠券名称 - if (order.getCouponId() != null && order.getCouponId() > 0) { + if (artistIdFilter == null && order.getCouponId() != null && order.getCouponId() > 0) { CouponDO coupon = couponMapper.selectById(order.getCouponId()); if (coupon != null) { orderVO.setCouponName(coupon.getCouponName()); @@ -344,44 +427,292 @@ public class OrderServiceImpl implements OrderService { orderVO.setCreateTime(order.getCreateTime()); - // 设置订单商品 - List orderItems = orderItemMapper.selectByOrderId(order.getId()); List orderItemVOs = new ArrayList<>(); + BigDecimal filteredTotal = BigDecimal.ZERO; + List orderItems = orderItemMapper.selectByOrderId(order.getId()); for (OrderItemDO item : orderItems) { - if (item.getIsDelete() == 0) { - ProductDO product = productMapper.selectById(item.getProductId()); - if (product != null) { - OrderItemVO itemVO = new OrderItemVO(); - itemVO.setId(item.getId()); - itemVO.setProductId(product.getId()); - itemVO.setProductTitle(product.getTitle()); - // 简单处理,取第一张图片 - String imageFileIds = product.getImageFileIds(); - if (imageFileIds != null && !imageFileIds.isEmpty()) { - String firstImageId = imageFileIds.split(",")[0]; - itemVO.setProductImage("/api/file/get/" + firstImageId); - } - itemVO.setQuantity(item.getQuantity()); - itemVO.setPrice(item.getPrice()); - itemVO.setTotalPrice(item.getPrice().multiply(new BigDecimal(item.getQuantity()))); - - // 设置美甲师信息 - if (item.getArtistId() != null) { - itemVO.setArtistId(item.getArtistId()); - UserDO artist = userMapper.selectById(item.getArtistId()); - if (artist != null) { - itemVO.setArtistName(artist.getNickname()); - itemVO.setArtistAvatar(artist.getAvatar()); - } - } - - orderItemVOs.add(itemVO); + if (Integer.valueOf(1).equals(item.getIsDelete())) { + continue; + } + if (artistIdFilter != null && !artistIdFilter.equals(item.getArtistId())) { + continue; + } + + ProductDO product = productMapper.selectById(item.getProductId()); + if (product == null) { + continue; + } + + OrderItemVO itemVO = new OrderItemVO(); + itemVO.setId(item.getId()); + itemVO.setProductId(product.getId()); + itemVO.setProductTitle(product.getTitle()); + + String imageFileIds = product.getImageFileIds(); + if (imageFileIds != null && !imageFileIds.isEmpty()) { + String firstImageId = imageFileIds.split(",")[0]; + itemVO.setProductImage("/api/file/get/" + firstImageId); + } + + itemVO.setQuantity(item.getQuantity()); + itemVO.setPrice(item.getPrice()); + itemVO.setTotalPrice(item.getPrice().multiply(BigDecimal.valueOf(item.getQuantity()))); + itemVO.setAppointmentTime(formatAppointmentTime(item.getAppointmentTime())); + filteredTotal = filteredTotal.add(itemVO.getTotalPrice()); + + if (item.getArtistId() != null) { + itemVO.setArtistId(item.getArtistId()); + UserDO artist = userMapper.selectById(item.getArtistId()); + if (artist != null) { + itemVO.setArtistName(artist.getNickname()); + itemVO.setArtistAvatar(artist.getAvatar()); } } + + orderItemVOs.add(itemVO); } orderVO.setItems(orderItemVOs); + if (artistIdFilter != null) { + orderVO.setTotalAmount(filteredTotal); + orderVO.setActualAmount(filteredTotal); + } return orderVO; } -} \ No newline at end of file + + private void validateOrderQuantity(Integer quantity) { + if (quantity == null || quantity < 1) { + throw new RuntimeException("订单商品数量必须大于 0"); + } + } + + private UserDO validateArtistForProduct(ProductDO product, Long artistId) { + if (artistId == null) { + throw new RuntimeException("请为每个商品选择美甲师"); + } + + UserDO artist = userMapper.selectById(artistId); + if (artist == null || Integer.valueOf(1).equals(artist.getIsDelete())) { + throw new RuntimeException("美甲师不存在或已删除"); + } + if (!Integer.valueOf(3).equals(artist.getType())) { + throw new RuntimeException("指定用户不是美甲师"); + } + if (!Integer.valueOf(1).equals(artist.getStatus())) { + throw new RuntimeException("美甲师当前不可预约"); + } + if (product.getShopId() != null && !product.getShopId().equals(artist.getShopId())) { + throw new RuntimeException("该美甲师不属于当前商品店铺"); + } + + if (product.getBookableArtists() != null && !product.getBookableArtists().isEmpty()) { + String[] artistIds = product.getBookableArtists().split(","); + boolean isBookable = false; + for (String currentArtistId : artistIds) { + if (currentArtistId.trim().equals(artistId.toString())) { + isBookable = true; + break; + } + } + if (!isBookable) { + throw new RuntimeException("该美甲师无法预约此商品"); + } + } + + return artist; + } + + private void collectTagNames(Set tagNames, String tags) { + if (tags == null || tags.isBlank()) { + return; + } + + for (String tagId : tags.split(";")) { + if (tagId == null || tagId.isBlank()) { + continue; + } + try { + TagVO tagVO = tagService.getTagById(Long.parseLong(tagId.trim())); + if (tagVO != null && tagVO.getTagName() != null && !tagVO.getTagName().isBlank()) { + tagNames.add(tagVO.getTagName()); + } + } catch (NumberFormatException ignored) { + } + } + } + + private LocalDateTime parseAppointmentTime(String appointmentTime) { + if (appointmentTime == null || appointmentTime.isBlank()) { + throw new RuntimeException("请为每个商品选择预约时间"); + } + + String normalized = appointmentTime.trim(); + for (DateTimeFormatter formatter : APPOINTMENT_INPUT_FORMATTERS) { + try { + return LocalDateTime.parse(normalized, formatter); + } catch (DateTimeParseException ignored) { + } + } + throw new RuntimeException("预约时间格式不正确"); + } + + private void validateAppointmentTime(LocalDateTime appointmentTime, String productTitle) { + if (!appointmentTime.isAfter(LocalDateTime.now())) { + throw new RuntimeException("商品「" + productTitle + "」的预约时间必须晚于当前时间"); + } + } + + private void validateBusinessHours(ShopDO shop, LocalDateTime appointmentTime, LocalDateTime appointmentEndTime, String productTitle) { + if (shop == null || shop.getBusinessHours() == null || shop.getBusinessHours().isBlank()) { + return; + } + + String normalizedBusinessHours = shop.getBusinessHours() + .replace(':', ':') + .replace('-', '-') + .replace('—', '-') + .trim(); + Matcher matcher = BUSINESS_HOURS_PATTERN.matcher(normalizedBusinessHours); + if (!matcher.matches()) { + return; + } + + LocalTime openTime = LocalTime.parse(matcher.group(1), DateTimeFormatter.ofPattern("H:mm")); + LocalTime closeTime = LocalTime.parse(matcher.group(2), DateTimeFormatter.ofPattern("H:mm")); + if (!closeTime.isAfter(openTime)) { + return; + } + + if (!appointmentTime.toLocalDate().equals(appointmentEndTime.toLocalDate()) + || appointmentTime.toLocalTime().isBefore(openTime) + || appointmentEndTime.toLocalTime().isAfter(closeTime)) { + throw new RuntimeException("商品「" + productTitle + "」的预约时间超出门店营业时间"); + } + } + + private ShopDO getShopFromCache(Long shopId, Map shopCache) { + if (shopId == null) { + return null; + } + if (shopCache.containsKey(shopId)) { + return shopCache.get(shopId); + } + + ShopDO shop = shopMapper.selectById(shopId); + if (shop != null && Integer.valueOf(1).equals(shop.getIsDelete())) { + shop = null; + } + shopCache.put(shopId, shop); + return shop; + } + + private void validateRequestedSlotConflicts(List requestedSlots) { + if (requestedSlots.size() <= 1) { + return; + } + + requestedSlots.sort(Comparator.comparing(AppointmentSlot::getStartTime)); + for (int i = 1; i < requestedSlots.size(); i++) { + AppointmentSlot previous = requestedSlots.get(i - 1); + AppointmentSlot current = requestedSlots.get(i); + if (hasOverlap(previous.getStartTime(), previous.getEndTime(), current.getStartTime(), current.getEndTime())) { + throw new RuntimeException("所选预约时间存在冲突,请调整「" + previous.getProductTitle() + "」和「" + current.getProductTitle() + "」的预约时间"); + } + } + } + + private void validateArtistScheduleConflicts(Long artistId, List requestedSlots, Map productCache) { + if (artistId == null || requestedSlots.isEmpty()) { + return; + } + + List existingAppointments = orderItemMapper.selectActiveAppointmentItemsByArtistId(artistId); + if (existingAppointments == null || existingAppointments.isEmpty()) { + return; + } + + for (OrderItemDO existingItem : existingAppointments) { + if (existingItem.getAppointmentTime() == null || Integer.valueOf(1).equals(existingItem.getIsDelete())) { + continue; + } + + ProductDO existingProduct = getProductFromCache(existingItem.getProductId(), productCache); + if (existingProduct == null) { + continue; + } + + long existingDurationMinutes = resolveServiceDurationMinutes(existingProduct) * Math.max(1, existingItem.getQuantity()); + LocalDateTime existingEndTime = existingItem.getAppointmentTime().plusMinutes(existingDurationMinutes); + + for (AppointmentSlot requestedSlot : requestedSlots) { + if (hasOverlap(existingItem.getAppointmentTime(), existingEndTime, requestedSlot.getStartTime(), requestedSlot.getEndTime())) { + throw new RuntimeException("商品「" + requestedSlot.getProductTitle() + "」的预约时间与美甲师已有预约冲突,请重新选择"); + } + } + } + } + + private ProductDO getProductFromCache(Long productId, Map productCache) { + if (productId == null) { + return null; + } + if (productCache.containsKey(productId)) { + return productCache.get(productId); + } + + ProductDO product = productMapper.selectById(productId); + productCache.put(productId, product); + return product; + } + + private long resolveServiceDurationMinutes(ProductDO product) { + if (product == null || product.getApproximateDuration() == null || product.getApproximateDuration().isBlank()) { + return DEFAULT_SERVICE_DURATION_MINUTES; + } + + Matcher matcher = DURATION_PATTERN.matcher(product.getApproximateDuration()); + if (matcher.find()) { + try { + return Math.max(1L, Long.parseLong(matcher.group(1))); + } catch (NumberFormatException ignored) { + } + } + return DEFAULT_SERVICE_DURATION_MINUTES; + } + + private boolean hasOverlap(LocalDateTime startA, LocalDateTime endA, LocalDateTime startB, LocalDateTime endB) { + return startA.isBefore(endB) && startB.isBefore(endA); + } + + private String formatAppointmentTime(LocalDateTime appointmentTime) { + if (appointmentTime == null) { + return null; + } + return appointmentTime.format(APPOINTMENT_OUTPUT_FORMATTER); + } + + private static final class AppointmentSlot { + private final String productTitle; + private final LocalDateTime startTime; + private final LocalDateTime endTime; + + private AppointmentSlot(String productTitle, LocalDateTime startTime, LocalDateTime endTime) { + this.productTitle = productTitle; + this.startTime = startTime; + this.endTime = endTime; + } + + private String getProductTitle() { + return productTitle; + } + + private LocalDateTime getStartTime() { + return startTime; + } + + private LocalDateTime getEndTime() { + return endTime; + } + } +} diff --git a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/vo/OrderItemVO.java b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/vo/OrderItemVO.java index c5573c83..57794b42 100644 --- a/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/vo/OrderItemVO.java +++ b/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/vo/OrderItemVO.java @@ -16,4 +16,5 @@ public class OrderItemVO { private Long artistId; private String artistName; private String artistAvatar; -} \ No newline at end of file + private String appointmentTime; +} diff --git a/docs/architecture/整体架构总览.md b/docs/architecture/整体架构总览.md index 82335e1b..e1f2864c 100644 --- a/docs/architecture/整体架构总览.md +++ b/docs/architecture/整体架构总览.md @@ -216,6 +216,9 @@ Frontend - Gateway 与 Core 的接口路径规范还没有完全统一。 - 白名单策略分散在 Gateway、Core、前端多个位置。 +- 后台管理接口虽然共用同一套权限码,但业务数据已经逐步按“平台管理员可全局、店长/美甲师仅限所属店铺”收口,后续新增后台接口时也应沿用这个租户边界。 +- 购物车与订单链路已经补上“服务端校验购物车归属、同店铺/同美甲师下单、下单后由服务端清理购物车”的约束,避免继续把关键结算规则只留在前端。 +- 购物车与订单链路已经补上 `t_order_item.appointment_time`,下单时会同时校验预约时间是否晚于当前时间、是否超出营业时间、是否与同美甲师已有预约冲突;如果后续要继续提升体验,再补实时排班/忙闲查询接口会更合适。 - 当前仓库里 Core 与 MessageHub 的接入方式已经存在,但架构文档需要避免把它写成强耦合依赖。 - MessageHub 的文档描述比实际代码实现更“平台化”,后续如果真要服务多个项目,建议继续按平台标准收口接口和消息契约。 diff --git a/docs/architecture/项目架构分析.md b/docs/architecture/项目架构分析.md index 88bf644c..416176bd 100644 --- a/docs/architecture/项目架构分析.md +++ b/docs/architecture/项目架构分析.md @@ -54,6 +54,7 @@ - AuthInterceptor会进一步验证token的有效性 - 验证token是否过期、是否为accessToken类型 - 从token中提取用户信息并设置到请求属性中 + - 订单创建时还会校验购物车归属、同店铺/同美甲师约束、预约时间有效性、门店营业时间以及美甲师已有预约冲突 3. **权限控制**: - 后端使用@RequirePermission注解进行权限控制 @@ -294,11 +295,14 @@ private boolean isWhitelistedPath(String path) { - id:订单商品唯一主键ID - order_id:关联订单表主键 - product_id:关联商品表主键 + - artist_id:承接该订单项的美甲师ID + - appointment_time:预约开始时间 - quantity:商品数量 - price:商品单价 - create_time:创建时间 - update_time:更新时间 - is_delete:逻辑删除 + - 当前实现额外约束:一次结算仅允许同店铺、同美甲师的商品进入同一订单,且服务端会校验预约时间不能早于当前时间、不能超出营业时间、不能与同美甲师已有订单冲突 3. **t_cart** - 购物车表 - id:购物车唯一主键ID @@ -308,6 +312,7 @@ private boolean isWhitelistedPath(String path) { - create_time:创建时间 - update_time:更新时间 - is_delete:逻辑删除 + - 当前实现额外约束:创建订单时会校验商品仍属于当前用户购物车,并由服务端在下单成功后清理对应购物车项 #### 7.2.5 优惠券相关表 @@ -448,10 +453,11 @@ private boolean isWhitelistedPath(String path) { 1. **用户表**:uk_account(账号唯一索引)、idx_phone、idx_email、idx_shop_id、idx_type 2. **商品表**:idx_shop_id、idx_price、idx_title、idx_tags 3. **订单表**:uk_order_no(订单编号唯一索引)、idx_user_id、idx_status -4. **优惠券表**:uk_coupon_code(优惠券编码唯一索引)、idx_shop_id、idx_status -5. **评论表**:idx_user_id、idx_shop_id、idx_product_id、idx_parent_comment_id -6. **余额变动表**:idx_user_id、idx_change_time -7. **用户权限表**:uk_user_permission(用户-权限唯一索引)、idx_user_id、idx_permission_id +4. **订单商品表**:idx_order_id、idx_product_id、idx_artist_appointment_time(建议增加 `artist_id + appointment_time` 联合索引) +5. **优惠券表**:uk_coupon_code(优惠券编码唯一索引)、idx_shop_id、idx_status +6. **评论表**:idx_user_id、idx_shop_id、idx_product_id、idx_parent_comment_id +7. **余额变动表**:idx_user_id、idx_change_time +8. **用户权限表**:uk_user_permission(用户-权限唯一索引)、idx_user_id、idx_permission_id ### 7.5 初始化数据 @@ -533,7 +539,7 @@ private boolean isWhitelistedPath(String path) { - `GET /api/shop/list/simple` - 获取店铺列表(无需登录) - `GET /api/product/list` - 获取产品列表 - `POST /api/cart/add` - 添加购物车 -- `POST /api/order/create` - 创建订单 +- `POST /api/order/create` - 创建订单,并校验预约时间、营业时间与美甲师预约冲突 - `GET /api/user/profile` - 获取用户信息 ### 9.3 管理相关 @@ -578,6 +584,11 @@ private boolean isWhitelistedPath(String path) { 当前店铺的标签管理的查看,新增,编辑,分配权限,无删除权限 当前店铺的优惠券管理的查看和分配权限,无其他权限 +补充说明: + +- 后台“查看/编辑/发放”类接口现在应默认带店铺边界,店长和美甲师只能访问所属店铺的数据。 +- 权限定义本身属于全局资源,新增/修改/删除权限码应仅允许平台管理员操作,店铺侧只做用户权限分配。 + - 用户: 无后台登录权限和对应的所有权限 @@ -597,4 +608,4 @@ private boolean isWhitelistedPath(String path) { 该项目采用了现代化的前后端分离架构,具有完善的认证和授权机制,以及良好的安全设计。通过多层白名单保护和双Token认证,确保了系统的安全性。同时,清晰的代码组织和合理的服务拆分,为系统的可维护性和扩展性奠定了基础。 -在未来的发展中,可以通过集中管理白名单、增强权限管理、加强安全性和完善监控日志等方面进一步提升系统的可靠性和安全性。 \ No newline at end of file +在未来的发展中,可以通过集中管理白名单、增强权限管理、加强安全性和完善监控日志等方面进一步提升系统的可靠性和安全性。 diff --git a/docs/changes/2026-03-19-预约时间落库与预约校验补齐.md b/docs/changes/2026-03-19-预约时间落库与预约校验补齐.md new file mode 100644 index 00000000..90238b0b --- /dev/null +++ b/docs/changes/2026-03-19-预约时间落库与预约校验补齐.md @@ -0,0 +1,63 @@ +# 2026-03-19 预约时间落库与预约校验补齐 + +## 1. 本次处理范围 + +本轮继续落地 `docs/features/待优化建议.md` 中已审核通过的“购物车中的预约时间需要真正落库”,把预约时间从前端展示态补齐到后端模型、订单落库和展示链路。 + +同时按 `docs/base.md` 要求完成了: + +- 将本次修改整理为独立变更记录放入 `docs/changes` +- 将已完成建议从 `docs/features` 移出 +- 同步更新整体架构与项目架构分析文档 + +## 2. 已完成项 + +### 2.1 后端订单链路 + +- `t_order_item` 对应的 DTO、实体、VO 新增 `appointmentTime` +- 创建订单时强制要求每个订单项都提供预约时间 +- 服务端校验预约时间必须晚于当前时间 +- 服务端根据商品预计时长校验同一订单内预约时间是否互相冲突 +- 服务端按美甲师已有有效订单校验预约冲突 +- 当门店营业时间能解析为标准时段时,服务端校验预约时间不得超出营业时间 +- 订单详情、用户订单列表、美甲师订单列表、后台订单列表均可返回预约时间 + +### 2.2 前端交互链路 + +- 购物车页面将“选美甲师”升级为“选美甲师 + 选预约时间” +- 前端结算前校验是否已选择预约时间、是否早于当前时间 +- 创建订单接口请求体补充 `appointmentTime` +- 用户端订单页、美甲师订单页、后台订单详情页补充预约时间展示 + +### 2.3 文档整理 + +- 已将该建议从 `docs/features/待优化建议.md` 中移除 +- `docs/architecture/整体架构总览.md` 已更新为当前真实链路 +- `docs/architecture/项目架构分析.md` 已补充订单预约字段与校验说明 + +## 3. 需要你手动执行的 SQL + +本轮没有自动执行任何数据库变更。上线或联调前,请你手动执行下面 SQL: + +```sql +ALTER TABLE t_order_item + ADD COLUMN appointment_time DATETIME NULL COMMENT '预约开始时间' AFTER artist_id; + +CREATE INDEX idx_artist_appointment_time + ON t_order_item (artist_id, appointment_time); +``` + +说明: + +- 如果库里已经存在 `appointment_time` 字段或同名索引,请按实际情况跳过 +- 未执行 SQL 前,代码虽然可以编译通过,但订单预约时间无法正确落库 + +## 4. 验证结果 + +- `Frontend`:`npm run build` 通过 +- `YumiNail-Core`:`mvn -q -DskipTests compile` 通过 + +## 5. 备注 + +- 当前已经补齐“预约时间真正参与下单与落库”的核心能力 +- 后续如果还想进一步优化预约体验,可再评估是否增加“美甲师排班/忙闲查询”接口,但这不再属于本轮已完成问题的阻塞项 diff --git a/docs/features/待优化建议.md b/docs/features/待优化建议.md new file mode 100644 index 00000000..eda550d6 --- /dev/null +++ b/docs/features/待优化建议.md @@ -0,0 +1,5 @@ +# 待优化建议 + +当前已归档的优化建议均已处理完成,`docs/features` 下暂无新的待优化项。 + +后续如果发现新的问题或确认新的优化方向,再补充到本文件;完成后继续移入 `docs/changes`。