coupon code system eingeführt. coupons werden vom super admin gemanaged. coupons werden mit paddle synchronisiert und dort validiert. plus: einige mobil-optimierungen im tenant admin pwa.
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<?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('coupons', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
$table->string('name');
|
||||
$table->string('code')->unique();
|
||||
|
||||
$table->string('type', 40);
|
||||
$table->decimal('amount', 10, 2)->default(0);
|
||||
$table->char('currency', 3)->nullable();
|
||||
|
||||
$table->string('status', 40)->default('draft');
|
||||
$table->boolean('is_stackable')->default(false);
|
||||
$table->boolean('enabled_for_checkout')->default(true);
|
||||
$table->boolean('auto_apply')->default(false);
|
||||
|
||||
$table->unsignedInteger('usage_limit')->nullable();
|
||||
$table->unsignedInteger('per_customer_limit')->nullable();
|
||||
$table->unsignedInteger('redemptions_count')->default(0);
|
||||
|
||||
$table->text('description')->nullable();
|
||||
$table->json('metadata')->nullable();
|
||||
|
||||
$table->timestamp('starts_at')->nullable();
|
||||
$table->timestamp('ends_at')->nullable();
|
||||
|
||||
$table->string('paddle_discount_id')->nullable()->unique();
|
||||
$table->string('paddle_mode', 40)->default('standard');
|
||||
$table->json('paddle_snapshot')->nullable();
|
||||
$table->timestamp('paddle_last_synced_at')->nullable();
|
||||
|
||||
$table->foreignIdFor(\App\Models\User::class, 'created_by')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->foreignIdFor(\App\Models\User::class, 'updated_by')->nullable()->constrained('users')->nullOnDelete();
|
||||
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->index(['status', 'starts_at', 'ends_at']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('coupons');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
<?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('coupon_package', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
$table->foreignIdFor(\App\Models\Coupon::class)->constrained()->cascadeOnDelete();
|
||||
$table->foreignIdFor(\App\Models\Package::class)->constrained()->cascadeOnDelete();
|
||||
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['coupon_id', 'package_id']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('coupon_package');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,47 @@
|
||||
<?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('coupon_redemptions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
$table->foreignIdFor(\App\Models\Coupon::class)->constrained()->cascadeOnDelete();
|
||||
$table->foreignUuid('checkout_session_id')->nullable()->constrained('checkout_sessions')->nullOnDelete();
|
||||
$table->foreignIdFor(\App\Models\Package::class)->nullable()->constrained()->nullOnDelete();
|
||||
$table->foreignIdFor(\App\Models\Tenant::class)->nullable()->constrained()->nullOnDelete();
|
||||
$table->foreignIdFor(\App\Models\User::class)->nullable()->constrained()->nullOnDelete();
|
||||
|
||||
$table->string('paddle_transaction_id')->nullable();
|
||||
$table->string('status', 40)->default('pending');
|
||||
$table->text('failure_reason')->nullable();
|
||||
|
||||
$table->decimal('amount_discounted', 10, 2)->default(0);
|
||||
$table->char('currency', 3)->default('EUR');
|
||||
$table->json('metadata')->nullable();
|
||||
|
||||
$table->timestamp('redeemed_at')->nullable();
|
||||
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['status', 'redeemed_at']);
|
||||
$table->unique('paddle_transaction_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('coupon_redemptions');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
<?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::table('checkout_sessions', function (Blueprint $table) {
|
||||
$table->foreignIdFor(\App\Models\Coupon::class)->nullable()->after('package_snapshot')->constrained()->nullOnDelete();
|
||||
$table->string('coupon_code')->nullable()->after('coupon_id');
|
||||
$table->json('coupon_snapshot')->nullable()->after('coupon_code');
|
||||
|
||||
$table->decimal('amount_discount', 10, 2)->default(0)->after('amount_total');
|
||||
$table->json('discount_breakdown')->nullable()->after('amount_discount');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('checkout_sessions', function (Blueprint $table) {
|
||||
$table->dropConstrainedForeignId('coupon_id');
|
||||
$table->dropColumn(['coupon_code', 'coupon_snapshot', 'amount_discount', 'discount_breakdown']);
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user