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