SiteStatusCheck.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Http\Models\Site;
  4. use Illuminate\Console\Command;
  5. use Illuminate\Support\Facades\DB;
  6. use Illuminate\Support\Facades\Log;
  7. class SiteStatusCheck extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'siteStatus:check';
  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(): void
  36. {
  37. return;
  38. $sites = Site::query()->get();
  39. foreach ($sites as $site) {
  40. if ($site->expired_at) {
  41. if (time() > strtotime($site->expired_at) && !in_array($site->status, [4, 6, 7])) {
  42. $site->update(['status' => 6]); //已过期
  43. continue;
  44. }
  45. if (strtotime('+3 month') > strtotime($site->expired_at) &&
  46. time() < strtotime($site->expired_at) && !in_array($site->status, [4, 5, 7])) {
  47. $site->update(['status' => 5]); //续费期
  48. continue;
  49. }
  50. }
  51. }
  52. $this->info('success');
  53. }
  54. }