|
|
@@ -16,10 +16,12 @@ import com.etotem.cfc.entity.Product;
|
|
|
import com.etotem.cfc.entity.ProductBundleItem;
|
|
|
import com.etotem.cfc.entity.ProductGiftRule;
|
|
|
import com.etotem.cfc.entity.ProductSku;
|
|
|
+import com.etotem.cfc.entity.SupplySystemMember;
|
|
|
import com.etotem.cfc.entity.User;
|
|
|
import com.etotem.cfc.mapper.ProductBundleItemMapper;
|
|
|
import com.etotem.cfc.mapper.ProductMapper;
|
|
|
import com.etotem.cfc.mapper.ProductSkuMapper;
|
|
|
+import com.etotem.cfc.mapper.SupplySystemMemberMapper;
|
|
|
import com.etotem.cfc.mapper.UserMapper;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
@@ -44,6 +46,9 @@ public class ProductService {
|
|
|
@Resource
|
|
|
private UserMapper userMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private SupplySystemMemberMapper supplySystemMemberMapper;
|
|
|
+
|
|
|
@Resource
|
|
|
private MembershipService membershipService;
|
|
|
|
|
|
@@ -173,11 +178,25 @@ wrapper.in(Product::getId, productIds)
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
- // 供应商可见过滤:仅对非供应商体系用户生效,供应商体系内用户可查看全部商品
|
|
|
- boolean isVendor = isVendorUser(userId, role);
|
|
|
- if (!isVendor && !isGuest(userId)) {
|
|
|
- // 非供应商用户:只展示 vendorVisible=false 或 NULL 的商品
|
|
|
- wrapper.and(w -> w.isNull(Product::getVendorVisible).or().eq(Product::getVendorVisible, false));
|
|
|
+ // 供应商可见过滤:vendorVisible=true 的商品仅同体系用户可见
|
|
|
+ // 同体系判定:用户在 supply_system_member 中有记录,且该产品的 distributionSystemId 在用户所属体系中
|
|
|
+ // teacher(规划师)和 admin 作为平台角色始终可见所有商品;游客(未登录)只可见公开商品
|
|
|
+ boolean isPlatform = ("teacher".equals(role) || "admin".equals(role));
|
|
|
+ if (!isPlatform) {
|
|
|
+ // 获取当前用户所属的供应商体系 ID 列表(游客返回空列表)
|
|
|
+ List<Long> mySystemIds = getMySupplySystemIds(userId);
|
|
|
+ if (!mySystemIds.isEmpty()) {
|
|
|
+ // 已加入供应商体系的用户:可见 vendorVisible=false/NULL 的商品,以及自身体系内的 vendorVisible=true 商品
|
|
|
+ wrapper.and(w -> {
|
|
|
+ w.isNull(Product::getVendorVisible)
|
|
|
+ .or().eq(Product::getVendorVisible, false)
|
|
|
+ .or(w2 -> w2.eq(Product::getVendorVisible, true)
|
|
|
+ .in(Product::getDistributionSystemId, mySystemIds));
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ // 游客或未加入任何供应商体系:只展示公开商品
|
|
|
+ wrapper.and(w -> w.isNull(Product::getVendorVisible).or().eq(Product::getVendorVisible, false));
|
|
|
+ }
|
|
|
}
|
|
|
if (query.getProductType() != null && !query.getProductType().isEmpty()) {
|
|
|
wrapper.eq(Product::getProductType, query.getProductType());
|
|
|
@@ -595,6 +614,19 @@ wrapper.in(Product::getId, productIds)
|
|
|
return userId == null;
|
|
|
}
|
|
|
|
|
|
+ /** 获取当前用户所属的供应商体系 ID 列表 */
|
|
|
+ private List<Long> getMySupplySystemIds(Long userId) {
|
|
|
+ if (userId == null) return new ArrayList<>();
|
|
|
+ return supplySystemMemberMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<SupplySystemMember>()
|
|
|
+ .eq(SupplySystemMember::getUserId, userId)
|
|
|
+ .eq(SupplySystemMember::getStatus, "active"))
|
|
|
+ .stream()
|
|
|
+ .map(SupplySystemMember::getSystemId)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
/** 判断用户是否为供应商体系内用户(审核通过的服务商或 teacher 角色) */
|
|
|
private boolean isVendorUser(Long userId, String role) {
|
|
|
if (userId == null) return false;
|