diff --git a/app/Enums/StrategyKey.php b/app/Enums/StrategyKey.php new file mode 100644 index 00000000..6b2b73b8 --- /dev/null +++ b/app/Enums/StrategyKey.php @@ -0,0 +1,14 @@ + ['required', 'confirmed', Rules\Password::defaults()], ]); + // TODO 获取默认组 + $user = User::create([ 'name' => $request->name, 'email' => $request->email, 'password' => Hash::make($request->password), + 'registered_ip' => $request->ip(), + 'status' => UserStatus::Normal, ]); event(new Registered($user)); diff --git a/app/Models/Album.php b/app/Models/Album.php new file mode 100644 index 00000000..1373a278 --- /dev/null +++ b/app/Models/Album.php @@ -0,0 +1,46 @@ + '', + ]; + + public function user(): BelongsTo + { + return $this->belongsTo(User::class, 'user_id', 'id'); + } + + public function images(): HasMany + { + return $this->hasMany(Image::class, 'album_id', 'id'); + } +} diff --git a/app/Models/Config.php b/app/Models/Config.php new file mode 100644 index 00000000..1d923d4c --- /dev/null +++ b/app/Models/Config.php @@ -0,0 +1,19 @@ + 'bool', + 'configs' => 'collection', + ]; + + public function users(): HasMany + { + return $this->hasMany(User::class, 'user_id', 'id'); + } + + public function strategies(): HasMany + { + return $this->hasMany(Strategy::class, 'group_id', 'id'); + } +} diff --git a/app/Models/Image.php b/app/Models/Image.php new file mode 100644 index 00000000..b07afb1f --- /dev/null +++ b/app/Models/Image.php @@ -0,0 +1,78 @@ + 'float', + 'is_unhealthy' => 'bool', + ]; + + public function user(): BelongsTo + { + return $this->belongsTo(User::class, 'user_id', 'id'); + } + + public function album(): BelongsTo + { + return $this->belongsTo(Album::class, 'album_id', 'id'); + } + + public function strategy(): BelongsTo + { + return $this->belongsTo(Strategy::class, 'strategy_id', 'id'); + } +} diff --git a/app/Models/Strategy.php b/app/Models/Strategy.php new file mode 100644 index 00000000..2a63e4ad --- /dev/null +++ b/app/Models/Strategy.php @@ -0,0 +1,57 @@ + '', + ]; + + protected $casts = [ + 'configs' => 'collection', + ]; + + public function group(): BelongsTo + { + return $this->belongsTo(Group::class, 'group_id', 'id'); + } + + public function images(): HasMany + { + return $this->hasMany(Image::class, 'strategy_id', 'id'); + } +} diff --git a/app/Models/User.php b/app/Models/User.php index fd31d7b5..4e5a512b 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -2,12 +2,36 @@ namespace App\Models; -use Illuminate\Contracts\Auth\MustVerifyEmail; +use Carbon\Carbon; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; +use Illuminate\Support\Collection; use Laravel\Sanctum\HasApiTokens; +/** + * @property int $id + * @property int $group_id + * @property string $name + * @property string $email + * @property string $password + * @property string $remember_token + * @property boolean $is_adminer + * @property float $capacity + * @property Collection $configs + * @property int $image_num + * @property int $album_num + * @property string $registered_ip + * @property string $status + * @property Carbon $email_verified_at + * @property Carbon $updated_at + * @property Carbon $created_at + * @property-read Group $group + * @property-read Album[] $albums + * @property-read Image[] $images + */ class User extends Authenticatable { use HasApiTokens, HasFactory, Notifiable; @@ -21,6 +45,8 @@ class User extends Authenticatable 'name', 'email', 'password', + 'configs', + 'registered_ip', ]; /** @@ -44,6 +70,34 @@ class User extends Authenticatable * @var array */ protected $casts = [ + 'capacity' => 'float', + 'is_adminer' => 'bool', + 'configs' => 'collection', 'email_verified_at' => 'datetime', ]; + + protected static function booted() + { + static::creating(function (self $user) { + $user->configs = collect([ + 'default_album' => 0, + 'default_strategy' => 0, + ])->merge($user->configs ?: []); + }); + } + + public function group(): BelongsTo + { + return $this->belongsTo(Group::class, 'group_id', 'id'); + } + + public function album(): HasMany + { + return $this->hasMany(Album::class, 'user_id', 'id'); + } + + public function images(): HasMany + { + return $this->hasMany(Image::class, 'user_id', 'id'); + } } diff --git a/composer.json b/composer.json index ac08734f..2b15f96d 100644 --- a/composer.json +++ b/composer.json @@ -6,6 +6,7 @@ "license": "MIT", "require": { "php": "^7.3|^8.0", + "bensampo/laravel-enum": "^4.1", "fruitcake/laravel-cors": "^2.0", "guzzlehttp/guzzle": "^7.0.1", "laravel/breeze": "^1.5", diff --git a/composer.lock b/composer.lock index 670ce6ef..b734438a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "83073760f6b879d24c8174081d99c814", + "content-hash": "e48f64e43c40bcd6fa323a8af28df3c2", "packages": [ { "name": "asm89/stack-cors", @@ -68,6 +68,95 @@ }, "time": "2021-03-11T06:42:03+00:00" }, + { + "name": "bensampo/laravel-enum", + "version": "v4.1.0", + "source": { + "type": "git", + "url": "https://github.com/BenSampo/laravel-enum.git", + "reference": "27e5a82e1830495e6b88bab6d38389b730c05e39" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/BenSampo/laravel-enum/zipball/27e5a82e1830495e6b88bab6d38389b730c05e39", + "reference": "27e5a82e1830495e6b88bab6d38389b730c05e39", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "hanneskod/classtools": "^1.2", + "illuminate/contracts": "^8.0", + "illuminate/support": "^8.0", + "laminas/laminas-code": "^3.4|^4.0", + "nikic/php-parser": "^4.10", + "php": "^7.3|^8.0" + }, + "require-dev": { + "doctrine/dbal": "^2.9|^3.0", + "mockery/mockery": "^1.4", + "orchestra/testbench": "^6.2", + "phpstan/phpstan": "^0.12.59", + "phpunit/phpunit": "^8.5", + "squizlabs/php_codesniffer": "^3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + }, + "laravel": { + "providers": [ + "BenSampo\\Enum\\EnumServiceProvider" + ] + }, + "phpstan": { + "includes": [ + "extension.neon" + ] + } + }, + "autoload": { + "psr-4": { + "BenSampo\\Enum\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ben Sampson", + "homepage": "https://sampo.co.uk", + "role": "Developer" + } + ], + "description": "Simple, extensible and powerful enumeration implementation for Laravel.", + "homepage": "https://github.com/bensampo/laravel-enum", + "keywords": [ + "bensampo", + "enum", + "laravel", + "package", + "validation" + ], + "support": { + "issues": "https://github.com/BenSampo/laravel-enum/issues", + "source": "https://github.com/BenSampo/laravel-enum/tree/v4.1.0" + }, + "funding": [ + { + "url": "https://github.com/bensampo", + "type": "github" + } + ], + "time": "2021-11-16T10:29:06+00:00" + }, { "name": "brick/math", "version": "0.9.3", @@ -1031,6 +1120,133 @@ ], "time": "2021-10-06T17:43:30+00:00" }, + { + "name": "hanneskod/classtools", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/hanneskod/classtools.git", + "reference": "d365ddac0e602027c0471ea292f4ba2afcb49394" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/hanneskod/classtools/zipball/d365ddac0e602027c0471ea292f4ba2afcb49394", + "reference": "d365ddac0e602027c0471ea292f4ba2afcb49394", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "nikic/php-parser": "^4", + "php": ">=7.1", + "symfony/finder": "^4|^5" + }, + "type": "library", + "autoload": { + "psr-4": { + "hanneskod\\classtools\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "WTFPL" + ], + "authors": [ + { + "name": "Hannes Forsgård", + "email": "hannes.forsgard@fripost.org" + } + ], + "description": "Find, extract and process classes from file system", + "homepage": "https://github.com/hanneskod/classtools", + "keywords": [ + "class finder", + "code generator", + "metaprogramming", + "minimizer" + ], + "support": { + "issues": "https://github.com/hanneskod/classtools/issues", + "source": "https://github.com/hanneskod/classtools/tree/1.0" + }, + "time": "2020-03-05T20:41:28+00:00" + }, + { + "name": "laminas/laminas-code", + "version": "4.5.0", + "source": { + "type": "git", + "url": "https://github.com/laminas/laminas-code.git", + "reference": "c99ef8e5629c33bfaa3a8f1df773e916af564cd6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laminas/laminas-code/zipball/c99ef8e5629c33bfaa3a8f1df773e916af564cd6", + "reference": "c99ef8e5629c33bfaa3a8f1df773e916af564cd6", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=7.4, <8.2" + }, + "require-dev": { + "doctrine/annotations": "^1.13.2", + "ext-phar": "*", + "laminas/laminas-coding-standard": "^2.3.0", + "laminas/laminas-stdlib": "^3.6.1", + "phpunit/phpunit": "^9.5.10", + "psalm/plugin-phpunit": "^0.16.1", + "vimeo/psalm": "^4.13.1" + }, + "suggest": { + "doctrine/annotations": "Doctrine\\Common\\Annotations >=1.0 for annotation features", + "laminas/laminas-stdlib": "Laminas\\Stdlib component" + }, + "type": "library", + "autoload": { + "psr-4": { + "Laminas\\Code\\": "src/" + }, + "files": [ + "polyfill/ReflectionEnumPolyfill.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "Extensions to the PHP Reflection API, static code scanning, and code generation", + "homepage": "https://laminas.dev", + "keywords": [ + "code", + "laminas", + "laminasframework" + ], + "support": { + "chat": "https://laminas.dev/chat", + "docs": "https://docs.laminas.dev/laminas-code/", + "forum": "https://discourse.laminas.dev", + "issues": "https://github.com/laminas/laminas-code/issues", + "rss": "https://github.com/laminas/laminas-code/releases.atom", + "source": "https://github.com/laminas/laminas-code" + }, + "funding": [ + { + "url": "https://funding.communitybridge.org/projects/laminas-project", + "type": "community_bridge" + } + ], + "time": "2021-12-07T06:00:32+00:00" + }, { "name": "laravel-lang/lang", "version": "10.1.11", diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index 2fafbd5d..84c56c04 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -30,7 +30,7 @@ class CreateUsersTable extends Migration $table->unsignedBigInteger('image_num')->default(0)->comment('图片数量'); $table->unsignedBigInteger('album_num')->default(0)->comment('相册数量'); $table->string('registered_ip')->default('')->comment('注册IP'); - $table->enum('status', ['normal', 'frozen'])->default('normal'); + $table->unsignedTinyInteger('status')->default(1)->comment('状态'); $table->timestamp('email_verified_at')->nullable(); $table->timestamps(); }); diff --git a/database/migrations/2021_12_11_184521_create_strategies_table.php b/database/migrations/2021_12_11_184521_create_strategies_table.php index f507ef81..9d47fd34 100644 --- a/database/migrations/2021_12_11_184521_create_strategies_table.php +++ b/database/migrations/2021_12_11_184521_create_strategies_table.php @@ -20,7 +20,7 @@ class CreateStrategiesTable extends Migration $table->id(); $table->foreignId('group_id')->comment('角色组')->constrained('groups')->onDelete('cascade'); - $table->enum('key', ['local'])->default('local'); + $table->unsignedTinyInteger('key'); $table->string('name', 64)->comment('策略名称'); $table->string('intro', 255)->default('')->comment('简介'); $table->json('configs')->comment('策略配置');