thisLoginLogId = $thisLoginLogId; $this->lastLoginLogId = $lastLoginLogId; } /** * Execute the job. * * @return void */ public function handle() { $thisLoginLog = LoginLog::query()->findOrFail($this->thisLoginLogId); $lastLoginLog = LoginLog::query()->findOrFail($this->lastLoginLogId); $user = User::query()->findOrFail($thisLoginLog->uid, User::$commonFields); $locale = $user->locale; $toolRep = new ToolRepository(); $subject = nexus_trans('message.login_notify.subject', ['site_name' => Setting::get('basic.SITENAME')], $locale); $body = nexus_trans('message.login_notify.body', [ 'this_login_time' => $thisLoginLog->created_at, 'this_ip' => $thisLoginLog->ip, 'this_location' => sprintf('%s·%s', $thisLoginLog->city, $thisLoginLog->country), 'last_login_time' => $lastLoginLog->created_at, 'last_ip' => $lastLoginLog->ip, 'last_location' => sprintf('%s·%s', $lastLoginLog->city, $lastLoginLog->country), ], $locale); $result = $toolRep->sendMail($user->email, $subject, $body); do_log(sprintf('user: %s login notify result: %s', $user->username, var_export($result, true))); } /** * Handle a job failure. * * @param \Throwable $exception * @return void */ public function failed(\Throwable $exception) { do_log("failed: " . $exception->getMessage() . $exception->getTraceAsString(), 'error'); } }