AutoDisableExpireUserJob.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Http\Models\Config;
  5. use App\Http\Models\User;
  6. use Log;
  7. class autoDisableExpireUserJob extends Command
  8. {
  9. protected $signature = 'autoDisableExpireUserJob';
  10. protected $description = '自动禁用到期用户';
  11. public function __construct()
  12. {
  13. parent::__construct();
  14. }
  15. public function handle()
  16. {
  17. // 到期账号禁用
  18. $config = $this->systemConfig();
  19. if ($config['is_ban_status']) {
  20. User::query()->where('enable', 1)->where('expire_time', '<=', date('Y-m-d'))->update(['enable' => 0, 'status' => -1]);
  21. } else {
  22. User::query()->where('enable', 1)->where('expire_time', '<=', date('Y-m-d'))->update(['enable' => 0]);
  23. }
  24. Log::info('定时任务:' . $this->description);
  25. }
  26. // 系统配置
  27. private function systemConfig()
  28. {
  29. $config = Config::query()->get();
  30. $data = [];
  31. foreach ($config as $vo) {
  32. $data[$vo->name] = $vo->value;
  33. }
  34. return $data;
  35. }
  36. }