feat(order): 统一网站自交接订单24小时自动完成倒计时

This commit is contained in:
yml
2026-11-30 17:05:49 +08:00
parent 295c88dd2f
commit 2992885a6d
32 changed files with 996 additions and 23 deletions
@@ -28,6 +28,7 @@ const actionLabels: Record<string, string> = {
owner_handoff_submitted: '号主提交交接',
platform_handoff_submitted: '客服代交接',
admin_force_handoff: '客服确认交接',
system_auto_handoff: '系统自动完成交接',
renter_received_confirmed: '租客确认收号',
checkout_submitted: '租客发起结账',
checkout_countered: '修改结账方案',
@@ -112,6 +112,8 @@ export function formatHandoffRecordType(type: string) {
const typeMap: Record<string, string> = {
owner_handoff: '卖家交接',
platform_handoff: '客服代交接',
admin_force_handoff: '客服一键交接',
system_auto_handoff: '系统自动交接',
renter_checkout: '买家结账',
owner_counter_checkout: '卖家反驳结账',
platform_checkout_counter: '客服修改结账',
@@ -50,7 +50,8 @@ import {
refundStatusLabel,
settlementStatusLabel,
} from '@/shared/utils/statusLabels'
import { formatDateTime } from '@/shared/utils/time'
import { useNowTick } from '@/shared/composables/useNowTick'
import { formatDateTime, formatHandoffCountdownDetail } from '@/shared/utils/time'
import { formatGameName, formatListingNo } from '@/shared/utils/listingDisplay'
import { useAdminSessionStore } from '@/stores/adminSession'
import AdminOrderMetrics, { type AdminOrderMetric } from '../components/AdminOrderMetrics.vue'
@@ -73,6 +74,17 @@ const adminSession = useAdminSessionStore()
const loading = ref(false)
const submitting = ref(false)
const order = ref<Order | null>(null)
const nowMs = useNowTick(1000)
const handoffCountdownText = computed(() => {
if (
!order.value ||
order.value.status !== 'pending_handoff' ||
!order.value.handoff_deadline_at
) {
return null
}
return formatHandoffCountdownDetail(order.value.handoff_deadline_at, nowMs.value)
})
const handoffRecords = ref<HandoffRecord[]>([])
const processEvents = ref<ProcessEvent[]>([])
const paymentRecords = ref<AdminPayment[]>([])
@@ -1218,6 +1230,13 @@ function formatRatioNumber(value: number) {
<dt>支付截止</dt>
<dd>{{ formatDateTime(order.payment_deadline_at, '未设置') }}</dd>
</div>
<div v-if="order.handoff_deadline_at">
<dt>自动交接截止</dt>
<dd>
{{ formatDateTime(order.handoff_deadline_at) }}
<template v-if="handoffCountdownText">({{ handoffCountdownText }})</template>
</dd>
</div>
<div>
<dt>开始租用</dt>
<dd>{{ formatDateTime(orderRentedAt(), '未开始') }}</dd>
@@ -92,6 +92,7 @@ export interface Order {
checkout?: Checkout
admin_actions?: AdminActions
payment_deadline_at?: string
handoff_deadline_at?: string
created_at: string
updated_at: string
}
@@ -115,6 +116,7 @@ export interface UserOrderListItem {
handoff_status: HandoffStatus
can_hide?: boolean
payment_deadline_at?: string
handoff_deadline_at?: string
created_at: string
}
@@ -140,6 +142,7 @@ export interface AdminOrderListItem {
handoff_mode: string
settlement_mode: string
settlement_status: SettlementStatus
handoff_deadline_at?: string
created_at: string
// 已结账/已仲裁时返回号主实际到手金额(分);未结账为 undefined,与到手 0 元可区分。
owner_income_amount_cent?: number
@@ -4,6 +4,7 @@ import type { Order } from '../api/orders'
import {
buildCheckoutContentWithSummary,
CHECKOUT_SYSTEM_SUMMARY_MARKER,
formatHandoffRecordType,
orderListRentalTerms,
orderRentalTerms,
parseCheckoutSystemSummary,
@@ -40,6 +41,12 @@ describe('orderListRentalTerms', () => {
})
})
describe('formatHandoffRecordType', () => {
it('formats system_auto_handoff cleanly', () => {
expect(formatHandoffRecordType('system_auto_handoff')).toBe('系统自动交接')
})
})
const ammoResource: CheckoutResource = {
key: 'ammo6',
label: '6级弹',
@@ -468,6 +468,7 @@ export function formatHandoffRecordType(type: string) {
owner_handoff: '卖家交接',
platform_handoff: '客服代交接',
admin_force_handoff: '客服一键交接',
system_auto_handoff: '系统自动交接',
renter_checkout: '买家结账',
owner_counter_checkout: '卖家反驳结账',
platform_checkout_counter: '客服修改结账',
@@ -419,3 +419,23 @@
.empty-wrap {
padding: 60px 0;
}
.handoff-countdown-card {
border: 1px solid #fcd34d;
background: linear-gradient(180deg, #fffbeb 0%, #fef3c7 100%);
}
.handoff-countdown-title {
display: block;
margin-bottom: 4px;
color: #92400e;
font-size: 14px;
font-weight: 700;
}
.handoff-countdown-desc {
margin: 0;
color: #b45309;
font-size: 12px;
line-height: 1.5;
}
@@ -18,7 +18,8 @@ import {
OrderResourceUsageEditor,
} from '@/features/orders'
import { orderHandoffStatusLabel, orderStatusLabel } from '@/shared/utils/statusLabels'
import { formatDateTime } from '@/shared/utils/time'
import { useNowTick } from '@/shared/composables/useNowTick'
import { formatDateTime, formatHandoffCountdownDetail } from '@/shared/utils/time'
// 移动端支付收银台(基于通用 useOrderPaymentCashier 的薄封装:注入 vant toast + App 浏览器跳转)。
const cashier = useMobilePaymentCashier()
@@ -129,6 +130,17 @@ const {
})
const rentalTerms = computed(() => orderRentalTerms(order.value))
const nowMs = useNowTick(1000)
const handoffCountdownText = computed(() => {
if (
!order.value ||
order.value.status !== 'pending_handoff' ||
!order.value.handoff_deadline_at
) {
return null
}
return formatHandoffCountdownDetail(order.value.handoff_deadline_at, nowMs.value)
})
// Mobile 独有 UI 状态:各类 popup 显隐。
const showDisputePopup = ref(false)
@@ -315,6 +327,18 @@ async function copyListingCode() {
</van-cell-group>
</section>
<section
v-if="handoffCountdownText && order.handoff_deadline_at"
class="card-section handoff-countdown-card"
>
<strong class="handoff-countdown-title">自动交接倒计时:{{ handoffCountdownText }}</strong>
<p class="handoff-countdown-desc">
将于
{{ formatDateTime(order.handoff_deadline_at) }}
自动完成交接并进入使用中;号主交接与租客确认共用此倒计时。
</p>
</section>
<!-- Renter Action: Pay / Cancel -->
<section v-if="order.status === 'pending_payment'" class="card-section action-card">
<p class="action-hint">订单已创建,请确认并在有效期内完成支付。过期订单将自动关闭。</p>
@@ -23,7 +23,8 @@ import {
type MohongOrder,
} from '@/features/mohong/api/mohong'
import { centToYuan, formatCent, formatMoney } from '@/shared/utils/money'
import { formatDateMinute } from '@/shared/utils/time'
import { useNowTick } from '@/shared/composables/useNowTick'
import { formatDateMinute, formatHandoffCountdownCompact } from '@/shared/utils/time'
import { formatListingNo } from '@/shared/utils/listingDisplay'
import { useDistributionSiteStore } from '@/stores/distributionSite'
@@ -57,6 +58,7 @@ const hidingOrderId = ref<number | null>(null)
const rentalTotal = ref(0)
const rentalPage = ref(1)
const rentalPageSize = 20
const nowMs = useNowTick(15000)
const {
paymentPopupVisible,
activePayment,
@@ -310,6 +312,11 @@ function formatListingCode(order: UserOrderListItem) {
return formatListingNo(order.listing_no, order.listing_id)
}
function getHandoffCountdownText(order: UserOrderListItem) {
if (order.status !== 'pending_handoff' || !order.handoff_deadline_at) return null
return formatHandoffCountdownCompact(order.handoff_deadline_at, nowMs.value)
}
async function copyListingCode(order: UserOrderListItem) {
try {
await navigator.clipboard.writeText(formatListingCode(order))
@@ -407,6 +414,10 @@ async function copyListingCode(order: UserOrderListItem) {
<span class="info-tag">{{ item.rental.server_region }}</span>
<span class="info-tag">{{ item.rental.login_platform }}</span>
</div>
<div v-if="getHandoffCountdownText(item.rental)" class="handoff-countdown-pill">
<van-icon name="clock-o" :size="12" />
<span>{{ getHandoffCountdownText(item.rental) }}</span>
</div>
</div>
<div class="rental-price-panel">
@@ -863,6 +874,19 @@ async function copyListingCode(order: UserOrderListItem) {
margin-bottom: 0;
}
.handoff-countdown-pill {
display: inline-flex;
align-items: center;
gap: 4px;
margin-top: 7px;
padding: 2px 8px;
border-radius: 4px;
background: #fef3c7;
color: #b45309;
font-size: 11px;
font-weight: 600;
}
.info-tag {
position: relative;
padding: 0;
@@ -385,6 +385,35 @@
line-height: 1.45;
}
.handoff-countdown-strip {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 14px;
padding: 14px 16px;
border: 1px solid #fcd34d;
border-radius: 8px;
background: linear-gradient(180deg, #fffbeb 0%, #fef3c7 100%);
}
.handoff-countdown-strip div {
display: grid;
gap: 4px;
flex: 1;
min-width: 0;
}
.handoff-countdown-strip strong {
color: #92400e;
font-size: 14px;
}
.handoff-countdown-strip span {
color: #b45309;
font-size: 12px;
line-height: 1.45;
}
.secondary-actions {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
@@ -19,7 +19,8 @@ import { useOrderActions } from '@/features/orders/composables/useOrderActions'
import { useOrderPaymentCashier } from '@/features/orders/composables/useOrderPaymentCashier'
import { formatCent } from '@/shared/utils/money'
import { orderHandoffStatusLabel, orderStatusLabel } from '@/shared/utils/statusLabels'
import { formatDateTime } from '@/shared/utils/time'
import { useNowTick } from '@/shared/composables/useNowTick'
import { formatDateTime, formatHandoffCountdownDetail } from '@/shared/utils/time'
import type { PaymentPayWay } from '@/features/orders/api/orders'
// 支付收银台:二维码渲染 + 轮询查询。PC 不做 App 浏览器跳转,直接渲染二维码弹窗。
@@ -123,6 +124,17 @@ const {
})
const rentalTerms = computed(() => orderRentalTerms(order.value))
const nowMs = useNowTick(1000)
const handoffCountdownText = computed(() => {
if (
!order.value ||
order.value.status !== 'pending_handoff' ||
!order.value.handoff_deadline_at
) {
return null
}
return formatHandoffCountdownDetail(order.value.handoff_deadline_at, nowMs.value)
})
// 支付弹窗别名:保持 template 字段名不变。
const paymentDialogVisible = cashier.paymentPopupVisible
@@ -352,6 +364,20 @@ watch([() => route.query.focus, order, loading], () => {
</el-steps>
</div>
<div
v-if="handoffCountdownText && order?.handoff_deadline_at"
class="handoff-countdown-strip"
>
<div>
<strong>统一自动交接倒计时:{{ handoffCountdownText }}</strong>
<span>
将于
{{ formatDateTime(order.handoff_deadline_at) }}
自动完成交接并进入使用中;号主交接与租客确认共用此倒计时。
</span>
</div>
</div>
<div
v-if="
isOwner &&
@@ -18,7 +18,8 @@ import {
} from '@/features/mohong/api/mohong'
import { centToYuan, formatCent, formatMoney } from '@/shared/utils/money'
import { orderStatusLabel } from '@/shared/utils/statusLabels'
import { formatDateTime } from '@/shared/utils/time'
import { useNowTick } from '@/shared/composables/useNowTick'
import { formatDateTime, formatHandoffCountdownCompact } from '@/shared/utils/time'
import { formatListingNo } from '@/shared/utils/listingDisplay'
import { useDistributionSiteStore } from '@/stores/distributionSite'
@@ -53,6 +54,7 @@ const siteStore = useDistributionSiteStore()
const rentalTotal = ref(0)
const rentalPage = ref(1)
const rentalPageSize = 20
const nowMs = useNowTick(15000)
const statusTabs = [
{ key: 'all', label: '全部' },
@@ -330,11 +332,15 @@ function getPaymentDeadline(order: UserOrderListItem) {
function getCountdownMinutes(order: UserOrderListItem) {
const deadline = getPaymentDeadline(order)
if (!deadline) return 0
const now = new Date()
const diff = deadline.getTime() - now.getTime()
const diff = deadline.getTime() - nowMs.value
return Math.max(0, Math.ceil(diff / 60000))
}
function getHandoffCountdownText(order: UserOrderListItem) {
if (order.status !== 'pending_handoff' || !order.handoff_deadline_at) return null
return formatHandoffCountdownCompact(order.handoff_deadline_at, nowMs.value)
}
function statusText(item: UnifiedOrderItem) {
if (item.bizType === 'crash') return mohongOrderStatusLabel(item.status)
return orderStatusLabel(item.status)
@@ -509,6 +515,14 @@ function bizTypeLabel(bizType: BizType) {
>
{{ getCountdownMinutes(row.rental) }}分钟后超时
</span>
<span
v-else-if="
row.bizType === 'rental' && row.rental && getHandoffCountdownText(row.rental)
"
class="countdown-badge"
>
{{ getHandoffCountdownText(row.rental) }}
</span>
</div>
</template>
</el-table-column>
@@ -622,6 +636,9 @@ function bizTypeLabel(bizType: BizType) {
>
{{ getCountdownMinutes(item.rental) }}分钟后超时
</span>
<span v-else-if="getHandoffCountdownText(item.rental)" class="countdown-badge">
{{ getHandoffCountdownText(item.rental) }}
</span>
</div>
<el-button
v-if="item.rental.can_hide"
@@ -8,7 +8,8 @@ import {
type UserOrderListItem,
} from '@/features/orders'
import { handoffStatusLabel, orderStatusLabel } from '@/shared/utils/statusLabels'
import { formatDateTime } from '@/shared/utils/time'
import { useNowTick } from '@/shared/composables/useNowTick'
import { formatDateTime, formatHandoffCountdownCompact } from '@/shared/utils/time'
import { centToYuan, formatMoney } from '@/shared/utils/money'
import { formatListingNo } from '@/shared/utils/listingDisplay'
@@ -23,6 +24,7 @@ const metrics = ref<SellerHandoffMetrics>({
pending_checkout: 0,
abnormal: 0,
})
const nowMs = useNowTick(15000)
onMounted(loadOrders)
@@ -69,6 +71,11 @@ function money(value: unknown) {
function sellerAmount(order: UserOrderListItem) {
return centToYuan(order.display_amount_cent)
}
function getHandoffCountdownText(order: UserOrderListItem) {
if (order.status !== 'pending_handoff' || !order.handoff_deadline_at) return null
return formatHandoffCountdownCompact(order.handoff_deadline_at, nowMs.value)
}
</script>
<template>
@@ -129,8 +136,19 @@ function sellerAmount(order: UserOrderListItem) {
<el-table-column label="订单状态" width="150">
<template #default="{ row }">{{ orderStatusLabel(row.status) }}</template>
</el-table-column>
<el-table-column label="交接状态" width="180">
<template #default="{ row }">{{ handoffStatusLabel(row.handoff_status) }}</template>
<el-table-column label="交接状态" width="210">
<template #default="{ row }">
<div>{{ handoffStatusLabel(row.handoff_status) }}</div>
<el-tag
v-if="getHandoffCountdownText(row)"
size="small"
type="warning"
effect="plain"
style="margin-top: 4px"
>
{{ getHandoffCountdownText(row) }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="创建时间" min-width="180">
<template #default="{ row }">{{ formatDateTime(row.created_at) }}</template>
@@ -0,0 +1,22 @@
import { onMounted, onUnmounted, ref } from 'vue'
export function useNowTick(intervalMs = 1000) {
const nowMs = ref(Date.now())
let timer: ReturnType<typeof setInterval> | null = null
onMounted(() => {
nowMs.value = Date.now()
timer = setInterval(() => {
nowMs.value = Date.now()
}, intervalMs)
})
onUnmounted(() => {
if (timer !== null) {
clearInterval(timer)
timer = null
}
})
return nowMs
}
@@ -0,0 +1,42 @@
import { describe, expect, it } from 'vitest'
import { formatHandoffCountdownCompact, formatHandoffCountdownDetail } from '../time'
describe('handoff countdown helpers', () => {
const base = Date.UTC(2026, 10, 30, 12, 0, 0)
it('returns null for empty or invalid deadline', () => {
expect(formatHandoffCountdownDetail(undefined, base)).toBeNull()
expect(formatHandoffCountdownDetail('', base)).toBeNull()
expect(formatHandoffCountdownDetail('invalid-date', base)).toBeNull()
expect(formatHandoffCountdownCompact(null, base)).toBeNull()
})
it('formats remaining hours, minutes and seconds for detail banner', () => {
const deadline23h = new Date(base + (23 * 3600 + 5 * 60 + 9) * 1000).toISOString()
expect(formatHandoffCountdownDetail(deadline23h, base)).toBe('23小时05分09秒')
const deadline12m = new Date(base + (12 * 60 + 3) * 1000).toISOString()
expect(formatHandoffCountdownDetail(deadline12m, base)).toBe('12分03秒')
const deadline20s = new Date(base + 20 * 1000).toISOString()
expect(formatHandoffCountdownDetail(deadline20s, base)).toBe('20秒')
})
it('formats compact countdown for order lists', () => {
const deadline24h = new Date(base + 24 * 3600 * 1000).toISOString()
expect(formatHandoffCountdownCompact(deadline24h, base)).toBe('24小时后自动交接')
const deadline2h15m = new Date(base + (2 * 3600 + 15 * 60) * 1000).toISOString()
expect(formatHandoffCountdownCompact(deadline2h15m, base)).toBe('2小时15分后自动交接')
const deadline45m = new Date(base + 45 * 60 * 1000).toISOString()
expect(formatHandoffCountdownCompact(deadline45m, base)).toBe('45分钟后自动交接')
})
it('shows expiring message once deadline has passed', () => {
const expired = new Date(base - 1000).toISOString()
expect(formatHandoffCountdownDetail(expired, base)).toBe('倒计时已到期,系统正在自动完成交接')
expect(formatHandoffCountdownCompact(expired, base)).toBe('即将自动交接')
})
})
@@ -36,6 +36,7 @@ const booleanOptions: SystemConfigOption[] = [
export const systemConfigSelectOptions: Record<string, SystemConfigOption[]> = {
'handoff.owner_submit_timeout_minutes': shortTimeoutOptions,
'handoff.renter_confirm_timeout_minutes': shortTimeoutOptions,
'handoff.auto_complete_timeout_minutes': longTimeoutOptions,
'handoff.owner_return_confirm_timeout_minutes': longTimeoutOptions,
'order.pending_payment_timeout_minutes': shortTimeoutOptions,
'order.return_overdue_grace_minutes': [
+44
View File
@@ -23,6 +23,50 @@ export function formatInputDate(value: Date = new Date()) {
return [value.getFullYear(), pad(value.getMonth() + 1), pad(value.getDate())].join('-')
}
export function formatHandoffCountdownDetail(
deadlineAt: DateInput,
nowMs: number = Date.now()
): string | null {
if (!deadlineAt) return null
const deadline = deadlineAt instanceof Date ? deadlineAt : new Date(deadlineAt)
if (Number.isNaN(deadline.getTime())) return null
const diffMs = deadline.getTime() - nowMs
if (diffMs <= 0) {
return '倒计时已到期,系统正在自动完成交接'
}
const totalSeconds = Math.ceil(diffMs / 1000)
const hours = Math.floor(totalSeconds / 3600)
const minutes = Math.floor((totalSeconds % 3600) / 60)
const seconds = totalSeconds % 60
if (hours > 0) {
return `${hours}小时${pad(minutes)}分${pad(seconds)}秒`
}
if (minutes > 0) {
return `${minutes}分${pad(seconds)}秒`
}
return `${seconds}秒`
}
export function formatHandoffCountdownCompact(
deadlineAt: DateInput,
nowMs: number = Date.now()
): string | null {
if (!deadlineAt) return null
const deadline = deadlineAt instanceof Date ? deadlineAt : new Date(deadlineAt)
if (Number.isNaN(deadline.getTime())) return null
const diffMs = deadline.getTime() - nowMs
if (diffMs <= 0) {
return '即将自动交接'
}
const totalMinutes = Math.ceil(diffMs / 60000)
if (totalMinutes >= 60) {
const hours = Math.floor(totalMinutes / 60)
const minutes = totalMinutes % 60
return minutes > 0 ? `${hours}小时${minutes}分后自动交接` : `${hours}小时后自动交接`
}
return `${totalMinutes}分钟后自动交接`
}
function pad(value: number) {
return String(value).padStart(2, '0')
}