Edit File: AlertAdminToAssignOrderCancelled.php
<?php namespace App\Console\Commands; use App\Enums\NotificationTypeEnum; use App\Enums\OrderStatusEnum; use App\Enums\ProductDeliveryTypesEnum; use App\Models\Admin; use App\Models\Order; use App\Notifications\OrderNotification; use Carbon\Carbon; use Illuminate\Console\Command; use Illuminate\Support\Facades\Notification; class AlertAdminToAssignOrderCancelled extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'order:notify-admin'; /** * The console command description. * * @var string */ protected $description = 'Notify admin to assign order to delegate after 5 minute without any delegates accept it from themself'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * Execute the console command. * * @return int */ public function handle() { $orders = Order::whereStatus(OrderStatusEnum::Prepared->value)->where([ 'delegate_id' => null, 'receiving_method' => ProductDeliveryTypesEnum::Home->value, 'is_notified_admin_no_delegate' => false, ])->get(); foreach ($orders as $order) { if (Carbon::parse($order->created_at)->addMinutes(5)->lt(Carbon::now())) { Notification::send(Admin::first(), new OrderNotification($order, NotificationTypeEnum::Order_Without_Delegate->value)); $order->update(['is_notified_admin_no_delegate' => true]); } } } }
Back to File Manager