That is my PHP Code, but I am not sure if it is doing everything I need it to. It doesn't seem to be adding the winner_id and changing the status in the database to closed.Code:/** * The function closes the auctions * * @return array Affected Auction */ function close() { $expireTime = time() + ($this->appConfigurations['cronTime'] * 60); while (time() < $expireTime) { // lets start by getting all the auctions that have closed $auctions = $this->Auction->find('all', array('contain' => '', 'conditions' => "Auction.winner_id = 0 AND Auction.end_time <= '" . date('Y-m-d H:i:s') . "' AND Auction.closed = 0")); if(!empty($auctions)) { foreach($auctions as $auction) { $isPeakNow = $this->isPeakNow(); // before we declare this user the winner, lets run some test to make sure the auction can definitely close if($this->Auction->checkCanClose($auction['Auction']['id'], $isPeakNow) == false) { // lets check to see if the reason we can't close it, is because its now offpeak and this is a peak auction if($auction['Auction']['peak_only'] == 1 && !$isPeakNow) { $peak = $this->nonPeakDates(); //Calculate how many seconds auction will end after peak end $seconds_after_peak = strtotime($auction['Auction']['end_time']) - strtotime($peak['peak_end']); $end_time = strtotime($peak['peak_start']) + $seconds_after_peak; $auction['Auction']['end_time'] = date('Y-m-d H:i:s', $end_time); $this->Auction->save($auction); } else { // lets check just how far ago this auction closed, and either place an autobid or extend the time $data['auction_time_increment'] = $this->Setting->get('auction_time_increment'); $newEndTime = strtotime($auction['Auction']['end_time']); if($newEndTime < time() - $data['auction_time_increment']) { $auction['Auction']['end_time'] = date('Y-m-d H:i:s', time() + ($auction['Auction']['time_extended'])); $this->Auction->save($auction); } else { //lets extend it by placing an autobid $data['bid_debit'] = $this->Setting->get('bid_debit'); $data['auction_price_increment'] = $this->Setting->get('auction_price_increment'); $data['auction_peak_start'] = $this->Setting->get('auction_peak_start'); $data['auction_peak_end'] = $this->Setting->get('auction_peak_end'); $data['isPeakNow'] = $this->isPeakNow(); $this->Auction->Autobid->placeAutobid($auction['Auction']['id'], $data); } } continue; } $bid = $this->Auction->Bid->find('first', array('conditions' => array('Bid.auction_id' => $auction['Auction']['id']), 'order' => array('Bid.id' => 'desc'))); if(!empty($bid)) { if($bid['User']['autobidder'] == 0) { // send the email to the winner $data['Auction'] = $auction['Auction']; $data['Bid'] = $bid['Bid']; $data['User'] = $bid['User']; $data['to'] = $data['User']['email']; $data['subject'] = sprintf(__('%s - You have won an auction', true), $this->appConfigurations['name']); $data['template'] = 'auctions/won_auction'; $this->_sendEmail($data); $auction['Auction']['status_id'] = 1; } $auction['Auction']['winner_id'] = $bid['Bid']['user_id']; } unset($auction['Auction']['modified']); $auction['Auction']['closed'] = 1; $this->Auction->save($auction); } } usleep(900000); } } }
What I need it to do is
IF the counter has run down, then add the user_id of the latest bidder to the table auctions and row winner_id.
It also needs to:
IF the counter has run down, then insert 1 into table auctions, row closed
Is it doing that at all?



Reply With Quote
Bookmarks