refactor(payment): code standards fixes and regression repairs

Backend:
- Split payment_order.go (546→314 lines) into payment_order_lifecycle.go
- Replace magic strings with constants in factory, easypay, webhook handler
- Add rate limit/validity unit constants in payment_order_lifecycle, payment_service
- Fix critical regression: add PaymentEnabled to GetPublicSettings response
- Add missing migration 099_fix_migrated_purchase_menu_label_icon.sql

Frontend:
- Fix StripePopupView.vue: replace `as any` with typed interface, use extractApiErrorMessage
- Fix AdminOrderTable.vue: replace hardcoded column labels with i18n t() calls
- Fix SubscriptionsView.vue: replace hardcoded Today/Tomorrow with i18n
- Extract duplicate statusBadgeClass/canRefund/formatOrderDateTime to orderUtils.ts
- Add missing i18n keys: common.today, common.tomorrow, payment.orders.orderType/actions
- Remove dead PurchaseSubscriptionView.vue (replaced by PaymentView)
This commit is contained in:
erio
2026-04-11 00:25:41 +08:00
parent 27cd2f8e96
commit e3a000e0d4
18 changed files with 405 additions and 445 deletions

View File

@@ -113,6 +113,7 @@
import { useI18n } from 'vue-i18n'
import BaseDialog from '@/components/common/BaseDialog.vue'
import type { PaymentOrder } from '@/types/payment'
import { statusBadgeClass, canRefund as canRefundStatus, formatOrderDateTime } from '@/components/payment/orderUtils'
const { t } = useI18n()
@@ -128,22 +129,11 @@ const emit = defineEmits<{
(e: 'refund', order: PaymentOrder): void
}>()
function statusBadgeClass(status: string): string {
const m: Record<string, string> = {
PENDING: 'badge-warning', PAID: 'badge-info', RECHARGING: 'badge-info',
COMPLETED: 'badge-success', EXPIRED: 'badge-secondary', CANCELLED: 'badge-secondary',
FAILED: 'badge-danger', REFUND_REQUESTED: 'badge-warning', REFUNDING: 'badge-warning',
PARTIALLY_REFUNDED: 'badge-warning', REFUNDED: 'badge-info', REFUND_FAILED: 'badge-danger',
}
return m[status] || 'badge-secondary'
}
function canRefund(order: PaymentOrder): boolean {
return ['COMPLETED', 'PARTIALLY_REFUNDED', 'REFUND_REQUESTED', 'REFUND_FAILED'].includes(order.status)
return canRefundStatus(order.status)
}
function formatDateTime(dateStr: string): string {
if (!dateStr) return '-'
return new Date(dateStr).toLocaleString()
return formatOrderDateTime(dateStr)
}
</script>

View File

