10.April 2026
This commit is contained in:
parent
a00c42e770
commit
f58c709945
208 changed files with 19280 additions and 2914 deletions
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