Fewos in CRM,
Fewo Clients Bookings create / edit / delelte via API in DB
This commit is contained in:
parent
aebfb0586a
commit
c0c2a1822c
55 changed files with 9787 additions and 1486 deletions
104
app/Http/Controllers/API/FewoController.php
Executable file
104
app/Http/Controllers/API/FewoController.php
Executable file
|
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\BookingDraftItem;
|
||||
use App\Models\TravelUser;
|
||||
use App\Models\TravelUserBookingFewo;
|
||||
use Carbon\Carbon;
|
||||
use Validator;
|
||||
|
||||
class FewoController extends Controller
|
||||
{
|
||||
public $successStatus = 200;
|
||||
public $errorStatus = 500;
|
||||
public $data = "";
|
||||
public $room_str = "";
|
||||
public $room_name = "";
|
||||
public $className = "";
|
||||
public $option = "";
|
||||
|
||||
public function action($action)
|
||||
{
|
||||
|
||||
|
||||
|
||||
if ($action == "create_travel_users") {
|
||||
$data = \Input::all();
|
||||
if(!isset($data['travel_user']) && !is_array($data['travel_user'])) {
|
||||
return response()->json(['error' => 'travel_user not exist, but need'], $this->errorStatus);
|
||||
}
|
||||
if(!isset($data['travel_user']['email'])){
|
||||
return response()->json(['error' => 'travel_user email not exist, but need'], $this->errorStatus);
|
||||
}
|
||||
|
||||
$rules = array(
|
||||
'salutation_id' => 'required',
|
||||
'travel_nationality_id' => 'required',
|
||||
'first_name'=>'required',
|
||||
'last_name'=>'required',
|
||||
'email' => 'required|string|email|max:255|'
|
||||
|
||||
);
|
||||
$validator = Validator::make($data['travel_user'], $rules);
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->messages(), $this->errorStatus);
|
||||
|
||||
}
|
||||
|
||||
$travel_user = TravelUser::where('email', trim($data['travel_user']['email']))->first();
|
||||
if(!$travel_user) {
|
||||
$travel_user = TravelUser::create($data['travel_user']);
|
||||
}else{
|
||||
$checked = [
|
||||
'salutation_id',
|
||||
'first_name',
|
||||
'last_name',
|
||||
'street',
|
||||
'zipcode',
|
||||
'city',
|
||||
'phone',
|
||||
'fax',
|
||||
'travel_nationality_id'
|
||||
];
|
||||
|
||||
$last_user_data = [];
|
||||
foreach ($checked as $check){
|
||||
if($travel_user->{$check} != $data['travel_user'][$check]){
|
||||
$last_user_data[$check] = $travel_user->{$check};
|
||||
}
|
||||
}
|
||||
$data['travel_user']['last_user_data'] = $last_user_data;
|
||||
$travel_user->fill($data['travel_user'])->save();
|
||||
}
|
||||
return response()->json(['success' => ['travel_user_id' => $travel_user->id]], $this->successStatus);
|
||||
}
|
||||
|
||||
|
||||
if ($action == "create_fewo_booking") {
|
||||
|
||||
$data = \Input::all();
|
||||
if(!isset($data['travel_user_booking_fewo']) && !is_array($data['travel_user_booking_fewo'])) {
|
||||
return response()->json(['error' => 'travel_user_booking_fewo not exist, but need'], $this->errorStatus);
|
||||
}
|
||||
$rules = array(
|
||||
'travel_user_id' => 'required',
|
||||
'fewo_lodging_id' => 'required',
|
||||
'from_date'=>'required',
|
||||
'to_date'=>'required',
|
||||
|
||||
);
|
||||
$validator = Validator::make($data['travel_user_booking_fewo'], $rules);
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->messages(), $this->errorStatus);
|
||||
|
||||
}
|
||||
|
||||
$travel_user_booking_fewo = TravelUserBookingFewo::create($data['travel_user_booking_fewo']);
|
||||
|
||||
return response()->json(['success' => ['travel_user_booking_fewo_id' => $travel_user_booking_fewo->id, 'crm_url' => route('travel_user_booking_fewo_detail', [$travel_user_booking_fewo->id])]], $this->successStatus);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue