增加文档

This commit is contained in:
yml
2026-11-14 15:03:44 +08:00
parent 7dc8ddd193
commit bc96295ed6
11 changed files with 2036 additions and 228 deletions
+1
View File
@@ -109,6 +109,7 @@ SKIP_CHECKS=1 git push
- [接口规划](docs/api.md) - [接口规划](docs/api.md)
- [业务规则](docs/business-rules.md) - [业务规则](docs/business-rules.md)
- [分销网管理后台设计方案](docs/分销网管理后台设计方案.md) - [分销网管理后台设计方案](docs/分销网管理后台设计方案.md)
- [双运营主体多租户改造分析](docs/双运营主体多租户改造分析.md)
### 分销独立测试库 ### 分销独立测试库
@@ -46,10 +46,7 @@ type ConfigDTO struct {
Status string `json:"status"` Status string `json:"status"`
Environment string `json:"environment"` Environment string `json:"environment"`
BusinessTags []string `json:"business_tags"` BusinessTags []string `json:"business_tags"`
ReferenceCount int64 `json:"reference_count"` HasPaymentRecords bool `json:"has_payment_records"`
TotalTransactions int64 `json:"total_transactions"`
TotalAmountCent int64 `json:"total_amount_cent"`
LastUsedAt *string `json:"last_used_at"`
CreatedBy *uint64 `json:"created_by"` CreatedBy *uint64 `json:"created_by"`
UpdatedBy *uint64 `json:"updated_by"` UpdatedBy *uint64 `json:"updated_by"`
CreatedAt string `json:"created_at"` CreatedAt string `json:"created_at"`
@@ -295,17 +295,17 @@ func (r *Repository) Delete(ctx context.Context, id uint64, actorID uint64, meta
return err return err
} }
var usedCount int64
usedDB := tx.Model(&model.PaymentOrder{}). usedDB := tx.Model(&model.PaymentOrder{}).
Where("payment_config_id = ?", item.ID). Where("payment_config_id = ?", item.ID).
Or("(payment_config_id = ? OR payment_config_id IS NULL) AND provider = ? AND merchant_id = ? AND pay_way = ?", 0, item.Provider, item.MerchantID, item.PayWay) Or("(payment_config_id = ? OR payment_config_id IS NULL) AND provider = ? AND merchant_id = ? AND pay_way = ?", 0, item.Provider, item.MerchantID, item.PayWay)
if err := usedDB. var usedPayment model.PaymentOrder
Count(&usedCount).Error; err != nil { err := usedDB.Select("id").Limit(1).Take(&usedPayment).Error
return err if err == nil {
}
if usedCount > 0 {
return ErrCannotDeleteInUse return ErrCannotDeleteInUse
} }
if !errors.Is(err, gorm.ErrRecordNotFound) {
return err
}
if err := tx.Delete(&item).Error; err != nil { if err := tx.Delete(&item).Error; err != nil {
return err return err
@@ -9,32 +9,25 @@ import (
// toDTO 转换为 DTO // toDTO 转换为 DTO
func (r *Repository) toDTO(item model.PaymentMerchantConfig, includeSecret bool) (ConfigDTO, error) { func (r *Repository) toDTO(item model.PaymentMerchantConfig, includeSecret bool) (ConfigDTO, error) {
dto := ConfigDTO{ dto := ConfigDTO{
ID: item.ID, ID: item.ID,
Name: item.Name, Name: item.Name,
Provider: item.Provider, Provider: item.Provider,
MerchantID: item.MerchantID, MerchantID: item.MerchantID,
GatewayURL: item.GatewayURL, GatewayURL: item.GatewayURL,
NotifyURL: item.NotifyURL, NotifyURL: item.NotifyURL,
JumpURL: item.JumpURL, JumpURL: item.JumpURL,
PayWay: item.PayWay, PayWay: item.PayWay,
JSPayFlag: item.JSPayFlag, JSPayFlag: item.JSPayFlag,
SignType: item.SignType, SignType: item.SignType,
ExtraConfig: item.ExtraConfig, ExtraConfig: item.ExtraConfig,
IsDefault: item.IsDefault, IsDefault: item.IsDefault,
Status: item.Status, Status: item.Status,
Environment: item.Environment, Environment: item.Environment,
BusinessTags: item.BusinessTags, BusinessTags: item.BusinessTags,
TotalTransactions: item.TotalTransactions, CreatedBy: item.CreatedBy,
TotalAmountCent: item.TotalAmountCent, UpdatedBy: item.UpdatedBy,
CreatedBy: item.CreatedBy, CreatedAt: item.CreatedAt.Format(time.RFC3339),
UpdatedBy: item.UpdatedBy, UpdatedAt: item.UpdatedAt.Format(time.RFC3339),
CreatedAt: item.CreatedAt.Format(time.RFC3339),
UpdatedAt: item.UpdatedAt.Format(time.RFC3339),
}
if item.LastUsedAt != nil {
s := item.LastUsedAt.Format(time.RFC3339)
dto.LastUsedAt = &s
} }
// 只有明确要求时才解密并返回密钥 // 只有明确要求时才解密并返回密钥
+17 -112
View File
@@ -2,9 +2,7 @@ package paymentconfig
import ( import (
"context" "context"
"database/sql/driver"
"errors" "errors"
"time"
"hfb_sys/backend/internal/model" "hfb_sys/backend/internal/model"
@@ -63,10 +61,8 @@ func (r *Repository) List(ctx context.Context, query ListQuery) ([]ConfigDTO, in
} }
dtos = append(dtos, dto) dtos = append(dtos, dto)
} }
if err := r.applySuccessfulPaymentStats(ctx, dtos); err != nil {
return nil, 0, err if err := r.applyPaymentReferenceFlags(ctx, dtos); err != nil {
}
if err := r.applyReferenceCounts(ctx, dtos); err != nil {
return nil, 0, err return nil, 0, err
} }
@@ -86,14 +82,12 @@ func (r *Repository) FindByID(ctx context.Context, id uint64, includeSecret bool
if err != nil { if err != nil {
return nil, err return nil, err
} }
statDTOs := []ConfigDTO{dto}
if err := r.applySuccessfulPaymentStats(ctx, statDTOs); err != nil { dtos := []ConfigDTO{dto}
if err := r.applyPaymentReferenceFlags(ctx, dtos); err != nil {
return nil, err return nil, err
} }
if err := r.applyReferenceCounts(ctx, statDTOs); err != nil { dto = dtos[0]
return nil, err
}
dto = statDTOs[0]
if includeSecret { if includeSecret {
if err := appendAuditLog(r.db.WithContext(ctx), actorID, "payment_config.view_secret", item.ID, meta, map[string]any{ if err := appendAuditLog(r.db.WithContext(ctx), actorID, "payment_config.view_secret", item.ID, meta, map[string]any{
"name": item.Name, "name": item.Name,
@@ -106,15 +100,9 @@ func (r *Repository) FindByID(ctx context.Context, id uint64, includeSecret bool
return &dto, nil return &dto, nil
} }
type paymentConfigSuccessStat struct { // applyPaymentReferenceFlags 批量标记配置是否已有支付单,用于前端提前禁用删除。
ConfigID uint64 // 真正的删除保护仍由 Delete 按包含历史数据的口径校验。
TotalTransactions int64 func (r *Repository) applyPaymentReferenceFlags(ctx context.Context, dtos []ConfigDTO) error {
TotalAmountCent int64
LastPaidAt nullableTime
}
// applySuccessfulPaymentStats 使用真实成功支付流水覆盖配置统计,避免仅打开二维码也被算作成交。
func (r *Repository) applySuccessfulPaymentStats(ctx context.Context, dtos []ConfigDTO) error {
if len(dtos) == 0 { if len(dtos) == 0 {
return nil return nil
} }
@@ -123,109 +111,26 @@ func (r *Repository) applySuccessfulPaymentStats(ctx context.Context, dtos []Con
for idx, dto := range dtos { for idx, dto := range dtos {
ids = append(ids, dto.ID) ids = append(ids, dto.ID)
indexByID[dto.ID] = idx indexByID[dto.ID] = idx
dtos[idx].TotalTransactions = 0 dtos[idx].HasPaymentRecords = false
dtos[idx].TotalAmountCent = 0
dtos[idx].LastUsedAt = nil
} }
var rows []paymentConfigSuccessStat var referencedIDs []uint64
if err := r.db.WithContext(ctx).Model(&model.PaymentOrder{}). if err := r.db.WithContext(ctx).Model(&model.PaymentOrder{}).
Select("payment_config_id AS config_id, COUNT(*) AS total_transactions, COALESCE(SUM(amount_cent), 0) AS total_amount_cent, MAX(paid_at) AS last_paid_at"). Where("payment_config_id IN ?", ids).
Where("payment_config_id IN ? AND biz_type = ? AND status = ?", ids, "order_pay", "paid"). Distinct().
Group("payment_config_id"). Pluck("payment_config_id", &referencedIDs).Error; err != nil {
Scan(&rows).Error; err != nil {
return err return err
} }
for _, row := range rows { for _, id := range referencedIDs {
idx, ok := indexByID[row.ConfigID] idx, ok := indexByID[id]
if !ok { if !ok {
continue continue
} }
dtos[idx].TotalTransactions = row.TotalTransactions dtos[idx].HasPaymentRecords = true
dtos[idx].TotalAmountCent = row.TotalAmountCent
if row.LastPaidAt.Time != nil {
value := row.LastPaidAt.Time.Format(time.RFC3339)
dtos[idx].LastUsedAt = &value
}
} }
return nil return nil
} }
// applyReferenceCounts 使用删除保护的同一口径统计配置被支付记录引用的次数。
func (r *Repository) applyReferenceCounts(ctx context.Context, dtos []ConfigDTO) error {
for idx := range dtos {
count, err := r.referenceCount(ctx, dtos[idx])
if err != nil {
return err
}
dtos[idx].ReferenceCount = count
}
return nil
}
func (r *Repository) referenceCount(ctx context.Context, dto ConfigDTO) (int64, error) {
var count int64
db := r.db.WithContext(ctx).Model(&model.PaymentOrder{}).
Where("payment_config_id = ?", dto.ID).
Or("(payment_config_id = ? OR payment_config_id IS NULL) AND provider = ? AND merchant_id = ? AND pay_way = ?", 0, dto.Provider, dto.MerchantID, dto.PayWay)
if err := db.Count(&count).Error; err != nil {
return 0, err
}
return count, nil
}
type nullableTime struct {
Time *time.Time
}
// Value 实现 driver.Valuer,让 GORM 能把 nullableTime 当作普通扫描字段处理。
func (nt nullableTime) Value() (driver.Value, error) {
if nt.Time == nil {
return nil, nil
}
return *nt.Time, nil
}
// Scan 兼容 MySQL 聚合函数可能返回的 time.Time 与字符串时间。
func (nt *nullableTime) Scan(value any) error {
switch v := value.(type) {
case nil:
nt.Time = nil
case time.Time:
nt.Time = &v
case []byte:
return nt.scanString(string(v))
case string:
return nt.scanString(v)
default:
nt.Time = nil
}
return nil
}
func (nt *nullableTime) scanString(value string) error {
if value == "" {
nt.Time = nil
return nil
}
for _, layout := range []string{
time.RFC3339Nano,
time.RFC3339,
"2006-01-02 15:04:05.999999999-07:00",
"2006-01-02 15:04:05-07:00",
"2006-01-02 15:04:05.999999999",
"2006-01-02 15:04:05",
} {
parsed, err := time.Parse(layout, value)
if err == nil {
nt.Time = &parsed
return nil
}
}
nt.Time = nil
return nil
}
// FindRuntimeByID 根据配置 ID 查询运行时配置,不写审计日志,供支付单回溯原配置使用。 // FindRuntimeByID 根据配置 ID 查询运行时配置,不写审计日志,供支付单回溯原配置使用。
func (r *Repository) FindRuntimeByID(ctx context.Context, id uint64, includeSecret bool) (*ConfigDTO, error) { func (r *Repository) FindRuntimeByID(ctx context.Context, id uint64, includeSecret bool) (*ConfigDTO, error) {
var item model.PaymentMerchantConfig var item model.PaymentMerchantConfig
@@ -67,8 +67,8 @@ func TestValidateCreateRequestRequiresShunchengSecretID(t *testing.T) {
} }
} }
// TestListUsesSuccessfulPaymentStats 验证配置页只统计成功支付,不把打开二维码或取消订单算作成交。 // TestListFlagsPaymentReferences 验证列表只批量标记是否存在支付引用,不再聚合所有支付记录。
func TestListUsesSuccessfulPaymentStats(t *testing.T) { func TestListFlagsPaymentReferences(t *testing.T) {
db := database.NewTestDB() db := database.NewTestDB()
if err := database.AutoMigrateIfMissing(db, &model.PaymentMerchantConfig{}, &model.PaymentOrder{}); err != nil { if err := database.AutoMigrateIfMissing(db, &model.PaymentMerchantConfig{}, &model.PaymentOrder{}); err != nil {
t.Fatalf("migrate failed: %v", err) t.Fatalf("migrate failed: %v", err)
@@ -142,13 +142,46 @@ func TestListUsesSuccessfulPaymentStats(t *testing.T) {
if total != 1 || len(items) != 1 { if total != 1 || len(items) != 1 {
t.Fatalf("items/total = %d/%d, want 1/1", len(items), total) t.Fatalf("items/total = %d/%d, want 1/1", len(items), total)
} }
if items[0].TotalTransactions != 1 || items[0].TotalAmountCent != 10130 { if !items[0].HasPaymentRecords {
t.Fatalf("success stats = %d/%d, want 1/10130", items[0].TotalTransactions, items[0].TotalAmountCent) t.Fatal("has_payment_records should be true")
} }
if items[0].ReferenceCount != 3 { }
t.Fatalf("reference_count = %d, want 3", items[0].ReferenceCount)
func TestDeleteRejectsReferencedConfig(t *testing.T) {
db := database.NewTestDB()
if err := database.AutoMigrateIfMissing(db, &model.PaymentMerchantConfig{}, &model.PaymentOrder{}); err != nil {
t.Fatalf("migrate failed: %v", err)
} }
if items[0].LastUsedAt == nil { config := model.PaymentMerchantConfig{
t.Fatal("last success pay time should not be nil") Name: "已有交易配置",
Provider: "lakala",
MerchantID: "M1",
PayWay: "WXZF",
Status: "active",
Environment: "production",
}
if err := db.Create(&config).Error; err != nil {
t.Fatalf("create config failed: %v", err)
}
payment := model.PaymentOrder{
PaymentNo: "PAY-DELETE-GUARD",
OrderID: 1,
OrderNo: "ORD-DELETE-GUARD",
UserID: 2,
PaymentConfigID: config.ID,
Provider: "lakala",
MerchantID: "M1",
ThirdOrderID: "PAY-DELETE-GUARD",
PayWay: "WXZF",
BizType: "order_pay",
Status: "paid",
}
if err := db.Create(&payment).Error; err != nil {
t.Fatalf("create payment failed: %v", err)
}
repo := NewRepository(db, nil)
if err := repo.Delete(t.Context(), config.ID, 0, AuditMeta{}); err != ErrCannotDeleteInUse {
t.Fatalf("Delete() error = %v, want ErrCannotDeleteInUse", err)
} }
} }
File diff suppressed because it is too large Load Diff
@@ -19,10 +19,7 @@ export interface PaymentConfig {
status: string status: string
environment: string environment: string
business_tags: string[] | null business_tags: string[] | null
reference_count: number has_payment_records: boolean
total_transactions: number
total_amount_cent: number
last_used_at: string | null
created_by: number | null created_by: number | null
updated_by: number | null updated_by: number | null
created_at: string created_at: string
@@ -62,7 +62,8 @@ const publishOptions = ref(emptyListingPublishOptions)
const listingColumnUnits = { const listingColumnUnits = {
code: 68, code: 68,
zone: 70, zone: 70,
region: 100, region: 62,
login: 38,
core: 80, core: 80,
level: 58, level: 58,
equipment: 78, equipment: 78,
@@ -161,10 +162,11 @@ const screenshotColumns = [
read: (row: Listing) => zoneCompensationText(row), read: (row: Listing) => zoneCompensationText(row),
}, },
{ {
label: '地区/上号/纯币', label: '地区/纯币',
width: 140, width: 105,
read: (row: Listing) => regionLoginCoinText(row), read: (row: Listing) => regionCoinText(row),
}, },
{ label: '上号方式', width: 70, read: (row: Listing) => loginMethodText(row) },
{ {
label: '保险/体力/负重', label: '保险/体力/负重',
width: 112, width: 112,
@@ -179,8 +181,8 @@ const screenshotColumns = [
{ label: '皮肤资产', width: 189, read: (row: Listing) => skinAssetText(row) }, { label: '皮肤资产', width: 189, read: (row: Listing) => skinAssetText(row) },
{ label: '人脸/全英雄', width: 81, read: (row: Listing) => faceHeroText(row) }, { label: '人脸/全英雄', width: 81, read: (row: Listing) => faceHeroText(row) },
{ label: '号主备注', width: 112, read: (row: Listing) => ownerRemarkText(row) }, { label: '号主备注', width: 112, read: (row: Listing) => ownerRemarkText(row) },
{ label: '租客纯币价格', width: 101, read: (row: Listing) => renterPureCoinPriceText(row) },
{ label: '租期', width: 70, read: (row: Listing) => rentalPeriodText(row) }, { label: '租期', width: 70, read: (row: Listing) => rentalPeriodText(row) },
{ label: '租客纯币价格', width: 101, read: (row: Listing) => renterPureCoinPriceText(row) },
{ label: '租金/押金', width: 106, read: (row: Listing) => rentAndDepositText(row) }, { label: '租金/押金', width: 106, read: (row: Listing) => rentAndDepositText(row) },
{ label: '比例', width: 42, read: (row: Listing) => formatRatio(row) }, { label: '比例', width: 42, read: (row: Listing) => formatRatio(row) },
{ label: '详情', width: 64, read: () => '详情' }, { label: '详情', width: 64, read: () => '详情' },
@@ -517,7 +519,7 @@ function renderTableScreenshotCanvas(rows: Listing[]) {
drawCellText( drawCellText(
ctx, ctx,
headerLines[columnIndex] ?? [column.label], headerLines[columnIndex] ?? [column.label],
x + cellPaddingX, x + column.width / 2,
y + cellPaddingY + 12, y + cellPaddingY + 12,
lineHeight lineHeight
) )
@@ -538,7 +540,7 @@ function renderTableScreenshotCanvas(rows: Listing[]) {
columnIndex === 0 columnIndex === 0
? '700 13px Arial, "Microsoft YaHei", sans-serif' ? '700 13px Arial, "Microsoft YaHei", sans-serif'
: '13px Arial, "Microsoft YaHei", sans-serif' : '13px Arial, "Microsoft YaHei", sans-serif'
drawCellText(ctx, lines, x + cellPaddingX, y + cellPaddingY + 14, lineHeight) drawCellText(ctx, lines, x + column.width / 2, y + cellPaddingY + 14, lineHeight)
x += column.width x += column.width
} }
drawLine(ctx, paddingX, y + rowHeight, paddingX + tableWidth, y + rowHeight) drawLine(ctx, paddingX, y + rowHeight, paddingX + tableWidth, y + rowHeight)
@@ -569,12 +571,13 @@ function wrapCanvasText(ctx: CanvasRenderingContext2D, text: string, maxWidth: n
function drawCellText( function drawCellText(
ctx: CanvasRenderingContext2D, ctx: CanvasRenderingContext2D,
lines: string[], lines: string[],
x: number, centerX: number,
y: number, y: number,
lineHeight: number lineHeight: number
) { ) {
ctx.textAlign = 'center'
lines.forEach((line, index) => { lines.forEach((line, index) => {
ctx.fillText(line, x, y + index * lineHeight) ctx.fillText(line, centerX, y + index * lineHeight)
}) })
} }
@@ -648,8 +651,12 @@ function zoneCompensationText(row: Listing) {
return `${zone}\n${compensation}` return `${zone}\n${compensation}`
} }
function regionLoginCoinText(row: Listing) { function regionCoinText(row: Listing) {
return [regionText(row), row.login_platform || '-', listingCoinM(row)].join('\n') return [regionText(row), listingCoinM(row)].join('\n')
}
function loginMethodText(row: Listing) {
return row.login_platform?.trim() || '-'
} }
function insuranceSlotText(row: Listing) { function insuranceSlotText(row: Listing) {
@@ -1070,15 +1077,22 @@ function formatQuantity(value: number) {
</template> </template>
</el-table-column> </el-table-column>
<el-table-column <el-table-column
label="地区/上号/纯币" label="地区/纯币"
:width="listingColumnWidths.region" :width="listingColumnWidths.region"
show-overflow-tooltip show-overflow-tooltip
label-class-name="listing-merged-header" label-class-name="listing-merged-header"
> >
<template #default="{ row }"> <template #default="{ row }">
<span class="listing-multiline-cell">{{ regionLoginCoinText(row) }}</span> <span class="listing-multiline-cell">{{ regionCoinText(row) }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column
label="上号方式"
:width="listingColumnWidths.login"
label-class-name="listing-merged-header"
>
<template #default="{ row }">{{ loginMethodText(row) }}</template>
</el-table-column>
<el-table-column <el-table-column
label="保险/体力/负重" label="保险/体力/负重"
:width="listingColumnWidths.core" :width="listingColumnWidths.core"
@@ -1130,6 +1144,12 @@ function formatQuantity(value: number) {
<el-table-column label="号主备注" :width="listingColumnWidths.remark" show-overflow-tooltip> <el-table-column label="号主备注" :width="listingColumnWidths.remark" show-overflow-tooltip>
<template #default="{ row }">{{ ownerRemarkText(row) }}</template> <template #default="{ row }">{{ ownerRemarkText(row) }}</template>
</el-table-column> </el-table-column>
<el-table-column label="租期" :width="listingColumnWidths.period">
<template #default="{ row }">
<span :title="estimateTitle(row)">{{ formatEstimatedRentalDuration(row) }}</span>
<span v-if="getDailyLoss(row)" class="table-subtext">日耗 {{ getDailyLoss(row) }}</span>
</template>
</el-table-column>
<el-table-column label="租客纯币价格" :width="listingColumnWidths.purePrice"> <el-table-column label="租客纯币价格" :width="listingColumnWidths.purePrice">
<template #default="{ row }"> <template #default="{ row }">
<span :title="`租客纯币价格(不含消耗品)${renterPureCoinPriceText(row)}`"> <span :title="`租客纯币价格(不含消耗品)${renterPureCoinPriceText(row)}`">
@@ -1137,12 +1157,6 @@ function formatQuantity(value: number) {
</span> </span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="租期" :width="listingColumnWidths.period">
<template #default="{ row }">
<span :title="estimateTitle(row)">{{ formatEstimatedRentalDuration(row) }}</span>
<span v-if="getDailyLoss(row)" class="table-subtext">日耗 {{ getDailyLoss(row) }}</span>
</template>
</el-table-column>
<el-table-column label="租金/押金" :width="listingColumnWidths.rentDeposit"> <el-table-column label="租金/押金" :width="listingColumnWidths.rentDeposit">
<template #default="{ row }">{{ rentAndDepositText(row) }}</template> <template #default="{ row }">{{ rentAndDepositText(row) }}</template>
</el-table-column> </el-table-column>
@@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { ElMessage, ElMessageBox } from 'element-plus' import { ElMessage, ElMessageBox } from 'element-plus'
import { computed, onMounted, ref } from 'vue' import { onMounted, ref } from 'vue'
import { import {
Plus, Plus,
Refresh, Refresh,
@@ -19,8 +19,6 @@ import {
importPaymentConfigBackup, importPaymentConfigBackup,
type PaymentConfig, type PaymentConfig,
} from '@/features/admin/api/paymentConfig' } from '@/features/admin/api/paymentConfig'
import { formatDateTime } from '@/shared/utils/time'
import { formatCent } from '@/shared/utils/money'
import { readError } from '@/shared/utils/error' import { readError } from '@/shared/utils/error'
import PaymentConfigDialog from '../components/PaymentConfigDialog.vue' import PaymentConfigDialog from '../components/PaymentConfigDialog.vue'
@@ -69,10 +67,6 @@ const environmentOptions = [
{ label: '测试环境', value: 'sandbox' }, { label: '测试环境', value: 'sandbox' },
] ]
const filteredConfigs = computed(() => {
return configs.value
})
onMounted(() => { onMounted(() => {
loadConfigs() loadConfigs()
}) })
@@ -267,10 +261,6 @@ function formatEnvironment(env: string) {
return map[env] || env return map[env] || env
} }
function formatAmount(amountCent: number) {
return formatCent(amountCent)
}
function getEnvironmentClass(env: string) { function getEnvironmentClass(env: string) {
const map: Record<string, string> = { const map: Record<string, string> = {
production: 'env-production', production: 'env-production',
@@ -298,12 +288,12 @@ function tableRowClassName({ row }: { row: PaymentConfig }) {
} }
function canDeleteConfig(row: PaymentConfig) { function canDeleteConfig(row: PaymentConfig) {
return (row.reference_count || 0) <= 0 return !row.has_payment_records
} }
function deleteDisabledReason(row: PaymentConfig) { function deleteDisabledReason(row: PaymentConfig) {
if (canDeleteConfig(row)) return '删除配置' if (canDeleteConfig(row)) return '删除配置'
return `已有 ${row.reference_count || 0} 条支付记录引用,需要保留用于退款、查询和回调验签` return '已有支付记录引用,需要保留用于退款、查询和回调验签'
} }
</script> </script>
@@ -413,7 +403,7 @@ function deleteDisabledReason(row: PaymentConfig) {
<div class="table-container"> <div class="table-container">
<el-table <el-table
:data="filteredConfigs" :data="configs"
v-loading="loading" v-loading="loading"
class="payment-config-table custom-enterprise-table" class="payment-config-table custom-enterprise-table"
:row-class-name="tableRowClassName" :row-class-name="tableRowClassName"
@@ -456,27 +446,6 @@ function deleteDisabledReason(row: PaymentConfig) {
<span v-else class="standby-badge">备用</span> <span v-else class="standby-badge">备用</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="支付记录" min-width="150">
<template #default="{ row }">
<div class="usage-cell">
<div>成功: {{ row.total_transactions }} 笔</div>
<div :class="{ 'usage-reference-locked': (row.reference_count || 0) > 0 }">
引用: {{ row.reference_count || 0 }} 条
</div>
<div>金额: ¥{{ formatAmount(row.total_amount_cent) }}</div>
</div>
</template>
</el-table-column>
<el-table-column
prop="last_used_at"
label="最后成功支付"
min-width="180"
show-overflow-tooltip
>
<template #default="{ row }">
{{ row.last_used_at ? formatDateTime(row.last_used_at, '-') : '-' }}
</template>
</el-table-column>
<el-table-column label="操作" width="226" class-name="operation-column"> <el-table-column label="操作" width="226" class-name="operation-column">
<template #default="{ row }"> <template #default="{ row }">
<div class="action-buttons"> <div class="action-buttons">
@@ -789,20 +758,6 @@ function deleteDisabledReason(row: PaymentConfig) {
font-weight: 600; font-weight: 600;
} }
.usage-cell {
display: grid;
gap: 4px;
font-size: 12px;
line-height: 1.35;
color: #3f4654;
white-space: nowrap;
}
.usage-reference-locked {
color: #dc2626;
font-weight: 600;
}
.action-buttons { .action-buttons {
display: flex; display: flex;
align-items: center; align-items: center;
+3
View File
@@ -1144,12 +1144,14 @@ h1 {
.admin-listings-table.el-table th { .admin-listings-table.el-table th {
font-size: 11px; font-size: 11px;
letter-spacing: 0; letter-spacing: 0;
text-align: center;
text-transform: none; text-transform: none;
} }
.admin-listings-table.el-table .cell { .admin-listings-table.el-table .cell {
padding: 0 5px; padding: 0 5px;
line-height: 1.35; line-height: 1.35;
text-align: center;
white-space: normal; white-space: normal;
word-break: break-word; word-break: break-word;
} }
@@ -1191,6 +1193,7 @@ h1 {
.admin-listings-table.el-table .el-table__cell { .admin-listings-table.el-table .el-table__cell {
padding: 8px 0; padding: 8px 0;
text-align: center;
} }
.admin-listings-table.el-table .el-button--small { .admin-listings-table.el-table .el-button--small {