Kernel.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Console;
  3. use App\Models\Notification;
  4. use App\Models\Order;
  5. use App\Models\OrderDevice;
  6. use Carbon\Carbon;
  7. use Illuminate\Console\Scheduling\Schedule;
  8. use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
  9. class Kernel extends ConsoleKernel
  10. {
  11. /**
  12. * The Artisan commands provided by your application.
  13. *
  14. * @var array
  15. */
  16. protected $commands = [
  17. //
  18. ];
  19. /**
  20. * Define the application's command schedule.
  21. *
  22. * @param \Illuminate\Console\Scheduling\Schedule $schedule
  23. * @return void
  24. */
  25. protected function schedule(Schedule $schedule)
  26. {
  27. $schedule->call(function () {
  28. // 租赁订单过期提醒|调用设备过期提醒-为一天后或三天后过期的订单发送
  29. $tomorrow = Carbon::tomorrow()->toDateString();
  30. $three_day = Carbon::today()->addDays(3)->toDateString();
  31. $order_ids = OrderDevice::whereIn('end_date', [$tomorrow, $three_day])->pluck('order_id')->unique();
  32. foreach($order_ids as $order_id) {
  33. Notification::send($order_id, true);
  34. }
  35. })->dailyAt('12:00');
  36. }
  37. /**
  38. * Register the Closure based commands for the application.
  39. *
  40. * @return void
  41. */
  42. protected function commands()
  43. {
  44. require base_path('routes/console.php');
  45. }
  46. }