08 2024
This commit is contained in:
parent
04d677d37a
commit
bfa3bb1df4
1191 changed files with 637397 additions and 10619 deletions
|
|
@ -17,7 +17,7 @@ class BusinessStore extends Command
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'business:store {month} {year}';
|
||||
protected $signature = 'business:store {month} {year}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
|
|
|
|||
159
app/Console/Commands/UserCleanUp.php
Normal file
159
app/Console/Commands/UserCleanUp.php
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\User;
|
||||
use Carbon\Carbon;
|
||||
use App\Services\UserUtil;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
|
||||
class UserCleanUp extends Command
|
||||
{
|
||||
/**
|
||||
* ln -sfv /usr/bin/php73 /usr/bin/php
|
||||
* php74 artisan user:cleanup
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'user:cleanup';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'User Clean Up inactive for Business Structur and UserDetails';
|
||||
private $timeStart;
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
$this->info('RUN Command user:cleanup');
|
||||
|
||||
$this->timeStart = microtime(true);
|
||||
|
||||
$this->deleteInavtiveUsers();
|
||||
//alle inaktive User werden deaktivert, die childs werden dem nächsten aktiven Berater (parent) zugewiesen.
|
||||
$this->cleanUpInActiveUser();
|
||||
|
||||
return 0;
|
||||
|
||||
//\Log::info('Cron is running');
|
||||
//return 0;
|
||||
}
|
||||
|
||||
//gibt es gelöschte Berater mit Kunden und childs???
|
||||
|
||||
private function deleteInavtiveUsers(){
|
||||
|
||||
$this->info('START Command deleteInavtiveUsers');
|
||||
$count = 0;
|
||||
|
||||
$date = Carbon::now()->modify('-2 month');
|
||||
$delete_users = User::where('admin', 0)->where('payment_account', '<', $date)->get();
|
||||
|
||||
foreach($delete_users as $delete_user){
|
||||
/*
|
||||
dump('delete_users ---------- ');
|
||||
dump($delete_user->id);
|
||||
dump($delete_user->email);
|
||||
*/
|
||||
//finde nächsten aktiven Sponsor $delete_user->id kann sponsor oder pre sponsor sein
|
||||
$active_sponsor = UserUtil::findNextActiveSponsor($delete_user->id);
|
||||
if($active_sponsor){
|
||||
//setze alle Berater vom Sponsor für alle childs
|
||||
UserUtil::setNewSponsorToChilds($delete_user->id, $active_sponsor->id);
|
||||
UserUtil::setShoppingUserToNewMember($delete_user->id, $active_sponsor->id);
|
||||
}else{
|
||||
\Log::channel('cleanup')->error('deleteInavtiveUsers find no active_sponsor by delete_user_id:'.$delete_user->id);
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
dump('findNextActiveSponsor');
|
||||
dump($active_sponsor->email);
|
||||
*/
|
||||
//make User to an Client from sponsor and delete User
|
||||
UserUtil::setUserToClient($delete_user->id, $active_sponsor->id);
|
||||
|
||||
$data = [
|
||||
'user_id' => $delete_user->id,
|
||||
'email' => $delete_user->email,
|
||||
'm_account' => $delete_user->account ? $delete_user->account->m_account : '',
|
||||
'm_first_name' => $delete_user->account ? $delete_user->account->m_first_name : '',
|
||||
'm_last_name' => $delete_user->account ? $delete_user->account->m_last_name : '',
|
||||
];
|
||||
$count ++;
|
||||
\Log::channel('cleanup')->info('deleteUser: '.json_encode($data));
|
||||
UserUtil::deleteUser($delete_user);
|
||||
}
|
||||
|
||||
$diff = microtime(true) - $this->timeStart;
|
||||
$sec = intval($diff);
|
||||
$micro = $diff - $sec;
|
||||
|
||||
$this->info('END Command deleteInavtiveUsers: '.$count. ' | Time: '.$sec. 'sec :' . round($micro * 1000, 4) . " ms");
|
||||
|
||||
}
|
||||
|
||||
private function cleanUpInActiveUser(){
|
||||
|
||||
$this->info('START Command cleanUpInActiveUser');
|
||||
$count = 0;
|
||||
|
||||
//clean up user where inactive since 2 weeks
|
||||
$date = Carbon::now()->modify('-2 weeks');
|
||||
|
||||
$inactive_users = User::where('active', true)->where('m_sponsor', '!=', null)->where('payment_account', '<', $date)->get();
|
||||
foreach($inactive_users as $inactive_user){
|
||||
/*
|
||||
dump('inactive_user ---------- ');
|
||||
dump($inactive_user->id);
|
||||
dump($inactive_user->email);
|
||||
*/
|
||||
$active_sponsor = UserUtil::findNextActiveSponsor($inactive_user->m_sponsor);
|
||||
if($active_sponsor){
|
||||
UserUtil::setNewSponsorToChilds($inactive_user->id, $active_sponsor->id);
|
||||
}else{
|
||||
\Log::channel('cleanup')->error('cleanUpInActiveUser find no active_sponsor by inactive_user:'.$inactive_user->id);
|
||||
}
|
||||
/*
|
||||
dump('findNextActiveSponsor');
|
||||
dump($active_sponsor->email);
|
||||
*/
|
||||
$data = [
|
||||
'user_id' => $inactive_user->id,
|
||||
'email' => $inactive_user->email,
|
||||
'm_account' => $inactive_user->account ? $inactive_user->account->m_account : '',
|
||||
'm_first_name' => $inactive_user->account ? $inactive_user->account->m_first_name : '',
|
||||
'm_last_name' => $inactive_user->account ? $inactive_user->account->m_last_name : '',
|
||||
];
|
||||
$count ++;
|
||||
|
||||
\Log::channel('cleanup')->info('inactive_user: '.json_encode($data));
|
||||
UserUtil::deactiveUser($inactive_user);
|
||||
}
|
||||
|
||||
$diff = microtime(true) - $this->timeStart;
|
||||
$sec = intval($diff);
|
||||
$micro = $diff - $sec;
|
||||
|
||||
$this->info('END Command cleanUpInActiveUser: '.$count. ' | Time: '.$sec. 'sec :' . round($micro * 1000, 4) . " ms");
|
||||
}
|
||||
}
|
||||
112
app/Console/Commands/UserRestore.php
Normal file
112
app/Console/Commands/UserRestore.php
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\User;
|
||||
use Carbon\Carbon;
|
||||
use App\Services\UserUtil;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
|
||||
class UserRestore extends Command
|
||||
{
|
||||
/**
|
||||
* ln -sfv /usr/bin/php73 /usr/bin/php
|
||||
* php artisan business:store month year
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'user:restore {user_id}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'User Restore active User where inactive for Business Structur and UserDetails';
|
||||
private $timeStart;
|
||||
private $user_id;
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
$this->info('RUN Command user:restore');
|
||||
|
||||
$this->timeStart = microtime(true);
|
||||
|
||||
$this->restoreInavtiveUsers();
|
||||
return 0;
|
||||
|
||||
//\Log::info('Cron is running');
|
||||
//return 0;
|
||||
}
|
||||
|
||||
//gibt es gelöschte Berater mit Kunden und childs???
|
||||
|
||||
private function restoreInavtiveUsers(){
|
||||
|
||||
$this->info('START Command restoreInavtiveUsers');
|
||||
$count = 0;
|
||||
|
||||
$this->user_id = $this->argument('user_id');
|
||||
|
||||
if(!$this->user_id){
|
||||
$this->info('NO user_id as argument');
|
||||
return;
|
||||
}
|
||||
|
||||
$this->info('RUN Command restoreInavtiveUsers on user_id: '.$this->user_id);
|
||||
|
||||
$user = User::find($this->user_id);
|
||||
|
||||
if(!$user){
|
||||
$this->info('restoreInavtiveUsers find no user by user_id:'.$this->user_id);
|
||||
\Log::channel('cleanup')->error('restoreInavtiveUsers find no user by user_id:'.$this->user_id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'user_id' => $user->id,
|
||||
'email' => $user->email,
|
||||
'm_account' => $user->account ? $user->account->m_account : '',
|
||||
'm_first_name' => $user->account ? $user->account->m_first_name : '',
|
||||
'm_last_name' => $user->account ? $user->account->m_last_name : '',
|
||||
];
|
||||
\Log::channel('cleanup')->info('reactiveUser: '.json_encode($data));
|
||||
|
||||
UserUtil::reactiveUser($user);
|
||||
//childs wieder herstellen
|
||||
UserUtil::resetChildsToSponsor($user->id);
|
||||
|
||||
|
||||
$diff = microtime(true) - $this->timeStart;
|
||||
$sec = intval($diff);
|
||||
$micro = $diff - $sec;
|
||||
|
||||
$this->info('END Command deleteInavtiveUsers: '.$count. ' | Time: '.$sec. 'sec :' . round($micro * 1000, 4) . " ms");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//497
|
||||
|
||||
//489 -> de
|
||||
|
||||
//478 new
|
||||
Loading…
Add table
Add a link
Reference in a new issue