ClearUser.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\Ticket;
  4. use App\Models\User;
  5. use Illuminate\Console\Command;
  6. class ClearUser extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'clear:user';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = '清理用户';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return mixed
  33. */
  34. public function handle()
  35. {
  36. $builder = User::where('plan_id', NULL)
  37. ->where('transfer_enable', 0)
  38. ->where('expired_at', 0)
  39. ->where('last_login_at', NULL);
  40. $count = $builder->count();
  41. if ($builder->delete()) {
  42. $this->info("已删除${count}位没有任何数据的用户");
  43. }
  44. }
  45. }