Server : Apache System : Linux 145.162.205.92.host.secureserver.net 5.14.0-611.45.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Apr 1 05:56:53 EDT 2026 x86_64 User : tradze ( 1001) PHP Version : 8.1.34 Disable Function : NONE Directory : /home/tradze/www/test.tradze.com/app_old/ |
<?php
namespace App;
use App\Modules\Schedules\Repositories\BookingRepository;
use App\Modules\Services\Models\ServiceDuration;
use App\Modules\Users\Models\UserServiceDuration;
use Bican\Roles\Models\Role;
use Carbon\Carbon;
use Illuminate\Contracts\Auth\CanResetPassword;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Bican\Roles\Traits\HasRoleAndPermission;
use Bican\Roles\Contracts\HasRoleAndPermission as HasRoleAndPermissionContract;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
//use Laravel\Cashier\Billable;
use Cmgmyr\Messenger\Traits\Messagable;
use App\Modules\Testimonials\Models\SalonReviews;
//class User extends Authenticatable implements AuthenticatableContract, CanResetPasswordContract, HasRoleAndPermissionContract
class User extends Authenticatable implements HasRoleAndPermissionContract
{
// use Billable;
use HasRoleAndPermission;
use Messagable;
use SoftDeletes;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'show_email', 'password', 'braintree_id', 'payment_method', 'instagram_id', 'facebook_id', 'tictok_id', 'youtube_id', 'website_redirect_url', 'paypal_email', 'card_brand', 'card_last_four', 'trial_ends_at','api_token', 'newsletter','salon_id', 'is_book_now', 'is_featured', 'lat','long','nr_crt',
];
protected $with = ['profile'];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
protected $appends = ['salon_overall_rating', 'therapist_overall_rating'];
/**
* Get the profile associated with the user.
*/
public function profile()
{
return $this->hasOne('App\Modules\Users\Models\UserProfile');
}
// get active users
public function stripeSubscription()
{
return $this->hasMany('App\StripeSubscription', 'user_id');
}
// Get Salon gallary
public function salongallaryall()
{
return $this->hasMany('App\Modules\Users\Models\SalonGallery');
}
// Get Salon reviews
public function reviews()
{
return $this->hasMany('App\Modules\Testimonials\Models\SalonReviews', 'salon_id')->where('is_approved', 1);
}
// Get Therapist Review
public function therapistreview() {
return $this->hasMany('App\Modules\Testimonials\Models\SalonReviews', 'therapist_id')->where('is_approved', 1);
}
//get therapist work
public function mywork()
{
return $this->hasMany('App\Modules\Users\Models\TherapistMyWork');
}
/**
* The address that belong to the user.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function address()
{
return $this->hasMany('App\Modules\Users\Models\UserAddress');
}
/**
* The billing address that belong to the user.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function billingaddress()
{
return $this->hasMany('App\Modules\Users\Models\UserBillingAddress');
}
/**
* Get the profile associated with the user.
*/
public function workingdays()
{
return $this->hasMany('App\Modules\Users\Models\UserWorkingDay');
}
/**
* Get the profile associated with the user.
*/
public function daysoff()
{
return $this->hasMany('App\Modules\Users\Models\UserSchedule');
}
/**
* Get user mobile devices
*/
public function devices()
{
return $this->hasMany('App\Modules\Users\Models\UserDevice');
}
/**
* The serviceTypes that belong to the user.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function servicetypes()
{
// dd("hree");
return $this->belongsToMany('App\Modules\Services\Models\ServiceType','users_servicetype', 'user_id', 'servicetype_id');
}
/**
* The salon serviceTypes that belong to the user.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function salonservicetypes()
{
// dd("hree");
return $this->belongsToMany('App\Modules\Services\Models\SalonCategory','users_servicetype', 'user_id', 'servicetype_id');
}
/**
* The serviceCommision that belong to the user.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function servicesDurationCommisions()
{
return $this->hasMany('App\Modules\Users\Models\UserServiceDuration');
}
/**
* The zone that belongs to the therapist
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function zones()
{
return $this->belongsToMany('App\Modules\Postcodes\Models\Zone', 'users_area_coverage', 'user_id', 'zone_id');
}
/**
* The booking that belong to the user.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function bookings()
{
return $this->hasMany('App\Modules\Schedules\Models\BookingOrder');
}
/**
* The booking that belong to the therapist.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function therapistbookings()
{
return $this->hasMany('App\Modules\Schedules\Models\TherapistBooking','therapist_id')->with('booking');
}
/**
* The basket session that belong to the therapist.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function sessionBlockedTherapists()
{
return $this->hasMany('App\Modules\Schedules\Models\BasketTherapist','therapist_id');
}
/**
* The booking invoice of the therapists
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function thinvoices()
{
return $this->morphMany('App\Modules\Invoices\Models\Invoice','invoiceable');
}
/**
* Get the profile associated with the user.
*/
public function geoLocation()
{
return $this->hasOne('App\Modules\Users\Models\UserLocation');
}
public function isBookingHour($date,$h)
{
$results = [];
//has been booked in date?
$bookings = $this->therapistbookings()->where('date',$date)
->whereHas('booking',function($query){
return $query->where('is_active',1);
})
->get();
//is in session basket for this date?
$sessionBasketBookings = $this->sessionBlockedTherapists()->where('date',$date)
->get();
foreach ($bookings as $bo){
$hour = $bo['hour'];
$results[$hour] = $hour;
}
//loop through session basket bookings
foreach ($sessionBasketBookings as $sbo) {
$shour = $sbo->hour;
$results[$shour] = $shour;
}
if($results && in_array($h,$results))
{
return true;
}
else
{
return false;
}
}
/**
* Get blocked date hours array
* @param $date
* @param int $duration
* @return array
*/
public function blockedHours($date,$duration=60)
{
$results = [];
$resultsDF = [];
$hours = [];
//the buffer between bookings
$buffer = 30;
//has been booked in date?
$bookings = $this->therapistbookings()->where('date',$date)
->whereHas('booking',function($query){
return $query->where('is_active',1);
})
->get();
//is in session basket for this date?
$sessionBasketBookings = $this->sessionBlockedTherapists()->where('date',$date)
->get();
//partial days-hours off
// DB::enableQueryLog();
//$daysHoursOff = $this->daysoff()->whereRaw('DATE(date_start) <= "'.$date.'"')->get();
$daysHoursOff = $this->daysoff()->whereRaw('DATE(date_start) <= "'.$date.'" AND DATE(date_end) >= "'.$date.'"')->get();
//print_r($daysHoursOff);
//stop script if there are no results
if (!$bookings && !$sessionBasketBookings && !$daysHoursOff)
return $results;
//loop throught partial days-hours off
$booking = session('booking');
foreach ($daysHoursOff as $offbo) {
$date_start = Carbon::createFromFormat('d F Y - h:i A', $offbo->date_start);
$date_end = Carbon::createFromFormat('d F Y - h:i A', $offbo->date_end);
$date_end_date = $date_end->format('Y-m-d');
//hour
$hour = $date_start->format('H:i');
$hourMin = explode(':', $date_start->format('H:i'));
if ($hourMin[1] > 30)
$hour = ($hourMin[0] + 1) . ":00";
elseif ($hourMin[1] > 0 && $hourMin[1] < 30)
$hour = $hourMin[0] . ":30";
//duration
if($date_end_date == $date){
// $date_format = date('d F Y',strtotime($date));
// $date_start_1 = $date_format.' - 09:00 AM';
// $date_start = Carbon::createFromFormat('d F Y - h:i A', $date_start_1);
$duration = $date_end->diffInMinutes($date_start);
}else{
$date_format = date('d F Y',strtotime($date));
$date_start_1 = $date_format.' - 09:00 AM';
$date_end_1 = $date_format.' - 11:00 PM';
$date_start = Carbon::createFromFormat('d F Y - h:i A', $date_start_1);
$date_end = Carbon::createFromFormat('d F Y - h:i A', $date_end_1);
$duration = $date_end->diffInMinutes($date_start);
}
//dd($duration);
$rest = $duration % 30;
if ($rest > 0 and $rest < 30)
$duration = $duration - $rest + 30;
elseif($rest > 30 and $rest < 60)
$duration = $duration - $rest + 60;
else
$duration = $duration;
//add to results array
$resultsDF[$hour] = [
'hour' => $hour,
'duration' => $duration,
'is_booking' => false,
];
}
//loop throw bookings
foreach ($bookings as $bo){
$hour = $bo['hour'];
$hourMin = explode(':',$bo['hour']);
if ($hourMin[1]>30)
$hour = ($hourMin[0]+1).":00";
elseif ($hourMin[1]>0 && $hourMin[1]<30)
$hour = $hourMin[0].":30";
$results[$hour] = [
'hour'=> $hour,
'duration' => $bo->duration,
'is_booking' => true,
];
} //endforeach
//loop through session basket bookings
foreach ($sessionBasketBookings as $sbo){
$shour = $sbo->hour;
$shourMin = explode(':',$sbo->hour);
if ($shourMin[1]>30)
$shour = ($shourMin[0]+1).":00";
elseif ($shourMin[1]>0 && $shourMin[1]<30)
$shour = $shourMin[0].":30";
$results[$shour] = [
'hour'=> $shour,
'duration' => $sbo->duration_min,
'is_booking' => true,
];
} //endforeach
//create blocked hours array
foreach($results as $r){
$min = Carbon::createFromFormat('H:i',$r['hour'])->format('H:i');
$max = Carbon::createFromFormat('H:i',$r['hour'])->addMinutes($r['duration']+$buffer)->format('H:i');
//$max = Carbon::createFromFormat('H:i',$r['hour'])->addMinutes($r['duration']+$buffer)->format('H:i');
if ((strtotime($max) > strtotime("23:30")) || (strtotime($max) < strtotime("08:00")))
$max="23:30";
$start = (int)strtotime($min);
$end = (int)strtotime($max);
$hours[$min] = $min;
while ($start !== $end)
{
$start = strtotime('+30 minutes',$start);
$key = date('H:i', $start);
$hours[$key] = $key;
} //end while
} //endforeach
//create blocked hours array
foreach($resultsDF as $r){
$min = Carbon::createFromFormat('H:i',$r['hour'])->format('H:i');
$max = Carbon::createFromFormat('H:i',$r['hour'])->addMinutes($r['duration'])->format('H:i');
if ((strtotime($max) > strtotime("23:30")) || (strtotime($max) < strtotime("08:00")))
$max="23:30";
$start = (int)strtotime($min);
$end = (int)strtotime($max);
$hours[$min] = $min;
while ($start !== $end)
{
$start = strtotime('+30 minutes',$start);
$key = date('H:i', $start);
if($key!=$max)
{
$hours[$key] = $key; // the end hour can be booked
}
} //end while
} //endforeach
//sort ascending
asort($hours);
//return blocked hours
return $hours;
}
/**
* Get blocked date hours array
* @param $date
* @param int $duration
* @return array
*/
public function blockedSalonHours($date, $duration = 60)
{
$results = [];
$resultsDF = [];
$hours = [];
// the buffer between bookings (in 10-minute intervals)
$buffer = 10;
// has been booked in date?
$bookings = $this->therapistbookings()->where('date', $date)
->whereHas('booking', function ($query) {
return $query->where('is_active', 1);
})
->get();
// is in session basket for this date?
$sessionBasketBookings = $this->sessionBlockedTherapists()->where('date', $date)
->get();
// partial days-hours off
$daysHoursOff = $this->daysoff()->whereRaw('DATE(date_start) <= "' . $date . '" AND DATE(date_end) >= "' . $date . '"')->get();
// stop script if there are no results
if (!$bookings && !$sessionBasketBookings && !$daysHoursOff)
return $results;
// loop through partial days-hours off
foreach ($daysHoursOff as $offbo) {
$date_start = Carbon::createFromFormat('d F Y - h:i A', $offbo->date_start);
$date_end = Carbon::createFromFormat('d F Y - h:i A', $offbo->date_end);
// hour
$hour = $date_start->format('H:i');
$hourMin = explode(':', $date_start->format('H:i'));
$hour = $hourMin[0] . ':' . round($hourMin[1] / 10) * 10; // Round to nearest 10 minutes
// duration
$duration = $date_end->diffInMinutes($date_start);
$rest = $duration % 10;
$duration = $duration - $rest + 10;
// add to results array
$resultsDF[$hour] = [
'hour' => $hour,
'duration' => $duration,
'is_booking' => false,
];
}
// loop through bookings
foreach ($bookings as $bo) {
$hour = $bo['hour'];
$hourMin = explode(':', $bo['hour']);
$hour = $hourMin[0] . ':' . round($hourMin[1] / 10) * 10; // Round to nearest 10 minutes
$results[$hour] = [
'hour' => $hour,
'duration' => $bo->duration,
'is_booking' => true,
];
}
// loop through session basket bookings
foreach ($sessionBasketBookings as $sbo) {
$hour = $sbo->hour;
$hourMin = explode(':', $sbo->hour);
$hour = $hourMin[0] . ':' . sprintf("%02d", round($hourMin[1] / 10) * 10); // Round to nearest 10 minutes
// dd($hour);
$results[$hour] = [
'hour' => $hour,
'duration' => $sbo->duration_min,
'is_booking' => true,
];
}
// return $results;
// create blocked hours array
foreach ($results as $r) {
$min = Carbon::createFromFormat('H:i', $r['hour'])->format('H:i');
$max = Carbon::createFromFormat('H:i', $r['hour'])->addMinutes($r['duration'] + $buffer)->format('H:i');
if ((strtotime($max) > strtotime("23:50")) || (strtotime($max) < strtotime("08:00")))
$max = "23:50";
$start = strtotime($min);
$end = strtotime($max);
$hours[$min] = $min;
while ($start !== $end) {
$start = strtotime('+10 minutes', $start); // Increment by 10 minutes
$key = date('H:i', $start);
$hours[$key] = $key;
}
}
// sort ascending
asort($hours);
//
// return blocked hours
return $hours;
}
/**
* Get user avatar image
*
* @return string
*/
public function getAvatar()
{
$avatar = file_get_contents(asset('/themes/admin/assets/admin/pages/media/profile/avatar.png'));
if ($this->profile){
if ($this->profile->avatar && Storage::disk('public_images')->exists($this->profile->avatar)){
$avatar = Storage::disk('public_images')->get($this->profile->avatar);
}
}
return $avatar;
}
/**
* Add Avatar image attribute
* @return string
*/
public function getAvatarAttribute()
{
return $this->getAvatar();
}
/**
* Add Mode of Transport attribute
* @return string
*/
public function getTransportModeAttribute()
{
return $this->profile->transport_mode;
}
/**
* Add Avatar image attribute
* @return string
*/
public function getAvatarUrlAttribute()
{
$avatar = asset('/themes/admin/assets/admin/pages/media/profile/avatar.png');
if ($this->profile){
if ($this->profile->avatar && Storage::disk('public_images')->exists($this->profile->avatar)){
$avatar = url('images/'.$this->profile->avatar);
}
}
return $avatar;
}
/**
* Add Avatar image attribute
* @return string
*/
public function getPublicAvatarUrlAttribute()
{
$avatar = null;
if ($this->profile){
if ($this->profile->avatar && Storage::disk('public_images')->exists($this->profile->avatar)){
$avatar = url('images/'.$this->profile->avatar);
}
}
return $avatar;
}
/**
* Get all service durations commisions
* @return \Illuminate\Support\Collection
*/
public function getServicesCommisionsAttribute()
{
$allServicesDurations = ServiceDuration::all();
$ServicesDurations = $this->servicesDurationCommisions;
$ServiceCommisions = [];
/*user services durations*/
foreach ($ServicesDurations as $commision)
{
$ServiceCommisions[$commision->services_duration_id] = [
'services_duration_id' => $commision->services_duration_id,
'name' => $commision->service_duration->name,
'price' => $commision->price,
'commision_co' => $commision->commision_co,
'commision_th' => $commision->commision_th,
'is_default' => $commision->service_duration->is_default,
'is_extra' => $commision->service_duration->is_extra,
];
}
/*all services durations*/
foreach ($allServicesDurations as $servicesDuration)
{
if(!isset($ServiceCommisions[$servicesDuration->id]))
{
$ServiceCommisions[$servicesDuration->id] = [
'services_duration_id' => $servicesDuration->id,
'name' => $servicesDuration->name,
'price' => $servicesDuration->price,
'commision_co' => $servicesDuration->commision_co,
'commision_th' => $servicesDuration->commision_th,
'is_default' => $servicesDuration->is_default,
'is_extra' => $servicesDuration->is_extra,
'is_custom' => false,
];
}
elseif (($servicesDuration->commision_co==$ServiceCommisions[$servicesDuration->id]['commision_co']) && ($servicesDuration->commision_th==$ServiceCommisions[$servicesDuration->id]['commision_th']))
{
$ServiceCommisions[$servicesDuration->id]['is_custom'] = false;
}
else
{
$ServiceCommisions[$servicesDuration->id]['is_custom'] = true;
}
}
$ServiceCommisions = collect($ServiceCommisions);
return $ServiceCommisions;
}
/**
* Add URL to therapist booking page
*
* @return string
*/
public function getUrlBookingAttribute()
{
$url = route('bookings.book_now');
return $url;
}
public function getSalonOverallRatingAttribute($value) {
// return $this->id;
$salon_rating = 0;
$atmosphere = 0;
$sanitation = 0;
$employees = 0;
$satisfaction = 0;
$reviews = SalonReviews::where('salon_id', $this->id)->get();
if(!empty($reviews) && count($reviews) != 0) {
foreach($reviews as $review) {
$salon_rating += $review->salon_rating;
$atmosphere += $review->atmosphere;
$sanitation += $review->sanitation;
$employees += $review->employees;
$satisfaction += $review->satisfaction;
}
$salon_rating = $salon_rating / count($reviews);
$atmosphere = $atmosphere / count($reviews);
$sanitation = $sanitation / count($reviews);
$employees = $employees / count($reviews);
$satisfaction = $satisfaction / count($reviews);
$salon_rating = round($salon_rating);
$atmosphere = round($atmosphere);
$sanitation = round($sanitation);
$employees = round($employees);
$satisfaction = round($satisfaction);
}
$salon_rating_array = [
'salon_rating' => $salon_rating,
'atmosphere' => $atmosphere,
'sanitation' => $sanitation,
'employees' => $employees,
'satisfaction' => $satisfaction,
];
return $salon_rating_array;
}
public function getTherapistOverallRatingAttribute($value) {
// return $this->id;
$therapist_rating = 0;
$atmosphere = 0;
$sanitation = 0;
$employees = 0;
$satisfaction = 0;
$reviews = SalonReviews::where('therapist_id', $this->id)->get();
if(!empty($reviews) && count($reviews) != 0) {
foreach($reviews as $review) {
$therapist_rating += $review->salon_rating;
$atmosphere += $review->atmosphere;
$sanitation += $review->sanitation;
$employees += $review->employees;
$satisfaction += $review->satisfaction;
}
$therapist_rating = $therapist_rating / count($reviews);
$atmosphere = $atmosphere / count($reviews);
$sanitation = $sanitation / count($reviews);
$employees = $employees / count($reviews);
$satisfaction = $satisfaction / count($reviews);
$therapist_rating = round($therapist_rating);
$atmosphere = round($atmosphere);
$sanitation = round($sanitation);
$employees = round($employees);
$satisfaction = round($satisfaction);
}
// $therapist_rating_array = [
// 'therapist_rating' => $therapist_rating,
// 'atmosphere' => $atmosphere,
// 'sanitation' => $sanitation,
// 'employees' => $employees,
// 'satisfaction' => $satisfaction,
// ];
return $therapist_rating;
}
public function getHasMassageTableAttribute()
{
if($this->profile->massage_table_status)
{
return true;
}
else
{
return false;
}
}
/**
* Scope a query to only include therapists users.
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeOfTherapists($query)
{
return $query->whereHas('roles',function($query){
return $query->where('slug','therapist');
});
}
public function scopeOfSalon($query)
{
return $query->whereHas('roles',function($query){
return $query->where('slug','salon');
});
}
/**
* Scope a query to only include therapists users.
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeOfClients($query)
{
return $query->whereHas('roles',function($query){
return $query->where('slug','customer');
});
}
/**
* Scope a query to only include therapists users.
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeOfName($query,$search=null)
{
if (!$search) return $query;
return $query->where('name', 'like', "%$search%");
}
/**
* Scope a query to only include therapists users.
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeOfPhone($query,$search=null)
{
if (!$search) return $query;
return $query->whereHas('profile',function($query) use ($search){
return $query->where('mobile_number','like',"%$search%");
});
}
public function scopeGetSubscribedSalonUser($query) {
return $query->whereHas('roles',function($query){
return $query->where('slug','salon');
})->whereHas('stripeSubscription', function ($query) {
$query->where('subscription_status', 'active');
}, '>', 0)->with(['stripeSubscription' => function ($query) {
$query->latest('created_at')->first();
}]);
}
public function scopeGetFeaturedSalonUser($query) {
return $query->whereHas('roles',function($query){
return $query->where('slug','salon');
})->where('is_featured', 1)->get();
}
public function scopeGetFeaturedTherapistUser($query) {
return $query->whereHas('roles',function($query){
return $query->where('slug','therapist');
})->where('is_featured', 1)->get();
}
/**
* Method to get a specific service duration commision
* @param $service_duration_id
*/
public function service_commision($service_duration_id)
{
/**
* TBD
*/
}
}