修复:对齐作品和购物车美甲师可用性

This commit is contained in:
xiaowang
2026-03-27 11:51:43 +08:00
parent b1fc6c3b79
commit d2c693e6a1
6 changed files with 172 additions and 17 deletions
+2
View File
@@ -14,6 +14,8 @@ export interface ProductVO {
estimatedTime: number
approximateDuration?: string
bookableArtists?: string
availableBookableArtistCount?: number
bookableArtistRestricted?: boolean
availableCoupons?: string
category: string
tags?: string
+9 -1
View File
@@ -163,13 +163,21 @@ const loadError = ref('')
const isLoggedIn = computed(() => Boolean(localStorage.getItem('accessToken') || sessionStorage.getItem('accessToken')))
const artistCount = computed(() => {
if (typeof product.value.availableBookableArtistCount === 'number') {
return product.value.availableBookableArtistCount
}
const rawValue = product.value.bookableArtists || ''
return rawValue
.split(',')
.map(id => Number(id.trim()))
.filter(id => Number.isFinite(id) && id > 0).length
})
const artistCountText = computed(() => (artistCount.value > 0 ? `${artistCount.value} 位` : '门店安排'))
const artistCountText = computed(() => {
if (artistCount.value > 0) {
return `${artistCount.value} 位`
}
return product.value.bookableArtistRestricted ? '暂无' : '门店安排'
})
const earliestBookableText = computed(() => estimateEarliestBookable(shopInfo.value?.businessHours))
const parseTimeRange = (businessHours?: string): { start: string; end: string } | null => {
@@ -9,16 +9,14 @@ import com.xiaowang.yuminailcore.entity.CouponDO;
import com.xiaowang.yuminailcore.entity.ProductDO;
import com.xiaowang.yuminailcore.entity.ShopDO;
import com.xiaowang.yuminailcore.entity.TagDO;
import com.xiaowang.yuminailcore.entity.UserDO;
import com.xiaowang.yuminailcore.mapper.CouponMapper;
import com.xiaowang.yuminailcore.mapper.ProductMapper;
import com.xiaowang.yuminailcore.mapper.ShopMapper;
import com.xiaowang.yuminailcore.mapper.TagMapper;
import com.xiaowang.yuminailcore.mapper.UserMapper;
import com.xiaowang.yuminailcore.service.ObjectStorageFileService;
import com.xiaowang.yuminailcore.service.ProductService;
import com.xiaowang.yuminailcore.service.TagService;
import com.xiaowang.yuminailcore.support.UserShopBindingSupport;
import com.xiaowang.yuminailcore.support.BookableArtistSupport;
import com.xiaowang.yuminailcore.vo.ObjectStorageFileVO;
import com.xiaowang.yuminailcore.vo.PageResultVO;
import com.xiaowang.yuminailcore.vo.ProductVO;
@@ -48,11 +46,10 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
private final ProductMapper productMapper;
private final TagService tagService;
private final ObjectStorageFileService objectStorageFileService;
private final UserMapper userMapper;
private final CouponMapper couponMapper;
private final ShopMapper shopMapper;
private final TagMapper tagMapper;
private final UserShopBindingSupport userShopBindingSupport;
private final BookableArtistSupport bookableArtistSupport;
@Override
public Long createProduct(ProductDTO productDTO) {
@@ -66,7 +63,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
productDO.setPrice(productDTO.getPrice());
productDO.setTags(productDTO.getTags());
productDO.setApproximateDuration(productDTO.getApproximateDuration());
productDO.setBookableArtists(productDTO.getBookableArtists());
productDO.setBookableArtists(bookableArtistSupport.filterValidBookableArtists(productDTO.getShopId(), productDTO.getBookableArtists()));
productDO.setAvailableCoupons(productDTO.getAvailableCoupons());
productDO.setIsDelete(0);
productMapper.insert(productDO);
@@ -88,7 +85,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
productDO.setPrice(productDTO.getPrice());
productDO.setTags(productDTO.getTags());
productDO.setApproximateDuration(productDTO.getApproximateDuration());
productDO.setBookableArtists(productDTO.getBookableArtists());
productDO.setBookableArtists(bookableArtistSupport.filterValidBookableArtists(productDTO.getShopId(), productDTO.getBookableArtists()));
productDO.setAvailableCoupons(productDTO.getAvailableCoupons());
return productMapper.updateById(productDO) > 0;
}
@@ -189,7 +186,10 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
productVO.setLikeCount(productDO.getLikeCount());
productVO.setCollectCount(productDO.getCollectCount());
productVO.setApproximateDuration(productDO.getApproximateDuration());
String validBookableArtists = bookableArtistSupport.filterValidBookableArtists(productDO.getShopId(), productDO.getBookableArtists());
productVO.setBookableArtists(productDO.getBookableArtists());
productVO.setAvailableBookableArtistCount(countBookableArtists(validBookableArtists));
productVO.setBookableArtistRestricted(StringUtils.hasText(productDO.getBookableArtists()));
productVO.setAvailableCoupons(productDO.getAvailableCoupons());
productVO.setCreateTime(productDO.getCreateTime());
productVO.setUpdateTime(productDO.getUpdateTime());
@@ -290,15 +290,8 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
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 (!userShopBindingSupport.isUserAccessibleInShop(artistId, shopId)) {
throw new RuntimeException("不可跨店铺配置可预约美甲师");
if (!bookableArtistSupport.isValidBookableArtist(shopId, artistId)) {
throw new RuntimeException("存在无效、已停用或不属于当前店铺的美甲师配置");
}
}
}
@@ -345,6 +338,16 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
return shopDO == null ? null : shopDO.getShopName();
}
private int countBookableArtists(String bookableArtists) {
if (!StringUtils.hasText(bookableArtists)) {
return 0;
}
return (int) java.util.Arrays.stream(bookableArtists.split(","))
.map(String::trim)
.filter(StringUtils::hasText)
.count();
}
private boolean containsAnyTagId(String tags, Set<String> targetTagIds) {
if (!StringUtils.hasText(tags) || targetTagIds == null || targetTagIds.isEmpty()) {
return false;
@@ -0,0 +1,62 @@
package com.xiaowang.yuminailcore.support;
import com.xiaowang.yuminailcore.entity.UserDO;
import com.xiaowang.yuminailcore.mapper.UserMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.stream.Collectors;
@Component
@RequiredArgsConstructor
public class BookableArtistSupport {
private final UserMapper userMapper;
private final UserShopBindingSupport userShopBindingSupport;
public boolean isValidBookableArtist(Long shopId, Long artistId) {
if (artistId == null || artistId <= 0) {
return false;
}
UserDO artist = userMapper.selectById(artistId);
if (artist == null || Integer.valueOf(1).equals(artist.getIsDelete())) {
return false;
}
if (!Integer.valueOf(3).equals(artist.getType())) {
return false;
}
if (!Integer.valueOf(1).equals(artist.getStatus())) {
return false;
}
return shopId == null || shopId <= 0 || userShopBindingSupport.isUserAccessibleInShop(artistId, shopId);
}
public String filterValidBookableArtists(Long shopId, String rawBookableArtists) {
if (!StringUtils.hasText(rawBookableArtists)) {
return "";
}
Set<Long> validArtistIds = new LinkedHashSet<>();
for (String artistIdText : rawBookableArtists.split(",")) {
if (!StringUtils.hasText(artistIdText)) {
continue;
}
try {
Long artistId = Long.parseLong(artistIdText.trim());
if (isValidBookableArtist(shopId, artistId)) {
validArtistIds.add(artistId);
}
} catch (NumberFormatException ignored) {
// Ignore invalid configured IDs and only expose currently valid artists.
}
}
return validArtistIds.stream()
.map(String::valueOf)
.collect(Collectors.joining(","));
}
}
@@ -92,6 +92,16 @@ public class ProductVO {
*/
private String bookableArtists;
/**
* 当前仍可预约的美甲师数量
*/
private Integer availableBookableArtistCount;
/**
* 商品是否配置了限定美甲师
*/
private Boolean bookableArtistRestricted;
/**
* 可用的优惠券ID集合,多个ID以逗号分隔
*/
@@ -0,0 +1,70 @@
# 2026-03-27 商品详情与购物车美甲师可约口径对齐
## 问题现象
- 商品详情页显示“有 1 位美甲师可以预约”
- 同一商品加入购物车后,点击选择美甲师却显示“暂无可预约美甲师”
## 根因分析
- 商品详情页原先直接按 `bookableArtists` 字段里配置的 ID 数量显示“可约美甲师”数量。
- 购物车选择美甲师时,并不会直接信任这个数量,而是会进一步校验这些 ID 对应的账号当前是否仍然满足:
- 用户未删除
- 用户类型仍为美甲师
- 账号状态为启用
- 仍绑定在当前商品所属店铺
- 当某个商品历史上配置过的美甲师,后来被停用、降级、解绑店铺后,`bookableArtists` 原始配置里仍然可能残留这个 ID。
- 于是就出现:
- 详情页数“原始配置”,看起来还有 1 位
- 购物车数“当前有效人员”,结果变成 0 位
## 本轮修复
### 1. 新增统一的有效美甲师校验支持
- 新增 [`BookableArtistSupport.java`](/E:/code/xiaowang/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/support/BookableArtistSupport.java)
- 统一判断“当前是否仍是可预约美甲师”:
- 必须存在
- 不能已删除
- 必须仍是 `type = 3`
- 必须是启用状态
- 必须仍绑定在当前店铺
### 2. 商品详情页改为显示“当前有效可约人数”
- 更新 [`ProductVO.java`](/E:/code/xiaowang/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/vo/ProductVO.java)
- 新增返回字段:
- `availableBookableArtistCount`
- `bookableArtistRestricted`
- 更新 [`ProductServiceImpl.java`](/E:/code/xiaowang/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/service/impl/ProductServiceImpl.java)
- 商品详情返回时:
- 仍保留原始 `bookableArtists` 配置语义
- 额外计算当前真正有效的可预约人数
### 3. 前端详情页提示口径修正
- 更新 [`product.ts`](/E:/code/xiaowang/Frontend/src/api/product.ts)
- 更新 [`ProductDetailView.vue`](/E:/code/xiaowang/Frontend/src/views/ProductDetailView.vue)
- 现在显示规则为:
- 有效人数 `> 0`:显示 `X 位`
- 商品配置了限定美甲师,但当前有效人数为 `0`:显示 `暂无`
- 商品本身没有限定美甲师:显示 `门店安排`
### 4. 商品保存时同步拦截失效美甲师配置
- 更新 [`ProductServiceImpl.java`](/E:/code/xiaowang/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/service/impl/ProductServiceImpl.java)
- 后台新建/编辑商品时,如果勾选的美甲师已经停用、降级或解绑店铺,会直接校验失败,避免继续写入脏配置。
## 影响说明
- 这次修复后,商品详情页不会再把“历史残留但已失效”的美甲师算进可预约人数。
- 购物车原有的预约限制语义保持不变,不会因为这次修复把“限定指定美甲师”误放宽成“任意门店美甲师都可选”。
## SQL 说明
- 本轮无 SQL 变动。
## 验证
- 后端执行 `mvn -q -DskipTests compile` 通过。
- 前端执行 `npm run build` 通过。