feat,wip: 입찰 기능 동작
This commit is contained in:
+35
-26
@@ -46,7 +46,7 @@ abstract class Auction
|
||||
{
|
||||
$db = DB::db();
|
||||
|
||||
if($this->_highestBid !== false){
|
||||
if ($this->_highestBid !== false) {
|
||||
return $this->_highestBid;
|
||||
}
|
||||
|
||||
@@ -75,11 +75,19 @@ abstract class Auction
|
||||
public function getMyPrevBid(): ?AuctionBidItem
|
||||
{
|
||||
$db = DB::db();
|
||||
$rawMyPrevBid = $db->queryFirstRow(
|
||||
'SELECT * FROM ng_auction_bid WHERE general_id = %i AND auction_id = %i ORDER BY `amount` DESC LIMIT 1',
|
||||
$this->general->getID(),
|
||||
$this->info->id
|
||||
);
|
||||
if (!$this->info->detail->isReverse) {
|
||||
$rawMyPrevBid = $db->queryFirstRow(
|
||||
'SELECT * FROM ng_auction_bid WHERE general_id = %i AND auction_id = %i ORDER BY `amount` DESC LIMIT 1',
|
||||
$this->general->getID(),
|
||||
$this->info->id
|
||||
);
|
||||
} else {
|
||||
$rawMyPrevBid = $db->queryFirstRow(
|
||||
'SELECT * FROM ng_auction_bid WHERE general_id = %i AND auction_id = %i ORDER BY `amount` ASC LIMIT 1',
|
||||
$this->general->getID(),
|
||||
$this->info->id
|
||||
);
|
||||
}
|
||||
if (!$rawMyPrevBid) {
|
||||
return null;
|
||||
}
|
||||
@@ -89,13 +97,14 @@ abstract class Auction
|
||||
public function __construct(protected readonly int $auctionID, protected General $general)
|
||||
{
|
||||
$db = DB::db();
|
||||
$rawAuctionInfo = $db->query('SELECT * FROM ng_auction WHERE id = %i', $auctionID);
|
||||
if ($rawAuctionInfo === null) {
|
||||
$rawAuctionInfo = $db->queryFirstRow('SELECT * FROM `ng_auction` WHERE id = %i', $auctionID);
|
||||
if (!$rawAuctionInfo) {
|
||||
throw new \RuntimeException("해당 경매가 없습니다: {$auctionID}");
|
||||
}
|
||||
$this->info = AuctionInfo::fromArray($rawAuctionInfo);
|
||||
if($this->info->type !== $this->auctionType){
|
||||
throw new \RuntimeException("잘못된 경매 타입입니다: {$this->info->type} != {$this->auctionType}");
|
||||
$thisAuctionType = static::$auctionType;
|
||||
if ($this->info->type !== $thisAuctionType) {
|
||||
throw new \RuntimeException("잘못된 경매 타입입니다: {$this->info->type->value} != {$thisAuctionType->value}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,8 +113,9 @@ abstract class Auction
|
||||
return $this->info;
|
||||
}
|
||||
|
||||
public function shrinkCloseDate(?DateTimeInterface $date): ?string{
|
||||
if($date === null){
|
||||
public function shrinkCloseDate(?DateTimeInterface $date): ?string
|
||||
{
|
||||
if ($date === null) {
|
||||
$date = new DateTimeImmutable();
|
||||
}
|
||||
|
||||
@@ -196,7 +206,7 @@ abstract class Auction
|
||||
if ($isRollback) {
|
||||
$highestBid = $this->getHighestBid();
|
||||
if ($highestBid !== null) {
|
||||
$this->refundBid($highestBid, "{$this->info->title} 경매가 취소되었습니다.");
|
||||
$this->refundBid($highestBid, "{$this->info->id}번 {$this->info->detail->title} 경매가 취소되었습니다.");
|
||||
}
|
||||
$this->rollbackAuction();
|
||||
}
|
||||
@@ -216,15 +226,10 @@ abstract class Auction
|
||||
return '현재입찰가보다 높게 입찰해야 합니다.';
|
||||
}
|
||||
|
||||
$rawMyPrevBid = $db->queryFirstRow(
|
||||
'SELECT * FROM ng_auction_bid WHERE general_id = %i AND auction_id = %i ORDER BY `amount` DESC LIMIT 1',
|
||||
$general->getID(),
|
||||
$auctionInfo->id
|
||||
);
|
||||
if ($rawMyPrevBid === null) {
|
||||
$myPrevBid = $this->getMyPrevBid();
|
||||
if($myPrevBid !== null && $highestBid->no !== $myPrevBid->no){
|
||||
//이미 환불 받았으니 무효.
|
||||
$myPrevBid = null;
|
||||
} else {
|
||||
$myPrevBid = AuctionBidItem::fromArray($rawMyPrevBid);
|
||||
}
|
||||
|
||||
$morePoint = $amount - ($myPrevBid ? $myPrevBid->amount : 0);
|
||||
@@ -269,8 +274,8 @@ abstract class Auction
|
||||
$general->increaseInheritancePoint(InheritanceKey::previous, -$morePoint);
|
||||
$general->increaseRankVar(RankColumn::inherit_point_spent_dynamic, $morePoint);
|
||||
|
||||
if ($myPrevBid === null || ($highestBid !== null && $myPrevBid->id !== $highestBid->id)) {
|
||||
$this->refundBid($highestBid, "{$auctionInfo->title} 경매에 상회입찰자가 나타났습니다.");
|
||||
if ($highestBid !== null && $myPrevBid === null) {
|
||||
$this->refundBid($highestBid, "{$auctionInfo->id}번 $auctionInfo->detail->title}에 상회입찰자가 나타났습니다.");
|
||||
}
|
||||
$general->applyDB($db);
|
||||
return null;
|
||||
@@ -326,6 +331,10 @@ abstract class Auction
|
||||
|
||||
|
||||
$myPrevBid = $this->getMyPrevBid();
|
||||
if($myPrevBid !== null && $highestBid->no !== $myPrevBid->no){
|
||||
//이미 환불 받았으니 무효.
|
||||
$myPrevBid = null;
|
||||
}
|
||||
|
||||
$morePoint = $amount - ($myPrevBid ? $myPrevBid->amount : 0);
|
||||
$resType = $auctionInfo->reqResource;
|
||||
@@ -361,8 +370,8 @@ abstract class Auction
|
||||
|
||||
$general->increaseVar($resType->value, -$morePoint);
|
||||
|
||||
if ($myPrevBid === null || ($highestBid !== null && $myPrevBid->id !== $highestBid->id)) {
|
||||
$this->refundBid($highestBid, "{$auctionInfo->title} 경매에 상회입찰자가 나타났습니다.");
|
||||
if ($highestBid !== null && $myPrevBid === null) {
|
||||
$this->refundBid($highestBid, "{$auctionInfo->id}번 {$auctionInfo->detail->title}에 상회입찰자가 나타났습니다.");
|
||||
}
|
||||
$general->applyDB($db);
|
||||
return null;
|
||||
@@ -382,7 +391,7 @@ abstract class Auction
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($highestBid->data->tryExtendCloseDate) {
|
||||
if ($highestBid->aux->tryExtendCloseDate) {
|
||||
//연장 요청이 있었다.
|
||||
$extendedCloseDate = $this->info->closeDate->add(TimeUtil::secondsToDateInterval(
|
||||
max(static::MIN_EXTENSION_MINUTES_BY_EXTENSION_QUERY, $this->info->turnTerm * static::COEFF_EXTENSION_MINUTES_BY_EXTENSION_QUERY) * 60
|
||||
|
||||
Reference in New Issue
Block a user