@@ -108,7 +108,7 @@
<span class="text-xs">{{ t('payment.admin.retry') }}</span>
</button>
<button
v-if="canRefund(row)"
v-if="canRefundRow(row)"
@click="emit('refund', row)"
class="flex flex-col items-center gap-0.5 rounded-lg p-1.5 text-gray-500 transition-colors hover:bg-red-50 hover:text-red-600 dark:hover:bg-red-900/20 dark:hover:text-red-400"
>
@@ -139,6 +139,7 @@ import DataTable from '@/components/common/DataTable.vue'
import Pagination from '@/components/common/Pagination.vue'
import Select from '@/components/common/Select.vue'
import Icon from '@/components/icons/Icon.vue'
import { statusBadgeClass, canRefund, formatOrderDateTime } from '@/components/payment/orderUtils'
const { t } = useI18n()
@@ -179,16 +180,16 @@ function emitFiltersChanged() {
})
}
const columns: Column[] = [
{ key: 'id', label: 'ID' },
{ key: 'user_id', label: 'User' },
{ key: 'amount', label: 'Amount' },
{ key: 'payment_type', label: 'Method' },
{ key: 'status', label: 'Status' },
{ key: 'order_type', label: 'Type' },
{ key: 'created_at', label: 'Created' },
{ key: 'actions', label: 'Actions' },
]
const columns = computed<Column[]>(() => [
{ key: 'id', label: t('payment.orders.orderId') },
{ key: 'user_id', label: t('payment.orders.userId') },
{ key: 'amount', label: t('payment.orders.amount') },
{ key: 'payment_type', label: t('payment.orders.paymentMethod') },
{ key: 'status', label: t('payment.orders.status') },
{ key: 'order_type', label: t('payment.orders.orderType') },
{ key: 'created_at', label: t('payment.orders.createdAt') },
{ key: 'actions', label: t('payment.orders.actions') },
])
const statusFilterOptions = computed(() => [
{ value: '', label: t('payment.admin.allStatuses') },
@@ -216,22 +217,11 @@ const orderTypeFilterOptions = computed(() => [
{ value: 'subscription', label: t('payment.admin.subscriptionOrder') },
])
function statusBadgeClass(status: string): string {
const m: Record<string, string> = {
PENDING: 'badge-warning', PAID: 'badge-info', RECHARGING: 'badge-info',
COMPLETED: 'badge-success', EXPIRED: 'badge-secondary', CANCELLED: 'badge-secondary',
FAILED: 'badge-danger', REFUND_REQUESTED: 'badge-warning', REFUNDING: 'badge-warning',
PARTIALLY_REFUNDED: 'badge-warning', REFUNDED: 'badge-info', REFUND_FAILED: 'badge-danger',
}
return m[status] || 'badge-secondary'
}
function canRefund(order: PaymentOrder): boolean {
return ['COMPLETED', 'PARTIALLY_REFUNDED', 'REFUND_REQUESTED', 'REFUND_FAILED'].includes(order.status)
function canRefundRow(order: PaymentOrder): boolean {
return canRefund(order.status)
}
function formatDateTime(dateStr: string): string {
if (!dateStr) return '-'
return new Date(dateStr).toLocaleString()
return formatOrderDateTime(dateStr)
}
</script>

View File

@@ -164,6 +164,7 @@ import { reactive, computed, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import BaseDialog from '@/components/common/BaseDialog.vue'
import type { PaymentOrder } from '@/types/payment'
import { formatOrderDateTime } from '@/components/payment/orderUtils'
const { t } = useI18n()
@@ -222,8 +223,7 @@ watch(() => props.show, (val) => {
})
function formatDateTime(dateStr: string): string {
if (!dateStr) return '-'
return new Date(dateStr).toLocaleString()
return formatOrderDateTime(dateStr)
}
function handleSubmit() {

View File

@@ -0,0 +1,34 @@
/**
* Shared utility functions for payment order display.
* Used by AdminOrderDetail, AdminOrderTable, AdminRefundDialog, AdminOrdersView, etc.
*/
const STATUS_BADGE_MAP: Record<string, string> = {
PENDING: 'badge-warning',
PAID: 'badge-info',
RECHARGING: 'badge-info',
COMPLETED: 'badge-success',
EXPIRED: 'badge-secondary',
CANCELLED: 'badge-secondary',
FAILED: 'badge-danger',
REFUND_REQUESTED: 'badge-warning',
REFUNDING: 'badge-warning',
PARTIALLY_REFUNDED: 'badge-warning',
REFUNDED: 'badge-info',
REFUND_FAILED: 'badge-danger',
}
const REFUNDABLE_STATUSES = ['COMPLETED', 'PARTIALLY_REFUNDED', 'REFUND_REQUESTED', 'REFUND_FAILED']
export function statusBadgeClass(status: string): string {
return STATUS_BADGE_MAP[status] || 'badge-secondary'
}
export function canRefund(status: string): boolean {
return REFUNDABLE_STATUSES.includes(status)
}
export function formatOrderDateTime(dateStr: string): string {
if (!dateStr) return '-'
return new Date(dateStr).toLocaleString()
}