$request->price , "date_at"=>date("Y-m-d"), "time_at"=>now()->format("H:m:s"), "user_id"=>auth('user')->id() ]); $candle = PriceCandle::whereDate('date_at',date("Y-m-d"))->first(); if (!is_null($candle)){ $candle->end = $request->price; if ($request->price < $candle->low){ $candle->low = $request->price; } elseif ($request->price > $candle->high){ $candle->high = $request->price; } $candle->save(); }else{ PriceCandle::create([ "start"=>$request->price, "end"=>$request->price, "high"=>$request->price, "low"=>$request->price, "date_at"=>date("Y-m-d") ]); } return response()->json(true); } public function priceData(Request $request){ $prise = Price::with('order'); TableEngine::create($prise, $request) ->initSearch(['price']) ->select(['*']) ->export($prise); return response()->json($prise); } public function chartPrices(ZaarboxPriceService $zaarboxPriceService) { return response()->json([ 'code' => 0, 'message' => 'عملیات با موفقیت انجام شد.', 'data' => [ 'prices' => $zaarboxPriceService->getAllPrices(), ], ]); } public function zaarboxProducts(ZaarboxPriceService $zaarboxPriceService) { return response()->json([ 'code' => 0, 'message' => 'عملیات با موفقیت انجام شد.', 'data' => [ 'items' => $zaarboxPriceService->listProductOptions(), 'api_url' => $zaarboxPriceService->apiUrl(), ], ]); } /** لیست مرجع قیمت برای ادمین قدیمی (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()) ->initSearch([]) ->select([ '*' ])->export($records); return response()->json($records); } }