Kernel.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. // Commands\UpdateRentDevice::class,
  19. Commands\UpdateApplyDevice::class,
  20. ];
  21. /**
  22. * Define the application's command schedule.
  23. *
  24. * @param \Illuminate\Console\Scheduling\Schedule $schedule
  25. * @return void
  26. */
  27. protected function schedule(Schedule $schedule)
  28. {
  29. $schedule->call(function () {
  30. // 租赁订单过期提醒|调用设备过期提醒-为一天后或三天后过期的订单发送
  31. $tomorrow = Carbon::tomorrow()->toDateString();
  32. $three_day = Carbon::today()->addDays(3)->toDateString();
  33. $order_ids = OrderDevice::whereIn('end_date', [$tomorrow, $three_day])->pluck('order_id')->unique();
  34. foreach($order_ids as $order_id) {
  35. Notification::send($order_id, true);
  36. }
  37. })->dailyAt('12:00');
  38. /*每分钟执行一次更新租赁设备的时间*/
  39. $schedule->command('updateApplyDevice')->everyMinute();
  40. }
  41. /**
  42. * Register the Closure based commands for the application.
  43. *
  44. * @return void
  45. */
  46. protected function commands()
  47. {
  48. require base_path('routes/console.php');
  49. }
  50. }