This commit is contained in:
2026-06-12 19:49:53 +03:30
parent 11fb7272cb
commit 98e1fe969c
6 changed files with 310 additions and 9 deletions
+28 -1
View File
@@ -36,8 +36,20 @@ class ProductDisplayPriceService
/**
* پر کردن price روی مدل‌ها برای پاسخ JSON — بدون UPDATE دیتابیس
*/
/** پر کردن کش مظنه اگر خالی باشد (قبل از enrich لیست مشتری) */
public function warmLivePriceCache(): void
{
if (! is_array(Cache::get(self::LIVE_PRICE_CACHE_KEY))) {
$this->resolveFallbackPayload();
}
}
public function enrichForApi(Collection|iterable $products): void
{
if (app(ConfigService::class)->isStore()) {
return;
}
$collection = collect($products);
$zaarbox = app(ZaarboxPriceService::class);
$zaarboxFeed = $zaarbox->getCachedPriceListOnly();
@@ -88,10 +100,15 @@ class ProductDisplayPriceService
? $this->resolveLiveBuyPriceWithFallback()
: $this->resolveStrictLiveBuyPrice();
if ($unitBuy <= 0 && ! $useLast && app(ConfigService::class)->getBool('show_last_price', false)) {
if ($unitBuy <= 0 && app(ConfigService::class)->getBool('show_last_price', false)) {
$unitBuy = $this->resolveHistoricalBasePrice();
}
$offset = ProductPriceService::offsetPercent($product);
if ($unitBuy > 0 && $offset != 0.0) {
$unitBuy = ProductPriceService::adjustedTotal($unitBuy, 0, $offset);
}
$this->applyPriceOrFallback($product, $unitBuy, $useLast);
}
@@ -247,6 +264,16 @@ class ProductDisplayPriceService
{
$row = $zaarbox->findFeedRow($feed, (string) $product->reading_method);
if ($row === null) {
$useLast = $this->productUsesLastPriceIfZero($product);
$offset = ProductPriceService::offsetPercent($product);
$historical = app(ConfigService::class)->getBool('show_last_price', false)
? $this->resolveHistoricalBasePrice()
: 0;
$computed = $historical > 0
? ProductPriceService::adjustedTotal($historical, 0, $offset)
: 0;
$this->applyPriceOrFallback($product, $computed, $useLast);
return;
}
+44
View File
@@ -23,6 +23,50 @@ class ProductPriceSyncService
) {
}
/**
* فروشگاه (قطره / کشکول) — همان getPrice قدیمی ghatreh:
* فید legacy + تطبیق reading_method با name + ذخیره خام price/profit (بدون offset).
*/
public function syncStorePrices(bool $forceRefresh = true): bool
{
$RPrices = $this->cachedLegacyPriceList($forceRefresh);
if ($RPrices === null) {
return false;
}
$products = Product::query()->whereNotNull('reading_method')->get();
$liquidGoldPrice = (int) $this->configService->getInt('montzar_live_price', 0);
if ($liquidGoldPrice <= 0) {
$liquidGoldPrice = app(ProductDisplayPriceService::class)->resolveHistoricalBasePrice();
}
$synced = false;
foreach ($products as $product) {
foreach ($RPrices as $RPrice) {
if ($product->reading_method != ($RPrice['name'] ?? null)) {
continue;
}
Product::where('id', $product->id)->update([
'price' => (int) ($RPrice['price'] ?? 0),
'price_profit' => (int) ($RPrice['profit'] ?? 0),
]);
$synced = true;
if ((int) ($product->bubble ?? 0) === 1 && $liquidGoldPrice > 0) {
$p = Product::find($product->id);
if ($p) {
$p->amount = (float) ($RPrice['price'] ?? 0) / $liquidGoldPrice;
$p->save();
}
}
}
}
return $synced;
}
/** @param bool $forceRefresh درخواست تازه از https://price.zaarbox.ir/api/free (کران) */
public function syncAll(bool $forceRefresh = false): bool
{