PHP - 如果时间在晚上 8 点到早上 8 点之间,则增加额外的运费
PHP - Adding extra shipping fee if time is between 8pm and 8am
我有一个我想添加的食品订购脚本如果交货时间在 8:00:00PM - 7:59:59AM 之间添加额外费用 5 美元,如果它在 8:00:00 AM 之间7:59:59 PM 以保持脚本中的交付。
这是我的代码,用于计算 returns 我们已经在控制面板中设置的运费。
我们想将此添加为一个修复程序,以增加夜间送货的费用。
当日送达 = 正常送货费
夜间派送 = 正常派送费 + 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") );
}
您可以通过使用 php 日期来获得所需时间之间的时间来实现这一点,这样您就可以相应地增加费用
*注意:PHP 从服务器获取日期,如果您要根据个人用户设置价格 timezone.Javascript 应该与 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
?>
脚本已清理...
<?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;
?>
我有一个我想添加的食品订购脚本如果交货时间在 8:00:00PM - 7:59:59AM 之间添加额外费用 5 美元,如果它在 8:00:00 AM 之间7:59:59 PM 以保持脚本中的交付。
这是我的代码,用于计算 returns 我们已经在控制面板中设置的运费。
我们想将此添加为一个修复程序,以增加夜间送货的费用。
当日送达 = 正常送货费 夜间派送 = 正常派送费 + 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") );
}
您可以通过使用 php 日期来获得所需时间之间的时间来实现这一点,这样您就可以相应地增加费用 *注意:PHP 从服务器获取日期,如果您要根据个人用户设置价格 timezone.Javascript 应该与 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
?>
脚本已清理...
<?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;
?>