payment api
This commit is contained in:
85
Modules/Linksehat/Transformers/Livechat/LivechatResource.php
Normal file
85
Modules/Linksehat/Transformers/Livechat/LivechatResource.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Linksehat\Transformers\Livechat;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use App\Models\Practitioner;
|
||||
use App\Models\PractitionerRole;
|
||||
use App\Models\Speciality;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Carbon\Carbon;
|
||||
use App\Helpers\Helper;
|
||||
use DB;
|
||||
|
||||
|
||||
class LivechatResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
|
||||
protected $request;
|
||||
|
||||
protected $connection = 'oldlms';
|
||||
|
||||
public function __construct($resource, $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
parent::__construct($resource);
|
||||
}
|
||||
|
||||
public function toArray($request)
|
||||
{
|
||||
// Specialis
|
||||
$specialists = Speciality::all();
|
||||
|
||||
// Doctor livechat
|
||||
$doctors = Practitioner::with('person', 'practitionerRoles.organization', 'practitionerRoles.speciality')
|
||||
->whereHas('person', function ($query) {
|
||||
$query->where('isOnline', 1); // hanya online
|
||||
})
|
||||
->get()
|
||||
->toArray();
|
||||
$doctorsLivechat = [];
|
||||
foreach($doctors as $doctor){
|
||||
$specialist = 'Umum';
|
||||
$year = 0;
|
||||
$price = 0;
|
||||
if (!empty($doctor['person']['start_date_work'])) {
|
||||
$starExperience = Carbon::parse($doctor['person']['start_date_work'])->format('Y-m-d');
|
||||
$experience = Carbon::createFromFormat('Y-m-d', $starExperience);
|
||||
$year = $experience->diffInYears(Carbon::now());
|
||||
}
|
||||
if ($doctor['practitioner_roles']) {
|
||||
if ($doctor['practitioner_roles'][0]['speciality']){
|
||||
$specialist = $doctor['practitioner_roles'][0]['speciality']['name'];
|
||||
}
|
||||
if ($doctor['practitioner_roles'][0]['price']){
|
||||
$price = $doctor['practitioner_roles'][0]['price'];
|
||||
}
|
||||
}
|
||||
$data = [
|
||||
'id' => $doctor['id'],
|
||||
'full_name' => $doctor['person']['name'],
|
||||
'specialist' => $specialist,
|
||||
'experience' => $year,
|
||||
'review' => $doctor['person']['review'],
|
||||
'price' => $price,
|
||||
'price_real' => $price
|
||||
];
|
||||
array_push($doctorsLivechat, $data);
|
||||
}
|
||||
|
||||
return [
|
||||
'jadwal_weekday' => 'Senin - Jumat (08:00 - 17:30)',
|
||||
'jadwal_weekend' => 'Sabtu (08:00 - 12:00)',
|
||||
'doctors_livechat' => [
|
||||
$doctorsLivechat
|
||||
],
|
||||
'specialist' => $specialists
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user