This commit is contained in:
2026-06-14 21:42:21 +03:30
parent b84b2df01a
commit 0c4cbd7c12
9 changed files with 80 additions and 23 deletions
@@ -127,6 +127,8 @@ class CartController extends Controller
{
// return $request;
app(ConfigService::class)->assertTradingOpen();
$data = $request->json()->all();
$user= auth()->user();
if ($user->is_legal == 0 || !$user) {
@@ -10,6 +10,7 @@ use App\Models\Order;
use App\Models\Price;
use App\Models\Setting;
use App\Models\User;
use App\Services\ConfigService;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Rooyesh\Wallet\interfaces\TransactionInterface;
@@ -40,6 +41,7 @@ class OrderController extends Controller
if (!auth('customer')->user()->trade_active){
throw new UnprocessableEntityHttpException('امکان سفارش برای شما غیرفعال است.');
}
app(ConfigService::class)->assertTradingOpen();
$wallet = Wallet::where('owner',auth('customer')->id())->whereNull('fund_id')
->first();
$wallet_interface = new WalletInterface($data['customer_id'], 1);
@@ -53,9 +53,7 @@ class SingleOrderController extends Controller
}
if ($toBool($config->Config('close_price'))) {
if (Cnt::where('key', 'app_closed')->value('value') == "true") {
throw new UnprocessableEntityHttpException('عدم ارائه سرویس.');
}
$config->assertTradingOpen();
}
// throw new UnprocessableEntityHttpException('به دلیل نوسانات سفارشات بسته میباشد.');
+2 -16
View File
@@ -206,22 +206,8 @@ class ReportController extends Controller
|--------------------------------------------------------------------------
*/
if ($toBool($config->Config('close_price'))) {
$startDay = $config->Config('startDay') ?: '00:00';
[$startHour, $startMinute] = explode(':', $startDay);
$endDay = $config->Config('endDay') ?: '23:59';
[$endHour, $endMinute] = explode(':', $endDay);
$current = Carbon::now();
$start = Carbon::today()->setTime((int) $startHour, (int) $startMinute);
$end = Carbon::today()->setTime((int) $endHour, (int) $endMinute);
if (!$current->between($start, $end)) {
// عمومی: در Cnt بماند
Cnt::where('key', 'app_closed')->update(['value' => 'true']);
// مربوط به منتزر: settings
$config->UpdateConfig('montzar_closed', 'true');
if ($config->isOutsideTradingHours()) {
$config->syncAppClosedFlag();
return $zeroResponse();
}
+66
View File
@@ -7,6 +7,8 @@ use App\Models\Price;
use App\Models\PriceCandle;
use App\Models\Product;
use App\Models\Setting;
use Carbon\Carbon;
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
class ConfigService
{
@@ -397,4 +399,68 @@ class ConfigService
'max' => $max,
];
}
public function isClosePriceEnabled(): bool
{
return $this->getBool('close_price', false);
}
/** @return array{start: string, end: string} */
public function tradingHourBounds(): array
{
return [
'start' => $this->normalizeTradingTime($this->getString('startDay', '00:00'), '00:00'),
'end' => $this->normalizeTradingTime($this->getString('endDay', '23:59'), '23:59'),
];
}
private function normalizeTradingTime(string $value, string $default): string
{
$value = trim($value);
if ($value === '') {
$value = $default;
}
if (preg_match('/^(\d{1,2}):(\d{2})(?::(\d{2}))?$/', $value, $matches)) {
return sprintf('%02d:%02d', (int) $matches[1], (int) $matches[2]);
}
return $default;
}
public function isOutsideTradingHours(?Carbon $now = null): bool
{
if (!$this->isClosePriceEnabled()) {
return false;
}
$now = $now ?? Carbon::now();
$bounds = $this->tradingHourBounds();
[$startHour, $startMinute] = array_map('intval', explode(':', $bounds['start']));
[$endHour, $endMinute] = array_map('intval', explode(':', $bounds['end']));
$start = $now->copy()->startOfDay()->setTime($startHour, $startMinute);
$end = $now->copy()->startOfDay()->setTime($endHour, $endMinute);
return !$now->between($start, $end);
}
public function syncAppClosedFlag(?Carbon $now = null): bool
{
$closed = $this->isOutsideTradingHours($now);
Cnt::where('key', 'app_closed')->update(['value' => $closed ? 'true' : 'false']);
if ($closed) {
$this->UpdateConfig('montzar_closed', 'true');
}
return $closed;
}
public function assertTradingOpen(?Carbon $now = null): void
{
if ($this->isOutsideTradingHours($now)) {
throw new UnprocessableEntityHttpException('فروشگاه در حال حاضر بسته است.');
}
}
}