2012-03-29 70 views
0

上午试图安排不同类型的企业根据其业务小时如何根据营业时间设置业务?

要创建2个表
1.业务
2.营业时间(根据周日,周一,周二,周三,因此,周五,周六)

例如: 商家名称: “山姆沙龙”
营业时间:周一10 am-2pm,星期二11点至晚5,结婚1个pm-5pm,.....

PLZ建议一相对表结构,wh将每个业务点指向其营业时间。

回答

2

Basicly我会使用:

business_id - int (11) 
weekday - enum('sun','mon','tue','wed','thu','fri','sat') 
start_unix - int(11) 
end_unix - int(11) 

一天有86400秒。您可以简单地保存从一天开始的秒数。

为了获取某些当天的opentimes你会做这样的事情:

$str_week_day = strtolower(date('D')); 

SELECT start_unix, end_unix 
FROM business_hours 
WHERE business_id = {$int_business_id} AND weekday = '{$str_week_day}' 

然后拿到的时候,你会这么:一排

$str_start = date('Ha', strtotime('today') + $row->start_unix); 
$str_end = date('Ha', strtotime('today') + $row->end_unix); 

echo "{$str_start}-{$start_end}"; 

在输入/创建,你只需做:

// $_POST['start_unix'] could be 09:50am 
$int_start_unix = strtotime($_POST['start_unix']) - strtotime('today'); 
2

的关系模型将是如下:

Business Table 
--------------- 
id - Primary Key - Auto Increment 
Business Name 

Busines Hours Table 
------------------- 
id - Primary Key - Auto Increment 
Business id - Foreign Key (Business Table id field) 
WeekDay (either number 0-6 or text for day) 
Start Hour - datetime format 
End Hour - datetime format 

对于工作日数系统0将是星期日和6将是星期六。如果你愿意,也可以自定义。

这将允许您轻松地添加地址/电话等其他业务信息,而不需要一个商店的多行。