khanegi setting and prices records
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Http\Controllers\Site\ReportController;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class LivePriceTickService
|
||||
{
|
||||
public function tick(): void
|
||||
{
|
||||
$config = app(ConfigService::class);
|
||||
$sync = app(ProductPriceSyncService::class);
|
||||
|
||||
if ($config->isStore()) {
|
||||
$sync->syncStorePrices(true);
|
||||
$source = 'zaarbox';
|
||||
$sourceUrl = app(ZaarboxPriceService::class)->apiUrl();
|
||||
} else {
|
||||
$sync->syncAll(true);
|
||||
$source = $config->priceProvider() ?: 'legacy';
|
||||
$sourceUrl = $source === 'zaarbox'
|
||||
? app(ZaarboxPriceService::class)->apiUrl()
|
||||
: null;
|
||||
}
|
||||
|
||||
$liquidGold = (int) $config->getInt('montzar_live_price', 0);
|
||||
if ($liquidGold <= 0) {
|
||||
$liquidGold = app(ProductDisplayPriceService::class)->resolveHistoricalBasePrice();
|
||||
}
|
||||
|
||||
$activeProducts = Product::query()
|
||||
->where('active', 1)
|
||||
->whereNotNull('reading_method')
|
||||
->count();
|
||||
|
||||
app(PriceSyncLogService::class)->recordTick($source, $sourceUrl, $liquidGold, $activeProducts);
|
||||
|
||||
$request = Request::create('/api/price/last', 'GET', ['force_refresh' => '1']);
|
||||
$response = app(ReportController::class)->lastPrice($request);
|
||||
$payload = json_decode($response->getContent(), true);
|
||||
|
||||
if (is_array($payload)) {
|
||||
app(PriceSnapshotService::class)->recordTick($payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user