feat(WIP): 베팅 상세 정보 반환
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\API\NationCommand;
|
||||
namespace sammo\API\NationBetting;
|
||||
|
||||
use sammo\Session;
|
||||
use DateTimeInterface;
|
||||
@@ -16,7 +16,7 @@ use sammo\Util;
|
||||
|
||||
use function sammo\getAllNationStaticInfo;
|
||||
|
||||
class PushCommand extends \sammo\BaseAPI
|
||||
class BetNation extends \sammo\BaseAPI
|
||||
{
|
||||
public function validateArgs(): ?string
|
||||
{
|
||||
@@ -127,7 +127,7 @@ class PushCommand extends \sammo\BaseAPI
|
||||
else{
|
||||
$general->increaseVar('gold', -$amount);
|
||||
}
|
||||
$db->insert('ng_betting', $bettingItem->toArray());
|
||||
$db->insertUpdate('ng_betting', $bettingItem->toArray());
|
||||
if(!$db->affected_rows){
|
||||
$general->flushUpdateValues();
|
||||
return '베팅을 실패했습니다.';
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\API\NationBetting;
|
||||
|
||||
use sammo\Session;
|
||||
use DateTimeInterface;
|
||||
use sammo\DB;
|
||||
use sammo\DTO\NationBettingInfo;
|
||||
use sammo\General;
|
||||
use sammo\KVStorage;
|
||||
use sammo\Validator;
|
||||
|
||||
use function sammo\increaseRefresh;
|
||||
|
||||
class GetBettingDetail extends \sammo\BaseAPI
|
||||
{
|
||||
public function validateArgs(): ?string
|
||||
{
|
||||
$v = new Validator($this->args);
|
||||
$v->rule('required', [
|
||||
'betting_id',
|
||||
])
|
||||
->rule('integer', 'betting_id');
|
||||
|
||||
if (!$v->validate()) {
|
||||
return $v->errorStr();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getRequiredSessionMode(): int
|
||||
{
|
||||
return static::REQ_GAME_LOGIN | static::REQ_READ_ONLY;
|
||||
}
|
||||
|
||||
public function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag)
|
||||
{
|
||||
$db = DB::db();
|
||||
|
||||
increaseRefresh("국가베팅장", 1);
|
||||
/** @var int */
|
||||
$bettingID = $this->arg['betting_id'];
|
||||
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
$nationBettingStor = KVStorage::getStorage($db, 'nation_betting');
|
||||
$rawBettingInfo = $nationBettingStor->getValue("id_{$bettingID}");
|
||||
if($rawBettingInfo === null){
|
||||
return '해당 베팅이 없습니다';
|
||||
}
|
||||
|
||||
try{
|
||||
$bettingInfo = new NationBettingInfo($rawBettingInfo);
|
||||
}
|
||||
catch(\Error $e){
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
[$year, $month] = $gameStor->getValuesAsArray(['year', 'month']);
|
||||
|
||||
$bettingDetail = [];
|
||||
|
||||
foreach ($db->queryAllLists(
|
||||
'SELECT betting_type, sum(amount) as sum_amount FROM ng_betting WHERE betting_id = %i GROUP BY betting_type',
|
||||
$bettingID
|
||||
) as [$bettingType, $amount]) {
|
||||
$bettingDetail[] = [$bettingType, $amount];
|
||||
}
|
||||
|
||||
[$year, $month] = $gameStor->getValuesAsArray(['year', 'month']);
|
||||
|
||||
$myBetting = [];
|
||||
foreach($db->queryAllLists(
|
||||
'SELECT betting_type, sum(amount) as sum_amount FROM ng_betting WHERE betting_id = %i AND user_id = %i GROUP BY betting_type',
|
||||
$bettingID, $session->userID
|
||||
) as [$bettingType, $amount]){
|
||||
$myBetting[] = [$bettingType, $amount];
|
||||
}
|
||||
|
||||
$general = General::createGeneralObjFromDB($session->generalID, ['gold', 'aux'], 1);
|
||||
|
||||
if($bettingInfo->reqInheritancePoint){
|
||||
$remainPoint = $general->getInheritancePoint('previous');
|
||||
}
|
||||
else{
|
||||
$remainPoint = $general->getVar('gold');
|
||||
}
|
||||
|
||||
return [
|
||||
'result' => false,
|
||||
'bettingInfo' => $rawBettingInfo,
|
||||
'bettingDetail' => $bettingDetail,
|
||||
'myBetting' => $myBetting,
|
||||
'remainPoint' => $remainPoint,
|
||||
'year' => $year,
|
||||
'month' => $month,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\API\NationCommand;
|
||||
namespace sammo\API\NationBetting;
|
||||
|
||||
use sammo\Session;
|
||||
use DateTimeInterface;
|
||||
@@ -11,7 +11,7 @@ use sammo\KVStorage;
|
||||
use function sammo\checkLimit;
|
||||
use function sammo\increaseRefresh;
|
||||
|
||||
class GetReservedCommand extends \sammo\BaseAPI
|
||||
class GetBettingList extends \sammo\BaseAPI
|
||||
{
|
||||
public function validateArgs(): ?string
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user