info('RUN Command Payments Account: '.date('d.m.Y H:i')); $this->timeStart = microtime(true); $this->updateUserNextLevel(); $this->updatePaymentsAccountsFree(); $this->reminderPaymentsAccounts(); return 0; } 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 ++; } $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"); } 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 ++; } $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"); } private function reminderPaymentsAccounts() { $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->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"); } }