diff --git a/app/Http/Controllers/Admin/System/SettingController.php b/app/Http/Controllers/Admin/System/SettingController.php index e1762cd..b64d417 100644 --- a/app/Http/Controllers/Admin/System/SettingController.php +++ b/app/Http/Controllers/Admin/System/SettingController.php @@ -10,7 +10,7 @@ use App\Http\Requests\Admin\System\Setting\MarketplaceRequest; use App\Http\Requests\Admin\System\Setting\SocialMediaRequest; use App\Http\Requests\Admin\System\Setting\SystemRequest; -use App\Services\Manage\OwnerVerificationService; +use App\Services\System\PushNotificationService; use App\Services\System\Setting\HomepageSettingService; use App\Services\System\Setting\HrSettingService; use App\Services\System\Setting\MarketplaceService; @@ -31,7 +31,7 @@ public function __construct( private readonly MarketplaceService $marketplaceService, private readonly HrSettingService $hrSettingService, private readonly HomepageSettingService $homepageSettingService, - private readonly OwnerVerificationService $ownerVerificationService, + private readonly PushNotificationService $pushNotificationService, ) {} public function index(Request $request): Response @@ -44,7 +44,6 @@ public function index(Request $request): Response 'marketplace' => $this->marketplaceService->marketplaceData(), 'hr' => $this->hrSettingService->hrData(), 'homepage' => $this->homepageSettingService->homepageData(), - 'hasPendingMarketplaceVerification' => $this->ownerVerificationService->hasPendingMarketplaceVerification(), 'canUpdateSystem' => $user->can(Permission::SETTINGS_UPDATE_SYSTEM->value), 'canUpdateSocialMedia' => $user->can(Permission::SETTINGS_UPDATE_SOCIAL_MEDIA->value), 'canUpdateMarketplace' => $user->can(Permission::SETTINGS_UPDATE_MARKETPLACE->value), @@ -57,6 +56,8 @@ public function updateSystem(SystemRequest $request): RedirectResponse { $this->systemService->updateSystem($request->validated()); + $this->notifyOwnerIfAdmin($request->user(), 'Sistem', 'Pengaturan sistem'); + $this->flashSuccess('Pengaturan sistem berhasil disimpan.'); return redirect()->route('admin.system.settings.index'); @@ -66,6 +67,8 @@ public function updateSocialMedia(SocialMediaRequest $request): RedirectResponse { $this->socialMediaService->updateSocialMedia($request->validated()); + $this->notifyOwnerIfAdmin($request->user(), 'Media Sosial', 'Pengaturan media sosial'); + $this->flashSuccess('Pengaturan media sosial berhasil disimpan.'); return redirect()->route('admin.system.settings.index'); @@ -75,11 +78,7 @@ public function updateMarketplace(MarketplaceRequest $request): RedirectResponse { $this->marketplaceService->updateMarketplace($request->validated(), $request->user()); - if ($this->ownerVerificationService->hasPendingMarketplaceVerification()) { - $this->flashSuccess('Perubahan pengaturan marketplace berhasil diajukan dan menunggu verifikasi owner.'); - } else { - $this->flashSuccess('Pengaturan marketplace berhasil disimpan.'); - } + $this->flashSuccess('Pengaturan marketplace berhasil disimpan.'); return redirect()->route('admin.system.settings.index'); } @@ -88,6 +87,8 @@ public function updateHr(HrSettingRequest $request): RedirectResponse { $this->hrSettingService->updateHr($request->validated()); + $this->notifyOwnerIfAdmin($request->user(), 'HR', 'Pengaturan HR'); + $this->flashSuccess('Pengaturan HR berhasil disimpan.'); return redirect()->route('admin.system.settings.index'); @@ -97,8 +98,24 @@ public function updateHomepage(HomepageSettingRequest $request): RedirectRespons { $this->homepageSettingService->updateHomepage($request->validated()); + $this->notifyOwnerIfAdmin($request->user(), 'Homepage', 'Pengaturan homepage'); + $this->flashSuccess('Pengaturan homepage berhasil disimpan.'); return redirect()->route('admin.system.settings.index'); } + + private function notifyOwnerIfAdmin($user, string $sectionLabel, string $settingLabel): void + { + if ($user->can(Permission::OWNER_VERIFICATIONS_VERIFY->value)) { + return; + } + + $this->pushNotificationService->sendToRoles( + "⚙️ {$sectionLabel} Diubah", + "{$settingLabel} telah diubah oleh '{$user->username}'.", + ['owner', 'developer'], + route('admin.system.settings.index'), + ); + } } diff --git a/app/Services/System/Setting/MarketplaceService.php b/app/Services/System/Setting/MarketplaceService.php index 12d1e4b..e03959b 100644 --- a/app/Services/System/Setting/MarketplaceService.php +++ b/app/Services/System/Setting/MarketplaceService.php @@ -3,8 +3,6 @@ namespace App\Services\System\Setting; use App\Enums\OrderChannel; -use App\Enums\OwnerVerificationAction; -use App\Enums\OwnerVerificationStatus; use App\Enums\Permission; use App\Models\OwnerVerificationRequest; use App\Models\User; @@ -14,7 +12,6 @@ use App\Settings\MarketplaceSettings; use App\Support\Marketplace\MarketplaceFeeCalculator; use App\Support\Marketplace\MarketplaceFeeRule; -use Illuminate\Validation\ValidationException; class MarketplaceService { @@ -80,62 +77,16 @@ public function updateMarketplace(array $validated, User $user): void { $this->runInTransaction( function () use ($validated, $user): void { - if ($user->can(Permission::OWNER_VERIFICATIONS_VERIFY->value)) { - $this->saveSettings($validated); + $this->saveSettings($validated); - return; + if (! $user->can(Permission::OWNER_VERIFICATIONS_VERIFY->value)) { + $this->pushNotificationService->sendToRoles( + '⚙️ Pengaturan Marketplace Diubah', + "Pengaturan marketplace telah diubah oleh '{$user->username}'.", + ['owner', 'developer'], + route('admin.system.settings.index'), + ); } - - $hasPending = OwnerVerificationRequest::query() - ->where('subject_type', MarketplaceSettings::class) - ->pending() - ->exists(); - - if ($hasPending) { - throw ValidationException::withMessages([ - 'system' => 'Perubahan pengaturan marketplace sedang menunggu verifikasi owner.', - ]); - } - - $settings = app(MarketplaceSettings::class); - $oldPayload = []; - $newPayload = []; - - foreach ($this->tiktokFeeKeys() as $key) { - $oldPayload[$key] = $this->presentFeeRule($settings->{$key}); - $newPayload[$key] = $this->normalizeFeeRule($validated[$key]); - } - - foreach ($this->shopeeFeeKeys() as $key) { - $oldPayload[$key] = $this->presentFeeRule($settings->{$key}); - $newPayload[$key] = $this->normalizeFeeRule($validated[$key]); - } - - OwnerVerificationRequest::create([ - 'action' => OwnerVerificationAction::UPDATE, - 'status' => OwnerVerificationStatus::PENDING, - 'subject_type' => MarketplaceSettings::class, - 'subject_id' => null, - 'submitted_by_id' => $user->id, - 'payload' => [ - 'old' => $oldPayload, - 'new' => $newPayload, - ], - ]); - - $this->pushNotificationService->sendToRoles( - '⚙️ Pengaturan Marketplace Menunggu Persetujuan Owner', - "Pengajuan ubah pengaturan marketplace oleh '{$user->username}' menunggu verifikasi owner.", - ['owner', 'developer', 'direktur'], - route('admin.system.settings.index'), - ); - - $this->pushNotificationService->sendToUser( - '📤 Pengajuan Terkirim', - "Pengajuan ubah pengaturan marketplace oleh {$user->profile?->full_name} menunggu verifikasi owner.", - $user->id, - route('admin.system.settings.index'), - ); }, 'Gagal memperbarui pengaturan marketplace', ); diff --git a/resources/js/pages/admin/system/setting/Index.vue b/resources/js/pages/admin/system/setting/Index.vue index a2b614c..a3f021c 100644 --- a/resources/js/pages/admin/system/setting/Index.vue +++ b/resources/js/pages/admin/system/setting/Index.vue @@ -24,7 +24,6 @@ defineProps<{ marketplace: MarketplaceSettingsData; hr: HrSettingsData; homepage: HomepageSettingsData; - hasPendingMarketplaceVerification: boolean; canUpdateSystem: boolean; canUpdateSocialMedia: boolean; canUpdateMarketplace: boolean; @@ -47,7 +46,7 @@ const activeSection = ref( - + diff --git a/resources/js/pages/admin/system/setting/form/MarketplaceSection.vue b/resources/js/pages/admin/system/setting/form/MarketplaceSection.vue index ca23d3d..3fba6ed 100644 --- a/resources/js/pages/admin/system/setting/form/MarketplaceSection.vue +++ b/resources/js/pages/admin/system/setting/form/MarketplaceSection.vue @@ -1,6 +1,6 @@