AutoReopenUserJob.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 AutoReopenUserJob extends Command
  8. {
  9. protected $signature = 'command:autoReopenUserJob';
  10. protected $description = '自动解封用户';
  11. public function __construct()
  12. {
  13. parent::__construct();
  14. }
  15. public function handle()
  16. {
  17. // 解封账号
  18. $userList = User::query()->where('status', '>=', 0)->where('ban_time', '>', 0)->get();
  19. foreach ($userList as $user) {
  20. if ($user->ban_time < time()) {
  21. User::query()->where('id', $user->id)->update(['enable' => 1, 'ban_time' => 0]);
  22. // 写入操作日志
  23. $this->log($user->id, 0, '【自动解封】-封禁到期');
  24. }
  25. }
  26. Log::info('定时任务:' . $this->description);
  27. }
  28. private function log($user_id, $minutes, $desc)
  29. {
  30. $log = new UserBanLog();
  31. $log->user_id = $user_id;
  32. $log->minutes = $minutes;
  33. $log->desc = $desc;
  34. $log->save();
  35. }
  36. }