获取在规定时间内配送的时间段
<?php
/**
* 预约上门服务时间
* User: john
* Date: 2015/7/10
* Time: 10:51
*/
class service_time extends Controller
{
function __construct($app)
{
parent::__construct($app);
}
function dispatch()
{
$config = array(
'09:00 - 12:00',
'12:00 - 15:00',
'15:00 - 18:00',
'18:00 - 21:00',
);
$day = 0;
$nowtime = date("H");
if($nowtime >= 18)
$day = 1;
$redata = array();
for($i=0;$i<=6;$i++){
//判断今天哪些时段不能被用户选择
$tmpConfig = $config;
if( $i==0 and $day == 0 ){
if( $nowtime >= 9 and $nowtime <12 ){
unset($tmpConfig[0]);
$items = array_values($tmpConfig);
}elseif( $nowtime >= 12 and $nowtime <15 ){
unset($tmpConfig[0]);
unset($tmpConfig[1]);
$items = array_values($tmpConfig);
}elseif( $nowtime >= 15 and $nowtime <18 ){
unset($tmpConfig[0]);
unset($tmpConfig[1]);
unset($tmpConfig[2]);
$items = array_values($tmpConfig);
}
}else{
$day += $i;
$items = $config;
}
$redata[] = array(
'time'=>date('m月d日',strtotime('+'. ($i+$day) .' day')),
'items'=> $items
);
}
return self::_return_json(2000,'ok',array('data'=>$redata));
}
}