Файловый менеджер - Редактировать - /home/clickysoft/public_html/somni.clickysoft.net/app/Repositories/LandlordRepository.php
Назад
<?php namespace App\Repositories; use App\Interfaces\LandlordRepositoryInterface; use App\Repositories\WalletRepository; use App\Models\Property; use App\Models\Unit; use App\Models\Country; use App\Models\City; use App\Models\State; use App\Models\User; use App\Models\UserInfo; use App\Models\Newsletter; use App\Models\InvitationPropertyUnit; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Str; class LandlordRepository implements LandlordRepositoryInterface { public function getLandlordById($user_id){ $landlord = User::whereHas('roles',function($query){ $query->whereTitle('Landlord'); })->whereId($user_id)->first(); return $landlord; } public function createLandlord($data){ DB::beginTransaction(); $info = []; $property = []; $walletRepo = new WalletRepository; //Landlord Creation // $name = explode('@', $data->email); $landlord['name'] = $data->firstname. ' ' . $data->lastname; $landlord['email'] = $data->email; $landlord['password'] = Hash::make($data->password); $landlord['has_completed_tour'] = 0; $landlord['created_at'] = now(); if(isset($data->phone_number)){ $landlord['phone'] = $data->phone_number; } $landlord_new = User::create($landlord); if($landlord_new){ $landlord_new->roles()->sync(config('constants.role.landlord')); } if(isset($data->company_phone)){ UserInfo::create(['user_id' => $landlord_new->id ,'company_phone' => $data->company_phone]); } //Property Creation $property['name'] = $data->property_name; $property['address'] = $data->address; $property['slug'] = str_slug($data->property_name); $property['created_at'] = now(); $property['user_id'] = $landlord_new->id; $property['is_selected'] = 1; // $property['country_id'] = $data->country_id; // $property['city_id'] = $data->city_id; // $property['state_id'] = $data->state_id; $property['country'] = $data->country; $property['city'] = $data->city; $property['state'] = $data->state; $property['zip_code'] = $data->zip_code; $property_new = Property::create($property); //Unit Creation $no_of_units = $data->no_of_units; for ($i=0; $i < $no_of_units; $i++) { $number = $this->generateRandomNameUsingNumberAndAlphabet(1,100); $unit['number'] = $number; $unit['slug'] = str_slug($number); $unit['lease_term'] = $data->lease_term; $unit['rent_due_date'] = $data->rent_due_date; $unit['monthly_rent'] = $data->monthly_rent; $unit['no_of_bathroom'] = $data->no_of_bathrooms; $unit['no_of_bedrooms'] = $data->no_of_bedrooms; $unit['property_id'] = $property_new->id; if(isset($data->unit_size)){ $unit['unit_size'] = $data->unit_size; } if(isset($data->security_deposit)){ $unit['security_deposit'] = $data->security_deposit; } if(isset($data->available_date)){ $unit['available_date'] = $data->available_date; } $new_unit = Unit::create($unit); if(isset($data->amenities) && !empty($data->amenities)){ $new_unit->amenities()->sync($data->amenities); } } if(isset($data->subscribe)){ Newsletter::create(['email' => $data->email ]); } $wallet['user_id'] = $landlord_new->id; $wallet['balance'] = 0; $wallet['created_at'] = now(); $wallet_created = $walletRepo->createWallet($wallet); DB::commit(); return $landlord_new->load('roles'); } public function getFirstProperty($user_id){ $property = Property::Complete()->where('user_id',$user_id)->orderBy('created_at','DESC')->first(); return $property; } public function getSelectedProperty($user_id){ $property = Property::Complete()->where('user_id',$user_id)->where('is_selected', 1)->orderBy('created_at','DESC')->first(); return $property; } public function generateRandomNameUsingNumberAndAlphabet($start_number, $end_number) { $number = mt_rand($start_number, $end_number); // Generate a random number between 1 and 100 $letter = chr(mt_rand(65, 90)); // Generate a random capital letter (ASCII code 65 to 90) return $number . $letter; // Combine the number and letter } public function getAllPropertiesWithUnitsCount($user_id){ $properties = Property::withCount('propertyUnits as units')->where('user_id',$user_id)->orderBy('id','DESC')->get(); return $properties; } public function getAllCompletePropertiesWithUnitsCount($user_id){ $properties = Property::withCount('propertyUnits as units')->where('user_id',$user_id)->where('is_complete', 1)->orderBy('id','DESC')->get(); return $properties; } public function changeSelectedPropertyLandlord($user_id,$property_id){ Property::where('user_id',$user_id)->update(['is_selected' => 0]); $update = Property::where('user_id',$user_id)->where('id',$property_id)->update(['is_selected' => 1]); return $update; } public function partialFilledProperty($user_id){ $property = Property::where('user_id',$user_id)->whereIsComplete(0)->first(); return $property; } public function getPartialCompletedUnitsByPropertyId($property_id){ $units = Unit::where('is_complete', 0)->where('property_id',$property_id)->where('special_unit', 0)->get(); return $units; } public function getSpecialPartialCompleteUnitsWithByPropertyId($property_id){ $units = Unit::select('id','number','special_unit','size','monthly_rent','lease_term')->where('is_complete', 0)->where('property_id',$property_id)->where('special_unit', 1)->get()->toArray(); return $units; } public function saveSteppedAddPropertyForm($data){ $partial_property = $this->partialFilledProperty(auth()->user()->id); $flag = false; $property_id = ''; $new_units_count = 0; $payment = false; switch ($data->step_count) { case 0: //First step if($partial_property){ $updateProperty['step_count'] = $data->step_count; $updateProperty['address'] = $data->property_address; $updateProperty['type'] = $data->property_type; // $updateProperty['is_complete'] = 0; $update = $partial_property->update($updateProperty); if($update){ $flag = true; } }else{ $saveProperty['user_id'] = auth()->user()->id; $saveProperty['step_count'] = $data->step_count; $saveProperty['address'] = $data->property_address; $saveProperty['type'] = $data->property_type; $saveProperty['is_complete'] = 0; $newProperty = Property::create($saveProperty); if($newProperty){ $property_id = $newProperty->id; $flag = true; } } break; case 1: // Second Step if($partial_property){ $updateProperty['name'] = $data->property_name; $updateProperty['slug'] = str_slug($data->property_name); // $updateProperty['country_id'] = (int)$data->country_id; // $updateProperty['city_id'] = (int)$data->city_id; // $updateProperty['state_id'] = (int)$data->state_id; $updateProperty['country'] = $data->country; $updateProperty['city'] = $data->city; $updateProperty['state'] = $data->state; $updateProperty['zip_code'] = $data->zip_code; $updateProperty['purchase_date'] = $data->date_of_purchase; $updateProperty['value'] = $data->property_value; $updateProperty['purchase_term'] = $data->purchase_term; // $update = Property::where('user_id',auth()->user()->id)->update($updateProperty); $update = $partial_property->update($updateProperty); if($update){ // $property_id = $update->id; $flag = true; } } // else{ // $saveProperty['name'] = $data->property_name; // $saveProperty['slug'] = str_slug($data->property_name); // $saveProperty['country_id'] = (int)$data->country_id; // $saveProperty['city_id'] = (int)$data->city_id; // $saveProperty['state_id'] = (int)$data->state_id; // $saveProperty['zip_code'] = $data->zip_code; // $saveProperty['purchase_date'] = $data->date_of_purchase; // $saveProperty['value'] = $data->property_value; // $saveProperty['purchase_term'] = $data->purchase_term; // $newProperty = Property::create($saveProperty); // if($newProperty){ // $flag = true; // } // } # code... break; case 2: //Third Step if($partial_property){ // $partial_units = $partial_property->propertyUnits->isNotEmpty() $partial_units = $partial_property->propertyUnits()->where('property_id', $partial_property->id)->where('is_complete', 0)->get(); if($partial_units->isNotEmpty()){ foreach ($partial_units as $unit) { $updateUnit['layout_type'] = $data->layout_type; $updateUnit['is_complete'] = "0"; $updateUnit['property_id'] = $partial_property->id; $updateUnit['format_style'] = $data->format_styles; $unit->update($updateUnit); } $flag = true; }else{ for ($i=0; $i < $data->number_of_units ; $i++) { Unit::create(['property_id' => $partial_property->id,'layout_type' => $data->layout_type, 'is_complete' => "0", 'format_styles' => $data->format_styles]); } $flag = true; } } break; case 3: //Fourth Step if($partial_property){ // $partial_units = $partial_property->propertyUnits->isNotEmpty() $partial_units = $partial_property->propertyUnits()->where('property_id', $partial_property->id)->where('is_complete', 0)->get(); // dd($partial_units); if($partial_units->isNotEmpty()){ if($data->special_units_check == 'no'){ foreach($data->units_diff_selected as $key => $unit){ $updateUnits['lease_term'] = $data->lease_term_different; $updateUnits['monthly_rent'] = $data->monthly_rent_diff; $updateUnits['security_deposit'] = $data->security_deposit_diff; $updateUnits['size'] = (float)$data->unit_size_diff; $updateUnits['number'] = $unit; $updateUnits['slug'] = str_slug($unit); $updateUnits['is_complete'] = "0"; $partial_units[$key]->update($updateUnits); $partial_units[$key]->amenities()->sync($data->amenities_different); } // Find items in $unit_diff that are not in $unit_original $remaining_units = array_diff($data->units_generated, $data->units_diff_selected); // Re-index the resulting array if needed $remain_units = array_values($remaining_units); if(!empty($remain_units)){ foreach ($remain_units as $key => $remain_unit) { // if($partial_units[$key]->number == null){ $updateUnitsRemain['lease_term'] = $data->lease_term; $updateUnitsRemain['monthly_rent'] = $data->monthly_rent; $updateUnitsRemain['security_deposit'] = $data->security_deposit; $updateUnitsRemain['size'] = (float)$data->unit_size; $updateUnitsRemain['number'] = $remain_unit; $updateUnitsRemain['slug'] = str_slug($remain_unit); $updateUnitsRemain['is_complete'] = "0"; foreach ($partial_units as $key => $unit) { if($unit->number == $remain_unit || $unit->number == null){ $unit->update($updateUnitsRemain); $unit->amenities()->sync($data->amenities); break; } } // } } } }else{ // dd($partial_units); foreach ($partial_units as $key => $unit) { $updateUnits['purchase_term'] = $data->purchase_term; $updateUnits['lease_term'] = $data->lease_term; $updateUnits['monthly_rent'] = $data->monthly_rent; $updateUnits['security_deposit'] = $data->security_deposit; $updateUnits['size'] = (float)$data->unit_size; $updateUnits['number'] = $data->units_generated[$key]; $updateUnits['slug'] = str_slug($data->units_generated[$key]); $updateUnits['is_complete'] = "0"; $unit->update($updateUnits); $unit->amenities()->sync($data->amenities); } } foreach ($partial_units as $key => $unit) { $updateUnit['rent_due_date'] = $data->rent_due_date; $unit->update($updateUnit); } $flag = true; }else{ if($data->special_units_check == 'no'){ foreach($data->units_diff_selected as $key => $unit){ $newUnit['lease_term'] = $data->lease_term_different; $newUnit['monthly_rent'] = $data->monthly_rent_diff; $newUnit['security_deposit'] = $data->security_deposit_diff; $newUnit['size'] = (float)$data->unit_size_diff; $newUnit['number'] = $unit; $newUnit['slug'] = str_slug($unit); $newUnit['is_complete'] = "0"; $new_unit = Unit::create($newUnit); $new_unit->amenities()->sync($data->amenities_different); } $remaining_units = array_diff($data->units_generated, $data->units_diff_selected); // Re-index the resulting array if needed $remain_units = array_values($remaining_units); if(!empty($remain_units)){ foreach ($remain_units as $key => $remain_unit) { // if($partial_units[$key]->number == null){ $newOther['lease_term'] = $data->lease_term; $newOther['monthly_rent'] = $data->monthly_rent; $newOther['security_deposit'] = $data->security_deposit; $newOther['size'] = (float)$data->unit_size; $newOther['number'] = $remain_unit; $newOther['slug'] = str_slug($remain_unit); $newOther['is_complete'] = "0"; $unit = Unit::create($newOther); // $unit->update($updateUnitsRemain); $unit->amenities()->sync($data->amenities); // } } break; } }else{ for ($i=0; $i < $data->number_of_units ; $i++) { $newUnit['property_id'] = $partial_property->id; $newUnit['purchase_term'] = $data->purchase_term; $newUnit['lease_term'] = $data->lease_term; $newUnit['monthly_rent'] = $data->monthly_rent_diff; $newUnit['security_deposit'] = $data->security_deposit_diff; $newUnit['size'] = (float)$data->unit_size; $newUnit['number'] = $data->units_generated[$i]; $newUnit['slug'] = str_slug($data->units_generated[$i]); $newUnit['is_complete'] = "0"; $new_unit = Unit::create($newUnit); $new_unit->amenities()->sync($data->amenities); } } $flag = true; } } break; case 4: //Final & Fifth Step $user = auth()->user(); $propertyInterfaceObj = new PropertyRepository(); $subscriptionInterfaceObj = new SubscriptionRepository(); $unitCount = $propertyInterfaceObj->getUsersActiveUnitsCount($user->id); $activePlan = $subscriptionInterfaceObj->getActivePackageOfUser($user->id); $total_units = $data->number_of_units + $unitCount; // if($total_units >= $activePlan->units_limit && $activePlan->id != 1){ // 'Unit Limit Reached! Upgrade Plan' // } if($partial_property){ $partial_units = $partial_property->propertyUnits()->where('property_id', $partial_property->id)->where('is_complete', 0)->get(); if($partial_units->isNotEmpty()){ foreach ($partial_units as $key => $unit) { $updateUnitsFinal['no_of_bedrooms'] = $data->no_of_bedrooms; $updateUnitsFinal['no_of_bathroom'] = $data->no_of_bathrooms; $updateUnitsFinal['available_date'] = $data->date_available; if($total_units >= $activePlan->units_limit && $activePlan->id != 1){ $updateUnitsFinal['is_complete'] = "0"; }else{ $updateUnitsFinal['is_complete'] = 1; } $unit->update($updateUnitsFinal); } } } if($total_units >= $activePlan->units_limit && $activePlan->id != 1){ $partial_property->update(['is_complete' => 0]); $payment = true; $new_units_count = $data->number_of_units; }else{ $partial_property->update(['is_complete' => 1]); } $flag = true; break; } return [ 'flag' => $flag, 'property_id' => $partial_property->id ?? null, 'payment' => $payment, 'new_units_count' => $new_units_count ]; // return $flag; } public function getUnitsByPropertyId($property_id){ $units = Unit::where('property_id',$property_id)->Complete()->orderBy('created_at', 'DESC')->get(); return $units; } public function getUnitsByPropertyIdLimit($property_id){ $units = Unit::where('property_id',$property_id)->Complete()->orderBy('created_at', 'DESC')->limit(5)->get(); return $units; } public function getUnitsByPropertyIdPaginate($property_id){ $units = Unit::where('property_id',$property_id)->Complete()->orderBy('created_at', 'DESC')->paginate(10); return $units; } public function getUnitsById($unit_id){ $unit = Unit::whereId($unit_id)->Complete()->first(); return $unit; } public function deleteUnitById($unit_id){ $delete = Unit::destroy($unit_id); return $delete; } public function createInvitationCode($email,$unit_id){ $invitationPropertyUnit['unit_id'] = $unit_id; $invitationPropertyUnit['email'] = $email; $invitationPropertyUnit['token'] = Str::random(16); $invitationPropertyUnit['invitation_code'] = rand(10000000, 99999999); $invitationPropertyUnit['invitation_message'] = "You are invited to rent a Unit"; $invitationPropertyUnit['is_accepted'] = false; $invitationPropertyUnit['created_at'] = now(); $created_invitation = InvitationPropertyUnit::create($invitationPropertyUnit); return $created_invitation; } public function checkInvitation($email, $unit_id){ $flag = InvitationPropertyUnit::where('email',$email)->where('unit_id',$unit_id)->first(); if($flag == null){ return false; } return true; } public function updateUnitById($unit_to_update,$amenities,$unit_id){ $unit_to_update['slug'] = str_slug($unit_to_update['number']); $updated = Unit::whereId($unit_id)->update($unit_to_update); $unit = $this->getUnitsById($unit_id); $unit->amenities()->sync($amenities); return $updated; } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.29 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка