store
This commit is contained in:
@@ -71,6 +71,33 @@ class PriceController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
/** لیست مرجع قیمت برای ادمین قدیمی (ghatreh_admin) — GET /admin/p */
|
||||
public function methodPrices(ZaarboxPriceService $zaarboxPriceService)
|
||||
{
|
||||
$prices = $zaarboxPriceService->cachedPriceList(false);
|
||||
if ($prices === null) {
|
||||
return response()->json([]);
|
||||
}
|
||||
|
||||
$items = collect($prices)
|
||||
->map(function ($row) use ($zaarboxPriceService) {
|
||||
$row = is_array($row) ? $row : (array) $row;
|
||||
$normalized = $zaarboxPriceService->normalizeFeedRow($row);
|
||||
|
||||
return [
|
||||
'id' => trim((string) ($row['id'] ?? $row['key'] ?? '')),
|
||||
'key' => trim((string) ($row['key'] ?? '')),
|
||||
'name' => trim((string) ($row['name'] ?? '')),
|
||||
'price' => (int) round((float) ($normalized['price'] ?? 0)),
|
||||
'profit' => (int) round((float) ($normalized['profit'] ?? 0)),
|
||||
];
|
||||
})
|
||||
->filter(fn (array $row) => $row['name'] !== '')
|
||||
->values();
|
||||
|
||||
return response()->json($items);
|
||||
}
|
||||
|
||||
public function table(Request $request){
|
||||
$records = Price::with(['user']);
|
||||
TableEngine::create($records, $request->all())
|
||||
|
||||
@@ -14,8 +14,10 @@ use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use \App\Http\Controllers\Customer\FundController;
|
||||
use App\Http\Controllers\Site\ReportController;
|
||||
use App\Services\ConfigService;
|
||||
use App\Services\ProductDisplayPriceService;
|
||||
use App\Services\ProductPriceService;
|
||||
use App\Services\ProductPriceSyncService;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
|
||||
@@ -151,9 +153,18 @@ class ProductController extends SuperController
|
||||
|
||||
public function listProduct()
|
||||
{
|
||||
// ادمین: sync اختیاری از کش — کاربر: فقط enrich از کش کران (بدون HTTP / بدون UPDATE)
|
||||
if (app(ConfigService::class)->isStore()) {
|
||||
app(ProductPriceSyncService::class)->syncStorePrices(true);
|
||||
$this->auto_close_open();
|
||||
|
||||
return response()->json(
|
||||
Product::with(['file'])->where('active', 1)->get()
|
||||
);
|
||||
}
|
||||
|
||||
// آبشده خانگی — ادمین: sync از کش؛ کاربر: enrich بدون UPDATE
|
||||
if (! str_contains(request()->path(), '/customer/')) {
|
||||
app(\App\Services\ProductPriceSyncService::class)->syncAll(false);
|
||||
app(ProductPriceSyncService::class)->syncAll(false);
|
||||
}
|
||||
|
||||
$products = Product::with(['file'])->where('active', 1)->get();
|
||||
@@ -162,7 +173,9 @@ class ProductController extends SuperController
|
||||
$displayPriceService = app(ProductDisplayPriceService::class);
|
||||
$displayPriceService->enrichForApi($products);
|
||||
$products->each(function (Product $product) use ($displayPriceService) {
|
||||
$product->setAttribute('show', $displayPriceService->resolveCustomerShow($product));
|
||||
if (! $displayPriceService->hasCustomerDisplayPrice($product)) {
|
||||
$product->setAttribute('show', false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -179,7 +192,7 @@ class ProductController extends SuperController
|
||||
|
||||
public function ProductById($id)
|
||||
{
|
||||
$this->getPrice();
|
||||
app(ProductPriceSyncService::class)->syncStorePrices(true);
|
||||
$this->auto_close_open();
|
||||
$product = Product::with(['file'])
|
||||
->where('id', $id)
|
||||
@@ -199,7 +212,11 @@ class ProductController extends SuperController
|
||||
|
||||
public function getPrice()
|
||||
{
|
||||
app(\App\Services\ProductPriceSyncService::class)->syncAll(true);
|
||||
if (app(ConfigService::class)->isStore()) {
|
||||
app(ProductPriceSyncService::class)->syncStorePrices(true);
|
||||
} else {
|
||||
app(ProductPriceSyncService::class)->syncAll(true);
|
||||
}
|
||||
|
||||
return response()->json(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user