This commit is contained in:
2026-06-14 22:00:21 +03:30
parent 0c4cbd7c12
commit b021acde56
7 changed files with 119 additions and 15 deletions
@@ -207,9 +207,7 @@ class ProductController extends SuperController
$displayPriceService->warmLivePriceCache();
$displayPriceService->enrichForApi($products);
$products->each(function (Product $product) use ($displayPriceService) {
if (! $displayPriceService->hasCustomerDisplayPrice($product)) {
$product->setAttribute('show', false);
}
$product->setAttribute('show', $displayPriceService->resolveCustomerShow($product));
});
}
@@ -257,12 +255,11 @@ class ProductController extends SuperController
public function auto_close_open()
{
$config = app(ConfigService::class);
$products = Product::with([])->get();
$current_time = now()->format('H:i:s');
foreach ($products as $product) {
$show = ($current_time >= $product->auto_open_at && $current_time <= $product->auto_close_at);
Product::where('id', $product->id)->update([
'show' => $show,
'show' => $config->isProductWithinTradingHours($product),
]);
}
@@ -358,13 +355,17 @@ class ProductController extends SuperController
}
/** فروشگاه — نمایش در اپ کاربر: فعال + قیمت ذخیره‌شده یا محصول وزنی */
/** فروشگاه — نمایش در اپ کاربر: فعال + ساعات + قیمت ذخیره‌شده یا محصول وزنی */
private function storeProductShowForCustomer(Product $product): bool
{
if (! $product->active) {
return false;
}
if (! app(ConfigService::class)->isProductWithinTradingHours($product)) {
return false;
}
$storedPrice = (int) ($product->price ?? 0) + (int) ($product->price_profit ?? 0);
if ($storedPrice > 0) {
return true;
@@ -364,6 +364,8 @@ class CartController extends Controller
throw new UnprocessableEntityHttpException("خرید {$product->title} در این لحظه مقدور نیست.");
}
app(ConfigService::class)->assertProductTradingOpen($product);
$line = $requestLines->get($item->product_id);
$qty = (int) $item->quantity;
@@ -42,6 +42,8 @@ class SingleOrderController extends Controller
return filter_var($value, FILTER_VALIDATE_BOOLEAN);
};
$config->assertTradingOpen();
if ($config->usesMontzarPricing()) {
$montzar_closed = $toBool($config->Config('montzar_closed'));
$montzar_buy = !$toBool($config->Config('montzar_open_buy')) && (int) $data['direction'] === 1;
@@ -52,10 +54,6 @@ class SingleOrderController extends Controller
}
}
if ($toBool($config->Config('close_price'))) {
$config->assertTradingOpen();
}
// throw new UnprocessableEntityHttpException('به دلیل نوسانات سفارشات بسته میباشد.');
$transactionType = $data['direction'] == 1 ? "خرید" : "فروش";
$customer = Customer::find(auth('customer')->id() ?? ($data['customer_id'] ?? null));
@@ -76,6 +74,9 @@ class SingleOrderController extends Controller
$latestPrice = Price::latest()->first();
if (!$latestPrice || $latestPrice->price == 0) {
if ($config->isOutsideTradingHours()) {
throw new UnprocessableEntityHttpException($config->tradingClosedMessage());
}
throw new UnprocessableEntityHttpException('عدم ارائه سرویس.');
}
$data['all_price'] = $latestPrice;
@@ -120,6 +121,8 @@ class SingleOrderController extends Controller
// Check if the user wants to transact with a product or non-product (gold)
if (isset($data['product_id']) and $data['product'] = Product::find($data['product_id'])) {
$config->assertProductTradingOpen($data['product']);
// Check if the user wants to buy
if ($data['direction'] == 1) {
@@ -166,6 +169,7 @@ class SingleOrderController extends Controller
if (!$data['product']) {
throw new UnprocessableEntityHttpException('محصول آبشده یافت نشد.');
}
$config->assertProductTradingOpen($data['product']);
if ($data['direction'] == 1) {
$data['difference'] = $this->resolveCashSpread($config, $data['product'], 1);
$data['service_charge_percentage'] = $data['product']['percent_fee_buy'];