update setting
This commit is contained in:
@@ -6,31 +6,101 @@ use App\Models\Setting;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* تثبیت can_edit=1 برای کلیدهای runtime tenant (Montzar، up/down_price، …).
|
||||
* بعد از deploy_settings_const.sql هم اجرا میشود تا حتی با SQL قدیمی روی سرور درست بماند.
|
||||
* تثبیت can_edit بعد از deploy_settings_const.sql / deploy:tenant:
|
||||
* - RUNTIME_KEYS → 1
|
||||
* - ADVANCED_PANEL_KEYS → 0 (فقط تنظیمات پیشرفته)
|
||||
* - chart_use_local_data → 1 (تنظیمات عادی → منبع قیمت و تابلو)
|
||||
*/
|
||||
class SettingsRuntimeCanEditSync
|
||||
{
|
||||
/**
|
||||
* کلیدهای can_edit=0 — فقط تنظیمات پیشرفته (ادمین دیپلوی).
|
||||
* همتراز آخرین override در deploy_settings_const.sql
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public const ADVANCED_PANEL_KEYS = [
|
||||
'up_price',
|
||||
'down_price',
|
||||
'price_extreme_date',
|
||||
'main_product',
|
||||
'price_provider',
|
||||
'zaarbox_api_url',
|
||||
'montzar_base_url',
|
||||
'montzar_diff',
|
||||
'montzar_closed',
|
||||
'montzar_order_response',
|
||||
'montzar_token',
|
||||
'montzar_live_price',
|
||||
'montzar_last_product_log',
|
||||
'montzar_truly_buy_mazaneh',
|
||||
'montzar_truly_sell_mazaneh',
|
||||
'montzar_mazaneh',
|
||||
'node_client_id',
|
||||
'node_shared_secret',
|
||||
'external_order_api_enabled',
|
||||
'deposit_method_gateway',
|
||||
'deposit_method_identified',
|
||||
'deposit_method_shetab',
|
||||
'payping_verify_url',
|
||||
'payping_start_url',
|
||||
'payping_strict_failed_withdraw',
|
||||
'payping_fin_token',
|
||||
'chart_id',
|
||||
'payping_round_toman',
|
||||
'payping_gateway_items',
|
||||
'payping_gateway_name',
|
||||
'payping_fin_customer_id',
|
||||
'payping_fin_url',
|
||||
];
|
||||
|
||||
/** @return list<string> */
|
||||
public function keys(): array
|
||||
{
|
||||
return SuperAdminProgramSettingsOverlay::RUNTIME_KEYS;
|
||||
}
|
||||
|
||||
/** @return list<string> */
|
||||
public function advancedKeys(): array
|
||||
{
|
||||
return self::ADVANCED_PANEL_KEYS;
|
||||
}
|
||||
|
||||
public function sync(): int
|
||||
{
|
||||
$keys = $this->keys();
|
||||
if ($keys === []) {
|
||||
return 0;
|
||||
$updated = 0;
|
||||
|
||||
$runtime = $this->keys();
|
||||
if ($runtime !== []) {
|
||||
$updated += Setting::query()
|
||||
->whereIn('key', $runtime)
|
||||
->where(function ($query) {
|
||||
$query->where('can_edit', '!=', 1)
|
||||
->orWhereNull('can_edit');
|
||||
})
|
||||
->update(['can_edit' => 1]);
|
||||
}
|
||||
|
||||
return Setting::query()
|
||||
->whereIn('key', $keys)
|
||||
$advanced = $this->advancedKeys();
|
||||
if ($advanced !== []) {
|
||||
$updated += Setting::query()
|
||||
->whereIn('key', $advanced)
|
||||
->where(function ($query) {
|
||||
$query->where('can_edit', '!=', 0)
|
||||
->orWhereNull('can_edit');
|
||||
})
|
||||
->update(['can_edit' => 0]);
|
||||
}
|
||||
|
||||
$updated += Setting::query()
|
||||
->where('key', 'chart_use_local_data')
|
||||
->where(function ($query) {
|
||||
$query->where('can_edit', '!=', 1)
|
||||
->orWhereNull('can_edit');
|
||||
})
|
||||
->update(['can_edit' => 1]);
|
||||
|
||||
return $updated;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,12 +125,44 @@ class SettingsRuntimeCanEditSync
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed> key => can_edit for all runtime keys present in DB
|
||||
* @return array<string, mixed> key => can_edit still not 0 among advanced keys
|
||||
*/
|
||||
public function advancedViolations(): array
|
||||
{
|
||||
$keys = $this->advancedKeys();
|
||||
if ($keys === []) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Setting::query()
|
||||
->whereIn('key', $keys)
|
||||
->where(function ($query) {
|
||||
$query->where('can_edit', '!=', 0)
|
||||
->orWhereNull('can_edit');
|
||||
})
|
||||
->orderBy('key')
|
||||
->pluck('can_edit', 'key')
|
||||
->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed> key => can_edit for runtime + sample advanced keys
|
||||
*/
|
||||
public function statusMap(): array
|
||||
{
|
||||
$keys = array_values(array_unique(array_merge(
|
||||
$this->keys(),
|
||||
[
|
||||
'price_provider',
|
||||
'montzar_token',
|
||||
'chart_id',
|
||||
'chart_use_local_data',
|
||||
'deposit_method_gateway',
|
||||
]
|
||||
)));
|
||||
|
||||
return Setting::query()
|
||||
->whereIn('key', $this->keys())
|
||||
->whereIn('key', $keys)
|
||||
->orderBy('key')
|
||||
->pluck('can_edit', 'key')
|
||||
->all();
|
||||
|
||||
Reference in New Issue
Block a user