AutoReleasePortJob.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Http\Models\User;
  5. use App\Http\Models\Config;
  6. use Log;
  7. class AutoReleasePortJob extends Command
  8. {
  9. protected $signature = 'autoReleasePortJob';
  10. protected $description = '自动释放端口';
  11. public function __construct()
  12. {
  13. parent::__construct();
  14. }
  15. public function handle()
  16. {
  17. $config = $this->systemConfig();
  18. if ($config['auto_release_port']) {
  19. $userList = User::query()->where('status', '<', 0)->get();
  20. if (!$userList->isEmpty()) {
  21. foreach ($userList as $user) {
  22. if ($user->port) {
  23. User::query()->where('id', $user->id)->update(['port' => 0]);
  24. }
  25. }
  26. }
  27. }
  28. Log::info('定时任务:' . $this->description);
  29. }
  30. // 系统配置
  31. private function systemConfig()
  32. {
  33. $config = Config::query()->get();
  34. $data = [];
  35. foreach ($config as $vo) {
  36. $data[$vo->name] = $vo->value;
  37. }
  38. return $data;
  39. }
  40. }