From a10f3911f24d909c15ba1d0a49ecf64bef5fe66a Mon Sep 17 00:00:00 2001 From: "Igor Barkov (iwork)" Date: Wed, 27 Jan 2021 13:30:11 +0200 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=BE=D0=B3=D0=B3=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D1=83=D0=B5=D1=85=D0=B0=D0=BB?= =?UTF-8?q?=D0=BE=20=D0=B2=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- classes/Battles/Bank.php | 12 +------- classes/Battles/GameLogs.php | 54 ++++++++++++++++++++++++++++++++++++ enter.php | 7 ++--- 3 files changed, 57 insertions(+), 16 deletions(-) create mode 100644 classes/Battles/GameLogs.php diff --git a/classes/Battles/Bank.php b/classes/Battles/Bank.php index 3cb4de2..b1c00a3 100644 --- a/classes/Battles/Bank.php +++ b/classes/Battles/Bank.php @@ -90,17 +90,7 @@ class Bank $receiverId = $this->user_id; $text .= " Комиссия: " . $this->bankCommission($amount); } - - $db = new SQLite3('databases/logs.sqlite'); - $db->exec("CREATE TABLE IF NOT EXISTS bank_logs (id integer constraint bank_logs_pk primary key autoincrement, sender_id integer, receiver_id integer, amount integer, type text, text text)"); - $logLine = $db->prepare("INSERT INTO bank_logs (sender_id, receiver_id, amount, type, text) VALUES (?, ?, ?, ?, ?)"); - $logLine->bindParam(1, $senderId, SQLITE3_INTEGER); - $logLine->bindParam(2, $receiverId, SQLITE3_INTEGER); - $logLine->bindParam(3, $amount, SQLITE3_INTEGER); - $logLine->bindParam(4, $operationType, SQLITE3_TEXT); - $logLine->bindParam(5, $text, SQLITE3_TEXT); - $logLine->execute(); - $logLine->close(); + GameLogs::addBankLog($senderId,$receiverId,$amount,$operationType,$text); } /** diff --git a/classes/Battles/GameLogs.php b/classes/Battles/GameLogs.php new file mode 100644 index 0000000..fd91a19 --- /dev/null +++ b/classes/Battles/GameLogs.php @@ -0,0 +1,54 @@ +prepare("INSERT INTO bank_logs (sender_id, receiver_id, amount, type, text) VALUES (?, ?, ?, ?, ?)"); + $row->bindParam(1, $senderId, SQLITE3_INTEGER); + $row->bindParam(2, $receiverId, SQLITE3_INTEGER); + $row->bindParam(3, $amount, SQLITE3_INTEGER); + $row->bindParam(4, $type, SQLITE3_TEXT); + $row->bindParam(5, $text, SQLITE3_TEXT); + $row->execute(); + $row->close(); + } + + /** + * Добавление записи в лог пользовательских операций (личное дело). + * @param int $userId кому добавляется запись. + * @param string $text текст записи. + * @param string $type тип записи. + * @param int $authorId кто добавляет запись. Использовать -1 для системной записи по умолчанию. + */ + public static function addUserLog(int $userId, string $text, string $type = '', int $authorId = 0) + { + if (empty($authorId)) { + $authorId = -1; + } + if (empty($type)) { + $type = "system"; + } + $db = new SQLite3('databases/logs.sqlite'); + $row = $db->prepare("INSERT INTO users_logs (user_id, author_id, type, text) VALUES (?,?,?,?)"); + $row->bindParam(1, $userId, SQLITE3_INTEGER); + $row->bindParam(2, $authorId, SQLITE3_INTEGER); + $row->bindParam(3, $type, SQLITE3_TEXT); + $row->bindParam(4, $text, SQLITE3_TEXT); + $row->execute(); + $row->close(); + } +} \ No newline at end of file diff --git a/enter.php b/enter.php index 92030f8..9ea620e 100644 --- a/enter.php +++ b/enter.php @@ -1,5 +1,6 @@ prepare("INSERT INTO users_logs (user_id, type, text) VALUES (?, 'multiaccounts', 'Разные ID на входе. Возможно используются несколько аккаунтов.')"); - $logLine->bindParam(1, $user_query['id'], SQLITE3_INTEGER); - $logLine->execute(); - $logLine->close(); + GameLogs::addUserLog($user_query['id'],'Разные ID на входе. Возможно используются несколько аккаунтов.', 'multiaccounts'); } setcookie("battle", $user_query['id']);