turkmentv/app/Http/Controllers/BukjaController.php

201 lines
5.8 KiB
PHP
Raw Normal View History

2020-08-11 09:21:44 +00:00
<?php
namespace App\Http\Controllers;
use App\Models\BukjaOrder;
use App\Models\Folder;
2021-04-06 07:39:14 +00:00
use App\User;
2020-08-11 09:21:44 +00:00
use App\Models\PropertyType;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
2020-08-11 09:21:44 +00:00
use function MongoDB\BSON\toJSON;
class BukjaController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
2022-02-22 10:39:05 +00:00
public function index(){
2020-08-11 09:21:44 +00:00
$folders = $this->getFolders();
2022-02-22 10:39:05 +00:00
$props = $this->getProps();
2021-04-06 07:39:14 +00:00
$userbukja = User::where('bukja', '!=' , false)->first();
2021-04-06 07:54:21 +00:00
if($userbukja){
$email = $userbukja->email;
}
else{
2022-02-22 10:39:05 +00:00
$email = "turkmentv.gov.tm@gmail.com";
2021-04-06 07:54:21 +00:00
}
2020-08-11 09:21:44 +00:00
return view('web.bukjalar')->with([
'title'=>'Mahabat Nyrhnama bukjalary',
'keywords'=>'',
'meta_description'=>'',
2021-04-06 07:39:14 +00:00
'folders'=> $folders,
'props'=> $props,
'email' => $email
2020-08-11 09:21:44 +00:00
]);
}
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)
{
2022-04-06 19:53:50 +00:00
//Mahri001@ qazwsx12
2022-04-06 19:23:51 +00:00
try{
$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;
}
2022-04-06 19:50:19 +00:00
}
foreach ($data as $val){
2022-04-06 20:00:11 +00:00
if(isset($val['id'])){
2022-04-06 20:01:16 +00:00
2022-04-06 19:23:51 +00:00
$bukjaOrder=new BukjaOrder();
$bukjaOrder->customer_name=$customer_name;
$bukjaOrder->customer_email=$customer_email;
$bukjaOrder->customer_phone=$customer_phone;
$bukjaOrder->customer_notes=$customer_notes;
2022-04-06 20:03:16 +00:00
2022-04-06 19:23:51 +00:00
$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;
2022-04-06 20:04:31 +00:00
2022-04-06 19:23:51 +00:00
$bukjaOrder->save();
2022-04-07 11:52:57 +00:00
$this->sendToMail($bukjaOrder);
2022-04-06 19:23:51 +00:00
}
2020-08-11 09:21:44 +00:00
}
2022-04-06 20:14:28 +00:00
return $bukjaOrder;
2022-04-06 19:23:51 +00:00
}
catch(\Exception $e){
return $e->getMessage();
2020-08-11 09:21:44 +00:00
}
}
2021-04-06 07:39:14 +00:00
/*
Send order to mail "mahabat@turkmentv.gov.tm"
2021-04-06 07:39:14 +00:00
*/
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){
2022-04-07 11:58:35 +00:00
$message->to('admin@turkmentv.gov.tm');
$message->subject('Mahabat Sargydy');
});
2022-04-06 19:23:51 +00:00
return response()->json(['message'=>'success'],201);
2020-08-11 09:21:44 +00:00
}
/**
* 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)
{
//
}
}