Updates to 03-2025
This commit is contained in:
parent
6167273a48
commit
9b54eb0512
348 changed files with 34535 additions and 5774 deletions
|
|
@ -21,7 +21,7 @@ class PaymentsAccounts extends Command
|
|||
|
||||
private $timeStart;
|
||||
|
||||
|
||||
private $dev = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
|
@ -35,86 +35,169 @@ class PaymentsAccounts extends Command
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
\Log::info('Starting PaymentsAccounts Command', ['timestamp' => now()]);
|
||||
$this->info('RUN Command Payments Account: '.date('d.m.Y H:i'));
|
||||
$this->timeStart = microtime(true);
|
||||
|
||||
$this->updateUserNextLevel();
|
||||
$this->updatePaymentsAccountsFree();
|
||||
$this->reminderPaymentsAccounts();
|
||||
|
||||
return 0;
|
||||
|
||||
try {
|
||||
$this->updateUserNextLevel();
|
||||
$this->updatePaymentsAccountsFree();
|
||||
$this->deactivateUserAccounts();
|
||||
$this->reminderPaymentsAccounts();
|
||||
|
||||
\Log::info('PaymentsAccounts Command completed successfully');
|
||||
return 0;
|
||||
} catch (\Exception $e) {
|
||||
\Log::error('PaymentsAccounts Command failed', [
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString()
|
||||
]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
private function updateUserNextLevel(){
|
||||
// now date - renewal_days
|
||||
$count = 0;
|
||||
$renewalDate = Carbon::now()->modify('+'.(config('main.renewal_days')).' days');
|
||||
$users = User::where('payment_account', '!=', NULL)
|
||||
->where('active', '=', 1)
|
||||
->where('blocked', '!=', 1)
|
||||
->where('payment_account', '<', $renewalDate)
|
||||
->whereColumn('m_level', '!=', 'next_m_level')
|
||||
->get();
|
||||
|
||||
foreach($users as $user){
|
||||
$user->m_level = $user->next_m_level;
|
||||
$user->save();
|
||||
$count ++;
|
||||
}
|
||||
try {
|
||||
// now date - renewal_days
|
||||
$count = 0;
|
||||
$renewalDate = Carbon::now()->modify('+'.(config('main.renewal_days')).' days');
|
||||
$users = User::where('payment_account', '!=', NULL)
|
||||
->where('active', '=', 1)
|
||||
->where('blocked', '!=', 1)
|
||||
->where('payment_account', '<', $renewalDate)
|
||||
->whereColumn('m_level', '!=', 'next_m_level')
|
||||
->where('deleted_at', NULL)
|
||||
->get();
|
||||
|
||||
foreach($users as $user){
|
||||
$user->m_level = $user->next_m_level;
|
||||
$user->save();
|
||||
$count ++;
|
||||
}
|
||||
|
||||
$diff = microtime(true) - $this->timeStart;
|
||||
$sec = intval($diff);
|
||||
$micro = $diff - $sec;
|
||||
$this->info('END Command updateUserNextLevel: '.$count.' | Time: '.$sec. 'sec :' . round($micro * 1000, 4) . " ms");
|
||||
$diff = microtime(true) - $this->timeStart;
|
||||
$sec = intval($diff);
|
||||
$micro = $diff - $sec;
|
||||
$this->info('END Command updateUserNextLevel: '.$count.' | Time: '.$sec. 'sec :' . round($micro * 1000, 4) . " ms");
|
||||
|
||||
\Log::info('updateUserNextLevel completed', [
|
||||
'users_updated' => $count,
|
||||
'execution_time' => $sec . 'sec :' . round($micro * 1000, 4) . "ms"
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
\Log::error('updateUserNextLevel failed', [
|
||||
'error' => $e->getMessage()
|
||||
]);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function updatePaymentsAccountsFree(){
|
||||
// now date - renewal_days -1 / user_levels.payment_year false is no payment
|
||||
$count = 0;
|
||||
$renewalDate = Carbon::now()->modify('+'.(config('main.renewal_days')-1).' days');
|
||||
$users = User::join('user_levels', 'm_level', '=', 'user_levels.id')->select('users.*')
|
||||
->where('users.payment_account', '!=', NULL)
|
||||
->where('users.active', '=', 1)
|
||||
->where('users.blocked', '!=', 1)
|
||||
->where('users.payment_account', '<', $renewalDate)
|
||||
->where('user_levels.payment_year', '=', 0)
|
||||
->get();
|
||||
|
||||
foreach($users as $user){
|
||||
$user->payment_account = Carbon::parse($user->payment_account)->modify('1 year');
|
||||
$user->save();
|
||||
$count ++;
|
||||
}
|
||||
try {
|
||||
// now date - renewal_days -1 / user_levels.payment_year false is no payment
|
||||
$count = 0;
|
||||
$renewalDate = Carbon::now()->modify('+'.(config('main.renewal_days')-1).' days');
|
||||
$users = User::join('user_levels', 'm_level', '=', 'user_levels.id')->select('users.*')
|
||||
->where('users.payment_account', '!=', NULL)
|
||||
->where('users.active', '=', 1)
|
||||
->where('users.blocked', '!=', 1)
|
||||
->where('users.payment_account', '<', $renewalDate)
|
||||
->where('user_levels.payment_year', '=', 0)//user_levels.payment_year false is no payment
|
||||
->where('users.deleted_at', NULL)
|
||||
->get();
|
||||
|
||||
foreach($users as $user){
|
||||
$user->payment_account = Carbon::parse($user->payment_account)->modify('1 year');
|
||||
$user->save();
|
||||
$count ++;
|
||||
}
|
||||
|
||||
$diff = microtime(true) - $this->timeStart;
|
||||
$sec = intval($diff);
|
||||
$micro = $diff - $sec;
|
||||
$this->info('END Command updatePaymentsAccountsFree: '.$count.' | Time: '.$sec. 'sec :' . round($micro * 1000, 4) . " ms");
|
||||
$diff = microtime(true) - $this->timeStart;
|
||||
$sec = intval($diff);
|
||||
$micro = $diff - $sec;
|
||||
$this->info('END Command updatePaymentsAccountsFree: '.$count.' | Time: '.$sec. 'sec :' . round($micro * 1000, 4) . " ms");
|
||||
|
||||
\Log::info('updatePaymentsAccountsFree completed', [
|
||||
'users_updated' => $count,
|
||||
'execution_time' => $sec . 'sec :' . round($micro * 1000, 4) . "ms"
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
\Log::error('updatePaymentsAccountsFree failed', [
|
||||
'error' => $e->getMessage()
|
||||
]);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
private function deactivateUserAccounts(){
|
||||
try {
|
||||
$count = 0;
|
||||
$sevenDaysAfterExpiry = Carbon::now()->subDays(7);
|
||||
$users = User::where('payment_account', '!=', NULL)
|
||||
->where('active', '=', 1)
|
||||
->where('blocked', '!=', 1)
|
||||
->where('payment_account', '<', $sevenDaysAfterExpiry)
|
||||
->where('deleted_at', NULL)
|
||||
->get();
|
||||
|
||||
foreach($users as $user){
|
||||
$user->active = 0;
|
||||
$user->save();
|
||||
$this->info('deactivateUserAccount | User: '.$user->id.' '.$user->email.' | Date :' . $user->getPaymentAccountDateFormat() . "");
|
||||
|
||||
$count ++;
|
||||
}
|
||||
|
||||
$diff = microtime(true) - $this->timeStart;
|
||||
$sec = intval($diff);
|
||||
$micro = $diff - $sec;
|
||||
$this->info('END Command deactivateUserAccounts: '.$count.' | Time: '.$sec. 'sec :' . round($micro * 1000, 4) . " ms");
|
||||
|
||||
\Log::info('deactivateUserAccounts completed', [
|
||||
'users_updated' => $count,
|
||||
'execution_time' => $sec . 'sec :' . round($micro * 1000, 4) . "ms"
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
\Log::error('deactivateUserAccounts failed', [
|
||||
'error' => $e->getMessage()
|
||||
]);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
private function reminderPaymentsAccounts()
|
||||
{
|
||||
try {
|
||||
$count = 0;
|
||||
$max_reminder_date = Carbon::now()->modify('+'.(config('main.remind_first_days')).' days');
|
||||
$users = User::where('payment_account', '!=', NULL)
|
||||
->where('active', '=', 1)
|
||||
->where('blocked', '!=', 1)
|
||||
->where('payment_account', '<', $max_reminder_date)
|
||||
->where('deleted_at', NULL)
|
||||
->get();
|
||||
|
||||
$count = 0;
|
||||
$max_reminder_date = Carbon::now()->modify('+'.(config('main.remind_first_days')).' days');
|
||||
$users = User::where('payment_account', '!=', NULL)
|
||||
->where('active', '=', 1)
|
||||
->where('blocked', '!=', 1)
|
||||
->where('payment_account', '<', $max_reminder_date)
|
||||
->get();
|
||||
foreach ($users as $user){
|
||||
$status = UserCheckPaymentsAccounts::userReminderPayments($user, $this->dev);
|
||||
$this->info('reminderPaymentsAccounts Status: '.$status.' | User: '.$user->id.' '.$user->email.' | Date :' . $user->getPaymentAccountDateFormat() . "");
|
||||
$count ++;
|
||||
}
|
||||
|
||||
foreach ($users as $user){
|
||||
$status = UserCheckPaymentsAccounts::userReminderPayments($user);
|
||||
$this->info('reminderPaymentsAccounts Status: '.$status.' | User: '.$user->id.' '.$user->email.' | Date :' . $user->getPaymentAccountDateFormat() . "");
|
||||
$count ++;
|
||||
}
|
||||
|
||||
$diff = microtime(true) - $this->timeStart;
|
||||
$sec = intval($diff);
|
||||
$micro = $diff - $sec;
|
||||
$this->info('END Command reminderPaymentsAccounts: '.$count.' | Time: '.$sec. 'sec :' . round($micro * 1000, 4) . " ms");
|
||||
$diff = microtime(true) - $this->timeStart;
|
||||
$sec = intval($diff);
|
||||
$micro = $diff - $sec;
|
||||
$this->info('END Command reminderPaymentsAccounts: '.$count.' | Time: '.$sec. 'sec :' . round($micro * 1000, 4) . " ms");
|
||||
|
||||
\Log::info('reminderPaymentsAccounts completed', [
|
||||
'users_processed' => $count,
|
||||
'execution_time' => $sec . 'sec :' . round($micro * 1000, 4) . "ms"
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
\Log::error('reminderPaymentsAccounts failed', [
|
||||
'error' => $e->getMessage()
|
||||
]);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,9 +25,12 @@ class Kernel extends ConsoleKernel
|
|||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
$schedule->command('payments:accounts')
|
||||
->sendOutputTo("cron.log");
|
||||
//->hourly();
|
||||
// ->emailOutputTo('kevin@adametz.media');
|
||||
->sendOutputTo(storage_path('logs/cron.log'))
|
||||
->appendOutputTo(storage_path('logs/cron-history.log'))
|
||||
->emailOutputOnFailure(config('app.exception_mail'))
|
||||
->onFailure(function () {
|
||||
\Log::error('Payments:accounts command failed');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue