feat,wip: 경매장 API 작성
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\API\Auction;
|
||||
|
||||
use sammo\Session;
|
||||
use DateTimeInterface;
|
||||
use sammo\AuctionBuyRice;
|
||||
use sammo\AuctionUniqueItem;
|
||||
use sammo\Validator;
|
||||
use sammo\General;
|
||||
|
||||
class BidBuyRiceAuction extends \sammo\BaseAPI
|
||||
{
|
||||
public function validateArgs(): ?string
|
||||
{
|
||||
$v = new Validator($this->args);
|
||||
$v->rule('required', [
|
||||
'auctionID',
|
||||
'amount',
|
||||
])
|
||||
->rule('int', 'amount')
|
||||
->rule('int', 'auctionID');
|
||||
|
||||
if (!$v->validate()) {
|
||||
return $v->errorStr();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getRequiredSessionMode(): int
|
||||
{
|
||||
return static::REQ_GAME_LOGIN;
|
||||
}
|
||||
|
||||
public function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag)
|
||||
{
|
||||
$auctionID = $this->args['auctionID'];
|
||||
$amount = $this->args['amount'];
|
||||
|
||||
$generalID = $session->generalID;
|
||||
$general = General::createGeneralObjFromDB($generalID);
|
||||
$auction = new AuctionBuyRice($auctionID, $general);
|
||||
$result = $auction->bid($amount, true);
|
||||
|
||||
if (is_string($result)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\API\Auction;
|
||||
|
||||
use sammo\Session;
|
||||
use DateTimeInterface;
|
||||
use sammo\AuctionSellRice;
|
||||
use sammo\Validator;
|
||||
use sammo\General;
|
||||
|
||||
class BidBuyRiceAuction extends \sammo\BaseAPI
|
||||
{
|
||||
public function validateArgs(): ?string
|
||||
{
|
||||
$v = new Validator($this->args);
|
||||
$v->rule('required', [
|
||||
'auctionID',
|
||||
'amount',
|
||||
])
|
||||
->rule('int', 'amount')
|
||||
->rule('int', 'auctionID');
|
||||
|
||||
if (!$v->validate()) {
|
||||
return $v->errorStr();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getRequiredSessionMode(): int
|
||||
{
|
||||
return static::REQ_GAME_LOGIN;
|
||||
}
|
||||
|
||||
public function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag)
|
||||
{
|
||||
$auctionID = $this->args['auctionID'];
|
||||
$amount = $this->args['amount'];
|
||||
|
||||
$generalID = $session->generalID;
|
||||
$general = General::createGeneralObjFromDB($generalID);
|
||||
$auction = new AuctionSellRice($auctionID, $general);
|
||||
$result = $auction->bid($amount, true);
|
||||
|
||||
if (is_string($result)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -9,22 +9,10 @@ use sammo\Validator;
|
||||
use sammo\GameConst;
|
||||
use sammo\General;
|
||||
|
||||
use function sammo\buildItemClass;
|
||||
|
||||
class BidUniqueAuction extends \sammo\BaseAPI
|
||||
{
|
||||
public function validateArgs(): ?string
|
||||
{
|
||||
$availableItems = [];
|
||||
foreach (GameConst::$allItems as $items) {
|
||||
foreach ($items as $itemKey => $amount) {
|
||||
if ($amount == 0) {
|
||||
continue;
|
||||
}
|
||||
$availableItems[$itemKey] = $amount;
|
||||
}
|
||||
}
|
||||
|
||||
$v = new Validator($this->args);
|
||||
$v->rule('required', [
|
||||
'auctionID',
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\API\Auction;
|
||||
|
||||
use sammo\Session;
|
||||
use DateTimeInterface;
|
||||
use sammo\AuctionSellRice;
|
||||
use sammo\DB;
|
||||
use sammo\DTO\AuctionBidItem;
|
||||
use sammo\Enums\AuctionType;
|
||||
use sammo\Validator;
|
||||
use sammo\General;
|
||||
use sammo\Json;
|
||||
use sammo\TimeUtil;
|
||||
use sammo\Util;
|
||||
|
||||
use function sammo\getAuctionLogRecent;
|
||||
|
||||
class GetActiveResourceAuctionList 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();
|
||||
|
||||
$buyRiceList = [];
|
||||
$sellRiceList = [];
|
||||
$rawAuctions = $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'];
|
||||
}
|
||||
|
||||
$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
|
||||
);
|
||||
|
||||
foreach ($rawAuctions as $rawAuction) {
|
||||
$detail = Json::decode($rawAuction['detail']);
|
||||
unset($rawAuction['detail']);
|
||||
$rawAuction = array_merge($rawAuction, $detail);
|
||||
|
||||
$highestBid = $highestBids[$rawAuction['id']] ?? null;
|
||||
if($highestBid === null){
|
||||
$rawAuction['highestBid'] = null;
|
||||
}
|
||||
else {
|
||||
$rawAuction['hightestBid'] = [
|
||||
'amount' => $highestBid->amount,
|
||||
'date' => TimeUtil::format($highestBid->date, false),
|
||||
'generalID' => $highestBid->generalID,
|
||||
'generalName' => $highestBid->data->generalName,
|
||||
];
|
||||
}
|
||||
|
||||
if ($rawAuction['type'] == AuctionType::BuyRice->value) {
|
||||
$buyRiceList[] = $rawAuction;
|
||||
} else {
|
||||
$sellRiceList[] = $rawAuction;
|
||||
}
|
||||
}
|
||||
|
||||
$recentLogs = getAuctionLogRecent(20);
|
||||
|
||||
return [
|
||||
'result' => true,
|
||||
'buyRice' => $buyRiceList,
|
||||
'sellRice' => $sellRiceList,
|
||||
'recentLogs' => $recentLogs
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -4,13 +4,11 @@ namespace sammo\API\Auction;
|
||||
|
||||
use sammo\Session;
|
||||
use DateTimeInterface;
|
||||
use sammo\AuctionUniqueItem;
|
||||
use sammo\AuctionBuyRice;
|
||||
use sammo\Validator;
|
||||
use sammo\GameConst;
|
||||
use sammo\General;
|
||||
|
||||
use function sammo\buildItemClass;
|
||||
|
||||
class OpenUniqueAuction extends \sammo\BaseAPI
|
||||
{
|
||||
public function validateArgs(): ?string
|
||||
@@ -27,12 +25,17 @@ class OpenUniqueAuction extends \sammo\BaseAPI
|
||||
|
||||
$v = new Validator($this->args);
|
||||
$v->rule('required', [
|
||||
'itemID',
|
||||
'amount'
|
||||
'amount',
|
||||
'closeTurnCnt',
|
||||
'startBidAmount',
|
||||
'finishBidAmount',
|
||||
])
|
||||
->rule('int', 'amount')
|
||||
->rule('min', 'amount', GameConst::$inheritItemUniqueMinPoint)
|
||||
->rule('keyExists', 'itemID', $availableItems);
|
||||
->rule('int', 'closeTurnCnt')
|
||||
->rule('min', 'amount', 100)
|
||||
->rule('max', 'amount', 10000)
|
||||
->rule('int', 'startBidAmount')
|
||||
->rule('int', 'finishBidAmount');
|
||||
|
||||
|
||||
if (!$v->validate()) {
|
||||
@@ -48,22 +51,34 @@ class OpenUniqueAuction extends \sammo\BaseAPI
|
||||
|
||||
public function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag)
|
||||
{
|
||||
$itemID = $this->args['itemID'];
|
||||
/** @var int */
|
||||
$amount = $this->args['amount'];
|
||||
/** @var int */
|
||||
$closeTurnCnt = $this->args['closeTurnCnt'];
|
||||
|
||||
/** @var int */
|
||||
$startBidAmount = $this->args['startBidAmount'];
|
||||
/** @var int */
|
||||
$finishBidAmount = $this->args['finishBidAmount'];
|
||||
$generalID = $session->generalID;
|
||||
|
||||
$itemObj = buildItemClass($itemID);
|
||||
$general = General::createGeneralObjFromDB($generalID);
|
||||
|
||||
$auctionResult = AuctionUniqueItem::openItemAuction($itemObj, $general, $amount);
|
||||
$auctionResult = AuctionBuyRice::openResourceAuction(
|
||||
$general,
|
||||
$amount,
|
||||
$closeTurnCnt,
|
||||
$startBidAmount,
|
||||
$finishBidAmount
|
||||
);
|
||||
|
||||
if(is_string($auctionResult)) {
|
||||
if (is_string($auctionResult)) {
|
||||
return $auctionResult;
|
||||
}
|
||||
|
||||
return [
|
||||
'result' => true,
|
||||
'auctionID' => $auctionResult->id,
|
||||
'auctionID' => $auctionResult->getInfo()->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\API\Auction;
|
||||
|
||||
use sammo\Session;
|
||||
use DateTimeInterface;
|
||||
use sammo\AuctionSellRice;
|
||||
use sammo\Validator;
|
||||
use sammo\GameConst;
|
||||
use sammo\General;
|
||||
|
||||
class OpenUniqueAuction extends \sammo\BaseAPI
|
||||
{
|
||||
public function validateArgs(): ?string
|
||||
{
|
||||
$availableItems = [];
|
||||
foreach (GameConst::$allItems as $items) {
|
||||
foreach ($items as $itemKey => $amount) {
|
||||
if ($amount == 0) {
|
||||
continue;
|
||||
}
|
||||
$availableItems[$itemKey] = $amount;
|
||||
}
|
||||
}
|
||||
|
||||
$v = new Validator($this->args);
|
||||
$v->rule('required', [
|
||||
'amount',
|
||||
'closeTurnCnt',
|
||||
'startBidAmount',
|
||||
'finishBidAmount',
|
||||
])
|
||||
->rule('int', 'amount')
|
||||
->rule('int', 'closeTurnCnt')
|
||||
->rule('min', 'amount', 100)
|
||||
->rule('max', 'amount', 10000)
|
||||
->rule('int', 'startBidAmount')
|
||||
->rule('int', 'finishBidAmount');
|
||||
|
||||
|
||||
if (!$v->validate()) {
|
||||
return $v->errorStr();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getRequiredSessionMode(): int
|
||||
{
|
||||
return static::REQ_GAME_LOGIN;
|
||||
}
|
||||
|
||||
public function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag)
|
||||
{
|
||||
/** @var int */
|
||||
$amount = $this->args['amount'];
|
||||
/** @var int */
|
||||
$closeTurnCnt = $this->args['closeTurnCnt'];
|
||||
|
||||
/** @var int */
|
||||
$startBidAmount = $this->args['startBidAmount'];
|
||||
/** @var int */
|
||||
$finishBidAmount = $this->args['finishBidAmount'];
|
||||
$generalID = $session->generalID;
|
||||
|
||||
$general = General::createGeneralObjFromDB($generalID);
|
||||
|
||||
$auctionResult = AuctionSellRice::openResourceAuction(
|
||||
$general,
|
||||
$amount,
|
||||
$closeTurnCnt,
|
||||
$startBidAmount,
|
||||
$finishBidAmount
|
||||
);
|
||||
|
||||
if (is_string($auctionResult)) {
|
||||
return $auctionResult;
|
||||
}
|
||||
|
||||
return [
|
||||
'result' => true,
|
||||
'auctionID' => $auctionResult->getInfo()->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ class OpenUniqueAuction extends \sammo\BaseAPI
|
||||
|
||||
return [
|
||||
'result' => true,
|
||||
'auctionID' => $auctionResult->id,
|
||||
'auctionID' => $auctionResult->getInfo()->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user