From e7e7631fa5127a89eaee37c9db3dfd5ea96a83d1 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 7 May 2026 00:28:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8E=88=E6=9D=83=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E8=AE=BE=E7=BD=AE=E5=8D=A1=E7=B1=BB=E4=BB=B7?= =?UTF-8?q?=E6=A0=BC=EF=BC=8C=E4=BB=A3=E7=90=86=E7=AE=A1=E7=90=86=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=B6=88=E8=B4=B9=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/internal/model/models.go | 8 ++-- backend/internal/router/admin/agent_apps.go | 21 ++++++--- .../src/pages/admin/agent-apps/create.vue | 46 +++++++------------ .../src/pages/admin/agent-apps/data/schema.ts | 18 +++++--- frontend/src/pages/admin/agent-apps/index.vue | 26 ++++++----- .../pages/admin/agents/components/columns.ts | 8 ++++ .../admin/agents/components/data-table.vue | 1 + .../src/pages/admin/agents/data/schema.ts | 1 + frontend/src/plugins/i18n/zh.json | 1 + 9 files changed, 74 insertions(+), 56 deletions(-) diff --git a/backend/internal/model/models.go b/backend/internal/model/models.go index 957a7d8..f846d8e 100644 --- a/backend/internal/model/models.go +++ b/backend/internal/model/models.go @@ -27,9 +27,10 @@ type User struct { ApiCallsResetAt *time.Time `json:"api_calls_reset_at"` ApiToken string `gorm:"size:64" json:"api_token"` - ParentAgentID *uint `gorm:"index" json:"parent_agent_id"` - CanCreateAgent bool `gorm:"default:false" json:"can_create_agent"` - Balance float64 `gorm:"default:0" json:"balance"` + ParentAgentID *uint `gorm:"index" json:"parent_agent_id"` + CanCreateAgent bool `gorm:"default:false" json:"can_create_agent"` + Balance float64 `gorm:"default:0" json:"balance"` + TotalConsumption float64 `gorm:"default:0" json:"total_consumption"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` @@ -626,6 +627,7 @@ type AgentApplicationCardType struct { AgentApplicationID uint `json:"agent_application_id"` CardTypeID uint `json:"card_type_id"` CanGenerate bool `gorm:"default:false" json:"can_generate"` + Price float64 `gorm:"type:decimal(10,2);default:0" json:"price"` CreatedAt time.Time `json:"created_at"` DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` diff --git a/backend/internal/router/admin/agent_apps.go b/backend/internal/router/admin/agent_apps.go index 1ce1c8c..863b50a 100644 --- a/backend/internal/router/admin/agent_apps.go +++ b/backend/internal/router/admin/agent_apps.go @@ -98,10 +98,13 @@ func handleGetAgentApps(c *gin.Context) { } type CardTypeResponse struct { - ID uint `json:"id"` - CardTypeID uint `json:"card_type_id"` - Name string `json:"name"` - CanGenerate bool `json:"can_generate"` + ID uint `json:"id"` + CardTypeID uint `json:"card_type_id"` + Name string `json:"name"` + BillingType string `json:"billing_type"` + CanGenerate bool `json:"can_generate"` + Price float64 `json:"price"` + OriginPrice float64 `json:"origin_price"` } type AgentAppResponse struct { @@ -142,7 +145,10 @@ func handleGetAgentApps(c *gin.Context) { ID: ct.ID, CardTypeID: ct.CardTypeID, Name: ct.CardType.Name, + BillingType: ct.CardType.RechargeType, CanGenerate: ct.CanGenerate, + Price: ct.Price, + OriginPrice: ct.CardType.Price, }) } @@ -746,8 +752,9 @@ func handleDirectAuthorize(c *gin.Context) { ApplicationID uint `json:"application_id" binding:"required"` Discount float64 `json:"discount"` CardTypes []struct { - CardTypeID uint `json:"card_type_id" binding:"required"` - CanGenerate bool `json:"can_generate"` + CardTypeID uint `json:"card_type_id" binding:"required"` + CanGenerate bool `json:"can_generate"` + Price float64 `json:"price"` } `json:"card_types"` } if err := c.ShouldBindJSON(&reqBody); err != nil { @@ -823,6 +830,7 @@ func handleDirectAuthorize(c *gin.Context) { AgentApplicationID: agentApp.ID, CardTypeID: ct.CardTypeID, CanGenerate: ct.CanGenerate, + Price: ct.Price, } if err := tx.Create(&agentCardType).Error; err != nil { tx.Rollback() @@ -838,6 +846,7 @@ func handleDirectAuthorize(c *gin.Context) { AgentApplicationID: agentApp.ID, CardTypeID: ct.ID, CanGenerate: false, + Price: ct.Price, } if err := tx.Create(&agentCardType).Error; err != nil { tx.Rollback() diff --git a/frontend/src/pages/admin/agent-apps/create.vue b/frontend/src/pages/admin/agent-apps/create.vue index 7a4d012..2dcfaa6 100644 --- a/frontend/src/pages/admin/agent-apps/create.vue +++ b/frontend/src/pages/admin/agent-apps/create.vue @@ -36,8 +36,7 @@ const cardTypes = ref([]) const form = ref({ agent_id: '', application_id: '', - discount: 1.0, - card_types: [] as Array<{ card_type_id: number, can_generate: boolean }>, + card_types: [] as Array<{ card_type_id: number, can_generate: boolean, price: number }>, }) async function fetchAgents() { @@ -72,6 +71,7 @@ async function fetchCardTypes(applicationId: string) { form.value.card_types = cardTypes.value.map(ct => ({ card_type_id: ct.id, can_generate: false, + price: ct.price, })) } catch (error) { @@ -139,7 +139,6 @@ async function handleSave() { await api.post('/dev/agent-apps/authorize', { agent_id: Number(form.value.agent_id), application_id: Number(form.value.application_id), - discount: form.value.discount, card_types: form.value.card_types, }) toast.success('授权成功') @@ -218,26 +217,6 @@ onMounted(() => { - -
- 折扣 -
- - - {{ (form.discount * 10).toFixed(1) }}折 - -
-

- 代理购买卡密的折扣,范围0.01-1 -

-
@@ -247,7 +226,7 @@ onMounted(() => { 卡密权限 - 配置代理可生成的卡密类型 + 配置代理可生成的卡密类型及价格
@@ -268,7 +247,8 @@ onMounted(() => { 卡类名称 计费类型 - 价格 + 原价 + 授权价格 @@ -297,6 +277,16 @@ onMounted(() => { ¥{{ cardTypes[index]?.price || 0 }} + + + @@ -323,13 +313,9 @@ onMounted(() => { 应用 {{ selectedApplication?.name || '-' }}
-
- 折扣 - {{ (form.discount * 10).toFixed(1) }}折 -
卡密权限 - {{ enabledCardTypesCount }}/{{ cardTypes.length }} + {{ enabledCardTypesCount }}/{{ cardTypes.length }}
diff --git a/frontend/src/pages/admin/agent-apps/data/schema.ts b/frontend/src/pages/admin/agent-apps/data/schema.ts index 4b1407f..805b00b 100644 --- a/frontend/src/pages/admin/agent-apps/data/schema.ts +++ b/frontend/src/pages/admin/agent-apps/data/schema.ts @@ -2,6 +2,16 @@ import { z } from 'zod' export const agentAppStatusSchema = z.enum(['active', 'inactive']) +export const cardTypeSchema = z.object({ + id: z.number().optional(), + card_type_id: z.number(), + name: z.string().optional(), + billing_type: z.string().optional(), + can_generate: z.boolean(), + price: z.number().optional(), + origin_price: z.number().optional(), +}) + export const agentAppSchema = z.object({ id: z.number(), agent_id: z.number(), @@ -12,13 +22,9 @@ export const agentAppSchema = z.object({ status: agentAppStatusSchema, discount: z.number(), balance: z.number(), - card_types: z.array(z.object({ - id: z.number().optional(), - card_type_id: z.number(), - name: z.string().optional(), - can_generate: z.boolean(), - })).optional(), + card_types: z.array(cardTypeSchema).optional(), created_at: z.string(), }) +export type CardTypeAuth = z.infer export type AgentApp = z.infer diff --git a/frontend/src/pages/admin/agent-apps/index.vue b/frontend/src/pages/admin/agent-apps/index.vue index 61a0589..0361a3a 100644 --- a/frontend/src/pages/admin/agent-apps/index.vue +++ b/frontend/src/pages/admin/agent-apps/index.vue @@ -80,6 +80,15 @@ async function handleRemove() { } } +function getBillingTypeText(type: string) { + const map: Record = { + subscription: '订阅', + time: '计时', + point: '点卡', + } + return map[type] || type +} + onMounted(() => { fetchData() }) @@ -119,10 +128,10 @@ onMounted(() => { 已启用 - + -
+
{{ activeCount }}
@@ -133,10 +142,10 @@ onMounted(() => { 已禁用 - + -
+
{{ inactiveCount }}
@@ -147,10 +156,10 @@ onMounted(() => { 代理余额总计 - + -
+
¥{{ totalBalance.toFixed(2) }}
@@ -201,7 +210,6 @@ onMounted(() => { 代理 应用 卡密权限 - 折扣 余额 状态 授权时间 @@ -236,16 +244,12 @@ onMounted(() => {
- - - {{ (item.discount * 10).toFixed(1) }}折 - ¥{{ (item.balance || 0).toFixed(2) }} {{ item.status === 'active' ? '已启用' : '已禁用' }} diff --git a/frontend/src/pages/admin/agents/components/columns.ts b/frontend/src/pages/admin/agents/components/columns.ts index 2406ca0..42e9918 100644 --- a/frontend/src/pages/admin/agents/components/columns.ts +++ b/frontend/src/pages/admin/agents/components/columns.ts @@ -97,6 +97,14 @@ export function getColumns(actions: { return `¥${balance.toFixed(2)}` }, }, + { + accessorKey: 'total_consumption', + header: () => t('admin.agents.columns.totalConsumption'), + cell: ({ row }) => { + const consumption = row.getValue('total_consumption') as number + return `¥${consumption.toFixed(2)}` + }, + }, { accessorKey: 'created_at', header: () => t('admin.agents.columns.createdAt'), diff --git a/frontend/src/pages/admin/agents/components/data-table.vue b/frontend/src/pages/admin/agents/components/data-table.vue index d44eca9..edc62f7 100644 --- a/frontend/src/pages/admin/agents/components/data-table.vue +++ b/frontend/src/pages/admin/agents/components/data-table.vue @@ -57,6 +57,7 @@ const columnLabels: Record = { cards_count: 'admin.agents.columns.cardsCount', child_agents_count: 'admin.agents.columns.childAgentsCount', balance: 'admin.agents.columns.balance', + total_consumption: 'admin.agents.columns.totalConsumption', created_at: 'admin.agents.columns.createdAt', last_login_at: 'admin.agents.columns.lastLoginAt', } diff --git a/frontend/src/pages/admin/agents/data/schema.ts b/frontend/src/pages/admin/agents/data/schema.ts index 019255a..82c40ca 100644 --- a/frontend/src/pages/admin/agents/data/schema.ts +++ b/frontend/src/pages/admin/agents/data/schema.ts @@ -10,6 +10,7 @@ export interface Agent { created_at: string last_login_at: string balance: number + total_consumption: number can_create_agent: boolean cards_count: number child_agents_count: number diff --git a/frontend/src/plugins/i18n/zh.json b/frontend/src/plugins/i18n/zh.json index f102399..9629348 100644 --- a/frontend/src/plugins/i18n/zh.json +++ b/frontend/src/plugins/i18n/zh.json @@ -1201,6 +1201,7 @@ "childAgentsCount": "下级代理", "canCreateAgent": "创建代理权限", "balance": "余额", + "totalConsumption": "消费", "createdAt": "注册时间", "lastLoginAt": "最后登录" },