diff --git a/app/Http/Controllers/Customer/OrdersController.php b/app/Http/Controllers/Customer/OrdersController.php index 4be4b2e..6057887 100644 --- a/app/Http/Controllers/Customer/OrdersController.php +++ b/app/Http/Controllers/Customer/OrdersController.php @@ -13,10 +13,14 @@ use App\Models\Product; use App\Models\ProductItems; use App\Models\ProductParamedicLevel; use App\Models\Recharge; +use App\Notifications\CustomerOrderCreated; +use App\Notifications\RechargePaid; use Carbon\Carbon; use Illuminate\Database\Eloquent\Relations\MorphTo; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Log; +use Illuminate\Support\Facades\Notification; class OrdersController extends CommonController { @@ -428,6 +432,12 @@ class OrdersController extends CommonController ]); $order->getSerial(); + if ($order->prokect->managers) { + foreach ($order->prokect->managers as $manager) { + Notification::send($manager, new CustomerOrderCreated($order)); + } + } + DB::commit(); return $this->getOrder($order->id); } catch (\Exception $exception) { @@ -505,7 +515,7 @@ class OrdersController extends CommonController public function cancelOrder($id) { $order = (new Orders())->with("orderItems")->find($id); - \Log::info($order); + Log::info($order); if ($order->status !== Orders::STATUS_UNCONFIRMED) { return response()->json([ "errorcode" => 50001, diff --git a/app/Notifications/CustomerOrderCreated.php b/app/Notifications/CustomerOrderCreated.php new file mode 100644 index 0000000..399754b --- /dev/null +++ b/app/Notifications/CustomerOrderCreated.php @@ -0,0 +1,65 @@ +order = $order; + } + + /** + * Get the notification's delivery channels. + * + * @param mixed $notifiable + * @return array + */ + public function via($notifiable) + { + return ['database']; + } + + /** + * Get the mail representation of the notification. + * + * @param mixed $notifiable + * @return \Illuminate\Notifications\Messages\MailMessage + */ + public function toMail($notifiable) + { + return (new MailMessage) + ->line('The introduction to the notification.') + ->action('Notification Action', url('/')) + ->line('Thank you for using our application!'); + } + + /** + * Get the array representation of the notification. + * + * @param mixed $notifiable + * @return array + */ + public function toArray($notifiable) + { + return [ + "order_id" => $this->order->id, + "order_serial" => $this->order->serial + ]; + } +}