mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-11-21 15:09:21 +00:00
Replace iframe-based external payment with native implementation: Backend (Go): - 5 new Ent schemas: PaymentOrder, PaymentAuditLog, PaymentChannel, SubscriptionPlan, PaymentProviderInstance - 5 SQL migrations (090-094) - Payment provider interface + registry + load balancer - 4 provider implementations (EasyPay, Alipay, WxPay, Stripe) - PaymentService (order lifecycle, fulfillment, refund 3-phase) - PaymentConfigService (settings, instance/channel/plan CRUD) - 31 API endpoints (9 user + 4 webhook + 18 admin) - Wire DI integration Frontend (Vue3): - Payment types, API modules, store, router changes - Sidebar: payment_enabled controls visibility, new menu items - User pages: PaymentView (replace iframe), QR payment, Stripe, result page, order list - Admin pages: Order management (4 tabs), provider instance mgmt - Settings: new payment tab, removed old purchase iframe config - i18n: full payment namespace (en + zh) Docs: - PAYMENT_FRONTEND_MIGRATION_PLAN.md - PAYMENT_BACKEND_MIGRATION_PLAN.md - PAYMENT_IMPLEMENTATION_ROADMAP.md
75 lines
1.9 KiB
Go
75 lines
1.9 KiB
Go
package schema
|
|
|
|
import (
|
|
"time"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect"
|
|
"entgo.io/ent/dialect/entsql"
|
|
"entgo.io/ent/schema"
|
|
"entgo.io/ent/schema/field"
|
|
"entgo.io/ent/schema/index"
|
|
)
|
|
|
|
// PaymentChannel holds the schema definition for the PaymentChannel entity.
|
|
//
|
|
// 删除策略:硬删除
|
|
// PaymentChannel 使用硬删除而非软删除,原因如下:
|
|
// - 渠道配置为管理员维护的元数据,删除即表示不再使用
|
|
// - 通过 enabled 字段控制是否启用,删除仅用于彻底移除
|
|
// - 保持查询简洁,无需额外的软删除过滤
|
|
type PaymentChannel struct {
|
|
ent.Schema
|
|
}
|
|
|
|
func (PaymentChannel) Annotations() []schema.Annotation {
|
|
return []schema.Annotation{
|
|
entsql.Annotation{Table: "payment_channels"},
|
|
}
|
|
}
|
|
|
|
func (PaymentChannel) Fields() []ent.Field {
|
|
return []ent.Field{
|
|
field.Int64("group_id").
|
|
Optional().
|
|
Nillable(),
|
|
field.String("name").
|
|
MaxLen(100).
|
|
NotEmpty(),
|
|
field.String("platform").
|
|
MaxLen(50).
|
|
Default("claude"),
|
|
field.Float("rate_multiplier").
|
|
SchemaType(map[string]string{dialect.Postgres: "decimal(10,4)"}).
|
|
Default(1.0),
|
|
field.String("description").
|
|
SchemaType(map[string]string{dialect.Postgres: "text"}).
|
|
Default(""),
|
|
field.String("models").
|
|
SchemaType(map[string]string{dialect.Postgres: "text"}).
|
|
Default(""),
|
|
field.String("features").
|
|
SchemaType(map[string]string{dialect.Postgres: "text"}).
|
|
Default(""),
|
|
field.Int("sort_order").
|
|
Default(0),
|
|
field.Bool("enabled").
|
|
Default(true),
|
|
field.Time("created_at").
|
|
Immutable().
|
|
Default(time.Now).
|
|
SchemaType(map[string]string{dialect.Postgres: "timestamptz"}),
|
|
field.Time("updated_at").
|
|
Default(time.Now).
|
|
UpdateDefault(time.Now).
|
|
SchemaType(map[string]string{dialect.Postgres: "timestamptz"}),
|
|
}
|
|
}
|
|
|
|
func (PaymentChannel) Indexes() []ent.Index {
|
|
return []ent.Index{
|
|
index.Fields("group_id"),
|
|
index.Fields("enabled"),
|
|
}
|
|
}
|