fix price force refresh 2

This commit is contained in:
2026-06-14 12:33:29 +03:30
parent 1abddfbab8
commit db0cc5f1a6
8 changed files with 246 additions and 120 deletions
+20 -55
View File
@@ -122,13 +122,13 @@ class ReportController extends Controller
];
}
protected function appendUpPrices(array $payload): array
protected function appendUpPrices(array $payload, bool $saveFullCache = false): array
{
$payload['up'] = $this->buildUpDownPrices();
$payload['last_historical'] = app(ProductDisplayPriceService::class)->resolveHistoricalBasePrice();
app(ProductDisplayPriceService::class)->cacheLivePricePayload($payload);
if (request()->boolean('force_refresh')) {
if ($saveFullCache || request()->boolean('force_refresh')) {
return app(LivePriceCacheService::class)->put($payload);
}
@@ -139,8 +139,9 @@ class ReportController extends Controller
{
$config = app(ConfigService::class);
$cache = app(LivePriceCacheService::class);
$forceRefresh = $request->boolean('force_refresh');
if (! $request->boolean('force_refresh')) {
if (! $forceRefresh) {
$cached = $cache->get();
if ($cached !== null) {
return $cached;
@@ -158,7 +159,7 @@ class ReportController extends Controller
'time' => now(),
'main_product' => 0,
'zaarbox' => 0,
], $this->storeLastPrice($config)));
], $this->storeLastPrice($config)), $forceRefresh);
}
$closed = false;
@@ -167,9 +168,6 @@ class ReportController extends Controller
$zaarbox_price = 0;
$pr_price = 0;
$open_buy = true;
$open_sell = true;
$montzar_open_buy = false;
$montzar_open_sell = false;
@@ -180,7 +178,7 @@ class ReportController extends Controller
return filter_var($value, FILTER_VALIDATE_BOOLEAN);
};
$zeroResponse = function () {
$zeroResponse = function () use ($forceRefresh) {
return $this->appendUpPrices([
'sell' => 0,
'buy' => 0,
@@ -191,7 +189,7 @@ class ReportController extends Controller
'zaarbox' => 0,
'closed' => true,
'time' => now(),
]);
], $forceRefresh);
};
$priceProvider = $config->priceProvider();
@@ -231,20 +229,13 @@ class ReportController extends Controller
|--------------------------------------------------------------------------
*/
$settings = Setting::whereIn('key', [
'fee_single',
'main_product_price',
'buy_fee',
'sell_fee',
])->get();
$settingsMap = $settings->pluck('value', 'key');
$show_last_price = $config->getBool('show_last_price', false);
$main_product_price = $settingsMap->get('main_product_price');
$difference = (float) $settingsMap->get('fee_single', 0);
$diff_buy = (float) $settingsMap->get('buy_fee', $difference);
$diff_sell = (float) $settingsMap->get('sell_fee', $difference);
/*
|--------------------------------------------------------------------------
| Montzar — فقط وقتی price_provider=montzar
@@ -402,7 +393,7 @@ class ReportController extends Controller
'zaarbox' => $zaarbox_price ?? 0,
'closed' => true,
'time' => now(),
]);
], $forceRefresh);
}
}
@@ -458,43 +449,17 @@ class ReportController extends Controller
| محاسبه sell / buy
|--------------------------------------------------------------------------
*/
if ($priceSource === 'montzar') {
$montzar_profit = (float) $config->Config('montzar_diff');
$final_buy_diff = $diff_buy + $montzar_profit;
$final_sell_diff = $diff_sell + $montzar_profit;
$sell = $montzar_open_sell
? ceil($priceValue - $final_sell_diff)
: 0;
$buy = $montzar_open_buy
? ceil($priceValue + $final_buy_diff)
: 0;
$priceLast = ceil($priceValue + $final_buy_diff);
} else {
$sell = $open_sell
? ceil($priceValue - $difference)
: 0;
$buy = $open_buy
? ceil($priceValue + $difference)
: 0;
$priceLast = ceil($priceValue + $difference);
}
/*
| main_product / zaarbox: buy/sell از همان قیمت زنده (نه رکورد قدیمی DB).
*/
if (in_array($priceProvider, ['main_product', 'zaarbox'], true) && !$closed) {
$base = (float) $priceValue;
$sell = $open_sell ? (int) ceil($base - $diff_sell) : 0;
$buy = $open_buy ? (int) ceil($base + $diff_buy) : 0;
$priceLast = (int) ceil($base + $diff_buy);
}
$display = $config->buildTradeDisplayPrices(
(float) $priceValue,
$priceSource,
[
'montzar_open_buy' => $montzar_open_buy,
'montzar_open_sell' => $montzar_open_sell,
]
);
$sell = $display['sell'];
$buy = $display['buy'];
$priceLast = $display['priceLast'];
if (!$closed && $priceValue > 0) {
$config->trackDailyPriceExtreme((float) $priceValue);
@@ -510,7 +475,7 @@ class ReportController extends Controller
'zaarbox' => $zaarbox_price ?? 0,
'closed' => false,
'time' => now(),
]);
], $forceRefresh);
}
/**