battles/bank.php

78 lines
2.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
use Battles\Bank;
use Battles\GameConfigs;
use Battles\Rooms;
use Battles\Template;
use Exceptions\GameException;
session_start();
require_once "functions.php";
const SUCCESS = "Успешная операция!";
$bank = new Bank($user->getId());
$status = '';
$toid = $_POST['to_id'] ?? 0;
$summa = $_POST['summa'] ?? 0;
$submit = $_POST['action'] ?? '';
try {
// Зачисление кредитов на счёт.
if ($submit === 'depositMoney' && $summa) {
$operation = $bank->depositMoney($summa);
$user->setMoney($operation['walletMoney']);
$bank->setMoney($operation['bankMoney']);
$status = SUCCESS;
}
// Снятие кредитов со счёта.
if ($submit === 'withdrawMoney' && $summa) {
$operation = $bank->withdrawMoney($summa);
$user->setMoney($operation['walletMoney']);
$bank->setMoney($operation['bankMoney']);
$status = SUCCESS;
}
// Перевод кредитов на другой счёт.
if ($submit === 'sendMoney' && $summa && $toid) {
$user->setMoney($bank->sendMoney($toid, $summa));
$status = SUCCESS;
}
} catch (GameException $e) {
echo 'Банковская ошибка!';
} finally {
unset($submit, $summa, $toid);
}
Template::header('Банк');
?>
<link href="css/secondary.css" rel="stylesheet"/>
<script src="js/main.js"></script>
<?php Template::buildingTop(Rooms::$roomNames[29], 'strah') ?>
<div><?= $status ?></div>
<div class="appblock appblock-main">
<span class="wrap">На счету: <span class="num"><?= $bank->getMoney() ?></span></span>
<hr>
<span class="wrap">На руках: <span class="num"><?= $user->getMoney() ?></span></span>
</div>
<div class="appblock">
<span class="legend">Работа со счётом</span>
<form method="post">
<input size="10" name="summa" placeholder="Сумма">
<input type="hidden" name="action" value="depositMoney">
<input type="submit" value="Положить деньги">
</form>
<form method="post">
<input size="10" name="summa" placeholder="Сумма">
<input type="hidden" name="action" value="withdrawMoney">
<input type="submit" value="Снять деньги">
</form>
</div>
<div class="appblock">
<span class="legend">Перевод кредитов</span>
<form method="post">
<input size="10" name="summa" placeholder="Сумма">
<input size="10" name="to-id" placeholder="Cчёт"><br>
<input type="hidden" name="action" value="sendMoney">
<input type="submit" value="Перевести кредиты">
</form>
<span class="wrap">Комиссия: <?= GameConfigs::BANK_COMISSION * 100 ?>% от переводимой суммы, но не менее 1 кр.</span>
</div>