database model for products and product package with different combinations

偶尔善良 提交于 2019-12-06 07:19:35

问题


How would you design your database to achieve this functionality?

Consider a scenario where we want to create a product relation (package)...

Say that we create a ProductTbl

prod_id   prod_name    prod_fee
1         prepaid-A    19 usd
2         prepaid-B    29 usd
3         prepaid-C    39 usd
4         internet      9 usd
5         mms           1 usd
6         email         3 usd

We want to offer a product package that provides better fees for customer.

E.g. if customer choose prepaid-A + internet + mms they will have a pkg fee by 25 usd (instead of 29 usd).

DESIGN

  • A pkg with same combination should only exist once.
  • A pkg can have unlimited number of products, if possible. (Normally will be 2-4).

E.g. of a pkg combination

ProdPkgTbl

ppkg_id   prod_name    prod_fee
1         prepaid-A    25 usd
1         mms          25 usd
1         internet     25 usd

2         internet     10 usd
2         email        10 usd

3         prepaid-C    45 usd
3         internet     45 usd
3         mms          45 usd
3         email        45 usd

This means that combination

  • pkgid 1 -> prepaid-a, mms, and internet for a pkg fee of 25 usd
  • pkgid 2 -> internet and email together for a fee of 10 usd
  • pkgid 3 -> prepaid-c, internet, mms, email all together for 45 usd

So if a customer got prepaid-c + internet only they not get the deal for 45 usd, they will pay normal fee of 39 + 9 = 48 usd.

NOW THIS TABLES are just for demo, I would like to get your input and advice to model it in a right direction.

We will need first to select-query a customer current fee plan (based on used products/services) and after that look into the product pkg and see if pkg deal is valid for them or not.

(How to do such selection? on pkg table?) How to have a good db model for this?

Please advice with urls, hints, anything with value to push me into the right direction.

Great thanks.


回答1:


You are selling goods or services from a catalog. You can also sell combinations of the above. This is called a Marketing Package (or Bundle or Combo).

A marketing package is also sold from the catalog. It can be comprised of goods, services, or other marketing packages.

The price is really different per order. You could set a base price in the good table, a monthly price in the service table, and a base price in the marketing package table.




回答2:


I was hoping for some input regarding this but maybe the question is to "messy" to answer. :o)

My model right now is like this:

ProductTbl

prod_id   prod_name    prod_fee
1         prepaid-A    19 usd
2         prepaid-B    29 usd
3         prepaid-C    39 usd
4         internet      9 usd
5         mms           1 usd
6         email         3 usd

ProductPkgTbl

ppkg_id   prod_id      prod_name 
1         1            prepaid-A 
1         5            mms       
1         4            internet  

2         4            internet  
2         6            email     

3         3            prepaid-C 
3         4            internet  
3         5            mms       
3         6            email     

ProductPkgFeeTbl

ppkg_id   ppkig_fee
1         25
2         10
3         45

But there are some flaws in above, and it is that someone could insert same products in different pkg and with different fees.

I really can't figure out how to be sure that a pkg is unique, with sql. Well, of course a programming language / stored procedure / triggers etc can make the check ! But I want to have a design that is 100% flawless.

Please push me in the right direction with your experience in matters like this...



来源:https://stackoverflow.com/questions/14527203/database-model-for-products-and-product-package-with-different-combinations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!