ServiceTimer.php 786 B

12345678910111213141516171819202122232425262728293031
  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()->where('expired_at', '<=', now())->chunk(sysConfig('tasks_chunk'), function ($orders) {
  20. $orders->each->expired(); // 过期订单
  21. });
  22. }
  23. }