update 20.10.2025

This commit is contained in:
Kevin Adametz 2025-10-20 17:42:08 +02:00
parent 8c11130b5d
commit a939cd51ef
616 changed files with 84821 additions and 4121 deletions

View file

@ -24,7 +24,7 @@ class BusinessStore extends Command
*
* @var string
*/
protected $description = 'Create Business Structur and UserDetails';
protected $description = 'Create Business Structure and UserDetails with optimized performance';
private $timeStart;
private $month;
@ -52,121 +52,140 @@ 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);
return 0;
}
$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->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
$this->executeWithErrorHandling('Business Structure Storage', function () {
$this->storeBusinessStructureUsersDetailMonth();
});
$this->executeWithErrorHandling('Commission Calculation', function () {
$this->userBusinessCommissionsToCredit();
});
// Auskommentierte Prozesse bleiben inaktiv
// $this->userCreatePaymentCreditsPDF();
// $this->userLevelUpdate();
// $this->storeBusinessStructureUsersDetailPeriod(1, 6);
$this->logExecutionTime('COMMAND COMPLETED SUCCESSFULLY');
$this->logMemoryUsage('Command End');
\Log::channel('cron')->info('COMMAND COMPLETED SUCCESSFULLY');
$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);
if($executeDay !== $presentDay){
$this->info('NOT RUN Command BusinessStore is not present Day: '. $presentDay);
return 0;
} catch (\Exception $e) {
$this->error('Command failed with error: ' . $e->getMessage());
$this->error('Stack trace: ' . $e->getTraceAsString());
$this->logExecutionTime('COMMAND FAILED');
return 1;
}
$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->info('RUN Command BusinessStore on month: '.$this->month.' | year: '.$this->year);
// Prozesse ausführen
$this->storeBusinessStructureUsersDetailMonth();
$this->userBusinessCommissionsToCredit();
// Auskommentierte Prozesse
// $this->userCreatePaymentCreditsPDF();
// $this->userLevelUpdate();
// $this->storeBusinessStructureUsersDetailPeriod(1, 6);
return 0;
}
private function storeBusinessStructureUsersDetailMonth(){
private function storeBusinessStructureUsersDetailMonth()
{
$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->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);
}
private function userBusinessCommissionsToCredit(){
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){
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:');
}
private function userCreatePaymentCreditsPDF(){
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){
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:');
$this->logExecutionTime('END Command userCreatePaymentCreditsPDF:');
}
private function userLevelUpdate(){
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();
foreach($levelUpdateUsers as $userBusiness){
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);
if ($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)
private function storeBusinessStructureUsersDetailPeriod($from, $to)
{
for($i = $from; $i <= $to; $i++){
$this->info('Store Business Structure Users Detail month: '.$i.' year:'.$this->year);
for ($i = $from; $i <= $to; $i++) {
$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);
}
}
private function logExecutionTime($message)
private function logExecutionTime($message)
{
$diff = microtime(true) - $this->timeStart;
$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");
}
}