Просмотр исходного кода

维护餐具费 订单新增字段

lutong 2 месяцев назад
Родитель
Сommit
9573820b50

+ 5 - 4
alien-dining/src/main/java/shop/alien/dining/controller/StoreInfoController.java

@@ -64,16 +64,17 @@ public class StoreInfoController {
         }
     }
 
-    @ApiOperation(value = "根据门店ID查询菜品种类及各类别下菜品", notes = "一次返回所有菜品种类及每个分类下的菜品列表")
+    @ApiOperation(value = "根据门店ID查询菜品种类及各类别下菜品", notes = "一次返回所有菜品种类及每个分类下的菜品列表;可选 keyword 按菜品名称模糊查询")
     @GetMapping("/categories-with-cuisines")
     public R<List<CategoryWithCuisinesVO>> getCategoriesWithCuisinesByStoreId(
-            @ApiParam(value = "门店ID", required = true) @RequestParam Integer storeId) {
-        log.info("StoreInfoController.getCategoriesWithCuisinesByStoreId?storeId={}", storeId);
+            @ApiParam(value = "门店ID", required = true) @RequestParam Integer storeId,
+            @ApiParam(value = "菜品名称模糊查询关键词(可选)") @RequestParam(required = false) String keyword) {
+        log.info("StoreInfoController.getCategoriesWithCuisinesByStoreId?storeId={}, keyword={}", storeId, keyword);
         try {
             if (storeId == null) {
                 return R.fail("门店ID不能为空");
             }
-            List<CategoryWithCuisinesVO> list = storeInfoService.getCategoriesWithCuisinesByStoreId(storeId);
+            List<CategoryWithCuisinesVO> list = storeInfoService.getCategoriesWithCuisinesByStoreId(storeId, keyword);
             return R.data(list);
         } catch (Exception e) {
             log.error("查询菜品种类及菜品失败: {}", e.getMessage(), e);

+ 2 - 1
alien-dining/src/main/java/shop/alien/dining/service/StoreInfoService.java

@@ -44,9 +44,10 @@ public interface StoreInfoService {
      * 根据门店ID查询菜品种类及每个分类下的菜品列表(一次返回种类+菜品)
      *
      * @param storeId 门店ID
+     * @param keyword 菜品名称模糊查询关键词(可选,为空则不按名称筛选)
      * @return 菜品种类及下属菜品列表
      */
-    List<CategoryWithCuisinesVO> getCategoriesWithCuisinesByStoreId(Integer storeId);
+    List<CategoryWithCuisinesVO> getCategoriesWithCuisinesByStoreId(Integer storeId, String keyword);
 
     /**
      * 删除菜品种类:仅逻辑删除分类并解除菜品与该分类的绑定关系,价目表(菜品)本身不改动

+ 61 - 32
alien-dining/src/main/java/shop/alien/dining/service/impl/CartServiceImpl.java

@@ -670,7 +670,7 @@ public class CartServiceImpl implements CartService {
      * 餐具的特殊ID(用于标识餐具项)
      */
     private static final Integer TABLEWARE_CUISINE_ID = -1;
-    private static final String TABLEWARE_NAME = "餐具";
+    private static final String TABLEWARE_NAME = "餐具";
 
     /**
      * 获取餐具单价(从 store_info 表获取)
@@ -719,39 +719,47 @@ public class CartServiceImpl implements CartService {
         }
         BigDecimal tablewareUnitPrice = getTablewareUnitPrice(storeId);
 
-        // 查找是否已存在餐具项
-        CartItemDTO tablewareItem = items.stream()
-                .filter(item -> TABLEWARE_CUISINE_ID.equals(item.getCuisineId()))
-                .findFirst()
-                .orElse(null);
+        // 商铺未设置餐具费时,不往购物车加餐具;若已有餐具项则移除
+        if (tablewareUnitPrice == null || tablewareUnitPrice.compareTo(BigDecimal.ZERO) <= 0) {
+            log.info("门店未设置餐具费, storeId={},设置就餐人数时不添加餐具", storeId);
+            CartItemDTO existing = items.stream()
+                    .filter(item -> TABLEWARE_CUISINE_ID.equals(item.getCuisineId()))
+                    .findFirst()
+                    .orElse(null);
+            if (existing != null) {
+                items.remove(existing);
+            }
+        } else {
+            // 查找是否已存在餐具项
+            CartItemDTO tablewareItem = items.stream()
+                    .filter(item -> TABLEWARE_CUISINE_ID.equals(item.getCuisineId()))
+                    .findFirst()
+                    .orElse(null);
 
-        // 获取当前用户信息
-        Integer userId = TokenUtil.getCurrentUserId();
-        String userPhone = TokenUtil.getCurrentUserPhone();
+            Integer userId = TokenUtil.getCurrentUserId();
+            String userPhone = TokenUtil.getCurrentUserPhone();
 
-        if (tablewareItem != null) {
-            // 下单后只能增不能减:已有已下单数量时,用餐人数不能少于已下单数量
-            Integer lockedQuantity = tablewareItem.getLockedQuantity();
-            if (lockedQuantity != null && lockedQuantity > 0 && dinerCount < lockedQuantity) {
-                throw new RuntimeException("餐具数量不能少于已下单数量(" + lockedQuantity + ")");
+            if (tablewareItem != null) {
+                Integer lockedQuantity = tablewareItem.getLockedQuantity();
+                if (lockedQuantity != null && lockedQuantity > 0 && dinerCount < lockedQuantity) {
+                    throw new RuntimeException("餐具数量不能少于已下单数量(" + lockedQuantity + ")");
+                }
+                tablewareItem.setQuantity(dinerCount);
+                tablewareItem.setUnitPrice(tablewareUnitPrice);
+                tablewareItem.setSubtotalAmount(tablewareUnitPrice.multiply(BigDecimal.valueOf(dinerCount)));
+            } else {
+                CartItemDTO newTablewareItem = new CartItemDTO();
+                newTablewareItem.setCuisineId(TABLEWARE_CUISINE_ID);
+                newTablewareItem.setCuisineName(TABLEWARE_NAME);
+                newTablewareItem.setCuisineType(0);
+                newTablewareItem.setCuisineImage("");
+                newTablewareItem.setUnitPrice(tablewareUnitPrice);
+                newTablewareItem.setQuantity(dinerCount);
+                newTablewareItem.setSubtotalAmount(tablewareUnitPrice.multiply(BigDecimal.valueOf(dinerCount)));
+                newTablewareItem.setAddUserId(userId);
+                newTablewareItem.setAddUserPhone(userPhone);
+                items.add(newTablewareItem);
             }
-            // 更新餐具数量和单价
-            tablewareItem.setQuantity(dinerCount);
-            tablewareItem.setUnitPrice(tablewareUnitPrice);
-            tablewareItem.setSubtotalAmount(tablewareUnitPrice.multiply(BigDecimal.valueOf(dinerCount)));
-        } else {
-            // 添加餐具项
-            CartItemDTO newTablewareItem = new CartItemDTO();
-            newTablewareItem.setCuisineId(TABLEWARE_CUISINE_ID);
-            newTablewareItem.setCuisineName(TABLEWARE_NAME);
-            newTablewareItem.setCuisineType(0); // 0表示餐具
-            newTablewareItem.setCuisineImage("");
-            newTablewareItem.setUnitPrice(tablewareUnitPrice);
-            newTablewareItem.setQuantity(dinerCount);
-            newTablewareItem.setSubtotalAmount(tablewareUnitPrice.multiply(BigDecimal.valueOf(dinerCount)));
-            newTablewareItem.setAddUserId(userId);
-            newTablewareItem.setAddUserPhone(userPhone);
-            items.add(newTablewareItem);
         }
 
         // 重新计算总金额和总数量
@@ -790,7 +798,6 @@ public class CartServiceImpl implements CartService {
         // 获取门店ID和餐具单价
         Integer storeId = cart.getStoreId();
         if (storeId == null) {
-            // 如果购物车中没有门店ID,从桌号获取
             StoreTable table = storeTableMapper.selectById(tableId);
             if (table != null) {
                 storeId = table.getStoreId();
@@ -798,6 +805,28 @@ public class CartServiceImpl implements CartService {
         }
         BigDecimal tablewareUnitPrice = getTablewareUnitPrice(storeId);
 
+        // 商铺未设置餐具费(单价为0或未配置)时,不往购物车加餐具;若已有餐具项则移除
+        if (tablewareUnitPrice == null || tablewareUnitPrice.compareTo(BigDecimal.ZERO) <= 0) {
+            log.info("门店未设置餐具费, storeId={},不添加餐具到购物车", storeId);
+            CartItemDTO existing = items.stream()
+                    .filter(item -> TABLEWARE_CUISINE_ID.equals(item.getCuisineId()))
+                    .findFirst()
+                    .orElse(null);
+            if (existing != null) {
+                items.remove(existing);
+                BigDecimal totalAmount = items.stream()
+                        .map(CartItemDTO::getSubtotalAmount)
+                        .reduce(BigDecimal.ZERO, BigDecimal::add);
+                Integer totalQuantity = items.stream()
+                        .mapToInt(CartItemDTO::getQuantity)
+                        .sum();
+                cart.setTotalAmount(totalAmount);
+                cart.setTotalQuantity(totalQuantity);
+                saveCart(cart);
+            }
+            return cart;
+        }
+
         // 查找餐具项
         CartItemDTO tablewareItem = items.stream()
                 .filter(item -> TABLEWARE_CUISINE_ID.equals(item.getCuisineId()))

+ 3 - 0
alien-dining/src/main/java/shop/alien/dining/service/impl/DiningUserServiceImpl.java

@@ -81,6 +81,9 @@ public class DiningUserServiceImpl implements DiningUserService {
                 log.warn("解析手机号失败,phoneCode可能已过期或无效");
             }
         }
+        if (StringUtils.isBlank(parsedPhone)) {
+            log.info("微信登录未传手机号或解析失败: openid={}, phoneCode={}", maskString(openid, 8), StringUtils.isNotBlank(phoneCode) ? "已传" : "未传");
+        }
 
         // 3. 查找或创建用户(传入解析后的手机号,避免重复解析)
         LifeUser user = findOrCreateUser(openid, parsedPhone);

+ 5 - 2
alien-dining/src/main/java/shop/alien/dining/service/impl/StoreInfoServiceImpl.java

@@ -105,8 +105,8 @@ public class StoreInfoServiceImpl implements StoreInfoService {
     }
 
     @Override
-    public List<CategoryWithCuisinesVO> getCategoriesWithCuisinesByStoreId(Integer storeId) {
-        log.info("根据门店ID查询菜品种类及下属菜品, storeId={}", storeId);
+    public List<CategoryWithCuisinesVO> getCategoriesWithCuisinesByStoreId(Integer storeId, String keyword) {
+        log.info("根据门店ID查询菜品种类及下属菜品, storeId={}, keyword={}", storeId, keyword);
         List<StoreCuisineCategory> categories = getCategoriesByStoreId(storeId);
         if (categories == null || categories.isEmpty()) {
             return new ArrayList<>();
@@ -119,11 +119,14 @@ public class StoreInfoServiceImpl implements StoreInfoService {
         if (allCuisines == null) {
             allCuisines = new ArrayList<>();
         }
+        boolean filterByName = StringUtils.isNotBlank(keyword);
+        String keywordLower = filterByName ? keyword.trim().toLowerCase() : null;
         List<CategoryWithCuisinesVO> result = new ArrayList<>();
         for (StoreCuisineCategory category : categories) {
             Integer categoryId = category.getId();
             List<StoreCuisine> cuisines = allCuisines.stream()
                     .filter(c -> belongsToCategory(c, categoryId))
+                    .filter(c -> !filterByName || (c.getName() != null && c.getName().toLowerCase().contains(keywordLower)))
                     .collect(Collectors.toList());
             result.add(new CategoryWithCuisinesVO(category, cuisines));
         }

+ 18 - 1
alien-dining/src/main/java/shop/alien/dining/service/impl/StoreOrderServiceImpl.java

@@ -1354,7 +1354,23 @@ public class StoreOrderServiceImpl extends ServiceImpl<StoreOrderMapper, StoreOr
         detailWrapper.orderByDesc(StoreOrderDetail::getCreatedTime);
         List<StoreOrderDetail> details = orderDetailMapper.selectList(detailWrapper);
         
-        // 转换为CartItemDTO
+        // 批量查询菜品标签(订单明细无 tags,从价目表取)
+        java.util.Set<Integer> cuisineIds = details.stream()
+                .map(StoreOrderDetail::getCuisineId)
+                .filter(java.util.Objects::nonNull)
+                .collect(Collectors.toSet());
+        java.util.Map<Integer, String> cuisineIdToTags = new java.util.HashMap<>();
+        if (!cuisineIds.isEmpty()) {
+            List<StoreCuisine> cuisines = storeCuisineMapper.selectBatchIds(cuisineIds);
+            if (cuisines != null) {
+                for (StoreCuisine c : cuisines) {
+                    cuisineIdToTags.put(c.getId(), c.getTags());
+                }
+            }
+        }
+        final java.util.Map<Integer, String> tagsMap = cuisineIdToTags;
+        
+        // 转换为CartItemDTO(含 tags)
         List<CartItemDTO> items = details.stream().map(detail -> {
             CartItemDTO item = new CartItemDTO();
             item.setCuisineId(detail.getCuisineId());
@@ -1367,6 +1383,7 @@ public class StoreOrderServiceImpl extends ServiceImpl<StoreOrderMapper, StoreOr
             item.setAddUserId(detail.getAddUserId());
             item.setAddUserPhone(detail.getAddUserPhone());
             item.setRemark(detail.getRemark());
+            item.setTags(detail.getCuisineId() != null ? tagsMap.get(detail.getCuisineId()) : null);
             return item;
         }).collect(Collectors.toList());
         

+ 3 - 0
alien-entity/src/main/java/shop/alien/entity/store/dto/CartItemDTO.java

@@ -48,4 +48,7 @@ public class CartItemDTO {
 
     @ApiModelProperty(value = "备注")
     private String remark;
+
+    @ApiModelProperty(value = "菜品标签(JSON数组,如:[\"招牌菜\",\"推荐\"])")
+    private String tags;
 }

+ 5 - 4
alien-store/src/main/java/shop/alien/store/controller/DiningServiceController.java

@@ -292,14 +292,15 @@ public class DiningServiceController {
         }
     }
 
-    @ApiOperation(value = "根据门店ID查询菜品种类及各类别下菜品", notes = "一次返回所有菜品种类及每个分类下的菜品列表")
+    @ApiOperation(value = "根据门店ID查询菜品种类及各类别下菜品", notes = "一次返回所有菜品种类及每个分类下的菜品列表;可选 keyword 按菜品名称模糊查询")
     @ApiOperationSupport(order = 11)
     @GetMapping("/store/info/categories-with-cuisines")
     public R<List<CategoryWithCuisinesVO>> getCategoriesWithCuisinesByStoreId(
-            @ApiParam(value = "门店ID", required = true) @RequestParam Integer storeId) {
+            @ApiParam(value = "门店ID", required = true) @RequestParam Integer storeId,
+            @ApiParam(value = "菜品名称模糊查询关键词(可选)") @RequestParam(required = false) String keyword) {
         try {
-            log.info("根据门店ID查询菜品种类及菜品: storeId={}", storeId);
-            return diningServiceFeign.getCategoriesWithCuisinesByStoreId(storeId);
+            log.info("根据门店ID查询菜品种类及菜品: storeId={}, keyword={}", storeId, keyword);
+            return diningServiceFeign.getCategoriesWithCuisinesByStoreId(storeId, keyword);
         } catch (Exception e) {
             log.error("查询菜品种类及菜品失败: {}", e.getMessage(), e);
             return R.fail("查询菜品种类及菜品失败: " + e.getMessage());

+ 4 - 2
alien-store/src/main/java/shop/alien/store/feign/DiningServiceFeign.java

@@ -227,14 +227,16 @@ public interface DiningServiceFeign {
             @RequestParam("storeId") Integer storeId);
 
     /**
-     * 根据门店ID查询菜品种类及各类别下菜品
+     * 根据门店ID查询菜品种类及各类别下菜品(可选按菜品名称模糊查询)
      *
      * @param storeId 门店ID
+     * @param keyword 菜品名称模糊查询关键词(可选)
      * @return R.data 为 List&lt;CategoryWithCuisinesVO&gt;
      */
     @GetMapping("/store/info/categories-with-cuisines")
     R<List<CategoryWithCuisinesVO>> getCategoriesWithCuisinesByStoreId(
-            @RequestParam("storeId") Integer storeId);
+            @RequestParam("storeId") Integer storeId,
+            @RequestParam(value = "keyword", required = false) String keyword);
 
     /**
      * 删除菜品种类(仅解除绑定+逻辑删分类,价目表菜品不变)