创建定价矩阵 - sql 还是常量数组?

发布于 2024-09-13 17:49:40 字数 233 浏览 4 评论 0原文

我计划为 Rails 中的一个项目创建一个定价矩阵。它应该是一个目的地和出发地点的表格,价格取决于您来的地方和计划去的地方。

我还没有决定如何更好地做到这一点:要么在数据库中为此矩阵制作一个表,要么制作一个大型常量数组。问题是,客户端应该能够编辑这个矩阵,因此它最有可能走数据库路线。

无论如何,什么是一个好的模式呢?目的地id,出发地id,然后价格?目的地和出发 ID 将是包含所有可能位置的表的外键。有更好的方法吗?

I am planning to create a pricing matrix for a project in Rails. It's supposed to be a table of destinations and departure locations, and prices depending on where you came and are planning to go.

I am kinda undecided on how to better do this: either making a table in the db for this matrix, or making a mega array of constants. Problem is, the client should be able to edit this matrix so its most likely going the database route.

Anyhow, what's a good schema for this? Destination id, Departure id, then price? destination and departure ids will be foreign keys for a table containing all possible locations. Is there a better way of doing this?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

把回忆走一遍 2024-09-20 17:49:41

使其成为数据库表。

价格唯一不变的就是它们会变化。

补充:

定价(也称为产品保理)是我有很多经验的事情。

您的客户可能还会要求/或欣赏额外的定价工具来帮助他们把事情做好。例如,您的 sw:

  • 可以拥有以专为定价人员设计的方式显示价格的报告。
  • 报告最高、最低价格(以帮助发现数据输入错误)
  • 查看定量信息的视觉设计,了解如何直观地显示目的地对的价格的想法
  • 确保目的地/出发地对仅添加一次。 (另一个方向没有重复。)

您可能还需要担心定价的有效日期。即如何以协调的方式推出一套新的价格。

Make it a db table.

The only thing constant about prices is that they change.

Added:

Pricing (also called product factoring) is something that I have a lot of experience with.

Your clients may also ask/or appreciate added pricing tools to help them get things right. Eg, your sw:

  • could have reports that show the the prices in a manner that is designed for the people doing the pricing.
  • report on the highest, lowest prices (to help catch data entry errors)
  • Check out visual design of quantitative information for ideas on how to visually show the prices for the destination pairs
  • make sure that a destination/departure pair is only added exactly once. (No duplicates in the other direction.)
  • etc

You may also need to worry about effective dates for the pricing. Ie how to roll-out a new set of prices in a co-ordinated way.

万劫不复 2024-09-20 17:49:41

我将使用两个表:Location 和 TravelPrice。

Location
----------
LocationID --PK
Name

TravelPrice
-------------
TravelPriceID --PK
DepartureLocationID --FK to Location
DestinationLocationID --FK to Location
Price
StartDate --date the price is effective from
EndDate --date the price is effective to (or NULL)

这使您可以保留价格历史记录,这对于报告、计费等非常重要。理想情况下,您可以在 TravelPrice 表上触发,确保给定 DepartureLocationID 的日期没有间隙或重叠/DestinationLocationID 组合,并且该对中只有一个 EndDate 为 NULL 的记录。

I would use two tables, Location and TravelPrice.

Location
----------
LocationID --PK
Name

TravelPrice
-------------
TravelPriceID --PK
DepartureLocationID --FK to Location
DestinationLocationID --FK to Location
Price
StartDate --date the price is effective from
EndDate --date the price is effective to (or NULL)

This allows you to keep a price history, important for reporting, billing, etc. Ideally you would have trigger on the TravelPrice table ensuring that there are no gaps or overlaps in dates for a given DepartureLocationID/DestinationLocationID combination, and that there is only one record with a NULL EndDate for that pair.

四叶草在未来唯美盛开 2024-09-20 17:49:41

我会将其添加到 3 列表中,因为它不一定是矩阵 - 您可能不会从所有地方旅行到所有其他地方。您希望能够编辑它。完成硬编码版本后,系统会要求您对其进行编辑。

LeavingFrom, TravellingTo, Price

此外,随着目的地列表的增长,查询性能和代码维护将成为一个因素。

I would add this to a 3-column table because it's not necessarily a matrix - you might not travel from all places to all other places. You want to be able to edit it. As soon as you are done with your hard-coded version, you'll be asked to edit it.

LeavingFrom, TravellingTo, Price

Also, as the list of destinations grows, query performance and code maintenance will become a factor.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文