Kernel.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Console;
  3. use App\Models\CheckCard;
  4. use Carbon\Carbon;
  5. use Illuminate\Console\Scheduling\Schedule;
  6. use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
  7. use Illuminate\Support\Facades\Log;
  8. class Kernel extends ConsoleKernel
  9. {
  10. /**
  11. * The Artisan commands provided by your application.
  12. *
  13. * @var array
  14. */
  15. protected $commands = [
  16. //
  17. ];
  18. /**
  19. * Define the application's command schedule.
  20. *
  21. * @param \Illuminate\Console\Scheduling\Schedule $schedule
  22. * @return void
  23. */
  24. protected function schedule(Schedule $schedule)
  25. {
  26. // $schedule->command('inspire')
  27. // ->hourly();
  28. $schedule->call(function () {
  29. $begin = Carbon::today()->toDateTimeString();
  30. $end = Carbon::tomorrow()->toDateTimeString();
  31. Log::info('定时器已经执行');
  32. $items = CheckCard::where([
  33. ['begin_date_time', '>=', $begin],
  34. ['begin_date_time', '<', $end],
  35. ])->whereNull('end_date_time')->get();
  36. foreach($items as $item) {
  37. $item->end_date_time = Carbon::createFromTimestamp(strtotime($item->begin_date_time))->addHours(2)->toDateTimeString();
  38. $item->save();
  39. }
  40. })->dailyAt('21:00');
  41. }
  42. /**
  43. * Register the Closure based commands for the application.
  44. *
  45. * @return void
  46. */
  47. protected function commands()
  48. {
  49. require base_path('routes/console.php');
  50. }
  51. }