DB Design允许用户定义产品、产品规格并让自己插入订单

发布于 2024-12-22 13:36:17 字数 845 浏览 0 评论 0原文

我正在设计一个数据库,因为我需要开发这样的 CRM,用户可以在其中指定新产品、产品规格和定价,然后让自己为上一步中指定的产品插入订单。当然,插入的数据需要根据它们在数据库中指定的内容进行评估。

我举个例子可能会更清楚:user1 创建一个产品“apple”,然后指定“颜色”和“重量”作为该产品的属性规格。然后user1说苹果定价是根据颜色和重量。 “黄”苹果的价格为 1 美元/重量单位,“红”苹果的价格为 2 美元/重量单位。

它还创建了一个具有“年份”、“型号”、“颜色”、“品牌”规格的产品“汽车”。这里还指定了价格组合。 最后,他创建了具有“尺寸”规格的产品“衬衫”,但每个尺寸的价格都是标准的。

处理此类数据的良好起点是什么? 我正在考虑创建一个表products(id,name,pricing_type)(pricing_type给出了它是固定定价还是根据某些字段的可变定价的想法)。 然后 productSpecsName (id, relatedProduct FK products (id), name)productSpecsValue (id, relatedSpecsName FK ProductSpecsName(id), value, conversion) (转换告诉我如何在代码中使用该数据 - 例如将其转换为整数、浮点数或布尔值,因为值始终是字符串)。

但是这个设计并没有给我带来我需要的灵活性,你能帮助我获得更好的设计吗?这是一个电子商务,但我想为用户提供创建自定义类型的机会。 我带来的第一个,可能也是最简单的设计是为每个产品创建一个表(每次用户需要添加产品时,我都会创建一个新表)或创建一个包含所有可能选项的大型表并将它们保留为空,但我会选择更灵活的选择。 等待更好的想法/建议。

I'm designing a db because I need to develop such a CRM, where the users are able to specify new products, products specs and pricing and then let themself to insert orders for that products specified in a previous step. Of course the data inserted needs to be evaluated according to what they specified in the db.

I may be more clear with an example: user1 creates a product "apple", specifies then "color" and "weight" as attribute specs for that product. Then user1 says that the apple pricing is based on the color and the weight. The apple "yellow" has a price of 1$/weight unit, the "red" apple has a price of 2$/weight unit.

It also creates a product "car" with specs "year", "model", "color", "brand". And also here it specifies prices combinations.
Finally he creates the product "shirts" with spec "size" but where the price is standard for each size

What's a good starting point to handle this kind of data?
I was thinking to create a table products (id, name, pricing_type) (pricing_type gives an idea if it's a fixed pricing or a variable pricing according to some field).
Then productSpecsName (id, relatedProduct FK products (id), name) and productSpecsValue (id, relatedSpecsName FK productSpecsName(id), value, conversion) (conversion tell me how to use that data in the code -such as transform it as integer, float or boolean, because value is always a string).

But this design doesn't give me as much flexibility as I need, can you help me getting a better design? It's such an ecommerce but I would like to give the user the opportunity to create custom types.
The first, and probably simplest design I came with is to create a table per product (each time the user needs to add a product I create a new table) or create a mega-table with all possible options and leave them nullable, but I would go with a more flexible option.
Waiting for better ideas/suggestions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文