|
|
@@ -46,7 +46,7 @@ class ProviderService
|
|
|
return DB::transaction(function () use ($data) {
|
|
|
$provider = Provider::create($data);
|
|
|
|
|
|
- if (! empty($data['recipient_code'])) {
|
|
|
+ if (! empty($data['recipient_name']) && ! empty($data['recipient_default_bank_account'])) {
|
|
|
$this->pagarmeRecipientService->createRecipientForProvider($provider, $data);
|
|
|
}
|
|
|
|
|
|
@@ -70,7 +70,9 @@ class ProviderService
|
|
|
sourceId: $model->id,
|
|
|
old: $model->profileMedia,
|
|
|
);
|
|
|
+
|
|
|
$data['profile_media_id'] = $media->id;
|
|
|
+
|
|
|
unset($data['avatar']);
|
|
|
}
|
|
|
|
|
|
@@ -79,19 +81,6 @@ class ProviderService
|
|
|
return $model->fresh(['user', 'profileMedia']);
|
|
|
}
|
|
|
|
|
|
- public function updateBankAccount(int $id, array $bankAccountData): ?Provider
|
|
|
- {
|
|
|
- $provider = $this->findById($id);
|
|
|
-
|
|
|
- if (! $provider) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- $this->pagarmeRecipientService->updateDefaultBankAccount($provider, $bankAccountData);
|
|
|
-
|
|
|
- return $provider->fresh(['user', 'profileMedia']);
|
|
|
- }
|
|
|
-
|
|
|
public function delete(int $id): bool
|
|
|
{
|
|
|
$model = $this->findById($id);
|
|
|
@@ -103,6 +92,8 @@ class ProviderService
|
|
|
return $model->delete();
|
|
|
}
|
|
|
|
|
|
+ //
|
|
|
+
|
|
|
public function getPending(int $page = 1, int $perPage = 10): LengthAwarePaginator
|
|
|
{
|
|
|
return Provider::query()
|
|
|
@@ -112,10 +103,13 @@ class ProviderService
|
|
|
->paginate($perPage, ['*'], 'page', $page);
|
|
|
}
|
|
|
|
|
|
+ //
|
|
|
+
|
|
|
public function approve(int $id): Provider
|
|
|
{
|
|
|
return DB::transaction(function () use ($id) {
|
|
|
$provider = Provider::findOrFail($id);
|
|
|
+
|
|
|
$provider->update(['approval_status' => ApprovalStatusEnum::ACCEPTED->value]);
|
|
|
|
|
|
return $provider->fresh(['user', 'profileMedia']);
|
|
|
@@ -126,12 +120,15 @@ class ProviderService
|
|
|
{
|
|
|
return DB::transaction(function () use ($id) {
|
|
|
$provider = Provider::findOrFail($id);
|
|
|
+
|
|
|
$provider->update(['approval_status' => ApprovalStatusEnum::REJECTED->value]);
|
|
|
|
|
|
return $provider->fresh(['user', 'profileMedia']);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ //
|
|
|
+
|
|
|
public function register(array $data): ?array
|
|
|
{
|
|
|
try {
|
|
|
@@ -173,6 +170,7 @@ class ProviderService
|
|
|
$user->save();
|
|
|
|
|
|
$provider = new Provider;
|
|
|
+
|
|
|
$provider->user_id = $user->id;
|
|
|
$provider->rg = $data['rg'] ?? null;
|
|
|
$provider->document = $this->sanitizeDigits($data['document'] ?? null);
|
|
|
@@ -182,7 +180,9 @@ class ProviderService
|
|
|
$provider->daily_price_4h = $data['daily_price_4h'] ?? null;
|
|
|
$provider->daily_price_2h = $data['daily_price_2h'] ?? null;
|
|
|
$provider->approval_status = ApprovalStatusEnum::PENDING->value;
|
|
|
+
|
|
|
$provider->save();
|
|
|
+
|
|
|
$provider->refresh();
|
|
|
|
|
|
$selfie = $this->mediaService->createFromFile(
|
|
|
@@ -191,6 +191,7 @@ class ProviderService
|
|
|
source: 'provider',
|
|
|
sourceId: $provider->id,
|
|
|
);
|
|
|
+
|
|
|
$provider->profile_media_id = $selfie->id;
|
|
|
|
|
|
$front = $this->mediaService->createFromFile(
|
|
|
@@ -200,6 +201,7 @@ class ProviderService
|
|
|
sourceId: $provider->id,
|
|
|
filename: 'frente.'.$data['document_front']->getClientOriginalExtension(),
|
|
|
);
|
|
|
+
|
|
|
$provider->document_front_media_id = $front->id;
|
|
|
|
|
|
$back = $this->mediaService->createFromFile(
|
|
|
@@ -209,13 +211,15 @@ class ProviderService
|
|
|
sourceId: $provider->id,
|
|
|
filename: 'verso.'.$data['document_back']->getClientOriginalExtension(),
|
|
|
);
|
|
|
+
|
|
|
$provider->document_back_media_id = $back->id;
|
|
|
|
|
|
$provider->save();
|
|
|
|
|
|
- if (! empty($data['recipient_code'])) {
|
|
|
+ if (! empty($data['recipient_name']) && ! empty($data['recipient_default_bank_account'])) {
|
|
|
$this->pagarmeRecipientService->createRecipientForProvider($provider, $data);
|
|
|
}
|
|
|
+
|
|
|
$this->createProviderAddress($provider->id, $data);
|
|
|
$this->createProviderServicesTypes($provider->id, $data);
|
|
|
$this->createProviderWorkingDays($provider->id, $data);
|
|
|
@@ -234,13 +238,30 @@ class ProviderService
|
|
|
return $result;
|
|
|
} catch (\Exception $e) {
|
|
|
DB::rollBack();
|
|
|
+
|
|
|
Log::error('Error registering provider: '.$e->getMessage(), [
|
|
|
'data' => $data,
|
|
|
]);
|
|
|
+
|
|
|
throw $e;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public function updateBankAccount(int $id, array $bankAccountData): ?Provider
|
|
|
+ {
|
|
|
+ $provider = $this->findById($id);
|
|
|
+
|
|
|
+ if (! $provider) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->pagarmeRecipientService->updateDefaultBankAccount($provider, $bankAccountData);
|
|
|
+
|
|
|
+ return $provider->fresh(['user', 'profileMedia']);
|
|
|
+ }
|
|
|
+
|
|
|
+ //
|
|
|
+
|
|
|
private function createProviderAddress(int $providerId, array $data): void
|
|
|
{
|
|
|
$state = null;
|
|
|
@@ -264,6 +285,7 @@ class ProviderService
|
|
|
}
|
|
|
|
|
|
$address = new Address;
|
|
|
+
|
|
|
$address->source = 'provider';
|
|
|
$address->source_id = $providerId;
|
|
|
$address->zip_code = $this->sanitizeDigits($data['zip_code'] ?? null);
|
|
|
@@ -275,6 +297,7 @@ class ProviderService
|
|
|
$address->address_type = $data['address_type'] ?? 'home';
|
|
|
$address->state_id = $state?->id;
|
|
|
$address->city_id = $city?->id;
|
|
|
+
|
|
|
$address->save();
|
|
|
}
|
|
|
|
|
|
@@ -295,10 +318,12 @@ class ProviderService
|
|
|
private function createProviderWorkingDays(int $providerId, array $data): void
|
|
|
{
|
|
|
$workingDays = $data['working_days'] ?? [];
|
|
|
+
|
|
|
$seen = [];
|
|
|
|
|
|
foreach ($workingDays as $workingDay) {
|
|
|
$day = (int) ($workingDay['day'] ?? -1);
|
|
|
+
|
|
|
$period = $workingDay['period'] ?? null;
|
|
|
|
|
|
if ($day < 0 || $day > 6 || ! in_array($period, ['morning', 'afternoon'], true)) {
|
|
|
@@ -306,6 +331,7 @@ class ProviderService
|
|
|
}
|
|
|
|
|
|
$uniqueKey = $day.'-'.$period;
|
|
|
+
|
|
|
if (isset($seen[$uniqueKey])) {
|
|
|
continue;
|
|
|
}
|