Kernel.php 1.6 KB

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