Основные классы переехали на обёртку PDO. Плановое №16.
This commit is contained in:
+10
-12
@@ -17,7 +17,7 @@ class Bank
|
||||
public $user_id;
|
||||
private $money;
|
||||
private $user;
|
||||
private $db;
|
||||
private static $db;
|
||||
|
||||
const ERROR_NO_MONEY_IN_WALLET = "Ошибка! Нет денег в кошельке!";
|
||||
const ERROR_NO_BANK_ACCOUNT = "Ошибка! Счёта не существует!";
|
||||
@@ -31,11 +31,11 @@ class Bank
|
||||
'clanRegister' => 'Оплата стоимости регистрации клана.',
|
||||
];
|
||||
|
||||
public function __construct($row)
|
||||
public function __construct(int $user_id)
|
||||
{
|
||||
$this->db = new DBPDO();
|
||||
$bank_row = $this->db->fetch('SELECT user_id, money FROM bank WHERE user_id = ?', $row);
|
||||
$this->user = $this->db->fetch('SELECT money FROM users WHERE id = ?', $row);
|
||||
self::$db = DBPDO::INIT();
|
||||
$bank_row = self::$db->fetch('SELECT user_id, money FROM bank WHERE user_id = ?', $user_id);
|
||||
$this->user = self::$db->fetch('SELECT money FROM users WHERE id = ?', $user_id);
|
||||
foreach ($this as $key => $value) {
|
||||
if (isset($bank_row[$key])) {
|
||||
$this->$key = $bank_row[$key];
|
||||
@@ -98,7 +98,7 @@ class Bank
|
||||
*/
|
||||
public function sendMoney(int $receiver, int $amount): int
|
||||
{
|
||||
$receiverWallet = $this->db->fetch('SELECT money FROM bank WHERE user_id = ?', $receiver);
|
||||
$receiverWallet = self::$db->fetch('SELECT money FROM bank WHERE user_id = ?', $receiver);
|
||||
if ($amount <= 0) {
|
||||
throw new GameException(self::ERROR_WRONG_AMOUNT);
|
||||
}
|
||||
@@ -134,7 +134,7 @@ class Bank
|
||||
if ($amount <= 0) {
|
||||
throw new GameException(self::ERROR_WRONG_AMOUNT);
|
||||
}
|
||||
$wallet = $this->db->fetch('SELECT money FROM users WHERE id = ?', $this->user_id);
|
||||
$wallet = self::$db->fetch('SELECT money FROM users WHERE id = ?', $this->user_id);
|
||||
if ($wallet->money < $amount) {
|
||||
throw new GameException(self::ERROR_NO_MONEY_IN_WALLET);
|
||||
}
|
||||
@@ -195,10 +195,9 @@ class Bank
|
||||
public static function setBankMoney(int $amount, int $user_id, string $operationType = ''): void
|
||||
{
|
||||
try {
|
||||
$db = new DBPDO();
|
||||
$db->execute('UPDATE bank SET money = ? WHERE user_id = ?', [$amount, $user_id]);
|
||||
self::$db->execute('UPDATE bank SET money = ? WHERE user_id = ?', [$amount, $user_id]);
|
||||
if ($operationType) {
|
||||
(new Bank($user_id))->bankLogs(0, $amount, $operationType);
|
||||
GameLogs::addBankLog(0, 0, $amount, $operationType, self::LOG[$operationType]);
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
echo "Не отработал запрос в БД в файле {$e->getFile()}({$e->getLine()})";
|
||||
@@ -217,8 +216,7 @@ class Bank
|
||||
public static function setWalletMoney(int $amount, int $user_id): void
|
||||
{
|
||||
try {
|
||||
$db = new DBPDO();
|
||||
$db->execute('UPDATE users SET money = ? WHERE id = ?', [$amount, $user_id]);
|
||||
self::$db->execute('UPDATE users SET money = ? WHERE id = ?', [$amount, $user_id]);
|
||||
} catch (Throwable $e) {
|
||||
echo "Не отработал запрос в БД в файле {$e->getFile()}({$e->getLine()})";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user