2026-08-18 16:10:37 +03:30
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* تنظیمات پیشرفته سوپرادمین برای ConfigService.
|
|
|
|
|
* کش پایدار ندارد؛ فقط یک بار در همان درخواست PHP نگه داشته میشود.
|
|
|
|
|
*/
|
|
|
|
|
class SuperAdminProgramSettingsOverlay
|
|
|
|
|
{
|
|
|
|
|
/** کلیدهایی که هنوز صفحهٔ اختصاصی ادمین خانگی مالکشان است */
|
|
|
|
|
public const LOCAL_OWNED_KEYS = [
|
|
|
|
|
'tracking_systems',
|
|
|
|
|
];
|
|
|
|
|
|
2026-08-19 19:55:29 +03:30
|
|
|
/** لاگ/قیمت لحظهای همکار — can_edit=1 در DB؛ کد مستقیم UpdateConfig میزند، نه سوپرادمین */
|
2026-08-18 16:10:37 +03:30
|
|
|
public const RUNTIME_KEYS = [
|
|
|
|
|
'montzar_last_product_log',
|
|
|
|
|
'montzar_order_response',
|
|
|
|
|
'montzar_live_price',
|
|
|
|
|
'montzar_mazaneh',
|
|
|
|
|
'montzar_diff',
|
|
|
|
|
'montzar_truly_buy_mazaneh',
|
|
|
|
|
'montzar_truly_sell_mazaneh',
|
|
|
|
|
'montzar_token',
|
|
|
|
|
'montzar_closed',
|
|
|
|
|
'up_price',
|
|
|
|
|
'down_price',
|
|
|
|
|
'price_extreme_date',
|
|
|
|
|
'do_send_liman',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/** @var array<string, array<string, mixed>>|null */
|
|
|
|
|
private static ?array $memo = null;
|
|
|
|
|
|
|
|
|
|
private static bool $loaded = false;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return array<string, array<string, mixed>>|null null = سوپرادمین در دسترس نبود
|
|
|
|
|
*/
|
|
|
|
|
public function map(): ?array
|
|
|
|
|
{
|
|
|
|
|
if (self::$loaded) {
|
|
|
|
|
return self::$memo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self::$loaded = true;
|
|
|
|
|
|
|
|
|
|
$items = app(SuperAdminProgramSettingsClient::class)->fetchItems();
|
|
|
|
|
if ($items === null) {
|
|
|
|
|
self::$memo = null;
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$map = [];
|
|
|
|
|
foreach ($items as $row) {
|
|
|
|
|
if (! is_array($row)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
$key = trim((string) ($row['key'] ?? ''));
|
|
|
|
|
if ($key === '' || in_array($key, self::LOCAL_OWNED_KEYS, true) || in_array($key, self::RUNTIME_KEYS, true)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2026-08-19 21:47:43 +03:30
|
|
|
// مقدار خالی قالب سوپرادمین نباید value لوکال tenant را پاک کند
|
|
|
|
|
$value = $row['value'] ?? null;
|
|
|
|
|
if ($value === null || $value === '') {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2026-08-18 16:10:37 +03:30
|
|
|
$map[$key] = $row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self::$memo = $map;
|
|
|
|
|
|
|
|
|
|
return $map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return array<int, array<string, mixed>>
|
|
|
|
|
*/
|
|
|
|
|
public function items(): array
|
|
|
|
|
{
|
|
|
|
|
$map = $this->map();
|
|
|
|
|
if ($map === null || $map === []) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return array_values($map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return array<string, mixed>|null
|
|
|
|
|
*/
|
|
|
|
|
public function row(string $key): ?array
|
|
|
|
|
{
|
|
|
|
|
$map = $this->map();
|
|
|
|
|
if ($map === null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
$key = trim($key);
|
|
|
|
|
if ($key === '' || ! array_key_exists($key, $map)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $map[$key];
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-18 18:52:29 +03:30
|
|
|
public static function isRuntime(string $key): bool
|
|
|
|
|
{
|
|
|
|
|
return in_array($key, self::RUNTIME_KEYS, true);
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-18 16:10:37 +03:30
|
|
|
public static function isLocalOwned(string $key): bool
|
|
|
|
|
{
|
|
|
|
|
return in_array($key, self::LOCAL_OWNED_KEYS, true);
|
|
|
|
|
}
|
|
|
|
|
}
|