turkmentv/app/Http/Controllers/BukjaController.php

196 lines
5.4 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\BukjaOrder;
use App\Models\Folder;
use App\User;
use App\Models\PropertyType;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
use function MongoDB\BSON\toJSON;
class BukjaController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
$folders = $this->getFolders();
$props=$this->getProps();
$userbukja = User::where('bukja', '!=' , false)->first();
$email = $userbukja->email;
return view('web.bukjalar')->with([
'title'=>'Mahabat Nyrhnama bukjalary',
'keywords'=>'',
'meta_description'=>'',
'folders'=> $folders,
'props'=> $props,
'email' => $email
]);
}
public function getFolders(){
$allFolders = Folder::all();
return $allFolders;
}
public function getProps(){
$allProps = PropertyType::all();
return $allProps;
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
$datas = $request->except('_token');
$time='Bukjada görkezizlen wagtlar!';
//dd($datas);
$datas = html_entity_decode($datas['choices']);
$data=json_decode($datas,true);
$bukjaOrder=new BukjaOrder();
foreach ($data as $val){
if (isset($val['customer'])){
$customer=$val['customer'];
$customer_name=$customer['name'];
$customer_email=$customer['email'];
$customer_phone=$customer['phone'];
$customer_notes=$customer['notes'];
$bukjaOrder->customer_name=$customer_name;
$bukjaOrder->customer_email=$customer_email;
$bukjaOrder->customer_phone=$customer_phone;
$bukjaOrder->customer_notes=$customer_notes;
}
}
foreach ($data as $val){
if (isset($val['id'])){
$bukjaOrder=new BukjaOrder();
$bukjaOrder->customer_name=$customer_name;
$bukjaOrder->customer_email=$customer_email;
$bukjaOrder->customer_phone=$customer_phone;
$bukjaOrder->customer_notes=$customer_notes;
$order_id = $val['id'];
$second=$val['second'];
$folder_id=$val['folder_id'];
$folder_name=$val['folder_name'];
$day=$val['day'];
$time=$val['time'];
$total=$val['total'];
$folder=Folder::find($folder_id);
$order_prop=$folder->property->title;
//
$bukjaOrder->order_id=$order_id;
$bukjaOrder->folder_id=$folder_id;
$bukjaOrder->folder_name=$folder_name;
$bukjaOrder->second=$second;
$bukjaOrder->day=$day;
$bukjaOrder->time=$time;
$bukjaOrder->total=$total;
$bukjaOrder->order_prop=$order_prop;
$bukjaOrder->save();
}
// if ($checked===true){
// return 'OrderSaved';
// }
}
$this->sendToMail($bukjaOrder);
}
/*
Send order to mail "mahabat@turkmentv.gov.tm"
*/
public function sendToMail($bukjaOrder){
$data = array(
'id' => utf8_encode($bukjaOrder->id),
'created_at' => $bukjaOrder->created_at,
'folder_name' => $bukjaOrder->folder_name,
'second' => $bukjaOrder->second,
'day' => $bukjaOrder->day,
'time' => $bukjaOrder->time,
'total' =>$bukjaOrder->total,
'order_prop' => $bukjaOrder->order_prop,
'customer_name' => $bukjaOrder->customer_name,
'customer_email' => $bukjaOrder->customer_email,
'customer_phone' => $bukjaOrder->customer_phone,
'customer_notes' => $bukjaOrder->customer_notes,
);
Mail::send('email_temp_folder_orders', [
'data' => $data
], function ($message){
$message->to('mahabat@turkmentv.gov.tm');
$message->subject('Mahabat Sargydy');
});
return response()->json(['message'=>'success'],201);
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}