From 7708c26b7100d3277f6cd079607ae86f44cf2702 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Sat, 23 Apr 2022 01:39:02 +0900 Subject: [PATCH] =?UTF-8?q?refac:=20Betting=20=EC=8B=9C=EC=9E=91=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=EB=A5=BC=20=EB=AA=A8=EB=93=88=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/Betting.php | 21 ++++++++++++++++++++ hwe/sammo/Event/Action/OpenNationBetting.php | 15 +++++--------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/hwe/sammo/Betting.php b/hwe/sammo/Betting.php index f816f8fc..ca33aa6b 100644 --- a/hwe/sammo/Betting.php +++ b/hwe/sammo/Betting.php @@ -10,6 +10,27 @@ class Betting private BettingInfo $info; + public CONST LAST_BETTING_ID_KEY = 'last_betting_id'; + + static public function genNextBettingID(): int{ + $db = DB::db(); + + $gameStor = KVStorage::getStorage($db, 'game_env'); + $gameStor->invalidateCacheValue(self::LAST_BETTING_ID_KEY); + $bettingID = ($gameStor->getValue(self::LAST_BETTING_ID_KEY) ?? 0) + 1; + + $gameStor->setValue(self::LAST_BETTING_ID_KEY, $bettingID); + + return $bettingID; + } + + static public function openBetting(BettingInfo $info){ + $db = DB::db(); + $bettingID = $info->id; + $bettingStor = KVStorage::getStorage($db, 'betting'); + $bettingStor->setValue("id_{$bettingID}", $info->toArray()); + } + public function __construct(private $bettingID) { $db = DB::db(); diff --git a/hwe/sammo/Event/Action/OpenNationBetting.php b/hwe/sammo/Event/Action/OpenNationBetting.php index 8384d25c..fb04c43f 100644 --- a/hwe/sammo/Event/Action/OpenNationBetting.php +++ b/hwe/sammo/Event/Action/OpenNationBetting.php @@ -2,6 +2,7 @@ namespace sammo\Event\Action; +use sammo\Betting; use \sammo\GameConst; use \sammo\Util; use \sammo\DB; @@ -28,12 +29,6 @@ class OpenNationBetting extends \sammo\Event\Action { $db = DB::db(); - $gameStor = KVStorage::getStorage($db, 'game_env'); - $gameStor->invalidateCacheValue('last_betting_id'); - $bettingID = ($gameStor->getValue('last_betting_id') ?? 0) + 1; - $gameStor->setValue('last_betting_id', $bettingID); - - $bettingStor = KVStorage::getStorage($db, 'betting'); [$year, $month] = [$env['year'], $env['month']]; if ($this->nationCnt == 1) { @@ -77,8 +72,9 @@ class OpenNationBetting extends \sammo\Event\Action aux: $nationRaw, ); } - - $bettingInfo = new BettingInfo( + + $bettingID = \sammo\Betting::genNextBettingID(); + Betting::openBetting(new BettingInfo( id: $bettingID, type: 'bettingNation', name: "{$name} 예상", @@ -88,8 +84,7 @@ class OpenNationBetting extends \sammo\Event\Action openYearMonth: $openYearMonth, closeYearMonth: $closeYearMonth, candidates: $candidates, - ); - $bettingStor->setValue("id_{$bettingID}", $bettingInfo->toArray()); + )); $db->insert('event', [ 'target' => 'DESTROY_NATION',