0

我想要完成的事情是我们每周二和周四发货,我想限制如果订单是在周一下午 5 点之后下达,那么他们必须等到周五。如果在星期四下午 5 点之后的订单,他们必须等到星期二。

function freeDelivery($date){
    $holidays = array("05/30/2012","07/04/2012","09/05/2012","11/24/2012","11/25/2012","12/25/2012","12/31/2012","01/01/2013","05/28/2013","07/04/2013","09/03/2013","11/22/2013","11/23/2013","12/25/2013");
    $checkday = strtotime($date);
    // check if it's a holiday
    while(in_array(date("m/d/Y",$checkday), $holidays)) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +1 day");
    }

    //sun
    if (date("w",$checkday) == 0) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +2 day");
    }
    //mon
    elseif (date("w",$checkday) == 1) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +1 days");
    }
    //tue
    elseif(date("w",$checkday) == 2) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +2 days");
    }
    //wen
    elseif (date("w",$checkday) == 3) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +1 days");
    }
    //thur
    elseif (date("w",$checkday) == 4) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +5 days");
    }
    //fri
    elseif (date("w",$checkday) == 5) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +4 days");
    }
    //sat
    elseif (date("w",$checkday) == 6) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +3 days");
    }

    // make sure it's not another holiday
    while(in_array(date("m/d/Y",$checkday), $holidays)) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +1 day");
    }
    return $checkday;
}

上面的代码用于根据一周中的日期确定发货日期。

谢谢您的任何帮助,非常感谢。

4

1 回答 1

3

假设您的意思是在星期一 5p 之后是Thursday,然后在星期三5p 之后您的意思是星期二...尝试以下操作:

编辑 最简单的方法是将您的代码添加回函数中。

function freeDelivery($date){
    $holidays = array("05/30/2012","07/04/2012","09/05/2012","11/24/2012","11/25/2012","12/25/2012","12/31/2012","01/01/2013","05/28/2013","07/04/2013","09/03/2013","11/22/2013","11/23/2013","12/25/2013");
    $checkday = strtotime($date);
    // check if it's a holiday
    while(in_array(date("m/d/Y",$checkday), $holidays)) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +1 day");
    }

    $thedate = date("m/d/Y",$checkday);
    $dayofweek = date("w",$checkday);
    $dayincrease = array(0 => 2, 1 => 1, 2 => 2, 3 => 1, 4 => 5, 5 => 4, 6 => 3);
    $after5 = (date("G",$checkday) >= 17);

    $increase = "";
    if($after5 && $dayofweek == 1) {
        // monday after 5p = thurs
        $increase = "+3 days";
    } elseif($after5 && $dayofweek == 3) {
        // wednesday after 5p = tues
        $increase = "+6 days";
    } else {
        $increase = "+" . $dayincrease[$dayofweek] . " days";
    }
    $checkday = strtotime($thedate." ".$increase);

    // make sure it's not another holiday
    while(in_array(date("m/d/Y",$checkday), $holidays)) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +1 day");
    }
    return $checkday;
}
于 2012-05-09T20:27:19.080 回答