diff --git a/app/Models/AdminUser.php b/app/Models/AdminUser.php index 99ddb4a..1383a71 100644 --- a/app/Models/AdminUser.php +++ b/app/Models/AdminUser.php @@ -10,6 +10,10 @@ class AdminUser extends BaseAdminModel { use HasApiTokens, Filterable; + protected $casts = [ + 'banned_at' => 'datetime', + ]; + protected $fillable = [ 'name', 'username', @@ -20,6 +24,8 @@ class AdminUser extends BaseAdminModel 'status', 'is_enable', 'view_all_bases', + 'banned_reason', + 'banned_at', ]; protected $hidden = [ diff --git a/database/migrations/2023_10_30_154347_add_view_all_bases_to_admin_users_table.php b/database/migrations/2023_10_30_154347_add_view_all_bases_to_admin_users_table.php index 4df3b42..03f7bf8 100644 --- a/database/migrations/2023_10_30_154347_add_view_all_bases_to_admin_users_table.php +++ b/database/migrations/2023_10_30_154347_add_view_all_bases_to_admin_users_table.php @@ -6,6 +6,16 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { + public function getConnection() + { + return $this->config('database.connection') ?: config('database.default'); + } + + public function config($key) + { + return config('admin.'.$key); + } + /** * Run the migrations. * @@ -13,7 +23,7 @@ return new class extends Migration */ public function up() { - Schema::table('admin_users', function (Blueprint $table) { + Schema::table($this->config('database.users_table'), function (Blueprint $table) { $table->boolean('view_all_bases')->default(false)->comment('是否可查看所有基地'); }); } @@ -25,7 +35,7 @@ return new class extends Migration */ public function down() { - Schema::table('admin_users', function (Blueprint $table) { + Schema::table($this->config('database.users_table'), function (Blueprint $table) { $table->dropColumn(['view_all_bases']); }); } diff --git a/database/migrations/2023_12_04_162706_add_banned_at_to_admin_users_table.php b/database/migrations/2023_12_04_162706_add_banned_at_to_admin_users_table.php new file mode 100644 index 0000000..3116075 --- /dev/null +++ b/database/migrations/2023_12_04_162706_add_banned_at_to_admin_users_table.php @@ -0,0 +1,43 @@ +config('database.connection') ?: config('database.default'); + } + + public function config($key) + { + return config('admin.'.$key); + } + + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::table($this->config('database.users_table'), function (Blueprint $table) { + $table->string('banned_reason')->nullable()->comment('封禁原因'); + $table->timestamp('banned_at')->nullable()->comment('封禁时间'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table($this->config('database.users_table'), function (Blueprint $table) { + $table->timestamp(['banned_reason', 'banned_at']); + }); + } +};