zarbox added

This commit is contained in:
2026-06-04 14:40:02 +03:30
parent f9c5ca109d
commit 92d01f96da
8 changed files with 208 additions and 181 deletions
+32 -10
View File
@@ -10,6 +10,8 @@ use App\Models\Setting;
use App\Models\ConfigStatic;
use App\Models\Customer;
use App\Services\MontzarService;
use App\Services\EtehadiePriceService;
use App\Services\ZaarboxPriceService;
use App\Models\Price;
use App\Models\PriceCandle;
use App\Models\PriceTrigger;
@@ -140,6 +142,7 @@ class ReportController extends Controller
$closed = false;
$montzar_price = 0;
$zaarbox_price = 0;
$tgn = 0;
$pr_price = 0;
@@ -165,6 +168,7 @@ class ReportController extends Controller
'main_product' => 0,
'taban_gohar' => 0,
'montzar' => 0,
'zaarbox' => 0,
'closed' => true,
'time' => now(),
]);
@@ -305,19 +309,31 @@ class ReportController extends Controller
}
}
/*
|--------------------------------------------------------------------------
| Zaarbox — price_provider=zaarbox + settings.zaarbox_price_key
|--------------------------------------------------------------------------
*/
if ($priceProvider === 'zaarbox' && !$closed) {
$zaarbox = app(ZaarboxPriceService::class)->fetchPrice();
$zaarbox_price = (int) ($zaarbox['order_price'] ?? 0);
}
/*
|--------------------------------------------------------------------------
| Main Product — settings.main_product سپس const
|--------------------------------------------------------------------------
*/
$main_product_id = $config->mainProductId();
if ($main_product_id && !$closed) {
if ($priceProvider === 'main_product' || $toBool($main_product_price)) {
$pr_product = Product::find($main_product_id);
if ($pr_product) {
$pr_price = (float) $pr_product['price'] + (float) $pr_product['price_profit'];
}
$pr_product = null;
if ($priceProvider === 'main_product' || $toBool($main_product_price)) {
$pr_product = $config->mainProduct();
}
if ($pr_product && !$closed) {
if ($priceProvider === 'main_product') {
app(EtehadiePriceService::class)->syncProductFromApi($pr_product->fresh());
$pr_product->refresh();
}
$pr_price = (float) $pr_product->price + (float) ($pr_product->price_profit ?? 0);
}
/*
@@ -349,7 +365,10 @@ class ReportController extends Controller
| انتخاب قیمت اصلی (همان price_provider)
|--------------------------------------------------------------------------
*/
if ($priceProvider === 'montzar' && ($montzar_price ?? 0) !== 0 && !$closed) {
if ($priceProvider === 'zaarbox' && $zaarbox_price > 0 && !$closed) {
$priceValue = $zaarbox_price;
$priceSource = 'zaarbox';
} elseif ($priceProvider === 'montzar' && ($montzar_price ?? 0) !== 0 && !$closed) {
$priceValue = (int) $montzar_price;
$priceSource = 'montzar';
} elseif ($priceProvider === 'taban_gohar' && $toBool($taban_gohar_price) && ($tgn ?? 0) !== 0 && !$closed) {
@@ -373,6 +392,7 @@ class ReportController extends Controller
'main_product' => $pr_price ?? 0,
'taban_gohar' => $tgn ?? 0,
'montzar' => $montzar_price ?? 0,
'zaarbox' => $zaarbox_price ?? 0,
'closed' => true,
'time' => now(),
]);
@@ -389,6 +409,7 @@ class ReportController extends Controller
'main_product' => $pr_price ?? 0,
'taban_gohar' => $tgn ?? 0,
'montzar' => $montzar_price ?? 0,
'zaarbox' => $zaarbox_price ?? 0,
'closed' => true,
'time' => now(),
]);
@@ -478,9 +499,9 @@ class ReportController extends Controller
}
/*
| main_product / گلد علی: سفارش از Price::latest() — نمایش buy/sell همان منبع.
| main_product / zaarbox: سفارش از Price::latest() — نمایش buy/sell همان منبع.
*/
if ($priceProvider === 'main_product' && !$closed) {
if (in_array($priceProvider, ['main_product', 'zaarbox'], true) && !$closed) {
$storedPrice = $lastPrice ?? Price::latest()->first();
if ($storedPrice && (float) $storedPrice->price > 0) {
$base = (float) $storedPrice->price;
@@ -502,6 +523,7 @@ class ReportController extends Controller
'main_product' => $pr_price ?? 0,
'taban_gohar' => $tgn ?? 0,
'montzar' => $montzar_price ?? 0,
'zaarbox' => $zaarbox_price ?? 0,
'closed' => false,
'time' => now(),
]);