From aec64397aa6f735443ec347c3e0012b574e02227 Mon Sep 17 00:00:00 2001 From: adonis Date: Sun, 14 Jun 2026 22:00:59 +0330 Subject: [PATCH] fix bug --- src/utils/storeHours.ts | 50 +++++++++++++++++-- src/views/base/copper&silver/index.vue | 6 +-- src/views/base/gold/index.vue | 6 +-- src/views/base/home/index.vue | 11 ++-- .../base/products/components/DealProduct.vue | 6 +-- src/views/base/products/index.vue | 33 ++++++++++-- 6 files changed, 91 insertions(+), 21 deletions(-) diff --git a/src/utils/storeHours.ts b/src/utils/storeHours.ts index 6a41347..7173084 100644 --- a/src/utils/storeHours.ts +++ b/src/utils/storeHours.ts @@ -7,6 +7,14 @@ export interface StoreTradingHours { closePriceEnabled: boolean } +export interface EffectiveTradingHours { + start: string + end: string + enforced: boolean +} + +let productTradingHours: { start: string; end: string } | null = null + function parseTimeToSeconds(time: string): number { const parts = time.trim().split(':').map(Number) const [hours = 0, minutes = 0, seconds = 0] = parts @@ -24,6 +32,12 @@ export function formatTradingTimeDisplay(time: string): string { return time } +export function setProductTradingHours(start?: string | null, end?: string | null) { + if (start && end) { + productTradingHours = { start, end } + } +} + export function getStoreTradingHours(): StoreTradingHours { const settings = useSettingsStore() const closeRaw = settings.getSettingByKey('close_price') @@ -39,9 +53,34 @@ export function getStoreTradingHours(): StoreTradingHours { } } +export function getEffectiveTradingHours(): EffectiveTradingHours { + const settings = getStoreTradingHours() + if (settings.closePriceEnabled) { + return { + start: settings.start, + end: settings.end, + enforced: true, + } + } + + if (productTradingHours?.start && productTradingHours?.end) { + return { + start: productTradingHours.start, + end: productTradingHours.end, + enforced: true, + } + } + + return { + start: settings.start, + end: settings.end, + enforced: false, + } +} + export function isStoreClosedBySchedule(now = new Date()): boolean { - const { start, end, closePriceEnabled } = getStoreTradingHours() - if (!closePriceEnabled) { + const { start, end, enforced } = getEffectiveTradingHours() + if (!enforced) { return false } @@ -60,4 +99,9 @@ export function isStoreClosed(): boolean { return isStoreClosedBySchedule() } -export const STORE_CLOSED_MESSAGE = 'فروشگاه در حال حاضر بسته است.' +export function getStoreClosedMessage(): string { + const { start, end } = getEffectiveTradingHours() + const open = formatTradingTimeDisplay(start) + const close = formatTradingTimeDisplay(end) + return `فروشگاه در حال حاضر بسته است. ساعت کاری از ${open} تا ${close} می‌باشد.` +} diff --git a/src/views/base/copper&silver/index.vue b/src/views/base/copper&silver/index.vue index ebd927c..b28432f 100644 --- a/src/views/base/copper&silver/index.vue +++ b/src/views/base/copper&silver/index.vue @@ -239,7 +239,7 @@ import {useConfigStore} from "@/store/configStore"; import { calcFeeInGrams } from '@/utils/serviceFee' import { formatCashWalletBalanceText, formatGoldWalletBalanceText } from '@/utils/productDealMethod' import { getCashWalletBalance } from '@/utils/productAssets' -import { isStoreClosed, STORE_CLOSED_MESSAGE } from '@/utils/storeHours' +import { isStoreClosed, getStoreClosedMessage } from '@/utils/storeHours' const infoVisible = ref(false) const walletStore = useWalletStore() @@ -643,7 +643,7 @@ async function initPrice() { function okConfirm() { if (isStoreClosed()) { - message.warning(STORE_CLOSED_MESSAGE) + message.warning(getStoreClosedMessage()) return } confirmAction.value = true @@ -651,7 +651,7 @@ function okConfirm() { async function ok() { if (isStoreClosed()) { - message.warning(STORE_CLOSED_MESSAGE) + message.warning(getStoreClosedMessage()) return } try { diff --git a/src/views/base/gold/index.vue b/src/views/base/gold/index.vue index c17c89b..3296c9e 100644 --- a/src/views/base/gold/index.vue +++ b/src/views/base/gold/index.vue @@ -236,7 +236,7 @@ import type { Product } from '@/models/products' import { useFundUserStore } from '@/store/fundStore' import {useConfigStore} from "@/store/configStore"; import { calcFeeInGrams, loadServiceFeeFromSettings } from '@/utils/serviceFee' -import { isStoreClosed, STORE_CLOSED_MESSAGE } from '@/utils/storeHours' +import { isStoreClosed, getStoreClosedMessage } from '@/utils/storeHours' import { formatCashWalletBalanceText, getWeightUnit } from '@/utils/productDealMethod' import { formatProductWalletBalanceText, getCashWalletBalance, getProductInventoryQuantity } from '@/utils/productAssets' import { useWalletAssets } from '@/composables/useWalletAssets' @@ -636,7 +636,7 @@ async function initPrice() { function okConfirm() { if (isStoreClosed()) { - message.warning(STORE_CLOSED_MESSAGE) + message.warning(getStoreClosedMessage()) return } if (cashValidationMessage.value) { @@ -648,7 +648,7 @@ function okConfirm() { async function ok() { if (isStoreClosed()) { - message.warning(STORE_CLOSED_MESSAGE) + message.warning(getStoreClosedMessage()) return } try { diff --git a/src/views/base/home/index.vue b/src/views/base/home/index.vue index 0c50ce7..8963b25 100644 --- a/src/views/base/home/index.vue +++ b/src/views/base/home/index.vue @@ -38,7 +38,7 @@ - + @@ -89,6 +89,7 @@ import {useConfigStore} from '@/store/configStore' import {useFundUserStore} from '@/store/fundStore' import {usePriceWithoutType} from '../../../utils/usePrice' import {getLastPrices, lastPrice, price, startLastPricePolling, stopLastPricePolling} from '@/utils/price' +import { getStoreClosedMessage, isStoreClosed } from '@/utils/storeHours' import {getConstByKey} from '@/api/const' import {message, Modal} from 'ant-design-vue' @@ -126,9 +127,11 @@ const { assetsSummary, loadWalletAssets } = useWalletAssets() // Config const isGaroosi = computed(() => configStore.config.name === 'garoosi') const closedMessage = computed(() => userStore.getValueByKey('closed_message')) -const showClosedMessage = computed(() => - closedMessage.value && - lastPrice?.value?.price_last === 0) +const marketClosedText = computed(() => { + if (!isStoreClosed()) return '' + return closedMessage.value || getStoreClosedMessage() +}) +const showClosedMessage = computed(() => !!marketClosedText.value) // State diff --git a/src/views/base/products/components/DealProduct.vue b/src/views/base/products/components/DealProduct.vue index 53b2832..f6275fc 100644 --- a/src/views/base/products/components/DealProduct.vue +++ b/src/views/base/products/components/DealProduct.vue @@ -297,7 +297,7 @@ import { } from '@/utils/productOrderLimit' import { useWalletAssets } from '@/composables/useWalletAssets' import { formatProductWalletBalanceText, getCashWalletBalance, getProductInventoryQuantity } from '@/utils/productAssets' -import { isStoreClosed, STORE_CLOSED_MESSAGE } from '@/utils/storeHours' +import { isStoreClosed, getStoreClosedMessage } from '@/utils/storeHours' const typeDeal = computed(() => getProductDealMethodOptions(props?.ProductItem?.group_type, isBuy.value)) @@ -798,7 +798,7 @@ async function initPrice() { function okConfirm() { if (isStoreClosed()) { - message.warning(STORE_CLOSED_MESSAGE) + message.warning(getStoreClosedMessage()) return } confirmAction.value = true @@ -807,7 +807,7 @@ function okConfirm() { async function ok() { if (isStoreClosed()) { - message.warning(STORE_CLOSED_MESSAGE) + message.warning(getStoreClosedMessage()) return } try { diff --git a/src/views/base/products/index.vue b/src/views/base/products/index.vue index 1c5655d..478f440 100644 --- a/src/views/base/products/index.vue +++ b/src/views/base/products/index.vue @@ -13,6 +13,15 @@ +
+
مشتریان گرامی
+

{{ storeClosedMessage }}

+

از همراهی و اعتماد شما سپاسگزاریم.🤍

+
+
مشتریان گرامی
-

فروشگاه در حال حاضر بسته است.

-

ساعت کاری فروشگاه از {{ openTime }} تا {{ closeTime }} می‌باشد.

+

{{ storeClosedMessage }}

از همراهی و اعتماد شما سپاسگزاریم.🤍

@@ -106,10 +114,12 @@ import { loadProductCategoryTabNames } from '@/utils/categoryTabs' import { getLastPrices, lastPrice, startLastPricePolling, stopLastPricePolling } from '@/utils/price' import { formatTradingTimeDisplay, - getStoreTradingHours, + getEffectiveTradingHours, + getStoreClosedMessage, isStoreClosed, - STORE_CLOSED_MESSAGE + setProductTradingHours } from '@/utils/storeHours' +import { useSettingsStore } from '@/store/settingsStore' const activekey = ref('طلا' ||'آبشده') const showFilter = ref(false) @@ -119,6 +129,8 @@ const closeTime = ref('') const openTime = ref('') const isAfterCloseTime = ref(false) const isProductInactive = ref(false) +const storeIsClosed = computed(() => isStoreClosed()) +const storeClosedMessage = computed(() => getStoreClosedMessage()) watch([openTime, closeTime], () => { syncStoreClosedState() @@ -178,6 +190,7 @@ const firstItems = ref() const items = ref() const typeItems = ref([]) let productListInterval: ReturnType | undefined +let storeHoursInterval: ReturnType | undefined async function loadCategoryTabs() { try { @@ -234,11 +247,16 @@ watch(() => lastPrice.value?.closed, syncStoreClosedState) onMounted(async () => { try { loading.value = true + await useSettingsStore().fetchSettings() await getLastPrices() startLastPricePolling() items.value = await getProducts() - const hours = getStoreTradingHours() + if (items.value?.length) { + setProductTradingHours(items.value[0].auto_open_at, items.value[0].auto_close_at) + } + + const hours = getEffectiveTradingHours() openTime.value = formatTradingTimeDisplay(hours.start) closeTime.value = formatTradingTimeDisplay(hours.end) syncStoreClosedState() @@ -247,6 +265,7 @@ onMounted(async () => { firstItems.value = items.value await loadServiceFeeFromSettings() productListInterval = setInterval(refreshProducts, 10000) + storeHoursInterval = setInterval(syncStoreClosedState, 30000) } catch (e) { console.log(e) @@ -274,6 +293,10 @@ onUnmounted(() => { clearInterval(productListInterval) productListInterval = undefined } + if (storeHoursInterval) { + clearInterval(storeHoursInterval) + storeHoursInterval = undefined + } }) // watch(lastPrice, async () => { // // console.log(items);