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/app/Modules/Users/Repositories/ |
<?php
namespace App\Modules\Users\Repositories;
use App\Modules\Postcodes\Models\Postcode;
use App\Modules\Postcodes\Models\TransportCost;
use App\User;
class ApiRepository
{
/**
* Calculate cost of transport
*
* @param $postcode
* @param $therapistIds
* @param int $quantity
* @return float|int
*/
public function cost_of_transport($post_code,$therapistIds,$quantity=1)
{
//initialize default cost value
$cost = 0;
//get massage location district
$postcode = Postcode::where('postcode',strtolower($post_code))->first();
$postcode_district = $postcode->zone->district()->first();
//get selected therapists
$users = User::whereIn('id',$therapistIds)->get();
//calculate transport cost for each selected therapist
foreach($users as $user){
$district = $user->profile->district;
$transportCost = TransportCost::where('from_id',$district->id)
->where('to_id',$postcode_district->id)
->first();
$cost += $transportCost->price;
} //endforeach
//return cost
if (!$cost)
return 0;
$costValue = $cost;
if ($quantity>1)
$costValue = $costValue/2;
return (float)$costValue;
}
}