我正在编写一个用于对项目进行自动出价的脚本。我认为描述我想要做的最简单的方法是给你一个场景。假设增加1,000美元:
Asking Price: $1,000
Bidder 1: Max Bid of $4,000 -> High Bid: $1,000
Bidder 2: Max Bid of $3,000 -> High Bid: $3,000 -> [AUTO BIDDER 1] High Bid: $4,000
Bidder 3: Max Bid of $8,000 -> High Bid: $5,000
Bidder 4: Max Bid of $10,000 -> [AUTO BIDDER 3] High Bid: $8,000 -> High Bid: $9,000
我正试图想出一个循环来完成它们,但我不确定如何。我想出了一个适合每次出价的循环,但我想跳过每1000美元的增量,而是根据最高出价跳出最高出价。
我有两个表设置:出价和 maxbids 。这是我想到的循环:
这可行,但正如我所说,这将继续插入所有$ 1,000增量。我宁愿按照我上面展示的方式工作。有什么建议吗?
答案 0 :(得分:4)
这是一个有趣的问题,根据我的理解,这个功能会在新的出价时触发。你想做的应该是:
下一步:
/**
* $currentBidder = The current high bidder
* $highBid = The current high bidder's high bid
* $thisBidder = Bidder placing the new bid
* $thisBid = The bid that triggered the function
* $increment = The minimum bid increment
*/
function placeBid($currentBidder,$highBid,$thisBidder,$thisBid,$increment) {
if($thisBid > $highBid) {
// Insert $highBid as current bid, for $currentBidder
if($thisBid > $highBid + $increment) {
// Insert $thisBid into highbids table
// Insert $highBid + $increment as current bid, for $thisBidder
} else {
// Insert $thisBid as current bid, for $thisBidder
}
} else {
// Insert $thisBid as current bid for $thisBidder
if($highBid > $thisBid + $increment) {
// Insert $thisBid + $increment as current bid, for $currentBidder
} else {
// Insert $thisBid as current bid, for $currentBidder
}
}
}
注意:
显然,您必须检查这是否是第一次出价,如果是,请将出价设置为最低要价。您必须检查出价是否有效(大于当前出价+增量。我没有包含该代码。
从我所看到的情况来看,如果每次出价都触发该功能,您根本不需要循环,只需要一个条件树。
情景:
Item Current Bids: A, 4000
Item Current Max: A, 4000
--> C bids 7500
Item Current Bids: A, 4000; C, 5000
Item Current Max: C, 7500
--> B bids 7500
Item Current Bids: A, 4000; C, 5000; B, 7500; C, 7500
Item Current Max: C, 7500
--> A bids 9000
Item Current Bids: A, 4000; C, 5000; B, 7000; C, 7500; A, 8500
Item Current Max: A, 9000