SELECT
p.*,
MIN(wp.price * (1 + wpe.addition / 100) * (1 + IFNULL(wpc.addition, 0) / 100)) AS minimal_price,
COUNT(p.id) AS total_found
FROM products AS p
JOIN warehouses_products AS wp
ON p.id=wp.product_id
JOIN warehouses_permissions AS wpe
ON wpe.warehouse_id=wp.warehouse_id
LEFT JOIN warehouses_permissions_categories AS wpc
ON wpc.warehouse_permission_id=wpe.id
WHERE wpe.user_id=1 AND (wpc.id IS NULL OR wpc.category_id=p.category_id)
GROUP BY p.id
问题:如果要添加此功能,我应该如何修改我的数据库结构和查询:用户可以拥有“共享”仓库 - 仓库具有来自给定仓库权限的产品。
- 用户 [1]:仓库 [1] 和产品 --> 仓库 [1] 的权限 [1] 用户 [2] 的附加 [1]
- 用户[2]:能够看到仓库[1] 和添加[1] | 仓库 [2] “共享”来自权限 [1] -> 仓库 [2] 的权限 [2] 用于用户 [2] 宽度添加 [2]
- 用户[3]:能够看到仓库[2]宽度加法[1]*加法[2]
如果要共享共享仓库,则开始递归。
有任何想法吗?