diff --git a/app/Services/ZaarboxPriceService.php b/app/Services/ZaarboxPriceService.php index 2e04f01..3de03e3 100644 --- a/app/Services/ZaarboxPriceService.php +++ b/app/Services/ZaarboxPriceService.php @@ -50,15 +50,31 @@ class ZaarboxPriceService )); } - /** UUID سری زمانی نمودار در API تاریخچه Zaarbox */ + /** + * UUID سری نمودار: settings.chart_id؛ وگرنه پیش‌فرض گلد علی. + * GET https://price.zaarbox.ir/api/history/{id} + */ public function historyId(): string { - $id = trim((string) $this->config->getString( - 'zaarbox_gold_history_id', - (string) config('price_providers.zaarbox_gold_history_id', self::DEFAULT_HISTORY_ID) - )); + $chartId = $this->config->getString('chart_id', ''); + if ($chartId !== '') { + return $chartId; + } - return $id !== '' ? $id : self::DEFAULT_HISTORY_ID; + $legacy = $this->config->getString( + 'zaarbox_gold_history_id', + (string) config('price_providers.zaarbox_gold_history_id', '') + ); + if ($legacy !== '') { + return $legacy; + } + + return self::DEFAULT_HISTORY_ID; + } + + private function cacheKey(): string + { + return self::CACHE_KEY . ':' . $this->historyId(); } /** @@ -66,7 +82,7 @@ class ZaarboxPriceService */ public function getAllPrices(): array { - $cached = Cache::get(self::CACHE_KEY); + $cached = Cache::get($this->cacheKey()); if (is_array($cached) && isset($cached['prices'])) { return $cached['prices']; @@ -82,7 +98,7 @@ class ZaarboxPriceService { $prices = $this->fetchChartPrices(); - Cache::put(self::CACHE_KEY, [ + Cache::put($this->cacheKey(), [ 'prices' => $prices, 'refreshed_at' => now()->toIso8601String(), ], now()->addMinutes(self::CACHE_TTL_MINUTES)); @@ -244,7 +260,7 @@ class ZaarboxPriceService $result[] = [ 'value' => intdiv($lastPoint['price'], 1000), - 'timestamp' => $lastPoint['timestamp'], + 'timestamp' => $bucket, ]; } diff --git a/config/price_providers.php b/config/price_providers.php index 60acc5d..7fc0b06 100644 --- a/config/price_providers.php +++ b/config/price_providers.php @@ -16,8 +16,8 @@ return [ 'etehadie_api_url' => 'http://109.122.246.48:4949/api/free', 'zaarbox_api_url' => 'https://price.zaarbox.ir/api/free', 'zaarbox_price_key' => '', - /** UUID سری زمانی نمودار — GET /api/history/{id} */ - 'zaarbox_gold_history_id' => 'ca3800a0-1f57-3528-b963-178f9168e04f', + /** UUID نمودار Zaarbox — خالی = پیش‌فرض ca3800a0-... در ZaarboxPriceService */ + 'chart_id' => '', 'price_method' => '', 'register_jibit_verify' => false, 'register_referral_sms_to_referrer' => false, diff --git a/database/sql/goldali_zaarbox_price.sql b/database/sql/goldali_zaarbox_price.sql index e92abcc..3f98287 100644 --- a/database/sql/goldali_zaarbox_price.sql +++ b/database/sql/goldali_zaarbox_price.sql @@ -20,6 +20,11 @@ SELECT 'zaarbox_price_key', 'estjt_41670cdf0270a874b68a0a95a235f9a1', 'شناس WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'zaarbox_price_key' LIMIT 1); UPDATE `settings` SET `value` = 'estjt_41670cdf0270a874b68a0a95a235f9a1' WHERE `key` = 'zaarbox_price_key'; +-- نمودار: chart_id = UUID از /api/history/{id} — اگر خالی باشد ca3800a0-1f57-3528-b963-178f9168e04f +INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`) +SELECT 'chart_id', '', 'UUID نمودار Zaarbox', 1, 1, 'خالی = پیش‌فرض آبشده گلد علی' +WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'chart_id' LIMIT 1); + COMMIT; -- بعد: GET /api/price/last