D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
tattooscyy
/
stage
/
app
/
Http
/
Controllers
/
Manager
/
Filename :
PromotionController.php
back
Copy
<?php namespace App\Http\Controllers\Manager; use Illuminate\Http\Request; use App\Http\Controllers\Controller; use Auth; use Mail; use App\Saloon; use App\Promotion; use App\PromotionEmail; use App\Contract; class PromotionController extends Controller { public function __construct() { set_time_limit(0); } public function getIndex(Request $request) { $saloon = $request->saloon; $id = (int)$saloon->id; if (Auth::user()->role_id == 1) { $promotions = Promotion::orderBy('id', 'DESC')->paginate('30'); $role_id = 1; } else { $promotions = Promotion::where('saloon_id', $saloon->id)->orderBy('id', 'DESC')->paginate('30'); $role_id = 0; } $saloons = Saloon::all(); return view('manager.promotions', compact('saloons', 'promotions', 'id', 'role_id')); } public function postIndex() { //dd($_POST); $saloon_id = (int)$_POST['saloon_id']; $obj = new Promotion; $obj->thema = $_POST['thema']; $obj->body = $_POST['body']; $obj->saloon_id = $saloon_id; $obj->type_tattoo = (isset($_POST['type_tatoo'])) ? $_POST['type_tatoo'] : ''; $obj->type_piercing = (isset($_POST['type_piercing'])) ? $_POST['type_piercing'] : ''; $obj->user_id = Auth::user()->id; $obj->save(); $arr_type = []; if (isset($_POST['type_piercing']) && $_POST['type_piercing'] == 'Piercing') { $arr_type[] = 'piercing'; } else { //echo "Do not Need wheelchair access."; } if (isset($_POST['type_tatoo']) && $_POST['type_tatoo'] == 'Tattoo') { $arr_type[] = 'tattoo'; } else { //echo "Do not Need wheelchair access."; } //$contrs = Contract::whereIn('type', $arr_type)->where('saloon_id', $saloon_id)->orderBy('id', 'DESC')->get(); $contrs = Contract::where('email', 'mikhalkevich@ya.ru')->orderBy('id', 'DESC')->get(); /* foreach($contrs as $one){ $to_name = $one->name; $to_email = $one->email; dump($one); } dd(); */ //$contrs = Contract::whereIn('id', [2548, 33802, 33803, 33804, 33805])->get(); //$contrs = Contract::whereIn('id', [2548])->get(); foreach ($contrs as $one) { $promm = PromotionEmail::where('email', $one->email)->where('putdate', date('y-m-d'))->first(); if (!$promm) { $to_name = $one->name; $to_email = $one->email; $data = array('name' => $one->name, "body" => $_POST['body']); if (filter_var($to_email, FILTER_VALIDATE_EMAIL) !== false) { Mail::send(['html' => 'emails'], $data, function ($message) use ($to_name, $to_email, $one, $obj) { if($obj->saloon_id == 5){ $saloon_name = 'Magic Circus'; }else{ $saloon_name = 'American Body Art'; } $message->to($to_email, $to_name)->subject($_POST['thema']); $message->from(env('MAIL_FROM_ADDRESS','noreply@americanbodyart.fr'), $saloon_name); $message->getHeaders() ->addTextHeader('Content-type', 'text/html; charset=utf-8 \r\n'); $pro = new PromotionEmail; $pro->email = $one->email; $pro->putdate = date('y-m-d'); $pro->promotion_id = $obj->id; $pro->contract_id = $one->id; $pro->save(); }); } } } return redirect()->back(); } }