From 39b76d0fa734357f5df6bb7eb14ea608aaa6ca46 Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Wed, 8 Mar 2023 00:44:52 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=96=B0=E5=A2=9E=E5=8A=A0=20?= =?UTF-8?q?=E5=91=A8=E6=9C=9F=E8=AE=A1=E8=B4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...94636_add_trial_ends_at_to_hosts_table.php | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 database/migrations/2023_03_07_194636_add_trial_ends_at_to_hosts_table.php diff --git a/database/migrations/2023_03_07_194636_add_trial_ends_at_to_hosts_table.php b/database/migrations/2023_03_07_194636_add_trial_ends_at_to_hosts_table.php new file mode 100644 index 0000000..d586733 --- /dev/null +++ b/database/migrations/2023_03_07_194636_add_trial_ends_at_to_hosts_table.php @@ -0,0 +1,55 @@ +enum('billing_cycle', ['hourly', 'monthly', 'once'])->default('hourly')->index()->after('status'); + $table->tinyInteger('day_at')->nullable()->index()->after('billing_cycle'); + $table->timestamp('trial_ends_at')->nullable()->after('day_at'); + + // 不自动续费 + $table->boolean('cancel_at_period_end')->default(false)->after('trial_ends_at'); + + // 上次扣费金额 + $table->decimal('last_paid', 10)->nullable()->after('cancel_at_period_end'); + $table->timestamp('last_paid_at')->nullable()->after('last_paid'); + + // 到期时间(下次扣费时间) + $table->timestamp('expired_at')->nullable()->after('last_paid_at'); + }); + + // 为已有的主机设置默认值 + Host::all()->each(function (Host $host) { + $host->day_at = $host->created_at->day; + + $host->save(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('hosts', function (Blueprint $table) { + $table->dropColumn('trial_ends_at'); + $table->dropColumn('day_at'); + $table->dropColumn('billing_cycle'); + $table->dropColumn('cancel_at_period_end'); + $table->dropColumn('last_paid'); + $table->dropColumn('last_paid_at'); + $table->dropColumn('expired_at'); + }); + } +};