我目前正在制作拍卖网站的项目。为了确保人们的出价不能高于目前的出价,我已经做了这个if语句:
if(
($this->getHighestBid() < 50 && $this->getHighestBid() >= 0 && $bid > $this->getHighestBid()+0.50) ||
($this->getHighestBid() < 500 && $this->getHighestBid() >= 50 && $bid > $this->getHighestBid()+1) ||
($this->getHighestBid() < 1000 && $this->getHighestBid() >= 500 && $bid > $this->getHighestBid()+5) ||
($this->getHighestBid() < 5000 && $this->getHighestBid() >= 1000 && $bid > $this->getHighestBid()+10) ||
($this->getHighestBid() >= 5000 && $bid > $this->getHighestBid()+50)
){
...
}
这应该使当当前最高出价在指定范围内时,您必须至少将价格提高到指定的价格。 我的问题在于它不会让我对任何事情进行投标。有谁知道这里发生了什么?
答案 0 :(得分:0)
您的代码似乎在我的测试中起作用,听起来变量的类型不是数字类型(浮点数或整数),实际上是字符串或类似的奇怪类型。
确认:
var_dump($this->getHighestBid());
我想在我写答案时添加,但您可能希望编辑代码以便更像:
function getMinimumBid() {
$maxBid = (float)$this->getHighestBid();
return $maxBid + $this->getBidIncrement();
}
function getBidIncrement() {
$maxBid = (float)$this->getHighestBid();
switch (true) {
case $maxBid < 50:
return 0.50;
case $maxBid < 500:
return 1;
case $maxBid < 1000:
return 5;
case $maxBid < 5000:
return 10;
default:
return 50;
}
}
// ...
if ($bid >= $this->getMinimumBid()) {
}
// ...
答案 1 :(得分:-1)
这是你的代码:
$highest_bid = $this->getHighestBid();
if(
($highest_bid < 50 && $highest_bid >= 1 && $bid > ($highest_bid+0.50)) ||
($highest_bid < 500 && $highest_bid >= 50 && $bid > ($highest_bid+1)) ||
($highest_bid < 1000 && $highest_bid >= 500 && $bid > ($highest_bid+5)) ||
($highest_bid < 5000 && $highest_bid >= 1000 && $bid > ($highest_bid+10)) ||
($highest_bid >= 5000 && $bid > ($highest_bid+50))
){
// Condition 1:
// Highest bid should be >= 1 and < 50
// Bid should be > 1.5 and < 50.5
// Condition 2:
// Highest bid should be >= 50 and < 500
// Bid should be > 51 and < 501
// Condition 3:
// Highest bid should be >= 500 and < 1000
// Bid should be > 505 and < 1005
// Condition 4:
// Highest bid should be >= 1000 and < 5000
// Bid should be > 1010 and < 5010
// Condition 5:
// Highest bid should be >= 5000
// Bid should be > 5050
}
这里有一个主要问题:
答案 2 :(得分:-1)
我稍微改变了你的代码,所以我可以在我的IDE中执行它:
<?php
$hbid = 50;
$bid = 52;
if(
($hbid < 50 && $hbid >= 0 && $bid > $hbid+0.50) ||
($hbid < 500 && $hbid >= 50 && $bid > $hbid+1) ||
($hbid < 1000 && $hbid >= 500 && $bid > $hbid+5) ||
($hbid < 5000 && $hbid >= 1000 && $bid > $hbid+10) ||
($hbid >= 5000 && $bid > $hbid+50)
)
{
echo "ok";
}
else
{
echo 'not ok';
}
?>
当我更改参数时,它总能正常工作。我想你的问题就在别的地方。