20-02-2026
This commit is contained in:
parent
a8b395e20d
commit
a00c42e770
252 changed files with 28785 additions and 8907 deletions
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Cron\BusinessUsersStore;
|
||||
use App\Cron\UserLevelUpdate;
|
||||
use App\Cron\UserPaymentCredits;
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class BusinessStore extends Command
|
||||
{
|
||||
|
|
@ -27,14 +27,15 @@ class BusinessStore extends Command
|
|||
protected $description = 'Create Business Structure and UserDetails with optimized performance';
|
||||
|
||||
private $timeStart;
|
||||
|
||||
private $month;
|
||||
|
||||
private $year;
|
||||
|
||||
private $sendCreditMail = false;
|
||||
|
||||
private $sendUpdateMail = false;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
|
|
@ -45,6 +46,58 @@ class BusinessStore extends Command
|
|||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft ob der Command heute ausgeführt werden soll
|
||||
*
|
||||
* WICHTIG: Diese Methode verhindert, dass der Command täglich läuft!
|
||||
* Der Command sollte nur am konfigurierten Tag des Monats laufen.
|
||||
*
|
||||
* @return bool True wenn Command ausgeführt werden soll, False sonst
|
||||
*/
|
||||
private function shouldExecuteToday(): bool
|
||||
{
|
||||
// Hole konfigurierten Ausführungstag (Standard: 1 = Monatserster)
|
||||
$executeDay = (int) Setting::getContentBySlug('day-exectute-business-structur');
|
||||
|
||||
// Fallback: Wenn Setting leer oder 0, verwende Tag 1
|
||||
if ($executeDay === 0) {
|
||||
$executeDay = 1;
|
||||
$this->warn('Setting "day-exectute-business-structur" ist leer oder 0. Verwende Standard: Tag 1');
|
||||
\Log::channel('cron')->warning('BusinessStore: Setting day-exectute-business-structur is empty, using default: 1');
|
||||
}
|
||||
|
||||
$presentDay = (int) date('d');
|
||||
|
||||
// Logging für Debugging
|
||||
$this->info("BusinessStore: Configured Day: {$executeDay}, Present Day: {$presentDay}");
|
||||
\Log::channel('cron')->info("BusinessStore: Configured Day: {$executeDay}, Present Day: {$presentDay}");
|
||||
|
||||
// Prüfe ob heute der konfigurierte Tag ist
|
||||
if ($executeDay !== $presentDay) {
|
||||
// Erlaubnis zum Überschreiben für Entwicklung/Testing
|
||||
// ENV-Variable BUSINESS_FORCE_EXECUTE=true überschreibt den Check
|
||||
if (env('BUSINESS_FORCE_EXECUTE', false) === true) {
|
||||
$this->warn('⚠️ BUSINESS_FORCE_EXECUTE ist aktiv - Command wird trotz falschem Tag ausgeführt!');
|
||||
$this->warn('⚠️ Dies sollte NUR auf Test-Servern verwendet werden!');
|
||||
\Log::channel('cron')->warning('BusinessStore: FORCED execution via BUSINESS_FORCE_EXECUTE');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Command sollte heute NICHT laufen
|
||||
$this->info("❌ Command wird NICHT ausgeführt - falscher Tag (erwartet: {$executeDay}, heute: {$presentDay})");
|
||||
\Log::channel('cron')->info("BusinessStore: NOT EXECUTED - wrong day (expected: {$executeDay}, today: {$presentDay})");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Command wird ausgeführt
|
||||
$this->info("✅ Command wird ausgeführt - korrekter Tag ({$presentDay})");
|
||||
\Log::channel('cron')->info("BusinessStore: EXECUTING - correct day ({$presentDay})");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
|
|
@ -53,29 +106,21 @@ class BusinessStore extends Command
|
|||
public function handle()
|
||||
{
|
||||
try {
|
||||
$executeDay = (int) Setting::getContentBySlug('day-exectute-business-structur');
|
||||
$presentDay = (int) date('d');
|
||||
|
||||
$this->info('RUN Command BusinessStore on Day: ' . $executeDay);
|
||||
$this->info('RUN Command BusinessStore present Day: ' . $presentDay);
|
||||
\Log::channel('cron')->info('RUN Command BusinessStore on Day: ' . $executeDay);
|
||||
\Log::channel('cron')->info('RUN Command BusinessStore present Day: ' . $presentDay);
|
||||
$this->logMemoryUsage('Command Start');
|
||||
|
||||
if ($executeDay !== $presentDay) {
|
||||
$this->info('NOT RUN Command BusinessStore is not present Day: ' . $presentDay);
|
||||
\Log::channel('cron')->info('NOT RUN Command BusinessStore is not present Day: ' . $presentDay);
|
||||
// Prüfe ob Command am richtigen Tag ausgeführt werden soll
|
||||
if (! $this->shouldExecuteToday()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$this->logMemoryUsage('Command Start');
|
||||
|
||||
$this->timeStart = microtime(true);
|
||||
|
||||
// Argumente mit Standardwerten für den Vormonat
|
||||
$this->month = $this->argument('month') ?: (int) date("m", strtotime("-1 month"));
|
||||
$this->year = $this->argument('year') ?: (int) date("Y", strtotime("-1 month"));
|
||||
$this->month = $this->argument('month') ?: (int) date('m', strtotime('-1 month'));
|
||||
$this->year = $this->argument('year') ?: (int) date('Y', strtotime('-1 month'));
|
||||
|
||||
$this->info('RUN Command BusinessStore on month: ' . $this->month . ' | year: ' . $this->year);
|
||||
\Log::channel('cron')->info('RUN Command BusinessStore on month: ' . $this->month . ' | year: ' . $this->year);
|
||||
$this->info('RUN Command BusinessStore on month: '.$this->month.' | year: '.$this->year);
|
||||
\Log::channel('cron')->info('RUN Command BusinessStore on month: '.$this->month.' | year: '.$this->year);
|
||||
$this->logMemoryUsage('Parameters initialized');
|
||||
|
||||
// Prozesse ausführen mit Fehlerbehandlung
|
||||
|
|
@ -98,9 +143,10 @@ class BusinessStore extends Command
|
|||
|
||||
return 0;
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Command failed with error: ' . $e->getMessage());
|
||||
$this->error('Stack trace: ' . $e->getTraceAsString());
|
||||
$this->error('Command failed with error: '.$e->getMessage());
|
||||
$this->error('Stack trace: '.$e->getTraceAsString());
|
||||
$this->logExecutionTime('COMMAND FAILED');
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -108,25 +154,25 @@ class BusinessStore extends Command
|
|||
private function storeBusinessStructureUsersDetailMonth()
|
||||
{
|
||||
|
||||
$this->info('storeBusinessStructureUsersDetailMonth month: ' . $this->month . ' year:' . $this->year);
|
||||
$this->info('storeBusinessStructureUsersDetailMonth month: '.$this->month.' year:'.$this->year);
|
||||
$businessUsersStore = new BusinessUsersStore($this->month, $this->year);
|
||||
$businessUsersStore->storeUserBusinessStructure();
|
||||
$businessUsersStore->storeBusinessUsersDetail();
|
||||
$bool = $businessUsersStore->storeBusinessCompleted();
|
||||
|
||||
$this->logExecutionTime('END Command storeBusinessStructureUsersDetailMonth: ' . $bool);
|
||||
$this->logExecutionTime('END Command storeBusinessStructureUsersDetailMonth: '.$bool);
|
||||
}
|
||||
|
||||
private function userBusinessCommissionsToCredit()
|
||||
{
|
||||
|
||||
$this->info('userBusinessCommissionsToCredit month: ' . $this->month . ' year:' . $this->year);
|
||||
$this->info('userBusinessCommissionsToCredit month: '.$this->month.' year:'.$this->year);
|
||||
$userPaymentCredits = new UserPaymentCredits($this->month, $this->year);
|
||||
$userBusinesses = $userPaymentCredits->getUserBusinessByMonthYear();
|
||||
|
||||
foreach ($userBusinesses as $userBusiness) {
|
||||
$ret = $userPaymentCredits->addUserCreditItem($userBusiness);
|
||||
$this->info('userBusinessCredit: ' . $ret->user_id . ' : Team: ' . $ret->commission_pp_total . ' | Shop: ' . $ret->commission_shop_sales);
|
||||
$this->info('userBusinessCredit: '.$ret->user_id.' : Team: '.$ret->commission_pp_total.' | Shop: '.$ret->commission_shop_sales);
|
||||
}
|
||||
$this->logExecutionTime('END Command userBusinessCommissionsToCredit:');
|
||||
}
|
||||
|
|
@ -134,13 +180,13 @@ class BusinessStore extends Command
|
|||
private function userCreatePaymentCreditsPDF()
|
||||
{
|
||||
|
||||
$this->info('userCreatePaymentCreditsPDF month: ' . $this->month . ' year:' . $this->year);
|
||||
$this->info('userCreatePaymentCreditsPDF month: '.$this->month.' year:'.$this->year);
|
||||
$userPaymentCredits = new UserPaymentCredits($this->month, $this->year);
|
||||
$creditItemUsers = $userPaymentCredits->getUserCreditItemUsersByMonthYear();
|
||||
|
||||
foreach ($creditItemUsers as $creditItemUser) {
|
||||
$bool = $userPaymentCredits->makeCreditPaymentPDF($creditItemUser->user_id, $this->sendCreditMail);
|
||||
$this->info('creditsPDF: ' . $bool . ' user_id: ' . $creditItemUser->user_id);
|
||||
$this->info('creditsPDF: '.$bool.' user_id: '.$creditItemUser->user_id);
|
||||
}
|
||||
|
||||
$this->logExecutionTime('END Command userCreatePaymentCreditsPDF:');
|
||||
|
|
@ -149,7 +195,7 @@ class BusinessStore extends Command
|
|||
private function userLevelUpdate()
|
||||
{
|
||||
|
||||
$this->info('userLevelUpdate month: ' . $this->month . ' year:' . $this->year);
|
||||
$this->info('userLevelUpdate month: '.$this->month.' year:'.$this->year);
|
||||
|
||||
$userLevelUpdate = new UserLevelUpdate($this->month, $this->year);
|
||||
$levelUpdateUsers = $userLevelUpdate->getUserBusinessByMonthYear();
|
||||
|
|
@ -157,26 +203,24 @@ class BusinessStore extends Command
|
|||
foreach ($levelUpdateUsers as $userBusiness) {
|
||||
$ret = $userLevelUpdate->makeUserLevelUpdate($userBusiness, $this->sendUpdateMail);
|
||||
if ($ret) {
|
||||
$this->info('updateLevel: ' . $userBusiness->user->id . ' | ' . $userBusiness->user->email . ' | ' .
|
||||
'from: ' . $userBusiness->m_level_id . ' ' . $userBusiness->user_level_name . ' | ' .
|
||||
'to: ' . $ret);
|
||||
$this->info('updateLevel: '.$userBusiness->user->id.' | '.$userBusiness->user->email.' | '.
|
||||
'from: '.$userBusiness->m_level_id.' '.$userBusiness->user_level_name.' | '.
|
||||
'to: '.$ret);
|
||||
}
|
||||
}
|
||||
$this->logExecutionTime('END Command userLevelUpdate:');
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function storeBusinessStructureUsersDetailPeriod($from, $to)
|
||||
{
|
||||
for ($i = $from; $i <= $to; $i++) {
|
||||
$this->info('Store Business Structure Users Detail month: ' . $i . ' year:' . $this->year);
|
||||
$this->info('Store Business Structure Users Detail month: '.$i.' year:'.$this->year);
|
||||
$businessUsersStore = new BusinessUsersStore($i, $this->year);
|
||||
$businessUsersStore->storeUserBusinessStructure();
|
||||
$businessUsersStore->storeBusinessUsersDetail();
|
||||
$bool = $businessUsersStore->storeBusinessCompleted();
|
||||
|
||||
$this->logExecutionTime('Period BusinessStore: ' . $bool);
|
||||
$this->logExecutionTime('Period BusinessStore: '.$bool);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -186,6 +230,6 @@ class BusinessStore extends Command
|
|||
$sec = intval($diff);
|
||||
$micro = $diff - $sec;
|
||||
|
||||
$this->info($message . ' | Time: ' . $sec . 'sec :' . round($micro * 1000, 4) . " ms");
|
||||
$this->info($message.' | Time: '.$sec.'sec :'.round($micro * 1000, 4).' ms');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue