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. }
  22. else{
  23. User::query()->where('enable', 1)->where('expire_time', '<=', date('Y-m-d'))->update(['enable' => 0]);
  24. }
  25. Log::info('定时任务:' . $this->description);
  26. }
  27. // 系统配置
  28. private function systemConfig()
  29. {
  30. $config = Config::query()->get();
  31. $data = [];
  32. foreach ($config as $vo) {
  33. $data[$vo->name] = $vo->value;
  34. }
  35. return $data;
  36. }
  37. }