WIP
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace sammo;
|
||||
|
||||
use Ds\Map;
|
||||
use sammo\DTO\AuctionInfo;
|
||||
|
||||
class Auction
|
||||
{
|
||||
|
||||
private AuctionInfo $info;
|
||||
public const LAST_AUCTION_ID_KEY = 'last_auction_id';
|
||||
|
||||
static public function genNextAuctionID(): int
|
||||
{
|
||||
$db = DB::db();
|
||||
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
$gameStor->invalidateCacheValue(self::LAST_AUCTION_ID_KEY);
|
||||
$auctionID = ($gameStor->getValue(self::LAST_AUCTION_ID_KEY) ?? 0) + 1;
|
||||
|
||||
$gameStor->setValue(self::LAST_AUCTION_ID_KEY, $auctionID);
|
||||
|
||||
return $auctionID;
|
||||
}
|
||||
|
||||
|
||||
static public function openAuction(AuctionInfo $info)
|
||||
{
|
||||
$db = DB::db();
|
||||
$auctionID = $info->id;
|
||||
$auctionStor = KVStorage::getStorage($db, 'auction');
|
||||
$auctionStor->setValue("id_{$auctionID}", $info->toArray());
|
||||
}
|
||||
|
||||
public function __construct(private readonly int $auctionID)
|
||||
{
|
||||
$db = DB::db();
|
||||
$auctionStor = KVStorage::getStorage($db, 'auction');
|
||||
$rawBettingInfo = $auctionStor->getValue("id_{$auctionID}");
|
||||
if ($rawBettingInfo === null) {
|
||||
throw new \RuntimeException("해당 경매가 없습니다: {$auctionID}");
|
||||
}
|
||||
$this->info = new AuctionInfo($rawBettingInfo);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\DTO;
|
||||
|
||||
use sammo\Json;
|
||||
use Spatie\DataTransferObject\DataTransferObject;
|
||||
use Spatie\DataTransferObject\Attributes\MapFrom;
|
||||
use Spatie\DataTransferObject\Attributes\MapTo;
|
||||
|
||||
class AuctionBidItem extends DataTransferObject{
|
||||
public int $id;
|
||||
#[MapFrom('auction_id')]
|
||||
#[MapTo('auction_id')]
|
||||
public int $auctionID;
|
||||
public ?int $owner;
|
||||
|
||||
#[MapFrom('general_id')]
|
||||
#[MapTo('general_id')]
|
||||
public int $generalID;
|
||||
|
||||
public int $amount;
|
||||
|
||||
public string $date;
|
||||
public AuctionBidItemData $data;
|
||||
|
||||
public static function parse(array $data): self
|
||||
{
|
||||
$data['data'] = Json::decode($data['data']);
|
||||
return new self($data);
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
$result = parent::toArray();
|
||||
$result['data'] = Json::encode($this->data);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\DTO;
|
||||
|
||||
use Spatie\DataTransferObject\DataTransferObject;
|
||||
|
||||
class AuctionBidItemData extends DataTransferObject{
|
||||
public string $ownerName;
|
||||
public string $generalName;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\DTO;
|
||||
|
||||
use Spatie\DataTransferObject\Attributes\CastWith;
|
||||
use Spatie\DataTransferObject\Attributes\Strict;
|
||||
use Spatie\DataTransferObject\DataTransferObject;
|
||||
|
||||
use sammo\Enums\ResourceType;
|
||||
use sammo\DTO\Caster\BackedEnumCaster;
|
||||
|
||||
//https://json2dto.atymic.dev/
|
||||
|
||||
|
||||
|
||||
#[Strict]
|
||||
class AuctionInfo extends DataTransferObject
|
||||
{
|
||||
public int $id;
|
||||
public int $openerName;
|
||||
public int $openerGeneralID;
|
||||
public string $type;
|
||||
public bool $finished;
|
||||
#[CastWith(BackedEnumCaster::class)]
|
||||
public ResourceType $reqResource;
|
||||
public string $openDate;
|
||||
public string $closeDate;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace sammo\Enums;
|
||||
|
||||
enum ResourceType: string
|
||||
{
|
||||
case gold = 'gold';
|
||||
case rice = 'rice';
|
||||
case inheritancePoint = 'inheritancePoint';
|
||||
}
|
||||
Reference in New Issue
Block a user