ServiceTimer.php 831 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\Order;
  4. use Illuminate\Console\Command;
  5. use Log;
  6. class ServiceTimer extends Command
  7. {
  8. protected $signature = 'serviceTimer';
  9. protected $description = '服务计时器';
  10. public function handle(): void
  11. {
  12. $jobTime = microtime(true);
  13. $this->expiredPlan(); // 过期套餐
  14. $jobTime = round(microtime(true) - $jobTime, 4);
  15. Log::info(__('----「:job」Completed, Used :time seconds ----', ['job' => $this->description, 'time' => $jobTime]));
  16. }
  17. private function expiredPlan(): void
  18. {
  19. Order::activePlan()
  20. ->where('expired_at', '<=', date('Y-m-d H:i:s'))
  21. ->chunk(config('tasks.chunk'), function ($orders) {
  22. $orders->each->expired(); // 过期订单
  23. });
  24. }
  25. }