【问题标题】:How to setup business according to its business-hour?如何根据营业时间设置业务?
【发布时间】:2012-03-29 07:26:30
【问题描述】:

我正在尝试根据营业时间安排不同类型的业务

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

示例: 商家名称:“山姆沙龙”
营业时间:周一 10am-2pm,周二 11am-5pm,周三 1pm-5pm,.....

请建议一个相对的表结构,其中每个业务都指向其营业时间。

【问题讨论】:

    标签: mysql phpmyadmin


    【解决方案1】:

    基本上我会使用:

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

    一天有 86 400 秒。您可以简单地保存从一天开始所经过的秒数。

    要获取特定日期的营业时间,您需要执行以下操作:

    $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 代表星期六。如果您愿意,也可以自定义。

      这将允许您轻松添加其他业务信息,例如地址/电话,而无需为一个商店设置多行。

      【讨论】:

        猜你喜欢
        • 2010-10-20
        • 1970-01-01
        • 1970-01-01
        • 2011-11-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-06-19
        • 1970-01-01
        相关资源
        最近更新 更多