后续:如何对数据库中的商品进行折扣建模?
我正在建立一个电子商务网站,并希望在有限的时间内为某些商品提供折扣。我想显示我们为每种产品提供多少折扣。因此,我需要每个产品有两个值:原始价格和给定持续时间内的折扣价格。
架构:
产品
- 产品ID
- 姓名
产品定价
- 产品 ID (FK)
- 开始日期时间戳
- 结束日期时间戳
- 价格
- 原价仅适用于我们使用方法 A(稍后提供)的情况
数据:
Product:
1 | Apple
2 | Banana
T1:2011 年 12 月 21 日:目前无交易
ProductPricing
1 | Dec 20, 2011, 00:00 | Jan 1, 2038, 00:00 | 10$ | 10$
2 | Dec 20, 2011, 00:00 | Jan 1, 2038, 00:00 | 20$ | 20$
T2:2011年12月24日:成交!从 12 月 25 日 14:00 至 12 月 26 日 14:00 对苹果应用 25% 的折扣
方法 A - 查询更新给定持续时间内的苹果价格
ProductPricing
1 | Dec 25, 2011, 14:00 | Dec 26, 2011, 14:00 | 7.5$| 10$
2 | Dec 20, 2011, 00:00 | Dec 25, 2038, 00:00 | 20$ | 20$
方法 B. - 查询添加另一条记录,其中包含给定持续时间的苹果价格
ProductPricing
1 | Dec 20, 2011, 00:00 | Jan 1, 2038, 00:00 | 10$ | 10$
2 | Dec 20, 2011, 00:00 | Dec 25, 2038, 00:00 | 20$ | 20$
1 | Dec 25, 2011, 14:00 | Dec 26, 2011, 14:00 | 7.5$| 10$
T3:2011 年 12 月 27 日 - 选项
方法 A。 此时,交易已过期,我是否应该使用触发器重置 endTimeStamp ?
方法B。 我是否应该删除交易刚刚过期的产品的最新记录?
I am building an ecommerce site and would like to offer discounts on certain items for a limited time. I would like to display how much discount we are offering per product. Hence, I need two values per product, original price and the discounted price for the given duration.
This is in followup to an answer for the question I asked
Schema:
Product
- productId
- Name
ProductPricing
- productId (FK)
- startDateTimeStamp
- endDateTimeStamp
- price
- original price only applicable if we use approach A (comes later on)
Data:
Product:
1 | Apple
2 | Banana
T1: Dec 21, 2011: No deals at this time
ProductPricing
1 | Dec 20, 2011, 00:00 | Jan 1, 2038, 00:00 | 10$ | 10$
2 | Dec 20, 2011, 00:00 | Jan 1, 2038, 00:00 | 20$ | 20$
T2: Dec 24, 2011: Deal! Apply discount of 25% on apples from Dec 25, 14:00 - Dec 26, 14:00
Approach A.
- Query updates apple prices for the given duration
ProductPricing
1 | Dec 25, 2011, 14:00 | Dec 26, 2011, 14:00 | 7.5$| 10$
2 | Dec 20, 2011, 00:00 | Dec 25, 2038, 00:00 | 20$ | 20$
Approach B.
- Query adds another record with apple prices for the given duration
ProductPricing
1 | Dec 20, 2011, 00:00 | Jan 1, 2038, 00:00 | 10$ | 10$
2 | Dec 20, 2011, 00:00 | Dec 25, 2038, 00:00 | 20$ | 20$
1 | Dec 25, 2011, 14:00 | Dec 26, 2011, 14:00 | 7.5$| 10$
T3: Dec 27, 2011 - Options
Approach A.
At this time, the deal is expired, should I reset the endTimeStamp using a trigger ?
Approach B.
Should I delete the most recent record for the product for which the deal just expired ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ProductPricing
表的设计使我们永远不必删除旧的定价数据(有时管理层需要基于该数据的报告)。根据您上面的描述,您可以像这样开始(我更改了开始日期,这样很容易看出,是的,这是系统到位时的原始价格):现在假设您给出折扣价在您的苹果上,您希望积极主动地设置销售结束时的系统:
我们在这里所做的是:
endDateTimeStamp
字段以反映的开始sale由于没有重叠的时间戳,因此当您在数据库中查询价格时,您一定会得到一条记录。因此,
将为您提供包含当前定价的产品列表。
The design of the
ProductPricing
table allows us to never have to delete old pricing data (sometimes management wants a report based on that data). With what you have described above, you'd start like this (I changed the starting date just so it's easy to pick out that yes, this was the original price when the system went into place):Now let's say you give a discount price on your apples, and you wanted to be proactive and set up the system for when the sale was over:
What we did here was:
endDateTimeStamp
field to reflect the beginning of the saleWith no overlapping timestamps, you're guaranteed to get a single record when you query the database for your price. Thus,
would get you a product list with current pricing.