美文网首页
使用mobile_select_area插件,(修改数据源为时间

使用mobile_select_area插件,(修改数据源为时间

作者: 笑看滔滔潮 | 来源:发表于2017-01-17 16:32 被阅读0次

    格式也是如下,产生固定的json

    public function test4(){

    //配送时间

    $delivery_widget = array();

    $a_time = time() < strtotime('2016-02-16') ? strtotime('2016-02-16') : time();

    $that_day = date('Y-m-d', time());

    //$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');

    //今天日期

    $today = strtotime(date('Y-m-d', $delivery_start)) <= strtotime('2017-1-18 23:59:59')?strtotime('2017-1-19'):strtotime(date('Y-m-d', $delivery_start));

    //echo $today;//1484618400

    $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(date('Y-m-d', $delivery_start)) >= strtotime('2017-1-18 23:59:59')){

    //当前时间早于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

    );

    }

    }else{

    $delivery_widget[] = array(

    'id' => $today,

    'name' => date('n.d', $today ),

    'child' => $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

    );

    print_r($delivery_widget);

    }

    相关文章

      网友评论

          本文标题:使用mobile_select_area插件,(修改数据源为时间

          本文链接:https://www.haomeiwen.com/subject/qigmbttx.html