Empty SuperAdmin chargeInfo was wiping sms_charge_* on header refresh. Seed those keys only when empty, and move referral_bonus_amount to can_edit=1. Co-authored-by: Cursor <cursoragent@cursor.com>
182 lines
5.0 KiB
PHP
182 lines
5.0 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\Setting;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
/**
|
|
* تثبیت 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',
|
|
'sms_charge_card_number',
|
|
'sms_charge_sheba',
|
|
'sms_charge_account_holder',
|
|
'sms_charge_note',
|
|
];
|
|
|
|
/** @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
|
|
{
|
|
$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]);
|
|
}
|
|
|
|
$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;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed> key => can_edit for rows still not 1
|
|
*/
|
|
public function violations(): array
|
|
{
|
|
$keys = $this->keys();
|
|
if ($keys === []) {
|
|
return [];
|
|
}
|
|
|
|
return Setting::query()
|
|
->whereIn('key', $keys)
|
|
->where(function ($query) {
|
|
$query->where('can_edit', '!=', 1)
|
|
->orWhereNull('can_edit');
|
|
})
|
|
->orderBy('key')
|
|
->pluck('can_edit', 'key')
|
|
->all();
|
|
}
|
|
|
|
/**
|
|
* @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', $keys)
|
|
->orderBy('key')
|
|
->pluck('can_edit', 'key')
|
|
->all();
|
|
}
|
|
|
|
public function useDatabase(string $database): void
|
|
{
|
|
$connection = (string) config('database.default', 'mysql');
|
|
config(["database.connections.{$connection}.database" => $database]);
|
|
DB::purge($connection);
|
|
}
|
|
}
|