AutoDisableUserJob.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Http\Models\UserBanLog;
  5. use App\Http\Models\User;
  6. use Log;
  7. class autoDisableUserJob extends Command
  8. {
  9. protected $signature = 'autoDisableUserJob';
  10. protected $description = '自动禁用流量超限的用户';
  11. public function __construct()
  12. {
  13. parent::__construct();
  14. }
  15. public function handle()
  16. {
  17. // 禁用流量超限账号
  18. $userList = User::query()->where('enable', 1)->whereRaw("u + d >= transfer_enable")->get();
  19. if (!$userList->isEmpty()) {
  20. foreach ($userList as $user) {
  21. User::query()->where('id', $user->id)->update(['enable' => 0]);
  22. // 写入日志
  23. $this->log($user->id, '【自动封禁】-流量超限');
  24. }
  25. }
  26. Log::info('定时任务:' . $this->description);
  27. }
  28. private function log($user_id, $desc)
  29. {
  30. $log = new UserBanLog();
  31. $log->user_id = $user_id;
  32. $log->minutes = 0;
  33. $log->desc = $desc;
  34. $log->save();
  35. }
  36. }