设计产品的数据结构

Design data structure for products

我需要设计包含产品数据的表结构以满足以下要求:

1. A product consists of the following fields: EAN, CN, description, pvp
2. There are several types of users that access the products. The user types are not stable, they can be added or deleted at any time.
3. Any of the fields of the products may vary depending on the type of user who views it. For example:

我们有三个用户:

1 - John - guest
2 - David - client
3 - Vicent - vip

默认情况下,我们有此产品的数据:

8470001234567 - 123456 - Iphone X - 9

来宾用户看不到此数据,而是看到以下内容:

8431239876547 - 987654 - Iphone X - 9

client用户默认看到数据,vip用户看到:

8470001234567 - 654321 - Iphone X Sale - 9

这意味着用户会看到给定产品的默认数据,除非其类型存在例外情况。异常可以影响任何字段(id 除外)。

我能想到这样的结构:

我验证了这个结构查询很多,你有没有想办法优化一下,这样就不用查询那么多了?

注意 1:产品包含在具有一定数量产品的报价中。 注2:我用的是Laravel。 Offer模型和products是有关系的,就是我是通过以下方式获取products的:$offer->products()

只看问题描述,我最终得到了这个,这等同于你用 Product_Exception:

提出的建议

推理:

  • 由于用户类型不同,您不能将值直接放在产品中table。前任。 3 种用户类型 == 3 种价格。不在这里。所以你需要一个 link table 在 Product 和 UserType 之间。
  • link table 将包含 1 个产品的特征,1 个用户类型。
  • 如果你想有一个默认值,你也可以把特性放在产品中table。但是随后您的查询变得更大!检查是否有异常值,如果没有则使用默认值。

所以你的解决方案对我来说很有意义。