92 lines
3.5 KiB
PHP
92 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Api\Access\User;
|
|
|
|
use App\Constant\Constant;
|
|
use App\Jobs\CertificateRequestJob;
|
|
use App\Models\UserHealthInsuranceCertificate;
|
|
use Carbon\Carbon;
|
|
|
|
class UserHealthInsuranceRepository
|
|
{
|
|
public function __construct(protected UserHealthInsuranceCertificate $userHealthInsuranceCertificate)
|
|
{}
|
|
|
|
public function storeCertificate($data): array
|
|
{
|
|
$auth = loggedInUser();
|
|
$aadharFront = uploadImage($data, 'aadhar_card_front_photo', Constant::USER_CERTIFICATES_UPLOAD_PATH);
|
|
$aadharBack = uploadImage($data, 'aadhar_card_back_photo', Constant::USER_CERTIFICATES_UPLOAD_PATH);
|
|
$aadharFrontPath = $aadharFront['image_name'];
|
|
$aadharBackPath = $aadharBack['image_name'];
|
|
|
|
if (array_key_exists('id', $data->toArray())) {
|
|
$result = $this->userHealthInsuranceCertificate::query()->find($data['id']);
|
|
$result->update([
|
|
'user_id' => $auth?->id,
|
|
'hospital_id' => $data['hospital_id'],
|
|
'full_name' => $data['full_name'],
|
|
'address' => $data['address'],
|
|
'email' => $data['email'],
|
|
'medical_problem' => $data['medical_problem'],
|
|
'aadhar_card_number' => $data['aadhar_card_number'],
|
|
'status' => 0,
|
|
'rejection_reason' => "",
|
|
'aadhar_card_front_photo' => $aadharFrontPath,
|
|
'aadhar_card_back_photo' => $aadharBackPath
|
|
]);
|
|
} else {
|
|
$result = $this->userHealthInsuranceCertificate::create([
|
|
'user_id' => $auth?->id,
|
|
'hospital_id' => $data['hospital_id'],
|
|
'full_name' => $data['full_name'],
|
|
'address' => $data['address'],
|
|
'email' => $data['email'],
|
|
'medical_problem' => $data['medical_problem'],
|
|
'aadhar_card_number' => $data['aadhar_card_number'],
|
|
'aadhar_card_front_photo' => $aadharFrontPath,
|
|
'aadhar_card_back_photo' => $aadharBackPath
|
|
]);
|
|
}
|
|
|
|
if ($result) {
|
|
$result->load('user');
|
|
dispatch(new CertificateRequestJob($result));
|
|
$response['status'] = Constant::CODE_200;
|
|
$response['data'] = $result;
|
|
$response['message'] = "Certificate generate request sent successfully.";
|
|
} else {
|
|
$response['status'] = Constant::CODE_500;
|
|
$response['message'] = "Something wants to wrong!";
|
|
}
|
|
|
|
return $response;
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function showCertificate() : array
|
|
{
|
|
$auth = loggedInUser();
|
|
$result = $this->userHealthInsuranceCertificate->where('user_id',$auth->id)
|
|
->with('hospital')
|
|
->latest()->first();
|
|
|
|
if($result) {
|
|
$expireData = Carbon::parse($result->generated_date)->addDays(2);
|
|
$result->expire_date = $expireData->format('Y-m-d H:i:s');
|
|
$currentTime = Carbon::now();
|
|
// $startTime = Carbon::parse($result->generated_date);
|
|
// $finishTime = Carbon::parse($expireData);
|
|
// $result->is_expired = ($finishTime->diffInSeconds($startTime)) ? Constant::STATUS_FALSE : Constant::STATUS_TRUE;
|
|
$result->is_expired = $currentTime->greaterThanOrEqualTo($expireData) ? Constant::STATUS_TRUE : Constant::STATUS_FALSE;
|
|
}
|
|
|
|
$response['status'] = Constant::CODE_200;
|
|
$response['data'] = $result;
|
|
|
|
return $response;
|
|
}
|
|
}
|