2026-01-24 14:03:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
|
|
use App\DB\Te\TableEngine;
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Models\Price;
|
|
|
|
|
use App\Models\PriceCandle;
|
2026-06-06 22:06:53 +03:30
|
|
|
use App\Services\ZaarboxPriceService;
|
2026-01-24 14:03:11 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
|
|
class PriceController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function store(Request $request){
|
|
|
|
|
Price::create([
|
|
|
|
|
"price"=>$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);
|
|
|
|
|
}
|
2026-06-06 22:06:53 +03:30
|
|
|
|
|
|
|
|
public function chartPrices(ZaarboxPriceService $zaarboxPriceService)
|
|
|
|
|
{
|
|
|
|
|
return response()->json([
|
|
|
|
|
'code' => 0,
|
|
|
|
|
'message' => 'عملیات با موفقیت انجام شد.',
|
|
|
|
|
'data' => [
|
|
|
|
|
'prices' => $zaarboxPriceService->getAllPrices(),
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-09 19:58:48 +03:30
|
|
|
public function zaarboxProducts(ZaarboxPriceService $zaarboxPriceService)
|
|
|
|
|
{
|
|
|
|
|
return response()->json([
|
|
|
|
|
'code' => 0,
|
|
|
|
|
'message' => 'عملیات با موفقیت انجام شد.',
|
|
|
|
|
'data' => [
|
|
|
|
|
'items' => $zaarboxPriceService->listProductOptions(),
|
|
|
|
|
'api_url' => $zaarboxPriceService->apiUrl(),
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-12 19:49:53 +03:30
|
|
|
/** لیست مرجع قیمت برای ادمین قدیمی (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);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-24 14:03:11 +00:00
|
|
|
public function table(Request $request){
|
|
|
|
|
$records = Price::with(['user']);
|
|
|
|
|
TableEngine::create($records, $request->all())
|
|
|
|
|
->initSearch([])
|
|
|
|
|
->select([
|
|
|
|
|
'*'
|
|
|
|
|
])->export($records);
|
|
|
|
|
return response()->json($records);
|
|
|
|
|
}
|
|
|
|
|
}
|