TaskMonthly.php 914 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\User;
  4. use Illuminate\Console\Command;
  5. use Log;
  6. class TaskMonthly extends Command
  7. {
  8. protected $signature = 'task:monthly';
  9. protected $description = '每月任务';
  10. public function handle(): void
  11. {
  12. $jobTime = microtime(true);
  13. if (sysConfig('data_exhaust_notification')) {
  14. $this->cleanAccounts(); // 用户流量超过警告阈值提醒
  15. }
  16. $jobTime = round(microtime(true) - $jobTime, 4);
  17. Log::info(__('----「:job」Completed, Used :time seconds ----', ['job' => $this->description, 'time' => $jobTime]));
  18. }
  19. private function cleanAccounts()
  20. {
  21. // 账号遗留结算的流量
  22. User::where('expired_at', '<', date('Y-m-d'))->where('transfer_enable', '==', 0)->whereEnable(0)
  23. ->whereRaw('u + d > transfer_enable')->update(['u' => 0, 'd' => 0]);
  24. }
  25. }