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..66a42a5 --- /dev/null +++ b/backend/db/models/Employee.php @@ -0,0 +1,33 @@ +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)) { + 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 @@ +