feat(wip): 유니크 옥션 시작
This commit is contained in:
+14
-17
@@ -17,7 +17,7 @@ use sammo\VO\InheritancePointType;
|
||||
class Auction
|
||||
{
|
||||
|
||||
private AuctionInfo $info;
|
||||
protected AuctionInfo $info;
|
||||
public const LAST_AUCTION_ID_KEY = 'last_auction_id';
|
||||
|
||||
static public function genNextAuctionID(): int
|
||||
@@ -55,7 +55,7 @@ class Auction
|
||||
$auctionStor->setValue("id_{$auctionID}", $info->toArray());
|
||||
}
|
||||
|
||||
public function getHighestBid(): AuctionBidItem
|
||||
public function getHighestBid(): ?AuctionBidItem
|
||||
{
|
||||
$db = DB::db();
|
||||
$rawHighestBid = $db->queryFirstRow(
|
||||
@@ -63,7 +63,7 @@ class Auction
|
||||
$this->info->id
|
||||
);
|
||||
if(!$rawHighestBid){
|
||||
throw new \Exception('입찰이 없습니다.');
|
||||
return null;
|
||||
}
|
||||
|
||||
return AuctionBidItem::fromArray($rawHighestBid);
|
||||
@@ -83,7 +83,7 @@ class Auction
|
||||
return AuctionBidItem::fromArray($rawMyPrevBid);
|
||||
}
|
||||
|
||||
public function __construct(private readonly int $auctionID, private General $general)
|
||||
public function __construct(protected readonly int $auctionID, protected General $general)
|
||||
{
|
||||
$db = DB::db();
|
||||
$auctionStor = KVStorage::getStorage($db, 'auction');
|
||||
@@ -166,7 +166,11 @@ class Auction
|
||||
$this->general->setAuxVar('openedAuction', $openedAuction);
|
||||
}
|
||||
if ($isRollback) {
|
||||
$this->refundBid($this->getHighestBid(), "{$this->info->title} 경매가 취소되었습니다.");
|
||||
$highestBid = $this->getHighestBid();
|
||||
if($highestBid !== null){
|
||||
$this->refundBid($highestBid, "{$this->info->title} 경매가 취소되었습니다.");
|
||||
}
|
||||
|
||||
}
|
||||
$auctionID = $this->info->id;
|
||||
$auctionStor->setValue("id_{$auctionID}", $this->info->toArray());
|
||||
@@ -180,7 +184,7 @@ class Auction
|
||||
$general = $this->general;
|
||||
|
||||
$highestBid = $this->getHighestBid();
|
||||
if ($amount <= $highestBid->amount) {
|
||||
if ($highestBid !== null && $amount <= $highestBid->amount) {
|
||||
throw new \RuntimeException('현재입찰가보다 높게 입찰해야 합니다.');
|
||||
}
|
||||
|
||||
@@ -220,7 +224,7 @@ class Auction
|
||||
$general->increaseInheritancePoint(InheritanceKey::previous, -$morePoint);
|
||||
$general->increaseRankVar(RankColumn::inherit_point_spent_dynamic, $morePoint);
|
||||
|
||||
if ($myPrevBid === null || $myPrevBid->id !== $highestBid->id) {
|
||||
if ($myPrevBid === null || ($highestBid !== null && $myPrevBid->id !== $highestBid->id)) {
|
||||
$this->refundBid($highestBid, "{$auctionInfo->title} 경매에 상회입찰자가 나타났습니다.");
|
||||
}
|
||||
$general->applyDB($db);
|
||||
@@ -257,15 +261,8 @@ class Auction
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
$rawHighestBid = $db->queryFirstRow(
|
||||
'SELECT * FROM ng_auction WHERE auction_id = %i ORDER BY `amount` DESC LIMIT 1',
|
||||
$auctionInfo->id
|
||||
);
|
||||
if (!$rawHighestBid) {
|
||||
throw new \RuntimeException('최고 입찰가가 없습니다.');
|
||||
}
|
||||
$highestBid = AuctionBidItem::fromArray($rawHighestBid);
|
||||
if ($amount <= $highestBid->amount) {
|
||||
$highestBid = $this->getHighestBid();
|
||||
if ($highestBid !== null && $amount <= $highestBid->amount) {
|
||||
throw new \RuntimeException('현재입찰가보다 높게 입찰해야 합니다.');
|
||||
}
|
||||
|
||||
@@ -300,7 +297,7 @@ class Auction
|
||||
|
||||
$general->setVar($resType->value, $general->getVar($resType->value) - $morePoint);
|
||||
|
||||
if ($myPrevBid === null || $myPrevBid->id !== $highestBid->id) {
|
||||
if ($myPrevBid === null || ($highestBid !== null && $myPrevBid->id !== $highestBid->id)) {
|
||||
$this->refundBid($highestBid, "{$auctionInfo->title} 경매에 상회입찰자가 나타났습니다.");
|
||||
}
|
||||
$general->applyDB($db);
|
||||
|
||||
Reference in New Issue
Block a user