简体   繁体   English

一年内处理开业时间的最佳方法PHP和MySQL

[英]Best way to handle business opening time in a year PHP and MySQL

We have developed a website for pharmacies in which we show the opened pharmacies in a specific city. 我们已经为药房开发了一个网站,其中显示了在特定城市开设的药房。

I handle this with a field named "timestamps" in wich it is stored all timestamps of opening hour every 15 minutes for a period of about 3 months. 我用一个名为“ timestamps”的字段来处理此问题,该字段每15分钟存储所有开放时间的时间戳,大约3个月。 For example if every days the farmacy is open from 8:00 to 19:00 there is a range of timestamps from one time to another, with an interval of 15 minutes. 例如,如果每天从8:00到19:00开放农场,则从一个时间到另一个时间会有一系列时间戳,间隔为15分钟。

While in the frontend we have a list of opened pharmacies and I could show opened ones by querying the database with for example: "WHERE timestamps LIKE('%1449820800%')" where the timestamp is the current time rounded to the nearest quarter hour. 在前端,我们有一个打开的药房列表,我可以通过查询数据库来显示已打开的药房,例如: "WHERE timestamps LIKE('%1449820800%')" ,其中时间戳记是当前时间,四舍五入到最近的四分之一小时。

The question is: considering the time ranges are different from week to week, is there a better way to handle this situation? 问题是:考虑到每个星期的时间范围不同,是否有更好的方法来处理这种情况? Also because we have 25.000 users and the website is slow if we have large amount of timestamps. 另外,因为我们有25.000个用户,并且如果我们有大量的时间戳记,则网站速度很慢。

Thank you in advance! 先感谢您!

You could just have a database with each day of openning for every store : 您可能只有一个数据库,每个商店的营业时间为:

-----------------------------------------
| StoreId  | Day | HourOpen | HourClose |
=========================================
|        1 |   1 | 8:30     | 21:15     |
-----------------------------------------
|        1 |   2 | 9:00     | 17:00     |
-----------------------------------------
|        2 |   1 | 10:00    | 12:30     |
-----------------------------------------
|        2 |   1 | 14:00    | 19:00     |
=========================================

In this table, the day represent the day of the week (1 for monday, 2 for tuesday for example) and then you just have to parameter the openniong hours for each store only once. 在此表中,日期代表星期几(例如1代表星期一,2代表星期二),然后您只需为每个商店设置一次开放时间即可。

You can then query this table to see if a store is open for a day of the week at the very moment. 然后,您可以查询该表以查看商店是否在一周中的这一天中的某一天营业。

If a pharmacy has an exceptionnal closure or openning hours for a day, i suggest an ovveride table like this one 如果某家药店一天有异常关闭或开放时间,我建议您使用像这样的ovveride桌子

----------------------------------------------------------
| StoreId  | Date        | isOpen | HourOpen | HourClose |
==========================================================
|        1 | 2015-12-20  |  true  | 10:00    | 16:00     |
----------------------------------------------------------
|        2 | 2015-12-20  | false  | null     | null      |
==========================================================

This way, you can check first if an pharmacy has any record in this table for the current day (not depending of the time) if it does, you check if there is an opening. 这样,您可以先检查药房当天在该表中是否有任何记录(不取决于时间),如果有,则检查是否有空缺。 If there is not any entry in the override table, you check with the first table. 如果替代表中没有任何条目,请检查第一个表。

You also can ahve a hour model table with opening and closing time, a day table, and an associative table that creates relations between stores, hours and days. 您还可以拥有带有打开和关闭时间的小时模型表,日表以及在商店,小时和天之间创建关系的关联表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM