SendRemindMail.php 1.6 KB

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