This commit is contained in:
ct
2025-07-01 23:13:09 +08:00
parent 79e7d7a49e
commit 209c022f1d
26 changed files with 374 additions and 50 deletions

View File

@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('plans', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('tier');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('plans');
}
};

View File

@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('user_plans', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id');
$table->foreignId('plan_id');
$table->dateTime('current_period_end')->nullable();
$table->dateTime('cancel_at')->nullable();
$table->dateTime('canceled_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('user_plans');
}
};

View File

@@ -0,0 +1,43 @@
<?php
namespace Database\Seeders;
use DB;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class PlanSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$plans = config('platform.purchases.subscriptions');
foreach ($plans as $plan) {
if ($plan['type'] !== 'subscription_plans') {
continue;
}
// Check if plan with this tier already exists
$existingPlan = DB::table('plans')
->where('tier', $plan['id'])
->first();
if (! $existingPlan) {
DB::table('plans')->insert([
'name' => $plan['name'],
'tier' => $plan['id'],
'created_at' => now(),
'updated_at' => now(),
]);
$this->command->info("Inserted plan: {$plan['name']}");
} else {
$this->command->info("Skipped existing plan tier: {$plan['id']}");
}
}
}
}