fix(settings): read SuperAdmin overlay via ConfigService everywhere

This commit is contained in:
2026-08-22 15:10:54 +03:30
parent 197b49b719
commit 7bdb2c91a0
9 changed files with 31 additions and 35 deletions
+3 -3
View File
@@ -260,9 +260,9 @@ class AuthController extends Controller
$message = "{$data['name']} عزیز، اکانت شما در پلتفرم {$this->Config('name_fa')} ایجاد شد.";
if ($cfg->getBool('register_referral_bonus_message', false)) {
$bonus = Setting::where('is_active', 1)->where('key', 'referral_bonus_amount')->first();
if ($bonus) {
$bonusValues = json_decode($bonus->value, true);
$bonusRaw = $cfg->getString('referral_bonus_amount');
if ($bonusRaw !== '') {
$bonusValues = json_decode($bonusRaw, true);
$message .= "\nپس از اولین خرید مقدار، " . number_format((int) ($bonusValues[0]['customer'] ?? 0)) . ' ریال پاداش دریافت خواهید کرد.';
}
}
+4 -14
View File
@@ -202,15 +202,10 @@ class Controller extends BaseController
])->post('https://tele.ygram.ir/send-message', ["message" => $msg, "chatId" => $to, "botToken" => 'Paramisgold_bot']);
return $response->json();
}
/** @deprecated alias — همان ConfigService::get؛ overlay سوپرادمین را هم می‌خواند */
public static function Config($name)
{
$row = Setting::where('key', $name)->first();
if ($row && $row->is_active && $row->value !== null && $row->value !== '') {
return $row->value;
}
return false;
return app(ConfigService::class)->Config($name);
}
/** دامنهٔ عمومی سایت — فقط از درخواست HTTP فعلی */
@@ -227,12 +222,7 @@ class Controller extends BaseController
protected static function metalTypeSettingValue(): ?string
{
$metalType = Setting::where('key', 'metal_type')->value('value');
if ($metalType === null) {
return null;
}
$metalType = trim((string) $metalType);
$metalType = trim((string) app(ConfigService::class)->getString('metal_type'));
return $metalType !== '' ? $metalType : null;
}
@@ -495,7 +485,7 @@ class Controller extends BaseController
public static function tradeWeightUnit(): string
{
return self::resolveTradeWeightUnit(
Setting::where('key', 'unit')->value('value')
app(ConfigService::class)->getString('unit')
);
}
@@ -1696,12 +1696,12 @@ class SingleOrderController extends Controller
private function bonusGift($customer, $referrer)
{
$bonus = Setting::where('key', 'referral_bonus_amount')->where('is_active', 1)->first();
if ($bonus === null) {
$bonusRaw = app(\App\Services\ConfigService::class)->getString('referral_bonus_amount');
if ($bonusRaw === '') {
return false;
}
$bonus = json_decode($bonus->value, true);
$bonus = json_decode($bonusRaw, true);
$customer_bonus = $bonus[0]['customer'] ?? 0;
$referrer_bonus = $bonus[0]['referrer'] ?? 0;
+5 -5
View File
@@ -2,7 +2,6 @@
namespace App\Services;
use App\Http\Controllers\Controller;
use App\Models\Setting;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
@@ -21,8 +20,9 @@ class ChatWebhookService
public function ensureRegisteredDetailed(int $maxAttempts = 3): array
{
$webhookUrl = $this->webhookUrl();
$chatApi = Controller::Config('chat_api');
$chatApiKey = Controller::Config('chat_api_key');
$config = app(ConfigService::class);
$chatApi = $config->getString('chat_api');
$chatApiKey = $config->getString('chat_api_key');
if (! $chatApi || ! $chatApiKey) {
return [
@@ -128,7 +128,7 @@ class ChatWebhookService
*/
public function webhookUrl(): string
{
$base = trim((string) Controller::Config('chat_webhook_base_url'));
$base = trim(app(ConfigService::class)->getString('chat_webhook_base_url'));
if ($base === '' || $base === '0' || strtolower($base) === 'false') {
$base = rtrim((string) config('app.url'), '/');
} else {
@@ -154,7 +154,7 @@ class ChatWebhookService
public function ensureSecret(): string
{
$existing = $this->sanitizeSecret((string) Controller::Config('chat_webhook_secret'));
$existing = $this->sanitizeSecret(app(ConfigService::class)->getString('chat_webhook_secret'));
if ($existing !== '') {
return $existing;
}
+2 -1
View File
@@ -20,7 +20,8 @@ class ConfigService
}
/**
* مقدار setting؛ اگر نبود از config/price_providers.php یا default پارامتر.
* مقدار setting؛ اول سوپرادمین، بعد DB لوکال، بعد price_providers.php.
* برای کلیدهای can_edit=0 همیشه از این مسیر (یا ConfigService) بخوانید — نه Setting::where مستقیم.
*/
public function get(string $key, $default = null)
{
+2 -1
View File
@@ -7,6 +7,7 @@ use App\Models\Customer;
use App\Models\Price;
use App\Models\PriceTrigger;
use App\Models\Product;
use App\Services\ConfigService;
use Illuminate\Support\Facades\Log;
class PriceTriggerService
@@ -162,7 +163,7 @@ class PriceTriggerService
$title = 'طلا';
}
$shopName = (string) Controller::Config('name_fa');
$shopName = (string) app(ConfigService::class)->getString('name_fa');
$message = 'قیمت ' . $title . ' به ' . number_format((int) $current) . " رسید\n" . $shopName;
if (! Controller::isSmsNotifEnabled('sms_notif_price_trigger')) {
+2 -1
View File
@@ -5,6 +5,7 @@ namespace App\Services\SmsBilling;
use App\Models\Setting;
use App\Models\SmsWallet;
use App\Models\User;
use App\Services\ConfigService;
class SmsAlertService
{
@@ -35,7 +36,7 @@ class SmsAlertService
return;
}
$appName = trim((string) Setting::where('key', 'name_fa')->value('value'));
$appName = trim(app(ConfigService::class)->getString('name_fa'));
if ($appName === '') {
$appName = 'این نسخه';
}
@@ -3,7 +3,7 @@
namespace App\Services\SmsBilling;
use App\Exceptions\SmsBlockedException;
use App\Models\Setting;
use App\Services\ConfigService;
use App\Services\SmsBilling\Contracts\SmsProviderInterface;
use App\Services\SmsBilling\Providers\CentralSmsApiProvider;
use App\Services\SmsBilling\Providers\MeliPayamakProvider;
@@ -188,12 +188,14 @@ class SmsGatewayService
private function buildProviderConfig(): array
{
$config = app(ConfigService::class);
return [
'melipayamak_user' => Setting::where('key', 'melipayamak_user')->value('value'),
'melipayamak_password' => Setting::where('key', 'melipayamak_password')->value('value'),
'melipayamak_from' => Setting::where('key', 'melipayamak_from')->value('value'),
'name_fa' => Setting::where('key', 'name_fa')->value('value'),
'name_en' => Setting::where('key', 'name_en')->value('value'),
'melipayamak_user' => $config->getString('melipayamak_user'),
'melipayamak_password' => $config->getString('melipayamak_password'),
'melipayamak_from' => $config->getString('melipayamak_from'),
'name_fa' => $config->getString('name_fa'),
'name_en' => $config->getString('name_en'),
];
}
+2 -1
View File
@@ -6,6 +6,7 @@ use App\Models\Setting;
use App\Models\SmsLedger;
use App\Models\SmsSendLog;
use App\Models\SmsWallet;
use App\Services\ConfigService;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
@@ -36,7 +37,7 @@ class SmsWalletService
/** Billing/panel فعال است مگر sms_panel صریحاً false باشد. */
public static function isBillingEnabled(): bool
{
$value = Setting::where('key', 'sms_panel')->value('value');
$value = app(ConfigService::class)->getString('sms_panel');
if ($value === null || trim((string) $value) === '') {
return true;