- Introduced routes for managing admin settings including system, homepage, social media, marketplace, and HR settings. - Created a comprehensive test suite for the AdminSettingsController to ensure proper functionality and validation of settings updates. - Implemented tests for authentication, data integrity, and realistic user scenarios to validate the settings management process.
147 lines
4.7 KiB
PHP
147 lines
4.7 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Admin;
|
|
|
|
use App\Settings\HRSettings;
|
|
use App\Settings\HomepageSettings;
|
|
use App\Settings\MarketplaceSettings;
|
|
use App\Settings\SocialMediaSettings;
|
|
use App\Settings\SystemSettings;
|
|
use App\Support\Marketplace\MarketplaceFeeRule;
|
|
|
|
class AdminSettingsService
|
|
{
|
|
public function getSystemData(): array
|
|
{
|
|
$settings = app(SystemSettings::class);
|
|
|
|
return [
|
|
'app_name' => $settings->app_name,
|
|
'about_app' => $settings->about_app,
|
|
'address' => $settings->address,
|
|
'email' => $settings->email,
|
|
'phone' => $settings->phone,
|
|
];
|
|
}
|
|
|
|
public function getHomepageData(): array
|
|
{
|
|
$settings = app(HomepageSettings::class);
|
|
|
|
return [
|
|
'hero_image_url' => $settings->hero_image_url,
|
|
'about_image_url' => $settings->about_image_url,
|
|
'gallery_images' => $settings->gallery_images,
|
|
];
|
|
}
|
|
|
|
public function getSocialMediaData(): array
|
|
{
|
|
$settings = app(SocialMediaSettings::class);
|
|
|
|
return [
|
|
'instagram_url' => $settings->instagram_url,
|
|
'facebook_url' => $settings->facebook_url,
|
|
'tiktok_url' => $settings->tiktok_url,
|
|
];
|
|
}
|
|
|
|
public function getMarketplaceData(): array
|
|
{
|
|
$settings = app(MarketplaceSettings::class);
|
|
|
|
return [
|
|
'tiktok_shop' => [
|
|
'platform_commission' => $settings->tiktok_shop_platform_commission->toArray(),
|
|
'logistics_service_fee' => $settings->tiktok_shop_logistics_service_fee->toArray(),
|
|
'dynamic_commission' => $settings->tiktok_shop_dynamic_commission->toArray(),
|
|
'order_processing_fee' => $settings->tiktok_shop_order_processing_fee->toArray(),
|
|
'affiliate' => $settings->tiktok_shop_affiliate->toArray(),
|
|
'pre_order_service_fee' => $settings->tiktok_shop_pre_order_service_fee->toArray(),
|
|
],
|
|
'shopee' => [
|
|
'admin_fee' => $settings->shopee_admin_fee->toArray(),
|
|
'program_fee' => $settings->shopee_program_fee->toArray(),
|
|
'shipping_savings' => $settings->shopee_shipping_savings->toArray(),
|
|
'premium' => $settings->shopee_premium->toArray(),
|
|
'service_fee' => $settings->shopee_service_fee->toArray(),
|
|
'order_processing_fee' => $settings->shopee_order_processing_fee->toArray(),
|
|
'ams_commission_fee' => $settings->shopee_ams_commission_fee->toArray(),
|
|
'pre_order' => $settings->shopee_pre_order->toArray(),
|
|
'live_extra' => $settings->shopee_live_extra->toArray(),
|
|
],
|
|
];
|
|
}
|
|
|
|
public function getHRData(): array
|
|
{
|
|
$settings = app(HRSettings::class);
|
|
|
|
return [
|
|
'scheduled_check_in_time' => $settings->scheduled_check_in_time,
|
|
'scheduled_check_out_time' => $settings->scheduled_check_out_time,
|
|
'late_penalty_amount' => $settings->late_penalty_amount,
|
|
'absent_penalty_amount' => $settings->absent_penalty_amount,
|
|
];
|
|
}
|
|
|
|
public function updateSystem(array $data): void
|
|
{
|
|
$settings = app(SystemSettings::class);
|
|
$settings->fill($data);
|
|
$settings->save();
|
|
}
|
|
|
|
public function updateHomepage(array $data): void
|
|
{
|
|
$settings = app(HomepageSettings::class);
|
|
$settings->fill($data);
|
|
$settings->save();
|
|
}
|
|
|
|
public function updateSocialMedia(array $data): void
|
|
{
|
|
$settings = app(SocialMediaSettings::class);
|
|
$settings->fill($data);
|
|
$settings->save();
|
|
}
|
|
|
|
public function updateMarketplace(array $data): void
|
|
{
|
|
$settings = app(MarketplaceSettings::class);
|
|
|
|
$feeKeys = [
|
|
'tiktok_shop_platform_commission',
|
|
'tiktok_shop_logistics_service_fee',
|
|
'tiktok_shop_dynamic_commission',
|
|
'tiktok_shop_order_processing_fee',
|
|
'tiktok_shop_affiliate',
|
|
'tiktok_shop_pre_order_service_fee',
|
|
'shopee_admin_fee',
|
|
'shopee_program_fee',
|
|
'shopee_shipping_savings',
|
|
'shopee_premium',
|
|
'shopee_service_fee',
|
|
'shopee_order_processing_fee',
|
|
'shopee_ams_commission_fee',
|
|
'shopee_pre_order',
|
|
'shopee_live_extra',
|
|
];
|
|
|
|
foreach ($feeKeys as $key) {
|
|
if (isset($data[$key])) {
|
|
$settings->{$key} = MarketplaceFeeRule::from($data[$key]);
|
|
}
|
|
}
|
|
|
|
$settings->save();
|
|
}
|
|
|
|
public function updateHR(array $data): void
|
|
{
|
|
$settings = app(HRSettings::class);
|
|
$settings->fill($data);
|
|
$settings->save();
|
|
}
|
|
}
|