AutoResetUserTrafficJob.php 927 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Http\Models\Config;
  5. use App\Http\Models\User;
  6. use Log;
  7. class AutoResetUserTrafficJob extends Command
  8. {
  9. protected $signature = 'command:autoResetUserTrafficJob';
  10. protected $description = '自动重置账号流量';
  11. protected static $config;
  12. public function __construct()
  13. {
  14. parent::__construct();
  15. $config = Config::query()->get();
  16. $data = [];
  17. foreach ($config as $vo) {
  18. $data[$vo->name] = $vo->value;
  19. }
  20. self::$config = $data;
  21. }
  22. public function handle()
  23. {
  24. if (self::$config['reset_traffic']) {
  25. $user_ids = User::query()->where('pay_way', '<>', 0)->select(['id'])->get();
  26. User::query()->whereIn('id', $user_ids)->update(['u' => 0, 'd' => 0]);
  27. }
  28. Log::info('定时任务:' . $this->description);
  29. }
  30. }