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
+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
{