Новый способ запрашивать константы.

This commit is contained in:
lopar 2020-10-28 01:52:53 +02:00
parent c05c3298f1
commit 0e73bcb1ae

View File

@ -15,10 +15,13 @@ class Bank
const ERROR_NO_BANK_ACCOUNT = "Ошибка! Счёта не существует!"; const ERROR_NO_BANK_ACCOUNT = "Ошибка! Счёта не существует!";
const ERROR_NO_MONEY_IN_BANK_ACCOUNT = "Ошибка! Нет денег на счету!"; const ERROR_NO_MONEY_IN_BANK_ACCOUNT = "Ошибка! Нет денег на счету!";
const ERROR_WRONG_AMOUNT = "Ошибка! Сумма должна быть положительной!"; const ERROR_WRONG_AMOUNT = "Ошибка! Сумма должна быть положительной!";
const LOG_SEND = "Банк: Перевод средств на другой счёт."; const LOG = [
const LOG_RECEIVE = "Банк: Получение средств."; 'sendMoney' => 'Банк: Перевод средств на другой счёт.',
const LOG_DEPOSIT = "Пополнение счёта."; 'receiveMoney' => 'Банк: Получение средств.',
const LOG_WITHDRAW = "Снятие денег со счёта."; 'depositMoney' => 'Пополнение счёта.',
'withdrawMoney' => 'Снятие денег со счёта.',
'clanRegister' => 'Оплата стоимости регистрации клана.',
];
public function __construct($row) public function __construct($row)
{ {
@ -43,7 +46,7 @@ class Bank
* *
* @return int * @return int
*/ */
private function bankCommission(int $amount):int private function bankCommission(int $amount): int
{ {
$bankCommission = round($amount * Config::$bank_commission); $bankCommission = round($amount * Config::$bank_commission);
if ($bankCommission < 1) { if ($bankCommission < 1) {
@ -64,22 +67,19 @@ class Bank
* @return void * @return void
* @throws \Krugozor\Database\Mysql\Exception * @throws \Krugozor\Database\Mysql\Exception
*/ */
private function bankLogs(int $receiverId, int $amount, string $operationType, int $senderId = 0):void private function bankLogs(int $receiverId, int $amount, string $operationType, int $senderId = 0): void
{ {
if (!$senderId) { if (!$senderId) {
$senderId = $this->user_id; $senderId = $this->user_id;
} }
$text = ''; $text = self::LOG[$operationType];
if ($operationType == "sendMoney") { if ($operationType == "sendMoney") {
$text = self::LOG_SEND . " Комиссия: " . $this->bankCommission($amount); $text .= " Комиссия: " . $this->bankCommission($amount);
} elseif ($operationType == "depositMoney") { } elseif ($operationType == "depositMoney") {
$receiverId = $this->user_id; $receiverId = $this->user_id;
$text = self::LOG_DEPOSIT;
} elseif ($operationType == "withdrawMoney") { } elseif ($operationType == "withdrawMoney") {
$receiverId = $this->user_id; $receiverId = $this->user_id;
$text = self::LOG_WITHDRAW . " Комиссия: " . $this->bankCommission($amount); $text .= " Комиссия: " . $this->bankCommission($amount);
} elseif ($operationType == "receiveMoney") {
$text = self::LOG_RECEIVE;
} }
db::c()->query('INSERT INTO `bank_logs` (sender_id, receiver_id, amount_result, type, text) db::c()->query('INSERT INTO `bank_logs` (sender_id, receiver_id, amount_result, type, text)
@ -204,7 +204,8 @@ class Bank
db::c()->query('UPDATE users SET money = ?i WHERE `id` = ?i', $amount, $user_id); db::c()->query('UPDATE users SET money = ?i WHERE `id` = ?i', $amount, $user_id);
} }
public function getBankMoney() { public function getBankMoney()
{
return $this->money; return $this->money;
} }
} }