khanegi setting and prices records

This commit is contained in:
2026-06-13 17:35:40 +03:30
parent c70cda0b6b
commit 91a82c06e4
15 changed files with 509 additions and 73 deletions
@@ -5,7 +5,7 @@ namespace App\Http\Controllers\Admin;
use App\DB\Te\TableEngine;
use App\Http\Controllers\Controller;
use App\Models\PriceSyncLog;
use App\Services\ProductPriceSyncService;
use App\Services\LivePriceTickService;
use Illuminate\Http\Request;
class PriceSyncLogController extends Controller
@@ -29,14 +29,14 @@ class PriceSyncLogController extends Controller
return response()->json($log);
}
public function runSync(ProductPriceSyncService $syncService)
public function runSync(LivePriceTickService $tickService)
{
$syncService->syncStorePrices(true);
$tickService->tick();
$log = PriceSyncLog::with('items')->orderByDesc('id')->first();
return response()->json([
'message' => $log ? 'قیمت‌ها به‌روزرسانی شد' : 'تغییری در قیمت محصولات نبود',
'message' => $log ? 'قیمت‌ها به‌روزرسانی شد' : 'همگام‌سازی انجام شد',
'data' => $log,
]);
}
@@ -175,15 +175,12 @@ class ProductController extends SuperController
return response()->json($products);
}
// آبشده خانگی — ادمین: sync از کش؛ کاربر: enrich بدون UPDATE
if (! str_contains(request()->path(), '/customer/')) {
app(ProductPriceSyncService::class)->syncAll(false);
}
// آبشده خانگی — کران قیمت را آپدیت می‌کند؛ list فقط از DB می‌خواند
$products = Product::with(['file'])->where('active', 1)->get();
if (str_contains(request()->path(), '/customer/')) {
$displayPriceService = app(ProductDisplayPriceService::class);
$displayPriceService->warmLivePriceCache();
$displayPriceService->enrichForApi($products);
$products->each(function (Product $product) use ($displayPriceService) {
if (! $displayPriceService->hasCustomerDisplayPrice($product)) {
+33 -23
View File
@@ -21,6 +21,7 @@ use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Mail;
use Morilog\Jalali\Jalalian;
use App\Services\ConfigService;
use App\Services\LivePriceCacheService;
use App\Services\ProductDisplayPriceService;
@@ -127,15 +128,37 @@ class ReportController extends Controller
$payload['last_historical'] = app(ProductDisplayPriceService::class)->resolveHistoricalBasePrice();
app(ProductDisplayPriceService::class)->cacheLivePricePayload($payload);
if (request()->boolean('force_refresh')) {
return app(LivePriceCacheService::class)->put($payload);
}
return $payload;
}
public function lastPrice()
public function lastPrice(Request $request)
{
$config = app(ConfigService::class);
$cache = app(LivePriceCacheService::class);
if (! $request->boolean('force_refresh')) {
$cached = $cache->get();
if ($cached !== null) {
return $cached;
}
$dbBuilt = $cache->buildFromDatabase();
if (($dbBuilt['price'] ?? 0) > 0) {
return $dbBuilt;
}
}
if ($config->isStore()) {
return $this->storeLastPrice($config);
return $this->appendUpPrices(array_merge([
'closed' => false,
'time' => now(),
'main_product' => 0,
'zaarbox' => 0,
], $this->storeLastPrice($config)));
}
$closed = false;
@@ -361,24 +384,14 @@ class ReportController extends Controller
}
if ($priceValue <= 0) {
if (!$show_last_price) {
return $this->appendUpPrices([
'sell' => 0,
'buy' => 0,
'price_last' => 0,
'price' => 0,
'main_product' => $pr_price ?? 0,
'montzar' => $montzar_price ?? 0,
'zaarbox' => $zaarbox_price ?? 0,
'closed' => true,
'time' => now(),
]);
}
$lastPrice = Price::latest()->first();
$storedPrice = $lastPrice ? (float) $lastPrice->price : 0.0;
$useFallback = $request->boolean('force_refresh') || $show_last_price;
if ($storedPrice <= 0) {
if ($storedPrice > 30_000_000 && $useFallback) {
$priceValue = $storedPrice;
$priceSource = 'database_last';
} else {
return $this->appendUpPrices([
'sell' => 0,
'buy' => 0,
@@ -391,9 +404,6 @@ class ReportController extends Controller
'time' => now(),
]);
}
$priceValue = $storedPrice;
$priceSource = 'database_last';
}
/*
@@ -406,9 +416,9 @@ class ReportController extends Controller
$lastPrice = Price::latest()->first();
if (
!$closed &&
(!$lastPrice || (float) $lastPrice->price != (float) $priceToStore) &&
$priceToStore > 1000000
! $closed &&
(! $lastPrice || (float) $lastPrice->price != (float) $priceToStore) &&
$priceToStore > 30_000_000
) {
$price = new Price();
$price->price = $priceToStore;