0

我有一个我想添加的食品订购脚本 如果交货时间在晚上 8:00:00 到早上 7:59:59 之间,则要添加 5 美元的额外费用,如果是在早上 8:00:00 到早上 7:59 之间:下午 59 点按脚本保持交付。

这是我计算运费的代码,它返回我们已经在仪表板中设置的运费。

我们希望将此添加为解决方案,以便为我们的夜间送货增加费用。

日间配送 = 正常配送费 夜间配送 = 正常配送费 + 5

谢谢你,我希望有人可以指导我。

    public static function verifyLocation($merchant_id=0, $lat=0, $lng=0,$order_subtotal=0)
{
    $resp = Yii::app()->db->createCommand()
      ->select('merchant_id,latitude,lontitude,minimum_order')
      ->from('{{merchant}}')        
      ->where("merchant_id=:merchant_id",array(
         ':merchant_id'=>(integer)$merchant_id,             
      )) 
      ->limit(1)   
      ->queryRow(); 
    if($resp){
        
        $provider = FunctionsV3::getMapProvider();          
        MapsWrapper::init($provider);
        $unit = FunctionsV3::getMerchantDistanceType($merchant_id); 
        $mode = isset($provider['mode'])?$provider['mode']:'driving';
            
                    
        $merchant_delivery_distance = getOption($merchant_id,'merchant_delivery_miles');   
        
        /*GET DELIVERY FEE*/
        $delivery_fee = getOption($merchant_id,'merchant_delivery_charges');    
        $resp_distance = array();
                
        if($merchant_delivery_distance>0){
            $resp_distance = MapsWrapper::getDistance($resp['latitude'],$resp['lontitude'],$lat,$lng,$unit,$mode);
            
            $distance = $resp_distance['distance'];
            if($merchant_delivery_distance>0){
                if($distance>$merchant_delivery_distance){                  
                   $pretty_distance = Yii::t("default","[distance] [unit]",array(
                                  '[distance]'=>$merchant_delivery_distance,
                                  '[unit]'=>MapsWrapper::prettyUnit($unit)
                                ));
                    $error = Yii::t("default","Sorry but this merchant delivers only with in [distance] your current distance is [current_distance]",array(
                       '[distance]'=>$pretty_distance,
                       '[current_distance]'=>$resp_distance['pretty_distance']
                    ));
                    throw new Exception( $error );
                } 
            }
            
            /*MINIMUM ORDER TABLE*/
            $min_tables_enabled = getOption($merchant_id,'min_tables_enabled');
            if($min_tables_enabled==1){                                     
                $min_order = self::getMinimumOrderTable(
                   $merchant_id,$resp_distance['distance'],$resp_distance['unit'],$resp['minimum_order']
                );                  
                if($min_order>$order_subtotal){
                    $error = Yii::t("default","Sorry but minimum order is [min_order] for distance [distance]",array(
                     '[min_order]'=>FunctionsV3::prettyPrice($min_order),
                     '[distance]'=>$resp_distance['pretty_distance']
                   ));
                   throw new Exception( $error );
                }
            }
            
            /*SHIPPING FEE*/
            $shipping_enabled = getOption($merchant_id,'shipping_enabled');
            if($shipping_enabled==2){                   
                $delivery_fee = self::getShippingFee($merchant_id,$resp_distance['distance'],$resp_distance['unit'],$delivery_fee);
            }       
        } 
                    
        return array_merge((array)$resp_distance, array('delivery_fee'=>$delivery_fee));
        
    } else throw new Exception( t("Merchant not found") );
}   
4

1 回答 1

0

You could achieve that by using php date to get time between desired time so you can increase the fee accordingly *Note : PHP gets date from server ,if you were to set the price based on the individual user timezone.Javascript should be used to integrate with PHP

<?php 
date_default_timezone_set('Africa/Johannesburg');   //Set your timezone here get php timezone from 

https://www.php.net/manual/en/timezones.php


$normalfee = "500"; //The variable containing the normal fee 
$tax = "5"; //The added tax for after 8pm fee increase

$getdate = date("Hi"); //Get some time from the server

echo $getdate."Debug : The current time now<br>"; //For debug purposes

if(($getdate > "759") && ($getdate < "2000")){

$finalfee = $normalfee; 

echo $finalfee."Debug : Still the same fee<br>"; //The fee should remain normal starting at 8:00am till 7:59:59pm


} else { 

$finalfee = $normalfee + $tax; 

echo $finalfee."Night time fee added<br>"; //The fee will increase by 5 starting from 8:00pm till 7:59:59am

 }


echo "Debug variable passed out of condition the dollar sign can now be added $".$finalfee."<br>"; 
//Again Debugging this is to show you can then use the $finalfee variable outside the conditions


?>

The script cleaned up...

<?php 
date_default_timezone_set('Africa/Johannesburg');

$normalfee = "500"; 
$tax = "5";
$getdate = date("Hi");

if(($getdate > "759") && ($getdate < "2000")){

$finalfee = $normalfee; 

} else { 

$finalfee = $normalfee + $tax; 

 }

$display = "Final price $".$finalfee;

?>
于 2021-04-04T23:29:15.203 回答