AutoRemoveDisabledUserLabelsJob.php 822 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Http\Models\User;
  4. use App\Http\Models\UserLabel;
  5. use Illuminate\Console\Command;
  6. use Log;
  7. class AutoRemoveDisabledUserLabelsJob extends Command
  8. {
  9. protected $signature = 'autoRemoveDisabledUserLabelsJob';
  10. protected $description = '自动移除被禁用用户的标签';
  11. public function __construct()
  12. {
  13. parent::__construct();
  14. }
  15. public function handle()
  16. {
  17. // 账号被禁用,则删除所有标签
  18. $userList = User::query()->where('enable', 0)->where('ban_time', 0)->get();
  19. if (!$userList->isEmpty()) {
  20. foreach ($userList as $user) {
  21. UserLabel::query()->where('user_id', $user->id)->delete();
  22. }
  23. }
  24. Log::info('定时任务:' . $this->description);
  25. }
  26. }