From 469163c3b495e9f334011fc0c145b5c0f34295a3 Mon Sep 17 00:00:00 2001 From: OtonariShunji Date: Fri, 31 Jul 2026 09:42:04 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=E5=BE=93=E6=A5=AD=E5=93=A1=E3=80=81?= =?UTF-8?q?=E9=A1=A7=E5=AE=A2=E3=80=81=E5=B1=A5=E6=AD=B4=E3=80=81=E5=BA=97?= =?UTF-8?q?=E8=88=97=E3=81=AE=E3=83=86=E3=83=BC=E3=83=96=E3=83=AB=E3=81=AB?= =?UTF-8?q?=E3=82=AB=E3=83=A9=E3=83=A0=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=97?= =?UTF-8?q?=E3=80=81=E3=83=A2=E3=83=87=E3=83=AB=E3=82=92=E4=BD=9C=E6=88=90?= =?UTF-8?q?=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/db/blueprint.sql | 2 + .../20260730124014_create_stores_table.php | 1 + .../20260730124217_create_employees_table.php | 3 ++ .../20260730124354_create_customers_table.php | 1 + .../20260730124432_create_histories_table.php | 1 + backend/db/models/Customer.php | 43 +++++++++++++++++++ backend/db/models/Employee.php | 27 ++++++++++++ backend/db/models/History.php | 19 ++++++++ backend/db/models/Store.php | 17 ++++++++ 9 files changed, 114 insertions(+) create mode 100644 backend/db/models/Customer.php create mode 100644 backend/db/models/Employee.php create mode 100644 backend/db/models/History.php create mode 100644 backend/db/models/Store.php diff --git a/backend/db/blueprint.sql b/backend/db/blueprint.sql index d74b773..c0f9daf 100644 --- a/backend/db/blueprint.sql +++ b/backend/db/blueprint.sql @@ -9,6 +9,8 @@ CREATE TABLE IF NOT EXISTS `employees` ( `id` INT AUTO_INCREMENT PRIMARY KEY, `store_id` INT NOT NULL, `name` VARCHAR(255) NOT NULL, + `password` VARCHAR(255) NOT NULL, + `role` ENUM('admin', 'staff') NOT NULL DEFAULT 'staff', FOREIGN KEY (`store_id`) REFERENCES `stores`(`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/backend/db/migrations/20260730124014_create_stores_table.php b/backend/db/migrations/20260730124014_create_stores_table.php index 8c7247f..b774fec 100644 --- a/backend/db/migrations/20260730124014_create_stores_table.php +++ b/backend/db/migrations/20260730124014_create_stores_table.php @@ -22,6 +22,7 @@ public function change(): void $table = $this->table('stores'); $table->addColumn('parent_id', 'integer', ['null' => true, 'default' => null, 'signed'=> false]) ->addColumn('name', 'string', ['limit' => 255, 'null' => false]) + ->addTimestamps() ->create(); $table->addForeignKey('parent_id', 'stores', 'id', ['delete' => 'SET_NULL', 'update' => 'NO_ACTION']) diff --git a/backend/db/migrations/20260730124217_create_employees_table.php b/backend/db/migrations/20260730124217_create_employees_table.php index 6169bec..8c62e96 100644 --- a/backend/db/migrations/20260730124217_create_employees_table.php +++ b/backend/db/migrations/20260730124217_create_employees_table.php @@ -22,6 +22,9 @@ public function change(): void $table = $this->table('employees'); $table->addColumn('store_id', 'integer', ['null' => false, 'signed'=>false]) // integerに変更 ->addColumn('name', 'string', ['limit' => 255, 'null' => false]) + ->addColumn('password', 'string', ['limit' => 255, 'null' => false]) + ->addColumn('role', 'enum', ['values' => ['admin', 'staff'], 'default' => 'staff', 'null' => false]) + ->addTimestamps() ->addForeignKey('store_id', 'stores', 'id', ['delete' => 'CASCADE', 'update' => 'NO_ACTION']) ->create(); } diff --git a/backend/db/migrations/20260730124354_create_customers_table.php b/backend/db/migrations/20260730124354_create_customers_table.php index 4745538..187cfa1 100644 --- a/backend/db/migrations/20260730124354_create_customers_table.php +++ b/backend/db/migrations/20260730124354_create_customers_table.php @@ -23,6 +23,7 @@ public function change(): void $table->addColumn('user_id', 'biginteger', ['null' => false]) ->addColumn('paid', 'boolean', ['null' => false, 'default' => false]) ->addColumn('disabled', 'boolean', ['null' => false, 'default' => false]) + ->addTimestamps() ->addIndex(['user_id'], ['unique' => true]) ->create(); } diff --git a/backend/db/migrations/20260730124432_create_histories_table.php b/backend/db/migrations/20260730124432_create_histories_table.php index bcb5ed4..79d51d9 100644 --- a/backend/db/migrations/20260730124432_create_histories_table.php +++ b/backend/db/migrations/20260730124432_create_histories_table.php @@ -24,6 +24,7 @@ public function change(): void ->addColumn('store_id', 'integer', ['null' => false, 'signed'=>false]) ->addColumn('score', 'integer', ['null' => false]) ->addColumn('time', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP']) + ->addTimestamps() ->addForeignKey('customer_user_id', 'customers', 'user_id', ['delete' => 'NO_ACTION', 'update' => 'NO_ACTION']) ->addForeignKey('store_id', 'stores', 'id', ['delete' => 'NO_ACTION', 'update' => 'NO_ACTION']) ->addIndex(['customer_user_id', 'time']) diff --git a/backend/db/models/Customer.php b/backend/db/models/Customer.php new file mode 100644 index 0000000..0353ab3 --- /dev/null +++ b/backend/db/models/Customer.php @@ -0,0 +1,43 @@ +user_id)) { + $customer->user_id = \Illuminate\Support\Facades\DB::raw('UUID_SHORT()'); + } + }); + } + + public function pay(): void + { + $this->paid = true; + $this->save(); + } + + public function disable(): void + { + $this->disabled = true; + $this->save(); + } + + public function canPlayGame(): bool + { + return $this->paid && !$this->disabled; + } +} \ No newline at end of file diff --git a/backend/db/models/Employee.php b/backend/db/models/Employee.php new file mode 100644 index 0000000..d459313 --- /dev/null +++ b/backend/db/models/Employee.php @@ -0,0 +1,27 @@ +first(); + if ($employee && password_verify($password, $employee->password)) { + return $employee; + } + return null; + } +} \ No newline at end of file diff --git a/backend/db/models/History.php b/backend/db/models/History.php new file mode 100644 index 0000000..d5a5ca3 --- /dev/null +++ b/backend/db/models/History.php @@ -0,0 +1,19 @@ + Date: Fri, 31 Jul 2026 09:50:07 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E3=83=91=E3=82=B9=E3=83=AF=E3=83=BC?= =?UTF-8?q?=E3=83=89=E3=83=95=E3=82=A3=E3=83=BC=E3=83=AB=E3=83=89=E3=82=92?= =?UTF-8?q?fillable=E3=81=8B=E3=82=89=E9=99=A4=E5=A4=96=E3=81=97=E3=80=81h?= =?UTF-8?q?idden=E3=83=97=E3=83=AD=E3=83=91=E3=83=86=E3=82=A3=E3=81=AB?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F=E3=80=82?= =?UTF-8?q?setPassword=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E3=81=97=E3=81=A6=E3=80=81=E3=83=91=E3=82=B9?= =?UTF-8?q?=E3=83=AF=E3=83=BC=E3=83=89=E3=81=AE=E3=83=8F=E3=83=83=E3=82=B7?= =?UTF-8?q?=E3=83=A5=E5=8C=96=E3=82=92=E8=A1=8C=E3=81=84=E3=81=BE=E3=81=99?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/db/models/Employee.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/db/models/Employee.php b/backend/db/models/Employee.php index d459313..66a42a5 100644 --- a/backend/db/models/Employee.php +++ b/backend/db/models/Employee.php @@ -13,10 +13,16 @@ class Employee extends Model protected $fillable = [ 'store_id', 'name', - 'password', 'role', ]; + protected $hidden = [ + 'password', + ]; + + public function setPassword($password) { + $this->password = password_hash($password, PASSWORD_DEFAULT); + } public static function tryLogin($name, $password) :?Employee { $employee = Employee::where('name', $name)->first(); if ($employee && password_verify($password, $employee->password)) {