- Updated CustomerService to simplify getAll method. - Refactored ProductService to utilize HasRoleChecks trait and improved role verification logic. - Enhanced ProductVariantService with new methods for fetching data for restocking and transactions. - Cleaned up RawMaterialService by removing unused methods and improving data retrieval. - Adjusted SupplierService to streamline getAll method. - Refactored RoleService to use Spatie's Role model and improved role filtering logic. - Updated NotificationService to handle role labels more effectively. - Improved StockMutationService by removing redundant paginated method. - Cleaned up various frontend components to directly accept necessary props instead of nested data objects. - Updated tests to reflect changes in service method names and ensure proper notification handling.
171 lines
5.6 KiB
PHP
171 lines
5.6 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Admin;
|
|
|
|
use App\Services\S3PresignedService;
|
|
use App\Settings\HomepageSettings;
|
|
use App\Settings\HRSettings;
|
|
use App\Settings\MarketplaceSettings;
|
|
use App\Settings\SocialMediaSettings;
|
|
use App\Settings\SystemSettings;
|
|
use App\Support\Marketplace\MarketplaceFeeRule;
|
|
|
|
class AdminSettingsService
|
|
{
|
|
public function __construct(
|
|
private S3PresignedService $s3Service,
|
|
) {}
|
|
|
|
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 ? $this->getTemporaryUrl($settings->hero_image_url) : null,
|
|
'hero_image_key' => $settings->hero_image_url,
|
|
'about_image_url' => $settings->about_image_url ? $this->getTemporaryUrl($settings->about_image_url) : null,
|
|
'about_image_key' => $settings->about_image_url,
|
|
'gallery_images' => array_map(
|
|
fn ($key) => $this->getTemporaryUrl($key),
|
|
$settings->gallery_images ?? [],
|
|
),
|
|
'gallery_image_keys' => $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->hero_image_url = $data['hero_image_key'] ?? null;
|
|
$settings->about_image_url = $data['about_image_key'] ?? null;
|
|
$settings->gallery_images = $data['gallery_image_keys'] ?? [];
|
|
|
|
$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();
|
|
}
|
|
|
|
private function getTemporaryUrl(string $key): string
|
|
{
|
|
if (str_starts_with($key, 'http')) {
|
|
return $key;
|
|
}
|
|
|
|
return $this->s3Service->getTemporaryUrl($key, 60);
|
|
}
|
|
}
|