mein-sterntours/app/Repositories/BookingRepository.php
2021-03-31 17:55:02 +02:00

137 lines
No EOL
4.5 KiB
PHP

<?php
namespace App\Repositories;
use App\Models\Booking;
use App\Models\BookingNotice;
use Auth;
use App\Models\BookingCompanyService;
use App\Models\BookingCountryService;
use App\Models\BookingProviderService;
class BookingRepository extends BaseRepository {
public function __construct(Booking $model)
{
$this->model = $model;
}
public function update($data)
{
return $this->model;
}
public function updateNotice($id, $data){
$this->model = Booking::findOrFail($id);
BookingNotice::create([
'booking_id' => $this->model->id,
'from_user_id' => Auth::user()->id,
'to_user_id' => isset($this->model->sf_guard_user->user_id) ? $this->model->sf_guard_user->user_id : null,
'message' => isset($data['booking_notice']) ? $data['booking_notice'] : "",
]
);
return $this->model;
}
public function updateBooking($id, $data){
$this->model = Booking::findOrFail($id);
$fill = [
'paying_out' => $data['paying_out'],
'paying_out_status' => $data['paying_out_status'],
'airline_id' => $data['airline_id'],
'refund' => $data['refund'],
'refund_date' => _reformat_date($data['refund_date']),
'lawyer_date' => _reformat_date($data['lawyer_date']),
'hold' => $data['hold'],
'xx_tkt' => $data['xx_tkt'],
'xx_tkt_date' => _reformat_date($data['xx_tkt_date']),
'filekey' => $data['filekey'],
'is_rail_fly' => isset($data['is_rail_fly']) ? true : false,
'notice' => $data['notice'],
];
$this->model->fill($fill);
$this->model->save();
if(isset($data['country_service'])){
$this->updateCountryService($data['country_service']);
}
if(isset($data['provider_service'])){
$this->updateProviderService($data['provider_service']);
}
if(isset($data['company_service'])){
$this->updateCompanyService($data['company_service']);
}
return $this->model;
}
public function updateCountryService($country_services){
foreach ($country_services as $country_service_id=>$val){
$booking_country_service = BookingCountryService::where('travel_country_service_id', '=', $country_service_id)
->where('booking_id', '=', $this->model->id)->first();
if(!$booking_country_service){
BookingCountryService::create([
'travel_country_service_id' => $country_service_id,
'booking_id' => $this->model->id,
'status' => $val
]);
}else{
$booking_country_service->fill([
'status' => $val
]);
$booking_country_service->save();
}
}
}
public function updateProviderService($provider_service){
foreach ($provider_service as $provider_service_id=>$val){
$booking_provider_service = BookingProviderService::where('service_provider_service_id', '=', $provider_service_id)
->where('booking_id', '=', $this->model->id)->first();
if(!$booking_provider_service){
BookingProviderService::create([
'service_provider_service_id' => $provider_service_id,
'booking_id' => $this->model->id,
'status' => $val
]);
}else{
$booking_provider_service->fill([
'status' => $val
]);
$booking_provider_service->save();
}
}
}
public function updateCompanyService($company_service){
foreach ($company_service as $company_service_id=>$val){
$booking_company_service = BookingCompanyService::where('travel_company_service_id', '=', $company_service_id)
->where('booking_id', '=', $this->model->id)->first();
if(!$booking_company_service){
BookingCompanyService::create([
'travel_company_service_id' => $company_service_id,
'booking_id' => $this->model->id,
'status' => $val
]);
}else{
$booking_company_service->fill([
'status' => $val
]);
$booking_company_service->save();
}
}
}
}