Created
January 26, 2019 08:10
-
-
Save nutch31/a221e408787e06137d53f61947250f80 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use Illuminate\Http\Request; | |
use App\Jobs\VerifyLeadsEveryCampaignEmail as VFR; | |
use App\VerifyLeadsEveryCampaign; | |
class VerifyLeadsEveryCampaignEmailController extends Controller | |
{ | |
// | |
public function __construct() | |
{ | |
} | |
public function verifyLeadsEveryCampaignEmail(Request $request) | |
{ | |
$json = file_get_contents("php://input"); | |
$request = json_decode($json, true); | |
$email_account_manager = array(); | |
$email_relate = array(); | |
$email_from = array(); | |
$subject_name = array(); | |
$email_bcc = array(); | |
foreach($request as $key => $r) | |
{ | |
if($r["lead_status"] == "Error") | |
{ | |
$email_account_manager[$key] = $r["email_account_manager"]; | |
$email_from[$key] = $r["email_from"]; | |
$subject_name[$key] = $r["subject_name"]; | |
$email_bcc[$key] = $r["email_bcc"]; | |
} | |
} | |
$email_account_manager = array_values(array_unique($email_account_manager)); | |
foreach($email_account_manager as $key => $e) | |
{ | |
foreach($request as $keyR => $r) | |
{ | |
if($r["lead_status"] == "Error") | |
{ | |
if($e == $r["email_account_manager"]) | |
{ | |
foreach($r["email"] as $keyE => $email) | |
{ | |
$email_relate[$key][] = $email; | |
} | |
} | |
} | |
} | |
$email_relate[$key] = array_values(array_unique($email_relate[$key])); | |
$email_relate[$key] = array('nut@heroleads.com', 'nut_ch31@hotmail.com'); | |
$email_from[$key] = "noreply@heroleads.com"; | |
$email_account_manager[$key] = "nut@heroleads.com"; | |
$email_bcc[$key] = array(); | |
$subject_name[$key] = "Subject : Notify Leads checking from Alpha"; | |
dispatch(new VFR($request, $email_relate[$key], $email_from[$key], $email_account_manager[$key], $email_bcc[$key], $subject_name[$key])); | |
$html = view('email.sendVerifyLeadsEveryCampaignEmail', array( | |
"data" => $request, | |
"email_relate" => $email_relate[$key], | |
"email_from" => $email_from[$key], | |
"email_account_manager" => $email_account_manager[$key], | |
"email_bcc" => $email_bcc[$key], | |
"subject_name" => $subject_name[$key] | |
)); | |
$verifyLeadsEveryCampaign = new VerifyLeadsEveryCampaign(); | |
$verifyLeadsEveryCampaign->name = json_encode($email_relate[$key]); | |
$verifyLeadsEveryCampaign->email_from = $email_from[$key]; | |
$verifyLeadsEveryCampaign->email = json_encode($email_account_manager[$key]); | |
$verifyLeadsEveryCampaign->email_cc = json_encode($email_relate[$key]); | |
$verifyLeadsEveryCampaign->email_bcc = json_encode($email_bcc[$key]); | |
$verifyLeadsEveryCampaign->subject_name = $subject_name[$key].' - '.date("Y-m-d"); | |
$verifyLeadsEveryCampaign->body_mail = $html; | |
$verifyLeadsEveryCampaign->status = 1; | |
$verifyLeadsEveryCampaign->save(); | |
} | |
return response(array( | |
'Status' => 'Success' | |
), '200'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Jobs; | |
use Illuminate\Bus\Queueable; | |
use Illuminate\Queue\SerializesModels; | |
use Illuminate\Queue\InteractsWithQueue; | |
use Illuminate\Contracts\Queue\ShouldQueue; | |
use Illuminate\Foundation\Bus\Dispatchable; | |
use Illuminate\Support\Facades\Mail; | |
class VerifyLeadsEveryCampaignJob implements ShouldQueue | |
{ | |
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | |
public $request; | |
public $email_relate; | |
public $email_from; | |
public $email_account_manager; | |
public $email_bcc; | |
public $subject_name; | |
public $timeout = 120; | |
public $tries = 3; | |
/** | |
* Create a new job instance. | |
* | |
* @return void | |
*/ | |
public function __construct($request, $email_relate, $email_from, $email_account_manager, $email_bcc, $subject_name) | |
{ | |
// | |
$this->request = $request; | |
$this->email_relate = $email_relate; | |
$this->email_from = $email_from; | |
$this->email_account_manager = $email_account_manager; | |
$this->email_bcc = $email_bcc; | |
$this->subject_name = $subject_name; | |
} | |
/** | |
* Execute the job. | |
* | |
* @return void | |
*/ | |
public function handle() | |
{ | |
// | |
$request = $this->request; | |
$email_relate = $this->email_relate; | |
$email_from = $this->email_from; | |
$email_account_manager = $this->email_account_manager; | |
$email_bcc = $this->email_bcc; | |
$subject_name = $this->subject_name; | |
$data = [ | |
'email_relate' => $email_relate, | |
'email_from' => $email_from, | |
'email_account_manager' => $email_account_manager, | |
'email_bcc' => $email_bcc, | |
'subject_name' => $subject_name | |
]; | |
Mail::send('email.sendVerifyLeadsEveryCampaignEmail', array( | |
"data" => $request, | |
"email_relate" => $email_relate, | |
"email_from" => $email_from, | |
"email_account_manager" => $email_account_manager, | |
"email_bcc" => $email_bcc, | |
"subject_name" => $subject_name | |
), function ($message) use ($data) | |
{ | |
$message->from($data['email_from']); | |
$message->to($data['email_account_manager']); | |
if(!empty($data['email_relate'])) | |
{ | |
$message->cc($data['email_relate']); | |
} | |
if(!empty($data['email_bcc'])) | |
{ | |
$message->bcc($data['email_bcc']); | |
} | |
$message->subject($data["subject_name"].' - '.date("Y-m-d")); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment