64 lines
1.9 KiB
PHP
64 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs\Mail;
|
|
|
|
use App\Http\Services\Telegram;
|
|
use App\Mail\CreateHosting;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
class SendInformationHosting implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
public $data = [];
|
|
public $customer;
|
|
/**
|
|
* Create a new job instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct($data = [],$customer)
|
|
{
|
|
$this->data = $data;
|
|
$this->customer = $customer;
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
try {
|
|
$email = new CreateHosting(3,$this->data);
|
|
Mail::to($this->customer->email)->send($email);
|
|
\App\Models\Mail::create([
|
|
'template_id' => 3,
|
|
'subject' => $email->envelope()->subject,
|
|
'to' => $this->customer->email,
|
|
'customer_id' => $this->customer->id,
|
|
'message' => $email->render()
|
|
]);
|
|
} catch (\Exception $exception)
|
|
{
|
|
throw new \Exception( $exception->getMessage());
|
|
}
|
|
}
|
|
|
|
public function failed(\Throwable $exception, Telegram $telegram)
|
|
{
|
|
|
|
Log::channel('Custom')->info("=================================");
|
|
Log::channel('Custom')->info("Thông báo lỗi lúc: " .Carbon::now());
|
|
Log::channel('Custom')->info("Notification Send Information Hosting: ");
|
|
Log::channel('Custom')->info("========");
|
|
Log::channel('Custom')->info($exception->getMessage());
|
|
Log::channel('Custom')->info("=================================");
|
|
|
|
$telegram->SendErrorMessage(json_decode($exception->getMessage()));
|
|
}
|
|
}
|