2018-02-27 03:53:10 +00:00
|
|
|
|
<?php
|
2021-02-01 16:42:52 +00:00
|
|
|
|
|
|
|
|
|
use Battles\Bank;
|
2021-03-10 21:03:59 +00:00
|
|
|
|
use Battles\GameConfigs;
|
2021-02-01 16:42:52 +00:00
|
|
|
|
use Battles\Rooms;
|
|
|
|
|
use Battles\Template;
|
|
|
|
|
use Exceptions\GameException;
|
|
|
|
|
|
2018-12-12 11:59:29 +00:00
|
|
|
|
require_once "functions.php";
|
2020-09-25 16:27:11 +00:00
|
|
|
|
const SUCCESS = "Успешная операция!";
|
2020-10-28 12:31:17 +00:00
|
|
|
|
|
2021-02-01 16:42:52 +00:00
|
|
|
|
$bank = new Bank($user->getId());
|
2020-09-30 12:39:42 +00:00
|
|
|
|
$status = '';
|
2018-01-28 16:40:49 +00:00
|
|
|
|
|
2020-10-28 20:21:08 +00:00
|
|
|
|
$toid = $_POST['to_id'] ?? 0;
|
|
|
|
|
$summa = $_POST['summa'] ?? 0;
|
2020-10-28 12:31:17 +00:00
|
|
|
|
$submit = $_POST['action'] ?? '';
|
2020-10-28 20:21:08 +00:00
|
|
|
|
try {
|
2020-10-28 12:31:17 +00:00
|
|
|
|
// Зачисление кредитов на счёт.
|
2020-10-28 20:21:08 +00:00
|
|
|
|
if ($submit === 'depositMoney' && $summa) {
|
|
|
|
|
$operation = $bank->depositMoney($summa);
|
2021-02-01 16:42:52 +00:00
|
|
|
|
$user->setMoney($operation['walletMoney']);
|
2020-10-28 20:21:08 +00:00
|
|
|
|
$bank->setMoney($operation['bankMoney']);
|
|
|
|
|
$status = SUCCESS;
|
|
|
|
|
}
|
2020-10-28 12:31:17 +00:00
|
|
|
|
// Снятие кредитов со счёта.
|
2020-10-28 20:21:08 +00:00
|
|
|
|
if ($submit === 'withdrawMoney' && $summa) {
|
|
|
|
|
$operation = $bank->withdrawMoney($summa);
|
2021-02-01 16:42:52 +00:00
|
|
|
|
$user->setMoney($operation['walletMoney']);
|
2020-10-28 20:21:08 +00:00
|
|
|
|
$bank->setMoney($operation['bankMoney']);
|
|
|
|
|
$status = SUCCESS;
|
|
|
|
|
}
|
2020-10-28 12:31:17 +00:00
|
|
|
|
// Перевод кредитов на другой счёт.
|
2020-10-28 20:21:08 +00:00
|
|
|
|
if ($submit === 'sendMoney' && $summa && $toid) {
|
2021-02-01 16:42:52 +00:00
|
|
|
|
$user->setMoney($bank->sendMoney($toid, $summa));
|
2020-10-28 20:21:08 +00:00
|
|
|
|
$status = SUCCESS;
|
|
|
|
|
}
|
2021-02-01 16:42:52 +00:00
|
|
|
|
} catch (GameException $e) {
|
2020-10-28 20:21:08 +00:00
|
|
|
|
echo 'Банковская ошибка!';
|
|
|
|
|
} finally {
|
|
|
|
|
unset($submit, $summa, $toid);
|
2020-10-28 12:31:17 +00:00
|
|
|
|
}
|
2021-02-01 16:42:52 +00:00
|
|
|
|
Template::header('Банк');
|
2020-07-03 10:26:38 +00:00
|
|
|
|
?>
|
2020-10-28 12:31:17 +00:00
|
|
|
|
<link href="css/secondary.css" rel="stylesheet"/>
|
|
|
|
|
<script src="js/main.js"></script>
|
2021-02-01 16:42:52 +00:00
|
|
|
|
<?php Template::buildingTop(Rooms::$roomNames[29], 'strah') ?>
|
2020-10-28 12:31:17 +00:00
|
|
|
|
<div><?= $status ?></div>
|
|
|
|
|
<div class="appblock appblock-main">
|
|
|
|
|
<span class="wrap">На счету: <span class="num"><?= $bank->getMoney() ?></span></span>
|
|
|
|
|
<hr>
|
2021-02-01 16:42:52 +00:00
|
|
|
|
<span class="wrap">На руках: <span class="num"><?= $user->getMoney() ?></span></span>
|
2020-10-28 12:31:17 +00:00
|
|
|
|
</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>
|
2021-03-10 21:03:59 +00:00
|
|
|
|
<span class="wrap">Комиссия: <?= GameConfigs::BANK_COMISSION * 100 ?>% от переводимой суммы, но не менее 1 кр.</span>
|
2020-10-28 12:31:17 +00:00
|
|
|
|
</div>
|