10.April 2026
This commit is contained in:
parent
a00c42e770
commit
f58c709945
208 changed files with 19280 additions and 2914 deletions
44
database/factories/IncentiveFactory.php
Normal file
44
database/factories/IncentiveFactory.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Incentive;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class IncentiveFactory extends Factory
|
||||
{
|
||||
protected $model = Incentive::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'Incentive '.$this->faker->city().' '.$this->faker->year(),
|
||||
'description' => $this->faker->sentence(),
|
||||
'terms' => $this->faker->paragraph(),
|
||||
'qualification_start' => '2026-04-01',
|
||||
'qualification_end' => '2026-07-31',
|
||||
'calculation_end' => '2026-08-31',
|
||||
'points_partner_onetime' => 600,
|
||||
'points_abo_onetime' => 400,
|
||||
'min_direct_partners' => 4,
|
||||
'min_customer_abos' => 6,
|
||||
'max_winners' => 30,
|
||||
'status' => 1, // active
|
||||
];
|
||||
}
|
||||
|
||||
public function draft(): static
|
||||
{
|
||||
return $this->state(['status' => 0]);
|
||||
}
|
||||
|
||||
public function active(): static
|
||||
{
|
||||
return $this->state(['status' => 1]);
|
||||
}
|
||||
|
||||
public function closed(): static
|
||||
{
|
||||
return $this->state(['status' => 2]);
|
||||
}
|
||||
}
|
||||
21
database/factories/IncentiveNewAboFactory.php
Normal file
21
database/factories/IncentiveNewAboFactory.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\IncentiveNewAbo;
|
||||
use App\Models\IncentiveParticipant;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class IncentiveNewAboFactory extends Factory
|
||||
{
|
||||
protected $model = IncentiveNewAbo::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'participant_id' => IncentiveParticipant::factory(),
|
||||
'user_abo_id' => $this->faker->randomNumber(3),
|
||||
'activated_at' => now(),
|
||||
];
|
||||
}
|
||||
}
|
||||
22
database/factories/IncentiveNewPartnerFactory.php
Normal file
22
database/factories/IncentiveNewPartnerFactory.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\IncentiveNewPartner;
|
||||
use App\Models\IncentiveParticipant;
|
||||
use App\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class IncentiveNewPartnerFactory extends Factory
|
||||
{
|
||||
protected $model = IncentiveNewPartner::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'participant_id' => IncentiveParticipant::factory(),
|
||||
'user_id' => fn () => User::inRandomOrder()->first()?->id ?? 1,
|
||||
'registered_at' => now(),
|
||||
];
|
||||
}
|
||||
}
|
||||
46
database/factories/IncentiveParticipantFactory.php
Normal file
46
database/factories/IncentiveParticipantFactory.php
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Incentive;
|
||||
use App\Models\IncentiveParticipant;
|
||||
use App\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class IncentiveParticipantFactory extends Factory
|
||||
{
|
||||
protected $model = IncentiveParticipant::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'incentive_id' => Incentive::factory(),
|
||||
'user_id' => fn () => User::inRandomOrder()->first()?->id ?? 1,
|
||||
'accepted_terms_at' => now(),
|
||||
'total_points' => 0,
|
||||
'qualified_partners' => 0,
|
||||
'qualified_abos' => 0,
|
||||
'is_qualified' => false,
|
||||
'rank' => null,
|
||||
];
|
||||
}
|
||||
|
||||
public function qualified(): static
|
||||
{
|
||||
return $this->state([
|
||||
'is_qualified' => true,
|
||||
'qualified_partners' => 4,
|
||||
'qualified_abos' => 6,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatisch angelegt, Teilnahmebedingungen noch nicht akzeptiert (anonym in der Rangliste).
|
||||
*/
|
||||
public function unconfirmed(): static
|
||||
{
|
||||
return $this->state([
|
||||
'accepted_terms_at' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
51
database/factories/IncentivePointsLogFactory.php
Normal file
51
database/factories/IncentivePointsLogFactory.php
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\IncentiveParticipant;
|
||||
use App\Models\IncentivePointsLog;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class IncentivePointsLogFactory extends Factory
|
||||
{
|
||||
protected $model = IncentivePointsLog::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'participant_id' => IncentiveParticipant::factory(),
|
||||
'type' => 'partner',
|
||||
'source_type' => 'App\\User',
|
||||
'source_id' => 1,
|
||||
'source_label' => $this->faker->name(),
|
||||
'month' => 4,
|
||||
'year' => 2026,
|
||||
'points_onetime' => 600,
|
||||
'points_accumulated' => 0,
|
||||
'is_storno' => false,
|
||||
];
|
||||
}
|
||||
|
||||
public function partner(): static
|
||||
{
|
||||
return $this->state([
|
||||
'type' => 'partner',
|
||||
'points_onetime' => 600,
|
||||
]);
|
||||
}
|
||||
|
||||
public function abo(): static
|
||||
{
|
||||
return $this->state([
|
||||
'type' => 'abo',
|
||||
'points_onetime' => 400,
|
||||
]);
|
||||
}
|
||||
|
||||
public function storno(): static
|
||||
{
|
||||
return $this->state([
|
||||
'is_storno' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateCountriesTable extends Migration
|
||||
{
|
||||
|
|
@ -35,13 +35,10 @@ class CreateCountriesTable extends Migration
|
|||
$table->boolean('currency_calc')->default(false);
|
||||
$table->decimal('currency_faktor', 4, 2)->nullable();
|
||||
|
||||
$table->boolean('active')->default(true);
|
||||
$table->text('trans_name')->nullable();
|
||||
$table->text('attr')->nullable();
|
||||
|
||||
$table->timestamps();
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,9 +11,11 @@ return new class extends Migration
|
|||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('dhl_package_shipments', function (Blueprint $table) {
|
||||
$table->string('routing_code')->nullable()->after('dhl_shipment_no');
|
||||
});
|
||||
if (! Schema::hasColumn('dhl_package_shipments', 'routing_code')) {
|
||||
Schema::table('dhl_package_shipments', function (Blueprint $table) {
|
||||
$table->string('routing_code')->nullable()->after('dhl_shipment_no');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('incentives', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
|
||||
$table->string('name', 255);
|
||||
$table->string('slug', 255)->unique();
|
||||
$table->text('description')->nullable();
|
||||
$table->string('image', 255)->nullable()->comment('Statisches Bild Dateiname');
|
||||
$table->text('terms')->nullable()->comment('Teilnahmebedingungen');
|
||||
|
||||
$table->date('qualification_start')->comment('Beginn Qualifikationszeitraum');
|
||||
$table->date('qualification_end')->comment('Ende Qualifikationszeitraum');
|
||||
$table->date('calculation_end')->comment('Ende Punkteberechnung (inkl. Verlaengerung)');
|
||||
|
||||
$table->unsignedInteger('points_partner_onetime')->default(600)->comment('Einmalpunkte pro Neupartner');
|
||||
$table->unsignedInteger('points_abo_onetime')->default(400)->comment('Einmalpunkte pro Kundenabo');
|
||||
$table->unsignedInteger('min_direct_partners')->default(4)->comment('Mindestanzahl direkte Teampartner');
|
||||
$table->unsignedInteger('min_customer_abos')->default(6)->comment('Mindestanzahl Kundenabos');
|
||||
$table->unsignedInteger('max_winners')->default(30)->comment('Maximale Anzahl Gewinner');
|
||||
|
||||
$table->unsignedTinyInteger('status')->default(0)->index()->comment('0=draft, 1=active, 2=closed');
|
||||
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('incentives');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('incentive_participants', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
|
||||
$table->unsignedInteger('incentive_id');
|
||||
$table->foreign('incentive_id')
|
||||
->references('id')
|
||||
->on('incentives')
|
||||
->onDelete('cascade');
|
||||
|
||||
$table->unsignedInteger('user_id');
|
||||
$table->foreign('user_id')
|
||||
->references('id')
|
||||
->on('users')
|
||||
->onDelete('cascade');
|
||||
|
||||
$table->datetime('accepted_terms_at')->comment('Zeitpunkt Teilnahme-Bestaetigung');
|
||||
|
||||
$table->integer('total_points')->default(0)->comment('Gesamtpunkte (Cache fuer Ranking)');
|
||||
$table->unsignedInteger('qualified_partners')->default(0)->comment('Anzahl qualifizierter Neupartner');
|
||||
$table->unsignedInteger('qualified_abos')->default(0)->comment('Anzahl qualifizierter Kundenabos');
|
||||
$table->boolean('is_qualified')->default(false)->index()->comment('Mindestqualifikation erreicht');
|
||||
$table->unsignedInteger('rank')->nullable()->comment('Aktuelle Platzierung');
|
||||
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['incentive_id', 'user_id'], 'incentive_user_unique');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('incentive_participants');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('incentive_points_log', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
|
||||
$table->unsignedInteger('participant_id');
|
||||
$table->foreign('participant_id')
|
||||
->references('id')
|
||||
->on('incentive_participants')
|
||||
->onDelete('cascade');
|
||||
|
||||
$table->string('type', 10)->index()->comment('partner oder abo');
|
||||
|
||||
$table->string('source_type', 100)->comment('Polymorphic: App\\User oder App\\Models\\UserAbo');
|
||||
$table->unsignedInteger('source_id')->comment('ID des Neupartners oder des Abos');
|
||||
$table->string('source_label', 255)->comment('Name/Bezeichnung fuer Anzeige');
|
||||
|
||||
$table->unsignedTinyInteger('month')->comment('Bezugsmonat');
|
||||
$table->unsignedSmallInteger('year')->comment('Bezugsjahr');
|
||||
|
||||
$table->integer('points_onetime')->default(0)->comment('Einmalpunkte (600 bzw. 400)');
|
||||
$table->integer('points_accumulated')->default(0)->comment('Akkumulierte Punkte des Monats');
|
||||
|
||||
$table->boolean('is_storno')->default(false)->index()->comment('Storno-Eintrag');
|
||||
$table->unsignedInteger('storno_of_id')->nullable()->comment('Referenz auf stornierten Eintrag');
|
||||
$table->foreign('storno_of_id')
|
||||
->references('id')
|
||||
->on('incentive_points_log');
|
||||
|
||||
$table->unsignedInteger('user_sales_volume_id')->nullable();
|
||||
$table->foreign('user_sales_volume_id')
|
||||
->references('id')
|
||||
->on('user_sales_volumes');
|
||||
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['participant_id', 'type']);
|
||||
$table->index(['source_type', 'source_id']);
|
||||
$table->index(['month', 'year']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('incentive_points_log');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('incentive_new_partners', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
|
||||
$table->unsignedInteger('participant_id');
|
||||
$table->foreign('participant_id')
|
||||
->references('id')
|
||||
->on('incentive_participants')
|
||||
->onDelete('cascade');
|
||||
|
||||
$table->unsignedInteger('user_id')->comment('Der neue Partner');
|
||||
$table->foreign('user_id')
|
||||
->references('id')
|
||||
->on('users')
|
||||
->onDelete('cascade');
|
||||
|
||||
$table->datetime('registered_at')->comment('Registrierungsdatum des Partners');
|
||||
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['participant_id', 'user_id'], 'participant_partner_unique');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('incentive_new_partners');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('incentive_new_abos', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
|
||||
$table->unsignedInteger('participant_id');
|
||||
$table->foreign('participant_id')
|
||||
->references('id')
|
||||
->on('incentive_participants')
|
||||
->onDelete('cascade');
|
||||
|
||||
$table->unsignedInteger('user_abo_id')->comment('Das Kundenabo');
|
||||
$table->foreign('user_abo_id')
|
||||
->references('id')
|
||||
->on('user_abos')
|
||||
->onDelete('cascade');
|
||||
|
||||
$table->datetime('activated_at')->comment('Aktivierungsdatum des Abos');
|
||||
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['participant_id', 'user_abo_id'], 'participant_abo_unique');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('incentive_new_abos');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('user_sales_volumes', function (Blueprint $table) {
|
||||
if (! Schema::hasColumn('user_sales_volumes', 'info')) {
|
||||
$table->string('info', 255)->nullable()->after('message');
|
||||
}
|
||||
if (! Schema::hasColumn('user_sales_volumes', 'month_KP_points')) {
|
||||
$table->decimal('month_KP_points', 13, 2)->nullable()->after('month_shop_points');
|
||||
}
|
||||
if (! Schema::hasColumn('user_sales_volumes', 'month_TP_points')) {
|
||||
$table->decimal('month_TP_points', 13, 2)->nullable()->after('month_KP_points');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('user_sales_volumes', function (Blueprint $table) {
|
||||
$table->dropColumn(['info', 'month_KP_points', 'month_TP_points']);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('incentives', function (Blueprint $table) {
|
||||
$table->json('trans_name')->nullable()->after('name');
|
||||
$table->json('trans_description')->nullable()->after('description');
|
||||
$table->json('trans_terms')->nullable()->after('terms');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('incentives', function (Blueprint $table) {
|
||||
$table->dropColumn(['trans_name', 'trans_description', 'trans_terms']);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('incentives', function (Blueprint $table) {
|
||||
$table->string('subtitle')->nullable()->after('name');
|
||||
$table->json('trans_subtitle')->nullable()->after('trans_name');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('incentives', function (Blueprint $table) {
|
||||
$table->dropColumn(['subtitle', 'trans_subtitle']);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('incentive_points_log', function (Blueprint $table) {
|
||||
$table->unsignedInteger('incentive_new_partner_id')->nullable()->after('user_sales_volume_id');
|
||||
$table->unsignedInteger('incentive_new_abo_id')->nullable()->after('incentive_new_partner_id');
|
||||
|
||||
$table->foreign('incentive_new_partner_id')
|
||||
->references('id')
|
||||
->on('incentive_new_partners')
|
||||
->nullOnDelete();
|
||||
|
||||
$table->foreign('incentive_new_abo_id')
|
||||
->references('id')
|
||||
->on('incentive_new_abos')
|
||||
->nullOnDelete();
|
||||
|
||||
$table->index('incentive_new_partner_id');
|
||||
$table->index('incentive_new_abo_id');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('incentive_points_log', function (Blueprint $table) {
|
||||
$table->dropForeign(['incentive_new_partner_id']);
|
||||
$table->dropForeign(['incentive_new_abo_id']);
|
||||
$table->dropColumn(['incentive_new_partner_id', 'incentive_new_abo_id']);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('incentive_participants', function (Blueprint $table) {
|
||||
$table->datetime('accepted_terms_at')->nullable()->change()->comment('Zeitpunkt Teilnahme-Bestaetigung; null = automatisch erfasst, noch nicht zugestimmt');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('incentive_participants', function (Blueprint $table) {
|
||||
$table->datetime('accepted_terms_at')->nullable(false)->change()->comment('Zeitpunkt Teilnahme-Bestaetigung');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
<?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('abo_chart_snapshots', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('user_id');
|
||||
$table->string('scope', 50); // 'ot' | 'team_abos' | 'team_cust_abos'
|
||||
$table->unsignedSmallInteger('year');
|
||||
$table->unsignedTinyInteger('month');
|
||||
$table->unsignedInteger('count')->default(0);
|
||||
$table->timestamp('calculated_at');
|
||||
$table->timestamps();
|
||||
|
||||
// Einmaliger Eintrag pro User/Scope/Monat – verhindert Doppeleinträge
|
||||
$table->unique(['user_id', 'scope', 'year', 'month']);
|
||||
$table->index(['user_id', 'scope', 'year']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('abo_chart_snapshots');
|
||||
}
|
||||
};
|
||||
53
database/seeders/IncentiveParticipantSeeder.php
Normal file
53
database/seeders/IncentiveParticipantSeeder.php
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\IncentiveParticipant;
|
||||
use App\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class IncentiveParticipantSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Spielt Teilnehmer fuer Incentive ID 1 ein.
|
||||
* Nimmt aktive Berater (mit m_sponsor) sortiert nach Anzahl direkter Partner.
|
||||
* Bereits bestehende Teilnehmer werden uebersprungen.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$incentive_id = 1;
|
||||
$limit = 50;
|
||||
|
||||
// Bereits teilnehmende User-IDs
|
||||
$existing_user_ids = IncentiveParticipant::where('incentive_id', $incentive_id)
|
||||
->pluck('user_id')
|
||||
->toArray();
|
||||
|
||||
// Aktive Berater mit den meisten direkten Partnern holen
|
||||
$consultants = User::where('active', 1)
|
||||
->whereNotNull('m_sponsor')
|
||||
->whereNotIn('id', $existing_user_ids)
|
||||
->select('users.*')
|
||||
->selectSub(
|
||||
DB::table('users as u2')->selectRaw('COUNT(*)')->whereColumn('u2.m_sponsor', 'users.id'),
|
||||
'direct_partners_count'
|
||||
)
|
||||
->orderByDesc('direct_partners_count')
|
||||
->limit($limit)
|
||||
->get();
|
||||
|
||||
$count = 0;
|
||||
foreach ($consultants as $consultant) {
|
||||
IncentiveParticipant::create([
|
||||
'incentive_id' => $incentive_id,
|
||||
'user_id' => $consultant->id,
|
||||
'accepted_terms_at' => Carbon::now(),
|
||||
]);
|
||||
$count++;
|
||||
}
|
||||
|
||||
$this->command->info("Incentive #{$incentive_id}: {$count} Teilnehmer hinzugefuegt (bestehende uebersprungen).");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue