fixed price
This commit is contained in:
@@ -487,11 +487,49 @@ class ConfigService
|
||||
$closed = $this->isOutsideTradingHours($now);
|
||||
Cnt::where('key', 'app_closed')->update(['value' => $closed ? 'true' : 'false']);
|
||||
|
||||
if ($closed) {
|
||||
$this->UpdateConfig('montzar_closed', 'true');
|
||||
return $closed;
|
||||
}
|
||||
|
||||
/**
|
||||
* montzar_closed فقط وضعیت sync زنده است — نباید بهتنهایی سفارش را ببندد.
|
||||
* اگر sync خطا داد ولی montzar_live_price و open_buy/sell معتبرند، معامله باز بماند.
|
||||
*/
|
||||
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'
|
||||
);
|
||||
}
|
||||
|
||||
public function assertMontzarOrderAllowed(int $direction): void
|
||||
{
|
||||
if (!$this->usesMontzarPricing()) {
|
||||
return;
|
||||
}
|
||||
|
||||
return $closed;
|
||||
$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 ($direction === 2 && !$openSell) {
|
||||
throw new UnprocessableEntityHttpException('عدم ارائه سرویس.');
|
||||
}
|
||||
|
||||
if ($this->getBool('montzar_closed', false)) {
|
||||
$basePrice = app(ProductDisplayPriceService::class)->resolveOrderBasePrice();
|
||||
if ($basePrice <= 0) {
|
||||
throw new UnprocessableEntityHttpException('عدم ارائه سرویس.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function formatTradingTimeForDisplay(string $time): string
|
||||
|
||||
@@ -360,6 +360,54 @@ class ProductDisplayPriceService
|
||||
return $this->extractBaseFromPayload($this->livePricePayload());
|
||||
}
|
||||
|
||||
/** قیمت پایه سفارش — همان منبع نمایش اپ (کش / montzar_live_price / prices) */
|
||||
public function resolveOrderBasePrice(?Product $product = null): int
|
||||
{
|
||||
$this->warmLivePriceCache();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if ($base <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$offset = Product::hasPriceOffsetColumn()
|
||||
? (float) ($product->price_offset_percent ?? 0)
|
||||
: 0.0;
|
||||
|
||||
return ProductPriceService::adjustedTotal($base, 0, $offset);
|
||||
}
|
||||
|
||||
if ($product->reading_method) {
|
||||
$this->enrichForApi(collect([$product]));
|
||||
$unit = (int) (($product->price ?? 0) + ($product->price_profit ?? 0));
|
||||
if ($unit > 0) {
|
||||
return $unit;
|
||||
}
|
||||
}
|
||||
|
||||
if ((int) ($product->direct_price ?? 0) === 1) {
|
||||
return (int) (($product->price ?? 0) + ($product->price_profit ?? 0));
|
||||
}
|
||||
}
|
||||
|
||||
$base = $this->resolveAppBasePrice();
|
||||
if ($base > 0) {
|
||||
return $base;
|
||||
}
|
||||
|
||||
return $this->resolveHistoricalBasePrice();
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $payload */
|
||||
private function extractBaseFromPayload(array $payload): int
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user