Before we go jumping into code and databases, let's take a moment and examine the needs and strategies, as well as the different types of auctions.
First of all, there are many different types of auctions (which we'll discuss in the next section), so you'll have to decide what your needs are, and adjust accordingly. I'll outline the needs for our auction here, and we'll reference these as we progress. First, let's get some definitions out of the way:
Buyer/Bidder - The person who places a bid, and wants to buy an item. Item/Lot - One listing in the auction (can be several actual items, but will be represented by one listing). Proxy bidding - A buyer places a maximum bid to never be exceeded. The actual bid then is simply the last highest winning bid plus the minimum increment. The actual bid will be increased automatically when outbid until the max is reached. Seller - The person who listed the item to be sold. Winning bid - The price a buyer pays to win an item. And now our assumptions:
"Second Price auction:" Bidders may place proxy bids. The winners will then end up paying the lowest winning bid for the item(s). We will only allow single lots to be sold. This means we will not allow groups of lots to be sold together (you won't be able to sell items A and B together). However, you can sell a bunch of items as one lot (i.e. 100 pencils in lot A). Once an auction is over, it is over. In some auctions, if a bid is placed within a certain amount of time (i.e. 5 seconds) before the end of an auction, the auction is extended for some time. We will not do that here. Number of items. In the case that two people bid the same thing, the person who bid for more items will win, regardless of who bid first. If both buyers bid for the same number of items, the earliest bid will win. Proxy bidding rounds. One round will be defined as when the auction engine cycles through all users and adjusts bids accordingly, based on the current high bid and the buyer's maximum bid. A round will commence once a buyer places a bid on a lot, and will proceed in the order the bids were placed. If at the end of the round, a resolution is not achieved, we will start over from the beginning. There are also two other types of auctions that we will not use here, but may be good for reference.
Winning Bid Auction - The winning buyer gets the requested lots for the price they bid. If there are multiple winners, everyone gets the price they bid. Clear Price Auction - The winning buyers get the requested lots for the lowest winning bid. Now that we've outlined our needs, let's take a look at the database structure behind the auction.