将日期和费率存储在数据库中 [英] Store dates and rates in a Database

查看:614
本文介绍了将日期和费率存储在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这种情况的最佳做法是什么?



我正在建立一个预订系统,我正在寻找捕获和存储信息的最佳方法用户。每个资源都可以使用一天,并且可以最大限度地接收任意数量的用户。举例来说,这是一个最多5人的热气球。我希望我的表单看起来像这样:

  [按钮选择客人数量] //所以如果用户想要相同的价格为1-3人,他只需要输入一次。 

从[START DATE]到[END DATE]:[RATE] //其中[]是用户的输入字段

我计划将每个价格存储在数据库中:

 日期,客人数量,费率

每个日期都有一行。



所以我需要将[ [START DATE] 转换为 [END DATE] 来存储每个日期的值。我应该在Javascript中使用客户端,还是在使用rails的控制器中?如果一组客人(即1-3位客人)的价格相同,是否有办法将其存储在数据库中以便更好地查询?或者我应该不打扰,因为如果明天用户想要更改2位客人的价格,那可能会让我的分贝数字变差。

/ code>与每个日期 - 几个条件:


  1. 如果用户想要预订3天的热气球,那么每天是同一个热气球吗?还是可以改变?如果可以不同,请将 resources.type 字段映射到多个 booked_resources.id


  2. 如果您使用单独的开始结束

    ,则需要检查资源使用的重叠情况。 code>日期。使用 booked_resource.id 存储每日一次的重复记录将消除重叠检查的需要。请参阅此主题以获取相关问题:在MySQL中存储日历数据


  3. 在开始日期和结束日期之间的每一天,为客户端JS发送每天日期数组可能比为每天提取更简单。选择最符合您当前的代码。请记住,无论如何,必须修改SQL /日期检查以发现不可用性。

  4. 如果用户可以更改客人数量并影响成本,那么存储每个单独的日期对于那种数据库更新更为方便(就像酒店的逐项比较)。否则,您需要为具有不同客人数的日期分割记录。

    What is the best practice for this situation?

    I am building a reservation system, and I'm looking at the best way to capture and store information from a user. Each resource is available for one day and can take any amount of users up to the maximum. So for example, say it's a hot air balloon with a maximum of 5 people. I want my form to look like this:

    [Buttons to select # of guests]  // So if a user wants the same price for 1-3 people he only has to enter it once.
    
    From [START DATE] to [END DATE]: [RATE]  // Where the []'s are input fields for the user
    

    I plan to store each price in the database as:

    Date, # of guests, rate
    

    So one row for each date.

    So I need to convert "[START DATE] to [END DATE]" to storing the values for each date. Should I do that client side in Javascript, or in my controller in rails? If the rates are the same for a set of guests, i.e. 1-3 guests, is there a way I can store that in the DB for better querying? Or should I not bother because if tomorrow the user wants to change the price for 2 guests, it might screw up my db.

    解决方案

    Start date and End date vs. Each date - several conditions:

    1. If the user wants to book a hot air balloon for 3 days, is it the same hot air balloon every day or can it change? If it can be different, have a resources.type field mapped to several booked_resources.id.

    2. You need to check for overlaps of resource usage if you use separate start and end dates. Storing repeated records one-per-date with the booked_resource.id would remove the need for overlap checks. See this thread for a related question: Storing Calendar Data in MySQL

    3. Sending the client-side JS an array of dates for each day can be more easy than extracting for each day between start date and end date. Pick whichever conforms best to your current code. Remember that either way, the SQL/date checking has to be modified to spot for unavailability.

    4. If a user can change the number of guests and that affects cost, then storing each individual date is more convenient for db updates of that kind (like the itemized billng by Hotels). Otherwise you would need to 'split' records for the dates which have different # of guests.

    这篇关于将日期和费率存储在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