File: /home/armgroup/libs/app/Notifications/OrderSent.php
<?php
namespace App\Notifications;
use App\Channels\SMSChannel;
use App\Models\Order;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class OrderSent extends Notification implements ShouldQueue
{
use Queueable;
public $order;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(Order $order)
{
$this->order = $order;
}
public function viaQueues()
{
return [
'mail' => 'mail-queue',
SMSChannel::class => 'sms-queue',
];
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
$available = [];
if ($notifiable->email && $notifiable->email_verified_at) {
array_push($available, 'mail');
}
if ($notifiable->mobile && (settings('order-sent-sms') == 1)) {
array_push($available, SMSChannel::class);
}
return $available;
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
$price = to_persian_numbers(number_format($this->order->price));
$text = '';
if ($this->order->delivery_date && $this->order->delivery_code) {
$text = "هنگام تحویل سفارش ارائه کد مقابل به پیک الزامی میباشد: {$this->order->delivery_code}";
} elseif ($this->order->delivery_code) {
$text = "کد رهگیری پستی سفارش: {$this->order->delivery_code}";
}
return (new MailMessage)
->subject(__("سفارش {$this->order->tracking_code} ارسال شد"))
->line("سفارش شما با کد پیگیری {$this->order->tracking_code} به مبلغ {$price} تومان برای شما ارسال شد.")
->line($text)
->action(__('جزئیات سفارش'), route('account.orders.show', $this->order->id));
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
public function toSMS($notifiable)
{
if ($this->order->delivery_date && $this->order->delivery_code) {
// اگر ارسال با پیک باشد و کد وجود داشته باشد
// return [
// 'tracking-code' => $this->order->tracking_code,
// 'delivery-code' => $this->order->delivery_code,
// 'pattern' => 'yfrxnkik0opw4bn',
// ];
return [
'var1' => (string) $this->order->user->name,
'var2' => (string) $this->order->tracking_code,
'var3' => '',
'pattern' => '410827',
];
} elseif ($this->order->delivery_code) {
// اگر ارسال با پست باشد و کد رهگیری وجود داشته باشد
// return [
// 'tracking-code' => $this->order->tracking_code,
// 'delivery-code' => $this->order->delivery_code,
// 'pattern' => 'wdlwe74m47r0yls',
// ];
return [
'var1' => (string) $this->order->user->name,
'var2' => (string) $this->order->tracking_code,
'var3' => '',
'pattern' => '410828',
];
}
// اگر هیچ کدی وجودد نداشته باشد
return [
'var1' => (string) $this->order->user->name,
'var2' => (string) $this->order->tracking_code,
'var3' => '',
'pattern' => '410829',
];
// return [
// 'tracking-code' => $this->order->tracking_code,
// 'pattern' => 'k79idu9vek42sa9',
// ];
}
}