72 lines
1.5 KiB
PHP
72 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace sammo\API\Auction;
|
|
|
|
use sammo\Session;
|
|
use DateTimeInterface;
|
|
use sammo\Betting;
|
|
use sammo\DB;
|
|
use sammo\DTO\BettingItem;
|
|
use sammo\Validator;
|
|
use sammo\GameConst;
|
|
use sammo\KVStorage;
|
|
use sammo\UserLogger;
|
|
use sammo\Util;
|
|
|
|
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', [
|
|
'itemID',
|
|
'amount'
|
|
])
|
|
->rule('int', 'amount')
|
|
->rule('min', 'amount', GameConst::$inheritItemUniqueMinPoint)
|
|
->rule('keyExists', 'item', $availableItems);
|
|
|
|
|
|
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 */
|
|
$bettingID = $this->args['bettingID'];
|
|
/** @var int[] */
|
|
$bettingType = $this->args['bettingType'];
|
|
/** @var int */
|
|
$amount = $this->args['amount'];
|
|
|
|
$bettingHelper = new Betting($bettingID);
|
|
try {
|
|
$bettingHelper->bet($session->generalID, $session->userID, $bettingType, $amount);
|
|
} catch (\Throwable $e) {
|
|
return $e->getMessage();
|
|
}
|
|
|
|
return [
|
|
'result' => true
|
|
];
|
|
}
|
|
}
|