Kernel.php 1.4 KB

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