AutoReopenUserJob.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 = '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. // SSR(R)被启用说明用户购买了流量
  27. User::query()->where('enable', 1)->where('ban_time', -1)->update(['ban_time' => 0]); // 重置ban_time
  28. $userList = User::query()->where('status', '>=', 0)->where('enable', 0)->where('ban_time', -1)->whereRaw("u + d < transfer_enable")->get();
  29. if (!$userList->isEmpty()) {
  30. foreach ($userList as $user) {
  31. User::query()->where('id', $user->id)->update(['enable' => 1, 'ban_time' => 0]);
  32. // 写入操作日志
  33. $this->log($user->id, 0, '【自动解封】-有流量解封');
  34. }
  35. }
  36. Log::info('定时任务:' . $this->description);
  37. }
  38. private function log($user_id, $minutes, $desc)
  39. {
  40. $log = new UserBanLog();
  41. $log->user_id = $user_id;
  42. $log->minutes = $minutes;
  43. $log->desc = $desc;
  44. $log->save();
  45. }
  46. }