fix(settings): push trading-hours changes to live user prices immediately

Recompute home price display on save, broadcast settings over SSE, and keep last-price status in sync without a user refresh.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-25 02:29:00 +03:30
co-authored by Cursor
parent 4562d00bd3
commit 8984899042
10 changed files with 300 additions and 44 deletions
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Setting;
use App\Services\ConfigService;
use App\Services\PriceChannelBroadcastService;
use App\Services\SuperAdminProgramSettingsOverlay;
use Illuminate\Http\Request;
@@ -167,6 +168,14 @@ class SettingsController extends Controller
})->afterResponse();
}
if (app(ConfigService::class)->isTradingHoursSettingKey($key)) {
try {
app(ConfigService::class)->notifyTradingHoursChanged();
} catch (\Throwable $e) {
report($e);
}
}
if ($isNew) {
$projectName = Setting::where('key', 'name_fa')->value('value') ?: 'پروژه';
$settingTitle = trim($request->title_fa ?? '') ?: $request->key;
@@ -61,6 +61,11 @@ class PriceStreamController extends Controller
$send('last', app(ZaarboxPriceService::class)->attachGoldOunceToPayload($last));
}
$hoursSettings = app(\App\Services\ConfigService::class)->clientTradingHoursSettings();
if ($hoursSettings !== []) {
$send('settings', $hoursSettings);
}
$list = app(PriceBroadcastService::class)->buildListPayload(false);
if (is_array($list) && $list !== []) {
$send('list', $list);
@@ -98,15 +98,8 @@ class ReportController extends Controller
protected function appendUpPrices(array $payload, bool $saveFullCache = false): array
{
// status: open | closed (خارج از ساعت کاری) | no_quote (مظنه در دسترس نیست)
if (!isset($payload['status'])) {
if (!empty($payload['closed'])) {
$payload['status'] = 'closed';
} elseif ((int) ($payload['price'] ?? 0) <= 0 && (int) ($payload['buy'] ?? 0) <= 0) {
$payload['status'] = 'no_quote';
} else {
$payload['status'] = 'open';
}
}
$payload = app(ConfigService::class)->applyHomePriceDisplayState($payload);
$payload = app(ConfigService::class)->attachTradingHoursSettingsPatch($payload);
$payload['up'] = $this->buildUpDownPrices();
$payload['last_historical'] = app(ProductDisplayPriceService::class)->resolveHistoricalBasePrice();