This commit is contained in:
2025-07-20 20:53:26 +08:00
parent 83bf9aea7d
commit 8ad1d7288e
158 changed files with 18156 additions and 13188 deletions

View File

@@ -3,6 +3,7 @@ package entities
import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
@@ -12,7 +13,7 @@ type Product struct {
Name string `gorm:"type:varchar(100);not null" comment:"产品名称"`
Code string `gorm:"type:varchar(50);uniqueIndex;not null" comment:"产品编号"`
Description string `gorm:"type:text" comment:"产品简介"`
Content string `gorm:"type:longtext" comment:"产品内容"`
Content string `gorm:"type:text" comment:"产品内容"`
CategoryID string `gorm:"type:varchar(36);not null" comment:"产品分类ID"`
Price float64 `gorm:"type:decimal(10,2);not null;default:0" comment:"产品价格"`
IsEnabled bool `gorm:"default:true" comment:"是否启用"`
@@ -32,6 +33,14 @@ type Product struct {
DeletedAt gorm.DeletedAt `gorm:"index" comment:"软删除时间"`
}
// BeforeCreate GORM钩子创建前自动生成UUID
func (p *Product) BeforeCreate(tx *gorm.DB) error {
if p.ID == "" {
p.ID = uuid.New().String()
}
return nil
}
// IsValid 检查产品是否有效
func (p *Product) IsValid() bool {
return p.DeletedAt.Time.IsZero() && p.IsEnabled

View File

@@ -3,6 +3,7 @@ package entities
import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
@@ -12,22 +13,26 @@ type ProductCategory struct {
Name string `gorm:"type:varchar(100);not null" comment:"分类名称"`
Code string `gorm:"type:varchar(50);uniqueIndex;not null" comment:"分类编号"`
Description string `gorm:"type:text" comment:"分类描述"`
ParentID *string `gorm:"type:varchar(36)" comment:"父分类ID"`
Level int `gorm:"default:1" comment:"分类层级"`
Sort int `gorm:"default:0" comment:"排序"`
IsEnabled bool `gorm:"default:true" comment:"是否启用"`
IsVisible bool `gorm:"default:true" comment:"是否展示"`
// 关联关系
Parent *ProductCategory `gorm:"foreignKey:ParentID" comment:"父分类"`
Children []ProductCategory `gorm:"foreignKey:ParentID" comment:"子分类"`
Products []Product `gorm:"foreignKey:CategoryID" comment:"产品列表"`
Products []Product `gorm:"foreignKey:CategoryID" comment:"产品列表"`
CreatedAt time.Time `gorm:"autoCreateTime" comment:"创建时间"`
UpdatedAt time.Time `gorm:"autoUpdateTime" comment:"更新时间"`
DeletedAt gorm.DeletedAt `gorm:"index" comment:"软删除时间"`
}
// BeforeCreate GORM钩子创建前自动生成UUID
func (pc *ProductCategory) BeforeCreate(tx *gorm.DB) error {
if pc.ID == "" {
pc.ID = uuid.New().String()
}
return nil
}
// IsValid 检查分类是否有效
func (pc *ProductCategory) IsValid() bool {
return pc.DeletedAt.Time.IsZero() && pc.IsEnabled
@@ -38,27 +43,6 @@ func (pc *ProductCategory) IsVisibleToUser() bool {
return pc.IsValid() && pc.IsVisible
}
// IsRoot 检查是否为根分类
func (pc *ProductCategory) IsRoot() bool {
return pc.ParentID == nil || *pc.ParentID == ""
}
// IsLeaf 检查是否为叶子分类
func (pc *ProductCategory) IsLeaf() bool {
return len(pc.Children) == 0
}
// GetFullPath 获取完整分类路径
func (pc *ProductCategory) GetFullPath() string {
if pc.IsRoot() {
return pc.Name
}
if pc.Parent != nil {
return pc.Parent.GetFullPath() + " > " + pc.Name
}
return pc.Name
}
// Enable 启用分类
func (pc *ProductCategory) Enable() {
pc.IsEnabled = true

View File

@@ -3,6 +3,7 @@ package entities
import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
@@ -11,11 +12,11 @@ type ProductDocumentation struct {
ID string `gorm:"primaryKey;type:varchar(36)" comment:"文档ID"`
ProductID string `gorm:"type:varchar(36);not null;uniqueIndex" comment:"产品ID"`
Title string `gorm:"type:varchar(200);not null" comment:"文档标题"`
Content string `gorm:"type:longtext;not null" comment:"文档内容"`
UsageGuide string `gorm:"type:longtext" comment:"使用指南"`
APIDocs string `gorm:"type:longtext" comment:"API文档"`
Examples string `gorm:"type:longtext" comment:"使用示例"`
FAQ string `gorm:"type:longtext" comment:"常见问题"`
Content string `gorm:"type:text;not null" comment:"文档内容"`
UsageGuide string `gorm:"type:text" comment:"使用指南"`
APIDocs string `gorm:"type:text" comment:"API文档"`
Examples string `gorm:"type:text" comment:"使用示例"`
FAQ string `gorm:"type:text" comment:"常见问题"`
Version string `gorm:"type:varchar(20);default:'1.0'" comment:"文档版本"`
Published bool `gorm:"default:false" comment:"是否已发布"`
@@ -27,6 +28,14 @@ type ProductDocumentation struct {
DeletedAt gorm.DeletedAt `gorm:"index" comment:"软删除时间"`
}
// BeforeCreate GORM钩子创建前自动生成UUID
func (pd *ProductDocumentation) BeforeCreate(tx *gorm.DB) error {
if pd.ID == "" {
pd.ID = uuid.New().String()
}
return nil
}
// IsValid 检查文档是否有效
func (pd *ProductDocumentation) IsValid() bool {
return pd.DeletedAt.Time.IsZero()

View File

@@ -3,25 +3,15 @@ package entities
import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
// SubscriptionStatus 订阅状态枚举
type SubscriptionStatus string
const (
SubscriptionStatusActive SubscriptionStatus = "active" // 活跃
SubscriptionStatusInactive SubscriptionStatus = "inactive" // 非活跃
SubscriptionStatusExpired SubscriptionStatus = "expired" // 已过期
SubscriptionStatusCanceled SubscriptionStatus = "canceled" // 已取消
)
// Subscription 订阅实体
type Subscription struct {
ID string `gorm:"primaryKey;type:varchar(36)" comment:"订阅ID"`
UserID string `gorm:"type:varchar(36);not null;index" comment:"用户ID"`
ProductID string `gorm:"type:varchar(36);not null;index" comment:"产品ID"`
Status SubscriptionStatus `gorm:"type:varchar(20);not null;default:'active'" comment:"订阅状态"`
Price float64 `gorm:"type:decimal(10,2);not null" comment:"订阅价格"`
APIUsed int64 `gorm:"default:0" comment:"已使用API调用次数"`
@@ -33,6 +23,14 @@ type Subscription struct {
DeletedAt gorm.DeletedAt `gorm:"index" comment:"软删除时间"`
}
// BeforeCreate GORM钩子创建前自动生成UUID
func (s *Subscription) BeforeCreate(tx *gorm.DB) error {
if s.ID == "" {
s.ID = uuid.New().String()
}
return nil
}
// IsValid 检查订阅是否有效
func (s *Subscription) IsValid() bool {
return s.DeletedAt.Time.IsZero()
@@ -43,16 +41,6 @@ func (s *Subscription) IncrementAPIUsage(count int64) {
s.APIUsed += count
}
// Activate 激活订阅
func (s *Subscription) Activate() {
s.Status = SubscriptionStatusActive
}
// Deactivate 停用订阅
func (s *Subscription) Deactivate() {
s.Status = SubscriptionStatusInactive
}
// ResetAPIUsage 重置API使用次数
func (s *Subscription) ResetAPIUsage() {
s.APIUsed = 0