File: /var/www/vhost/disk-apps/qas.sports-crowd.com/app/Mail/TransferTicket.php
<?php
namespace App\Mail;
use App\Core\Parameter\Application\ParameterService;
use App\Core\Ticket\Application\TicketService;
use App\Core\Ticket\Application\TransferService;
use App\Core\User\Application\UserService;
use App\TicketUserLog;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class TransferTicket extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;
private $parameterService;
private $ticketService;
private $tranferService;
private $userService;
public $transferGroupId;
public $newUser = false;
public $time;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($transferGroupId)
{
$this->parameterService = new ParameterService();
$this->ticketService = new TicketService();
$this->tranferService = new TransferService();
$this->userService = new UserService();
$this->transferGroupId = $transferGroupId;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$ticketUserLog = TicketUserLog::where('transfer_group', $this->transferGroupId)->first();
if (!is_null($ticketUserLog->new_user_id)) {
$recipient = $this->userService->find($ticketUserLog->new_user_id)->email;
} else {
$recipient = $ticketUserLog->email;
$this->newUser = true;
}
$this->time = Carbon::parse($ticketUserLog->expires_at)->diffForHumans();
return $this->from('noreply@sports-crowd.com', 'Sports Crowd')
->subject(__('transfer-ticket.email.subject'))
->view('mails.ticket.transfer-ticket')
->to($recipient)
->with('transfer', (object) ($ticketUserLog->toArray()))
->with('event', $this->ticketService->getTicketByTicketId($ticketUserLog->ticket_id)->match_event)
->with('zone', $this->ticketService->getTicketByTicketId($ticketUserLog->ticket_id)->zone)
->with('sender', $this->userService->find($ticketUserLog->previous_user_id))
->with('recipient', $recipient)
->with('appStoreUrl', $this->parameterService->appStoreUrl())
->with('playStoreUrl', $this->parameterService->playStoreUrl())
->with('count', $this->tranferService->countTicketsTransferByTransferGroup(
$ticketUserLog->transfer_group
));
}
}