fix price
This commit is contained in:
@@ -5,7 +5,6 @@ namespace App\Http\Controllers\Site;
|
||||
use App\Http\Controllers\Admin\PriceController;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Cnt;
|
||||
use App\Models\Setting;
|
||||
use App\Models\ConfigStatic;
|
||||
use App\Services\MontzarService;
|
||||
use App\Services\ZaarboxPriceService;
|
||||
@@ -248,13 +247,9 @@ class ReportController extends Controller
|
||||
| Settings
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
$settings = Setting::whereIn('key', [
|
||||
'main_product_price',
|
||||
])->get();
|
||||
|
||||
$settingsMap = $settings->pluck('value', 'key');
|
||||
$show_last_price = $config->getBool('show_last_price', false);
|
||||
$main_product_price = $settingsMap->get('main_product_price');
|
||||
// main_product_price کلید سوپرادمین است — از ConfigService خوانده شود، نه جدول لوکال
|
||||
$main_product_price = $config->getBool('main_product_price', false);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -352,7 +347,7 @@ class ReportController extends Controller
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
$pr_product = null;
|
||||
if ($priceProvider === 'main_product' || $toBool($main_product_price)) {
|
||||
if ($priceProvider === 'main_product' || $main_product_price) {
|
||||
$pr_product = $config->mainProduct();
|
||||
}
|
||||
if ($pr_product && !$closed) {
|
||||
|
||||
@@ -2,12 +2,26 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
/**
|
||||
* تنظیمات پیشرفته سوپرادمین برای ConfigService و get_settings.
|
||||
* کش پایدار ندارد؛ فقط یک بار در همان درخواست PHP نگه داشته میشود.
|
||||
* در هر درخواست یک بار fetch میشود؛ آخرین پاسخ سالم برای قطعی لحظهای کش میماند.
|
||||
*/
|
||||
class SuperAdminProgramSettingsOverlay
|
||||
{
|
||||
/**
|
||||
* آخرین پاسخ سالم سوپرادمین.
|
||||
*
|
||||
* کلیدهای can_edit=0 مالکشان سوپرادمین است و کپیشان در جدول settings لوکال
|
||||
* ممکن است ماندهٔ deploy باشد. بدون این کش، یک timeout لحظهای باعث میشود
|
||||
* ConfigService به آن کپی سقوط کند — مثلاً price_provider از zaarbox به montzar
|
||||
* میپرید و مظنهٔ قدیمی montzar_live_price بهجای قیمت زنده نمایش داده میشد.
|
||||
*/
|
||||
private const LAST_GOOD_CACHE_KEY = 'superadmin:program_settings:last_good';
|
||||
|
||||
private const LAST_GOOD_CACHE_MINUTES = 1440;
|
||||
|
||||
/** کلیدهایی که هنوز صفحهٔ اختصاصی ادمین خانگی مالکشان است */
|
||||
public const LOCAL_OWNED_KEYS = [
|
||||
'tracking_systems',
|
||||
@@ -81,6 +95,13 @@ class SuperAdminProgramSettingsOverlay
|
||||
self::$loaded = true;
|
||||
|
||||
$items = app(SuperAdminProgramSettingsClient::class)->fetchItems();
|
||||
|
||||
if ($items !== null) {
|
||||
$this->rememberLastGood($items);
|
||||
} else {
|
||||
$items = $this->lastGoodItems();
|
||||
}
|
||||
|
||||
if ($items === null) {
|
||||
self::$memo = null;
|
||||
|
||||
@@ -104,6 +125,34 @@ class SuperAdminProgramSettingsOverlay
|
||||
return $map;
|
||||
}
|
||||
|
||||
/** @param array<int, array<string, mixed>> $items */
|
||||
private function rememberLastGood(array $items): void
|
||||
{
|
||||
try {
|
||||
Cache::put(
|
||||
self::LAST_GOOD_CACHE_KEY,
|
||||
$items,
|
||||
now()->addMinutes(self::LAST_GOOD_CACHE_MINUTES)
|
||||
);
|
||||
} catch (\Throwable $e) {
|
||||
// کش در دسترس نیست — همان رفتار قبلی
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array<string, mixed>>|null
|
||||
*/
|
||||
private function lastGoodItems(): ?array
|
||||
{
|
||||
try {
|
||||
$cached = Cache::get(self::LAST_GOOD_CACHE_KEY);
|
||||
} catch (\Throwable $e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return is_array($cached) && $cached !== [] ? $cached : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user