battles/bank.php

86 lines
3.0 KiB
PHP
Raw Normal View History

<?php
2018-01-28 16:40:49 +00:00
ob_start("ob_gzhandler");
session_start();
2019-01-28 15:56:35 +00:00
if (empty($_SESSION['uid'])) {
header("Location: index.php");
exit;
}
require_once "functions.php";
$user = $user ?? [];
if ($user->room != 29) {
header("Location: main.php");
exit;
}
if ($user->battle != 0) {
header('location: fbattle.php');
exit;
}
const SUCCESS = "Успешная операция!";
$bank = new \Battles\Bank($user->id);
$status = '';
2018-01-28 16:40:49 +00:00
$toid = $_POST['to_id'] ?? 0;
$summa = $_POST['summa'] ?? 0;
$submit = $_POST['action'] ?? '';
try {
// Зачисление кредитов на счёт.
if ($submit === 'depositMoney' && $summa) {
$operation = $bank->depositMoney($summa);
$user->money = $operation['walletMoney'];
$bank->setMoney($operation['bankMoney']);
$status = SUCCESS;
}
// Снятие кредитов со счёта.
if ($submit === 'withdrawMoney' && $summa) {
$operation = $bank->withdrawMoney($summa);
$user->money = $operation['walletMoney'];
$bank->setMoney($operation['bankMoney']);
$status = SUCCESS;
}
// Перевод кредитов на другой счёт.
if ($submit === 'sendMoney' && $summa && $toid) {
$user->money = $bank->sendMoney($toid, $summa);
$status = SUCCESS;
}
} catch (\Exceptions\GameException $e) {
echo 'Банковская ошибка!';
} finally {
unset($submit, $summa, $toid);
}
\Battles\Template::header('Банк');
?>
<link href="css/secondary.css" rel="stylesheet"/>
<script src="js/main.js"></script>
<?php \Battles\Template::buildingTop(\Battles\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->money ?></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">Комиссия: <?= Config::$bank_commission * 100 ?>% от переводимой суммы, но не менее 1 кр.</span>
</div>