Files
api-extranetwork/app/Core/Mail/TrialFirstMail.php
ExtraNetwork e5c4b6aa13 first commit
2026-05-12 17:04:54 +03:00

105 lines
3.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Core\Mail;
use App\Exceptions\ApiErrorException;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Config;
class TrialFirstMail extends Mailable
{
use Queueable, SerializesModels;
public $tries = 5;
public $timeout = 30;
protected $param;
public function __construct($param)
{
$this->param = $param;
}
public function build()
{
try {
$params = $this->param;
$mailSenderAddress = Config::get('app.mailSenderAddress');
$propertyService = App::make('App\Core\Service\PropertyService');
$propertySelectCriteria = [
'criteria' => [
['field' => 'id', 'condition' => '=', 'value' => $params['propertyId']],
],
'with' => ['userPropertyMapping.user'],
'firstRow' => true
];
$propertyData = $propertyService->select($propertySelectCriteria);
if($propertyData['status'] == 'success') {
$userPropertyMappingCollect = collect($propertyData['data']['user_property_mapping']);
$userPropertyMapping = $userPropertyMappingCollect->where('status',1)->where('user.status',1)->sortBy('id');
$userPropertyMapping = $userPropertyMapping ? $userPropertyMapping->toArray() : [];
$defaultUser = reset($userPropertyMapping);
$mailData['to'] = [
'email' => $defaultUser['user']['email'],
'nameSurname' => $defaultUser['user']['nameSurname'],
];
$mailData['bcc'] = [];
foreach ($userPropertyMapping as $user) {
//$mailData['bcc'][] = $user['user']['email'];
}
$mailData['bcc'] = 'channel@extranetwork.com';//TODO: Delete
$mailParams= [
'email' => $mailData['to']['email'],
'nameSurname' => $mailData['to']['nameSurname'],
'propertyName' => $propertyData['data']['name'],
];
$mailTitle = 'Rezervasyonlarını ikiye katlamaya hazır mısın? 🚀';
//app('translator')->setLocale('en');
//echo view('emails.reminder.trialFirstMail', compact('mailParams')); die();
return $this->from($mailSenderAddress, 'Extranetwork')
->view('emails.reminder.trialFirstMail', compact('mailParams'))
->to($mailData['to']['email'], $mailData['to']['nameSurname'])
->bcc($mailData['bcc'])
->subject($mailTitle)
->with(['message' => $this]);
}
} catch (ApiErrorException $e) {
return output(['status' => -1, 'message' => $e->getMessage()]);
} catch (Exception $e) {
$message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
Log::error($message);
return output(['status' => -1, 'message' => $e->getMessage()]);
}
}
}