SendRemindMail.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\User;
  5. use App\Models\MailLog;
  6. use App\Jobs\SendEmailJob;
  7. class SendRemindMail extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'send:remindMail';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = '发送提醒邮件';
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. }
  30. /**
  31. * Execute the console command.
  32. *
  33. * @return mixed
  34. */
  35. public function handle()
  36. {
  37. $users = User::all();
  38. foreach ($users as $user) {
  39. if ($user->remind_expire) $this->remindExpire($user);
  40. }
  41. }
  42. private function remindExpire($user)
  43. {
  44. if ($user->expired_at !== NULL && ($user->expired_at - 86400) < time() && $user->expired_at > time()) {
  45. SendEmailJob::dispatch([
  46. 'email' => $user->email,
  47. 'subject' => '在' . config('v2board.app_name', 'V2board') . '的服务即将到期',
  48. 'template_name' => 'remindExpire',
  49. 'template_value' => [
  50. 'name' => config('v2board.app_name', 'V2Board'),
  51. 'url' => config('v2board.app_url')
  52. ]
  53. ]);
  54. }
  55. }
  56. }