feat,wip: 경매장 API export
This commit is contained in:
@@ -8,7 +8,7 @@ use sammo\AuctionSellRice;
|
||||
use sammo\Validator;
|
||||
use sammo\General;
|
||||
|
||||
class BidBuyRiceAuction extends \sammo\BaseAPI
|
||||
class BidSellRiceAuction extends \sammo\BaseAPI
|
||||
{
|
||||
public function validateArgs(): ?string
|
||||
{
|
||||
|
||||
@@ -7,6 +7,7 @@ use DateTimeInterface;
|
||||
use sammo\AuctionSellRice;
|
||||
use sammo\DB;
|
||||
use sammo\DTO\AuctionBidItem;
|
||||
use sammo\DTO\AuctionInfo;
|
||||
use sammo\Enums\AuctionType;
|
||||
use sammo\Validator;
|
||||
use sammo\General;
|
||||
@@ -34,17 +35,18 @@ class GetActiveResourceAuctionList extends \sammo\BaseAPI
|
||||
|
||||
$buyRiceList = [];
|
||||
$sellRiceList = [];
|
||||
$rawAuctions = $db->query(
|
||||
/** @var AuctionInfo[] */
|
||||
$auctions = array_map(fn ($raw) => AuctionInfo::fromArray($raw), $db->query(
|
||||
'SELECT * FROM `ng_auction` WHERE `type` IN %ls AND `finished` != 0 ORDER BY `close_date` DESC',
|
||||
[
|
||||
AuctionType::BuyRice->value,
|
||||
AuctionType::SellRice->value,
|
||||
]
|
||||
);
|
||||
));
|
||||
|
||||
$auctionIDList = [];
|
||||
foreach ($rawAuctions as $rawAuction) {
|
||||
$auctionIDList[] = $rawAuction['id'];
|
||||
foreach ($auctions as $auction) {
|
||||
$auctionIDList[] = $auction->id;
|
||||
}
|
||||
|
||||
$rawHighestBids = Util::convertArrayToDict($db->query(
|
||||
@@ -64,17 +66,24 @@ class GetActiveResourceAuctionList extends \sammo\BaseAPI
|
||||
$rawHighestBids
|
||||
);
|
||||
|
||||
foreach ($rawAuctions as $rawAuction) {
|
||||
$detail = Json::decode($rawAuction['detail']);
|
||||
unset($rawAuction['detail']);
|
||||
$rawAuction = array_merge($rawAuction, $detail);
|
||||
foreach ($auctions as $auction) {
|
||||
$rawAuction = [
|
||||
'id' => $auction->id,
|
||||
'type' => $auction->type->value,
|
||||
'hostGeneralID' => $auction->hostGeneralID,
|
||||
'hostName' => $auction->detail->hostName,
|
||||
'openDate' => TimeUtil::format($auction->openDate, false),
|
||||
'closeDate' => TimeUtil::format($auction->closeDate, false),
|
||||
'amount' => $auction->detail->amount,
|
||||
'startBidAmount' => $auction->detail->startBidAmount,
|
||||
'finishBidAmount' => $auction->detail->finishBidAmount,
|
||||
];
|
||||
|
||||
$highestBid = $highestBids[$rawAuction['id']] ?? null;
|
||||
if($highestBid === null){
|
||||
if ($highestBid === null) {
|
||||
$rawAuction['highestBid'] = null;
|
||||
}
|
||||
else {
|
||||
$rawAuction['hightestBid'] = [
|
||||
} else {
|
||||
$rawAuction['highestBid'] = [
|
||||
'amount' => $highestBid->amount,
|
||||
'date' => TimeUtil::format($highestBid->date, false),
|
||||
'generalID' => $highestBid->generalID,
|
||||
@@ -95,7 +104,8 @@ class GetActiveResourceAuctionList extends \sammo\BaseAPI
|
||||
'result' => true,
|
||||
'buyRice' => $buyRiceList,
|
||||
'sellRice' => $sellRiceList,
|
||||
'recentLogs' => $recentLogs
|
||||
'recentLogs' => $recentLogs,
|
||||
'generalID' => $session->generalID,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\API\Auction;
|
||||
|
||||
use sammo\Session;
|
||||
use DateTimeInterface;
|
||||
use sammo\DB;
|
||||
use sammo\DTO\AuctionBidItem;
|
||||
use sammo\DTO\AuctionInfo;
|
||||
use sammo\Enums\AuctionType;
|
||||
use sammo\Validator;
|
||||
|
||||
class GetUniqueItemAuctionDetail extends \sammo\BaseAPI
|
||||
{
|
||||
public function validateArgs(): ?string
|
||||
{
|
||||
$v = new Validator($this->args);
|
||||
$v->rule('required', [
|
||||
'auction_id',
|
||||
])
|
||||
->rule('integer', 'auction_id');
|
||||
|
||||
if (!$v->validate()) {
|
||||
return $v->errorStr();
|
||||
}
|
||||
$this->args['auction_id'] = (int)$this->args['auction_id'];
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getRequiredSessionMode(): int
|
||||
{
|
||||
return static::REQ_GAME_LOGIN;
|
||||
}
|
||||
|
||||
public function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag)
|
||||
{
|
||||
$db = DB::db();
|
||||
|
||||
$generalID = $session->generalID;
|
||||
$auctionID = $this->args['auction_id'];
|
||||
|
||||
$rawAuction = $db->queryFirstRow(
|
||||
'SELECT * FROM `ng_auction` WHERE `type` = %s AND `auction_id` = %s',
|
||||
AuctionType::UniqueItem,
|
||||
$auctionID
|
||||
);
|
||||
|
||||
if (!$rawAuction) {
|
||||
return '선택한 경매가 없습니다.';
|
||||
}
|
||||
|
||||
$auction = AuctionInfo::fromArray($rawAuction);
|
||||
|
||||
/** @var AuctionBidItem[] */
|
||||
$bidList = array_map(fn ($raw) => AuctionBidItem::fromArray($raw), $db->query(
|
||||
'SELECT * FROM `ng_auction_bid` WHERE `auction_id` = %s ORDER BY `amount` DESC',
|
||||
$auctionID
|
||||
) ?? []);
|
||||
|
||||
$responseBid = [];
|
||||
foreach ($bidList as $bid) {
|
||||
$responseBid[] = [
|
||||
'generalName' => $bid->data->generalName,
|
||||
'amount' => $bid->amount,
|
||||
'isCallerHighestBidder' => $bid->generalID === $generalID,
|
||||
'date' => $bid->date,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'result' => true,
|
||||
'auction' => [
|
||||
'id' => $auction->id,
|
||||
'finished' => $auction->finished,
|
||||
'title' => $auction->detail->title,
|
||||
'target' => $auction->target,
|
||||
'isCallerHost' => $auction->openerGeneralID === $generalID,
|
||||
'hostName' => $auction->detail->hostName,
|
||||
'remainCloseDateExtensionCnt' => $auction->detail->remainCloseDateExtensionCnt,
|
||||
'availableLatestBidCloseDate' => $auction->detail->availableLatestBidCloseDate,
|
||||
],
|
||||
'bidList' => $responseBid,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\API\Auction;
|
||||
|
||||
use sammo\Session;
|
||||
use DateTimeInterface;
|
||||
use sammo\DB;
|
||||
use sammo\DTO\AuctionBidItem;
|
||||
use sammo\DTO\AuctionInfo;
|
||||
use sammo\Enums\AuctionType;
|
||||
use sammo\Util;
|
||||
|
||||
class GetUniqueItemAuctionList extends \sammo\BaseAPI
|
||||
{
|
||||
public function validateArgs(): ?string
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getRequiredSessionMode(): int
|
||||
{
|
||||
return static::REQ_GAME_LOGIN;
|
||||
}
|
||||
|
||||
public function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag)
|
||||
{
|
||||
$db = DB::db();
|
||||
|
||||
$generalID = $session->generalID;
|
||||
|
||||
/** @var AuctionInfo[] */
|
||||
$auctions = array_map(fn($raw)=>AuctionInfo::fromArray($raw), $db->query(
|
||||
'SELECT * FROM `ng_auction` WHERE `type` = %s ORDER BY `close_date` DESC',
|
||||
AuctionType::UniqueItem->value
|
||||
) ?? []);
|
||||
|
||||
$auctionIDList = [];
|
||||
foreach ($auctions as $auction) {
|
||||
$auctionIDList[] = $auction->id;
|
||||
}
|
||||
|
||||
$rawHighestBids = Util::convertArrayToDict($db->query(
|
||||
'SELECT bid.* FROM `ng_auction_bid` bid INNER JOIN (
|
||||
SELECT `auction_id`, MAX(`amount`) as `max_amount`
|
||||
FROM `ng_auction_bid`
|
||||
WHERE `auction_id` IN %li
|
||||
GROUP BY `auction_id`
|
||||
ORDER BY `amount`
|
||||
) AS max_bid
|
||||
ON bid.`auction_id` = max_bid.`auction_id` AND bid.`amount` = max_bid.`max_amount`',
|
||||
$auctionIDList,
|
||||
) ?? [], 'auction_id');
|
||||
/** @var array<int,AuctionBidItem> */
|
||||
$highestBids = Util::mapWithKey(
|
||||
fn ($auctionID, $bid) => AuctionBidItem::fromArray($bid),
|
||||
$rawHighestBids
|
||||
);
|
||||
|
||||
$response = [];
|
||||
foreach ($auctions as $auction) {
|
||||
$auctionID = $auction->id;
|
||||
$highestBid = $highestBids[$auctionID] ?? null;
|
||||
if($highestBid === null){
|
||||
continue;
|
||||
}
|
||||
|
||||
$response[] = [
|
||||
'id' => $auctionID,
|
||||
'finished' => $auction->finished,
|
||||
'title' => $auction->detail->title,
|
||||
'target' => $auction->target,
|
||||
'isCallerHost' => $auction->openerGeneralID === $generalID,
|
||||
'hostName' => $auction->detail->hostName,
|
||||
'remainCloseDateExtensionCnt' => $auction->detail->remainCloseDateExtensionCnt,
|
||||
'availableLatestBidCloseDate' => $auction->detail->availableLatestBidCloseDate,
|
||||
'highestBid' => [
|
||||
'generalName' => $highestBid->data->generalName,
|
||||
'amount' => $highestBid->amount,
|
||||
'isCallerHighestBidder' => $highestBid->generalID === $generalID,
|
||||
'date' => $highestBid->date,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'result' => true,
|
||||
'list' => $response,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ use sammo\Validator;
|
||||
use sammo\GameConst;
|
||||
use sammo\General;
|
||||
|
||||
class OpenUniqueAuction extends \sammo\BaseAPI
|
||||
class OpenBuyRiceAuction extends \sammo\BaseAPI
|
||||
{
|
||||
public function validateArgs(): ?string
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ use sammo\Validator;
|
||||
use sammo\GameConst;
|
||||
use sammo\General;
|
||||
|
||||
class OpenUniqueAuction extends \sammo\BaseAPI
|
||||
class OpenSellRiceAuction extends \sammo\BaseAPI
|
||||
{
|
||||
public function validateArgs(): ?string
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user