fixed price

This commit is contained in:
2026-06-28 10:51:56 +03:30
parent dec13e8537
commit 14055c5770
4 changed files with 28 additions and 48 deletions
@@ -46,8 +46,6 @@ class SingleOrderController extends Controller
$config->assertTradingOpen();
$config->assertMontzarOrderAllowed((int) ($data['direction'] ?? 0));
// throw new UnprocessableEntityHttpException('به دلیل نوسانات سفارشات بسته میباشد.');
$transactionType = $data['direction'] == 1 ? "خرید" : "فروش";
$customer = Customer::find(auth('customer')->id() ?? ($data['customer_id'] ?? null));
+13 -17
View File
@@ -298,17 +298,13 @@ class ReportController extends Controller
json_encode($montzarProduct, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)
);
$montzar_open_sell = $toBool($montzarProduct['open_sell'] ?? false);
$montzar_open_buy = $toBool($montzarProduct['open_buy'] ?? false);
$montzarFlags = $config->syncMontzarOpenFlagsFromProduct($montzarProduct);
$montzar_open_buy = $montzarFlags['open_buy'];
$montzar_open_sell = $montzarFlags['open_sell'];
$config->UpdateConfig('montzar_open_sell', $montzar_open_sell ? 'true' : 'false');
$config->UpdateConfig('montzar_open_buy', $montzar_open_buy ? 'true' : 'false');
$montzar_price = (int) $customPrice['price'];
if ($montzar_open_sell || $montzar_open_buy) {
$montzar_price = (int) $customPrice['price'];
}
$config->UpdateConfig('montzar_closed', $montzar_price == 0 ? 'true' : 'false');
$config->UpdateConfig('montzar_closed', 'false');
} catch (\Throwable $e) {
$montzar_price = 0;
@@ -533,19 +529,19 @@ class ReportController extends Controller
json_encode($montzarProduct, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)
);
$openBuy = $toBool($montzarProduct['open_buy'] ?? false);
$openSell = $toBool($montzarProduct['open_sell'] ?? false);
$config->UpdateConfig('montzar_open_buy', $openBuy ? 'true' : 'false');
$config->UpdateConfig('montzar_open_sell', $openSell ? 'true' : 'false');
$montzarFlags = $config->syncMontzarOpenFlagsFromProduct($montzarProduct);
$openBuy = $montzarFlags['open_buy'];
$openSell = $montzarFlags['open_sell'];
if ($openBuy || $openSell) {
$montzar = (int) $customPrice['price'];
}
$montzar = (int) $customPrice['price'];
$config->UpdateConfig('montzar_closed', $montzar === 0 ? 'true' : 'false');
$config->UpdateConfig('montzar_closed', 'false');
} catch (\Throwable $e) {
$montzar = 0;
$config->applyMontzarSyncFailure();
if (!$config->getBool('montzar_closed', true)) {
$montzar = $config->getInt('montzar_live_price', 0);
}
\Log::error('STORE MONZAR PRICE ERROR', ['message' => $e->getMessage()]);
}
}
+9 -22
View File
@@ -497,39 +497,26 @@ class ConfigService
public function applyMontzarSyncFailure(): void
{
$staleLive = $this->getInt('montzar_live_price', 0);
$stillOpen = $this->getBool('montzar_open_buy', false)
|| $this->getBool('montzar_open_sell', false);
$this->UpdateConfig(
'montzar_closed',
($staleLive > 0 && $stillOpen) ? 'false' : 'true'
);
$this->UpdateConfig('montzar_closed', $staleLive > 0 ? 'false' : 'true');
}
public function assertMontzarOrderAllowed(int $direction): void
public function syncMontzarOpenFlagsFromProduct(array $montzarProduct): array
{
if (!$this->usesMontzarPricing()) {
return;
}
$direction = (int) $direction;
$openBuy = $this->getBool('montzar_open_buy', true);
$openSell = $this->getBool('montzar_open_sell', true);
if ($direction === 1 && !$openBuy) {
throw new UnprocessableEntityHttpException('عدم ارائه سرویس.');
if (array_key_exists('open_buy', $montzarProduct)) {
$openBuy = filter_var($montzarProduct['open_buy'], FILTER_VALIDATE_BOOLEAN);
$this->UpdateConfig('montzar_open_buy', $openBuy ? 'true' : 'false');
}
if ($direction === 2 && !$openSell) {
throw new UnprocessableEntityHttpException('عدم ارائه سرویس.');
if (array_key_exists('open_sell', $montzarProduct)) {
$openSell = filter_var($montzarProduct['open_sell'], FILTER_VALIDATE_BOOLEAN);
$this->UpdateConfig('montzar_open_sell', $openSell ? 'true' : 'false');
}
if ($this->getBool('montzar_closed', false)) {
$basePrice = app(ProductDisplayPriceService::class)->resolveOrderBasePrice();
if ($basePrice <= 0) {
throw new UnprocessableEntityHttpException('عدم ارائه سرویس.');
}
}
return ['open_buy' => $openBuy, 'open_sell' => $openSell];
}
public function formatTradingTimeForDisplay(string $time): string
+6 -7
View File
@@ -367,13 +367,12 @@ class ProductDisplayPriceService
if ($product instanceof Product) {
if ($this->usesAppPrice($product)) {
$useLast = $this->productUsesLastPriceIfZero($product);
$base = $useLast
? $this->resolveAppBasePrice()
: $this->resolveStrictLiveAppBasePrice();
if ($base <= 0 && $useLast) {
return $this->resolveLastPriceFallback($product);
$base = $this->resolveAppBasePrice();
if ($base <= 0) {
$base = $this->resolveHistoricalBasePrice();
}
if ($base <= 0 && $this->productUsesLastPriceIfZero($product)) {
$base = $this->resolveLastPriceFallback($product);
}
if ($base <= 0) {