update setting

This commit is contained in:
2026-08-26 12:56:57 +03:30
parent c635ab5f5f
commit ad78545ebd
7 changed files with 202 additions and 66 deletions
@@ -146,14 +146,14 @@ class DeploySettingsConstCommand extends Command
$sync = app(SettingsRuntimeCanEditSync::class);
$sync->useDatabase($database);
$updated = $sync->sync();
$this->line(" runtime can_edit sync: {$updated} row(s) updated");
$this->line(" can_edit sync: {$updated} row(s) updated");
$status = $sync->statusMap();
if ($status !== []) {
$preview = collect($status)
->map(fn ($canEdit, $key) => "{$key}={$canEdit}")
->implode(', ');
$this->line(" runtime keys: {$preview}");
$this->line(" can_edit sample: {$preview}");
}
$violations = $sync->violations();
@@ -161,6 +161,11 @@ class DeploySettingsConstCommand extends Command
$this->warn(' WARN: runtime keys still can_edit≠1: '.implode(', ', array_keys($violations)));
}
$advancedViolations = $sync->advancedViolations();
if ($advancedViolations !== []) {
$this->warn(' WARN: advanced keys still can_edit≠0: '.implode(', ', array_keys($advancedViolations)));
}
$fee = \App\Models\Setting::query()
->where('key', 'fee_deduct_from_gold')
->first(['key', 'can_edit']);
+111 -9
View File
@@ -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();
@@ -60,20 +60,11 @@ class SuperAdminProgramSettingsOverlay
'tracking_systems',
];
/** لاگ/قیمت لحظه‌ای همکار — can_edit=1 در DB؛ کد مستقیم UpdateConfig می‌زند، نه سوپرادمین */
/**
* فقط کلیدهایی که هنوز از پنل قابل ویرایش نیستند و کد tenant می‌نویسد.
* بقیهٔ سابق (montzar_* / up_price / …) can_edit=0 و فقط در تنظیمات پیشرفته ویرایش می‌شوند.
*/
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',
];