diff --git a/src/shop/orderConfirm/index.tsx b/src/shop/orderConfirm/index.tsx index 422c754..44b4d3e 100644 --- a/src/shop/orderConfirm/index.tsx +++ b/src/shop/orderConfirm/index.tsx @@ -58,7 +58,16 @@ const OrderConfirm = () => { const [error, setError] = useState('') const [payLoading, setPayLoading] = useState(false) // 配送时间(仅水票套票商品需要) - const [sendTime, setSendTime] = useState(() => dayjs().startOf('day').toDate()) + // 当日截单时间:超过该时间下单,最早配送日顺延到次日(避免 21:00 下单仍显示“当天配送”) + const DELIVERY_CUTOFF_HOUR = 21 + const getMinSendDate = () => { + const now = dayjs() + const cutoff = now.hour(DELIVERY_CUTOFF_HOUR).minute(0).second(0).millisecond(0) + const startOfToday = now.startOf('day') + // >= 截单时间则最早只能选次日 + return now.isSame(cutoff) || now.isAfter(cutoff) ? startOfToday.add(1, 'day') : startOfToday + } + const [sendTime, setSendTime] = useState(() => getMinSendDate().toDate()) const [sendTimePickerVisible, setSendTimePickerVisible] = useState(false) // 水票套票活动(若存在则按规则限制最小购买量等) @@ -446,6 +455,17 @@ const OrderConfirm = () => { Taro.showToast({ title: '请选择配送时间', icon: 'none' }) return } + if (hasTicketTemplate) { + const min = getMinSendDate() + if (dayjs(sendTime).isBefore(min, 'day')) { + setSendTime(min.toDate()) + Taro.showToast({ + title: `已过当日${DELIVERY_CUTOFF_HOUR}点截单,最早配送:${min.format('YYYY-MM-DD')}`, + icon: 'none' + }) + return + } + } // 水票套票活动:最小购买量校验 if (isTicketTemplateActive && quantity < minBuyQty) { @@ -716,7 +736,7 @@ const OrderConfirm = () => { useEffect(() => { // 切换商品时重置配送时间,避免沿用上一次选择 if (!isLoggedIn()) return - setSendTime(dayjs().startOf('day').toDate()) + setSendTime(getMinSendDate().toDate()) setSendTimePickerVisible(false) loadAllData() }, [goodsId]); @@ -786,7 +806,14 @@ const OrderConfirm = () => { )} - onClick={() => setSendTimePickerVisible(true)} + onClick={() => { + // 若页面停留跨过截单时间,打开选择器前再校正一次最早可选日期 + const min = getMinSendDate() + if (dayjs(sendTime).isBefore(min, 'day')) { + setSendTime(min.toDate()) + } + setSendTimePickerVisible(true) + }} /> )} @@ -1087,7 +1114,7 @@ const OrderConfirm = () => { visible={sendTimePickerVisible} title="选择配送时间" type="date" - startDate={dayjs().startOf('day').toDate()} + startDate={getMinSendDate().toDate()} endDate={dayjs().add(30, 'day').toDate()} value={sendTime} onClose={() => setSendTimePickerVisible(false)} diff --git a/src/user/address/add.tsx b/src/user/address/add.tsx index 54b87de..99c9420 100644 --- a/src/user/address/add.tsx +++ b/src/user/address/add.tsx @@ -589,11 +589,13 @@ const AddUserAddress = () => {