//配送时间
$delivery_widget = array();
$t = time();
$a_time = $t;
$that_day = date('Y-m-d',$t);
//$a_time = strtotime($that_day . ' 13:30');
$delivery_start = strtotime($that_day . ' 10:00');
$delivery_end = strtotime($that_day . ' 21:00');
$work_start = strtotime($that_day . ' 9:00');
$work_end = strtotime($that_day . ' 20:00');
//开始配送时间
$start_today = strtotime('2017-2-4');
$today = strtotime(date('Y-m-d', $delivery_start));
//停止配送开始时间
$stop_start = strtotime('2017-1-25');
//停止配送结束时间
$stop_end = strtotime('2017-2-3');
$show_times = array();
for ($i = 22; $i <= 42; $i++) {
$show_times[] = array(
'id' => $i,
'name' => ($i%2 == 0) ? intval($i/2) . ':00' : intval($i/2) . ':30'
);
}
//今天日期
if(strtotime($that_day) >= $stop_start && strtotime($that_day) <= $stop_end){
$delivery_widget[] = array(
'id' => $start_today,
'name' => date('n.d', $start_today),
'child' => $show_times
);
$delivery_widget[] = array(
'id' => $start_today + 3600 * 24 ,
'name' => date('n.d', $start_today + 3600 * 24),
'child' => $show_times
);
$delivery_widget[] = array(
'id' => $start_today + 3600 * 24 * 2,
'name' => date('n.d', $start_today + 3600 * 24 * 2),
'child' => $show_times
);
}elseif(strtotime($that_day) < $stop_start){
//当前时间早于9点
if ($a_time < $work_start) {
$delivery_widget[] = array(
'id' => $today,
'name' => '今天',
'child' => $show_times
);
} elseif ($a_time >= $work_start && $a_time <= $delivery_start) {
$start_i = date('i', $a_time)/60 < 0.5 ? date('H', $a_time) * 2 : date('H', $a_time) * 2 + 1;
$start_i += 4;
for ($i = $start_i; $i <= 42; $i++) {
$cur_show_times[] = array(
'id' => $i,
'name' => ($i%2 == 0) ? intval($i/2) . ':00' : intval($i/2) . ':30'
);
}
$delivery_widget[] = array(
'id' => $today,
'name' => '今天',
'child' => $cur_show_times
);
} elseif ($a_time >= $delivery_start && $a_time < $work_end) {
//当前时间于10点和20点之间
//出现立即配送
$start_i = date('i', $a_time)/60 < 0.5 ? date('H', $a_time) * 2 : date('H', $a_time) * 2 + 1;
$start_i += 4;
$cur_show_times = array(
0 => array(
'id' => 0,
'name' => '立即配送'
)
);
for ($i = $start_i; $i <= 42; $i++) {
$cur_show_times[] = array(
'id' => $i,
'name' => ($i%2 == 0) ? intval($i/2) . ':00' : intval($i/2) . ':30'
);
}
$delivery_widget[] = array(
'id' => $today,
'name' => '今天',
'child' => $cur_show_times
);
}
if( $today + 3600 * 24 *2 < $stop_start){
$delivery_widget[] = array(
'id' => $today + 3600 * 24,
'name' => date('n.d', $today + 3600 * 24),
'child' => $show_times
);
$delivery_widget[] = array(
'id' => $today + 3600 * 24 * 2,
'name' => date('n.d', $today + 3600 * 24 * 2),
'child' => $show_times
);
}elseif($today + 3600 * 24 < $stop_start && $today + 3600 * 24 *2 >= $stop_start){
$delivery_widget[] = array(
'id' => $today + 3600 * 24 ,
'name' => date('n.d', $today + 3600 * 24),
'child' => $show_times
);
$delivery_widget[] = array(
'id' => $start_today,
'name' => date('n.d', $start_today),
'child' => $show_times
);
}elseif($today + 3600 * 24 >= $stop_start){
$delivery_widget[] = array(
'id' => $start_today,
'name' => date('n.d', $start_today),
'child' => $show_times
);
$delivery_widget[] = array(
'id' => $start_today + 3600 * 24 ,
'name' => date('n.d', $start_today + 3600 * 24 ),
'child' => $show_times
);
}
}elseif(strtotime($that_day) > $stop_end){
//当前时间早于9点
if ($a_time < $work_start) {
$delivery_widget[] = array(
'id' => $today,
'name' => '今天',
'child' => $show_times
);
} elseif ($a_time >= $work_start && $a_time <= $delivery_start) {
$start_i = date('i', $a_time)/60 < 0.5 ? date('H', $a_time) * 2 : date('H', $a_time) * 2 + 1;
$start_i += 4;
for ($i = $start_i; $i <= 42; $i++) {
$cur_show_times[] = array(
'id' => $i,
'name' => ($i%2 == 0) ? intval($i/2) . ':00' : intval($i/2) . ':30'
);
}
$delivery_widget[] = array(
'id' => $today,
'name' => '今天',
'child' => $cur_show_times
);
} elseif ($a_time >= $delivery_start && $a_time < $work_end) {
//当前时间于10点和19点之间
//出现立即配送
$start_i = date('i', $a_time)/60 < 0.5 ? date('H', $a_time) * 2 : date('H', $a_time) * 2 + 1;
$start_i += 4;
$cur_show_times = array(
0 => array(
'id' => 0,
'name' => '立即配送'
)
);
for ($i = $start_i; $i <= 42; $i++) {
$cur_show_times[] = array(
'id' => $i,
'name' => ($i%2 == 0) ? intval($i/2) . ':00' : intval($i/2) . ':30'
);
}
$delivery_widget[] = array(
'id' => $today,
'name' => '今天',
'child' => $cur_show_times
);
}
$delivery_widget[] = array(
'id' => $today + 3600 * 24,
'name' => date('n.d', $today + 3600 * 24),
'child' => $show_times
);
$delivery_widget[] = array(
'id' => $today + 3600 * 24 * 2,
'name' => date('n.d', $today + 3600 * 24 * 2),
'child' => $show_times
);
};
//echo $today; //1484618400
print_r($delivery_widget);
}