ResetTraffic.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\User;
  5. class ResetTraffic extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'reset:traffic';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = '流量清空';
  19. /**
  20. * Create a new command instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. }
  28. /**
  29. * Execute the console command.
  30. *
  31. * @return mixed
  32. */
  33. public function handle()
  34. {
  35. $user = User::where('expired_at', '!=', NULL);
  36. $resetTrafficMethod = (int)config('v2board.reset_traffic_method', 0);
  37. switch ($resetTrafficMethod) {
  38. // 1 a month
  39. case 0:
  40. $user->update([
  41. 'u' => 0,
  42. 'd' => 0
  43. ]);
  44. break;
  45. // expire day
  46. case 1:
  47. $startAt = strtotime(date('Y-m-d', time()));
  48. $user->where('expired_at', '>=', $startAt)
  49. ->where('expired_at', '<', $startAt + 24 * 3600)
  50. ->update([
  51. 'u' => 0,
  52. 'd' => 0
  53. ]);
  54. }
  55. }
  56. }