Jelajahi Sumber

商家端 线上预订 商家加时 修改

qinxuyang 4 minggu lalu
induk
melakukan
029019854f

+ 22 - 6
alien-store/src/main/java/shop/alien/store/service/impl/StoreBookingCategoryServiceImpl.java

@@ -230,16 +230,32 @@ public class StoreBookingCategoryServiceImpl extends ServiceImpl<StoreBookingCat
             throw new RuntimeException("分类不存在");
         }
         
-        // 校验:检查当前分类下是否有桌号,如果有则不允许删除
+        // 查询当前分类下的所有桌号
         LambdaQueryWrapper<StoreBookingTable> tableWrapper = new LambdaQueryWrapper<>();
         tableWrapper.eq(StoreBookingTable::getCategoryId, id);
-        long tableCount = storeBookingTableService.count(tableWrapper);
-        if (tableCount > 0) {
-            log.warn("删除预订服务分类失败:当前分类下存在桌号,需要先删除桌号才能删除该分类,categoryId={}, tableCount={}", id, tableCount);
-            throw new RuntimeException("当前分类下存在桌号,需要先删除桌号才能删除该分类");
+        // @TableLogic 会自动过滤已删除的记录(delete_flag=0)
+        List<StoreBookingTable> tables = storeBookingTableService.list(tableWrapper);
+        
+        // 如果存在桌号,先批量删除这些桌号
+        if (tables != null && !tables.isEmpty()) {
+            List<Integer> tableIds = tables.stream()
+                    .map(StoreBookingTable::getId)
+                    .collect(java.util.stream.Collectors.toList());
+            
+            log.info("删除分类时同时删除该分类下的所有桌号,categoryId={}, tableCount={}, tableIds={}", 
+                    id, tables.size(), tableIds);
+            
+            // 批量逻辑删除桌号
+            boolean deleteTablesResult = storeBookingTableService.removeByIds(tableIds);
+            if (!deleteTablesResult) {
+                log.warn("删除分类下的桌号失败,categoryId={}, tableIds={}", id, tableIds);
+                throw new RuntimeException("删除分类下的桌号失败");
+            }
+            
+            log.info("成功删除分类下的所有桌号,categoryId={}, tableCount={}", id, tables.size());
         }
         
-        // 逻辑删除
+        // 逻辑删除分类
         return this.removeById(id);
     }
 

+ 2 - 2
alien-store/src/main/java/shop/alien/store/service/impl/StoreReservationServiceImpl.java

@@ -761,11 +761,11 @@ public class StoreReservationServiceImpl extends ServiceImpl<StoreReservationMap
             queryBaseTime = addTimeStart;
         }
 
-        // 查询同一门店、同一日期、状态为已确认(status=1)的预约
+        // 查询同一门店、同一日期、状态为已确认(status=1 2)的预约
         LambdaQueryWrapper<UserReservation> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(UserReservation::getStoreId, reservation.getStoreId())
                 .apply("DATE(user_reservation.reservation_date) = DATE({0})", reservation.getReservationDate())
-                .eq(UserReservation::getStatus, 1) // 已确认
+                .in(UserReservation::getStatus,1,2)
                 .ge(UserReservation::getStartTime, queryBaseTime)
                 .ne(UserReservation::getId, reservation.getId())
                 .eq(UserReservation::getDeleteFlag, 0)