我正在制作租赁脚本但是当他们租用一个物品超过5天时会出现问题。
这是它应该如何运作的:
当有人租用对象1到5天时,他们应该支付这么多天,但是当他们租了6或7天他们只需要支付5天时,这就是他们租用物品的每7天。所以10天将是8天付款
这是我已有的剧本:
function bedrag($fietsnummers, $aantaldagen)
{
$fiets = explode(',', $fietsnummers);
foreach($fiets as $fiets1)
{
$sql2 = "SELECT * FROM `fietsen` WHERE `fietsnummer` LIKE '".$fiets1."' LIMIT 0, 30 ";
$nummer = mysql_query($sql2)or die(mysql_error());
while ($fietsinfo = mysql_fetch_array($nummer))
{
$nummer1 = $fietsinfo['huurprijs'];
$bonus = intval($aantaldagen / 7);
$aantaldagen -= 2 * $bonus;
if($aantaldagen == "0")
{
$aantaldagen = "1";
}
$bedrag = $nummer1 * $aantaldagen;
$amount += intval($bedrag);
}
}
return $amount;
}
答案 0 :(得分:0)
此处函数返还账单天数
function billablePeriod($days){
$full_weeks = intval($days/7);
$current = $days%7;
$bonus = $full_weeks*2;
$bonus += ($current-5)>0? ($current-5) : 0;
return $days -$bonus;
}
在评论中添加和修复
你的代码中的:
$amount =0;
while ($fietsinfo = mysql_fetch_array($nummer))
{
$amount += $fietsinfo['huurprijs'] * billablePeriod($aantaldagen);
}