This commit is contained in:
2025-12-19 17:05:09 +08:00
parent cc3472ff40
commit 39c46937ea
307 changed files with 87686 additions and 129 deletions

View File

@@ -1,34 +0,0 @@
package entities
import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
// ComponentReportCache 报告文件匹配缓存
type ComponentReportCache struct {
ID string `gorm:"primaryKey;type:varchar(36)" json:"id" comment:"缓存ID"`
ProductCode string `gorm:"type:varchar(50);not null;uniqueIndex" json:"product_code" comment:"产品编号"`
MatchedPath string `gorm:"type:varchar(500);not null" json:"matched_path" comment:"匹配到的文件夹/文件路径"`
FileType string `gorm:"type:varchar(20);not null" json:"file_type" comment:"文件类型folder, file"`
CacheKey string `gorm:"type:varchar(64);not null;uniqueIndex" json:"cache_key" comment:"缓存键"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at" comment:"创建时间"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at" comment:"更新时间"`
}
// TableName 指定数据库表名
func (ComponentReportCache) TableName() string {
return "component_report_cache"
}
// BeforeCreate GORM钩子创建前自动生成UUID
func (c *ComponentReportCache) BeforeCreate(tx *gorm.DB) error {
if c.ID == "" {
c.ID = uuid.New().String()
}
return nil
}

View File

@@ -10,30 +10,30 @@ import (
// ComponentReportDownload 组件报告下载记录
type ComponentReportDownload struct {
ID string `gorm:"primaryKey;type:varchar(36)" json:"id" comment:"下载记录ID"`
UserID string `gorm:"type:varchar(36);not null;index" json:"user_id" comment:"用户ID"`
ProductID string `gorm:"type:varchar(36);not null;index" json:"product_id" comment:"产品ID"`
ProductCode string `gorm:"type:varchar(50);not null;index" json:"product_code" comment:"产品编号"`
SubProductIDs string `gorm:"type:text" json:"sub_product_ids" comment:"子产品ID列表JSON数组"`
SubProductCodes string `gorm:"type:text" json:"sub_product_codes" comment:"子产品编号列表JSON数组"`
DownloadPrice decimal.Decimal `gorm:"type:decimal(10,2);not null" json:"download_price" comment:"实际支付价格"`
OriginalPrice decimal.Decimal `gorm:"type:decimal(10,2);not null" json:"original_price" comment:"原始总价"`
DiscountAmount decimal.Decimal `gorm:"type:decimal(10,2);default:0" json:"discount_amount" comment:"减免金额"`
PaymentOrderID *string `gorm:"type:varchar(64)" json:"payment_order_id,omitempty" comment:"支付订单号"`
PaymentType *string `gorm:"type:varchar(20)" json:"payment_type,omitempty" comment:"支付类型alipay, wechat"`
PaymentStatus string `gorm:"type:varchar(20);default:'pending';index" json:"payment_status" comment:"支付状态pending, success, failed"`
FilePath *string `gorm:"type:varchar(500)" json:"file_path,omitempty" comment:"生成的ZIP文件路径"`
FileHash *string `gorm:"type:varchar(64)" json:"file_hash,omitempty" comment:"文件哈希值"`
DownloadCount int `gorm:"default:0" json:"download_count" comment:"下载次数"`
LastDownloadAt *time.Time `json:"last_download_at,omitempty" comment:"最后下载时间"`
ExpiresAt *time.Time `gorm:"index" json:"expires_at,omitempty" comment:"下载有效期"`
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"`
ProductCode string `gorm:"type:varchar(50);not null;index" comment:"产品编号"`
SubProductIDs string `gorm:"type:text" comment:"子产品ID列表JSON数组,组合包使用"`
SubProductCodes string `gorm:"type:text" comment:"子产品编号列表JSON数组"`
DownloadPrice decimal.Decimal `gorm:"type:decimal(10,2);not null" comment:"实际支付价格"`
OriginalPrice decimal.Decimal `gorm:"type:decimal(10,2);not null" comment:"原始总价"`
DiscountAmount decimal.Decimal `gorm:"type:decimal(10,2);default:0" comment:"减免金额"`
PaymentOrderID *string `gorm:"type:varchar(64);index" comment:"支付订单号(关联充值记录)"`
PaymentType *string `gorm:"type:varchar(20)" comment:"支付类型alipay, wechat"`
PaymentStatus string `gorm:"type:varchar(20);default:'pending';index" comment:"支付状态pending, success, failed"`
FilePath *string `gorm:"type:varchar(500)" comment:"生成的ZIP文件路径(用于二次下载)"`
FileHash *string `gorm:"type:varchar(64)" comment:"文件哈希值(用于缓存验证)"`
DownloadCount int `gorm:"default:0" comment:"下载次数"`
LastDownloadAt *time.Time `comment:"最后下载时间"`
ExpiresAt *time.Time `gorm:"index" comment:"下载有效期支付成功后30天"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at" comment:"创建时间"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at" comment:"更新时间"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-" comment:"软删除时间"`
CreatedAt time.Time `gorm:"autoCreateTime" comment:"创建时间"`
UpdatedAt time.Time `gorm:"autoUpdateTime" comment:"更新时间"`
DeletedAt gorm.DeletedAt `gorm:"index" comment:"软删除时间"`
}
// TableName 指定数据库表名
// TableName 指定表名
func (ComponentReportDownload) TableName() string {
return "component_report_downloads"
}
@@ -46,8 +46,8 @@ func (c *ComponentReportDownload) BeforeCreate(tx *gorm.DB) error {
return nil
}
// IsPaymentSuccess 检查是否支付成功
func (c *ComponentReportDownload) IsPaymentSuccess() bool {
// IsPaid 检查是否支付
func (c *ComponentReportDownload) IsPaid() bool {
return c.PaymentStatus == "success"
}
@@ -61,25 +61,5 @@ func (c *ComponentReportDownload) IsExpired() bool {
// CanDownload 检查是否可以下载
func (c *ComponentReportDownload) CanDownload() bool {
return c.IsPaymentSuccess() && !c.IsExpired()
return c.IsPaid() && !c.IsExpired()
}
// MarkPaymentSuccess 标记支付成功
func (c *ComponentReportDownload) MarkPaymentSuccess(orderID string, paymentType string) {
c.PaymentOrderID = &orderID
paymentTypeStr := paymentType
c.PaymentType = &paymentTypeStr
c.PaymentStatus = "success"
// 设置30天有效期
expiresAt := time.Now().Add(30 * 24 * time.Hour)
c.ExpiresAt = &expiresAt
}
// IncrementDownloadCount 增加下载次数
func (c *ComponentReportDownload) IncrementDownloadCount() {
c.DownloadCount++
now := time.Now()
c.LastDownloadAt = &now
}

View File

@@ -25,6 +25,9 @@ type Product struct {
IsPackage bool `gorm:"default:false" comment:"是否组合包"`
// 组合包相关关联
PackageItems []*ProductPackageItem `gorm:"foreignKey:PackageID" comment:"组合包项目列表"`
// UI组件相关字段
SellUIComponent bool `gorm:"default:false" comment:"是否出售UI组件"`
UIComponentPrice decimal.Decimal `gorm:"type:decimal(10,2);default:0" comment:"UI组件销售价格组合包使用"`
// SEO信息
SEOTitle string `gorm:"type:varchar(200)" comment:"SEO标题"`
SEODescription string `gorm:"type:text" comment:"SEO描述"`

View File

@@ -0,0 +1,36 @@
package entities
import (
"time"
"github.com/google/uuid"
"github.com/shopspring/decimal"
"gorm.io/gorm"
)
// ProductUIComponent 产品UI组件关联实体
type ProductUIComponent struct {
ID string `gorm:"primaryKey;type:varchar(36)" comment:"关联ID"`
ProductID string `gorm:"type:varchar(36);not null;index" comment:"产品ID"`
UIComponentID string `gorm:"type:varchar(36);not null;index" comment:"UI组件ID"`
Price decimal.Decimal `gorm:"type:decimal(10,2);not null;default:0" comment:"销售价格"`
IsEnabled bool `gorm:"default:true" comment:"是否启用销售"`
CreatedAt time.Time `gorm:"autoCreateTime" comment:"创建时间"`
UpdatedAt time.Time `gorm:"autoUpdateTime" comment:"更新时间"`
DeletedAt gorm.DeletedAt `gorm:"index" comment:"软删除时间"`
// 关联关系
Product *Product `gorm:"foreignKey:ProductID" comment:"产品"`
UIComponent *UIComponent `gorm:"foreignKey:UIComponentID" comment:"UI组件"`
}
func (ProductUIComponent) TableName() string {
return "product_ui_components"
}
func (p *ProductUIComponent) BeforeCreate(tx *gorm.DB) error {
if p.ID == "" {
p.ID = uuid.New().String()
}
return nil
}

View File

@@ -0,0 +1,39 @@
package entities
import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
// UIComponent UI组件实体
type UIComponent struct {
ID string `gorm:"primaryKey;type:varchar(36)" json:"id" comment:"组件ID"`
ComponentCode string `gorm:"type:varchar(50);not null;uniqueIndex" json:"component_code" comment:"组件编码"`
ComponentName string `gorm:"type:varchar(100);not null" json:"component_name" comment:"组件名称"`
Description string `gorm:"type:text" json:"description" comment:"组件描述"`
FilePath *string `gorm:"type:varchar(500)" json:"file_path" comment:"组件文件路径"`
FileHash *string `gorm:"type:varchar(64)" json:"file_hash" comment:"文件哈希值"`
FileSize *int64 `gorm:"type:bigint" json:"file_size" comment:"文件大小"`
FileType *string `gorm:"type:varchar(50)" json:"file_type" comment:"文件类型"`
FolderPath *string `gorm:"type:varchar(500)" json:"folder_path" comment:"组件文件夹路径"`
IsExtracted bool `gorm:"default:false" json:"is_extracted" comment:"是否已解压"`
Version string `gorm:"type:varchar(20)" json:"version" comment:"组件版本"`
IsActive bool `gorm:"default:true" json:"is_active" comment:"是否启用"`
SortOrder int `gorm:"default:0" json:"sort_order" comment:"排序"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at" comment:"创建时间"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at" comment:"更新时间"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at" comment:"软删除时间"`
}
func (UIComponent) TableName() string {
return "ui_components"
}
func (u *UIComponent) BeforeCreate(tx *gorm.DB) error {
if u.ID == "" {
u.ID = uuid.New().String()
}
return nil
}

View File

@@ -2,23 +2,31 @@ package repositories
import (
"context"
"tyapi-server/internal/domains/product/entities"
)
// ComponentReportRepository 组件报告仓储接口
type ComponentReportRepository interface {
// 下载记录相关
// 创建下载记录
CreateDownload(ctx context.Context, download *entities.ComponentReportDownload) (*entities.ComponentReportDownload, error)
// 更新下载记录
UpdateDownload(ctx context.Context, download *entities.ComponentReportDownload) error
// 根据ID获取下载记录
GetDownloadByID(ctx context.Context, id string) (*entities.ComponentReportDownload, error)
// 获取用户的下载记录列表
GetUserDownloads(ctx context.Context, userID string, productID *string) ([]*entities.ComponentReportDownload, error)
// 检查用户是否已下载过指定产品编号的组件
HasUserDownloaded(ctx context.Context, userID string, productCode string) (bool, error)
// 获取用户已下载的产品编号列表
GetUserDownloadedProductCodes(ctx context.Context, userID string) ([]string, error)
// 根据支付订单号获取下载记录
GetDownloadByPaymentOrderID(ctx context.Context, orderID string) (*entities.ComponentReportDownload, error)
// 缓存相关
GetCacheByProductCode(ctx context.Context, productCode string) (*entities.ComponentReportCache, error)
CreateCache(ctx context.Context, cache *entities.ComponentReportCache) error
UpdateCache(ctx context.Context, cache *entities.ComponentReportCache) error
}

View File

@@ -0,0 +1,16 @@
package repositories
import (
"context"
"tyapi-server/internal/domains/product/entities"
)
// ProductUIComponentRepository 产品UI组件关联仓储接口
type ProductUIComponentRepository interface {
Create(ctx context.Context, relation entities.ProductUIComponent) (entities.ProductUIComponent, error)
GetByProductID(ctx context.Context, productID string) ([]entities.ProductUIComponent, error)
GetByUIComponentID(ctx context.Context, componentID string) ([]entities.ProductUIComponent, error)
Delete(ctx context.Context, id string) error
DeleteByProductID(ctx context.Context, productID string) error
BatchCreate(ctx context.Context, relations []entities.ProductUIComponent) error
}

View File

@@ -0,0 +1,17 @@
package repositories
import (
"context"
"tyapi-server/internal/domains/product/entities"
)
// UIComponentRepository UI组件仓储接口
type UIComponentRepository interface {
Create(ctx context.Context, component entities.UIComponent) (entities.UIComponent, error)
GetByID(ctx context.Context, id string) (*entities.UIComponent, error)
GetByCode(ctx context.Context, code string) (*entities.UIComponent, error)
List(ctx context.Context, filters map[string]interface{}) ([]entities.UIComponent, int64, error)
Update(ctx context.Context, component entities.UIComponent) error
Delete(ctx context.Context, id string) error
GetByCodes(ctx context.Context, codes []string) ([]entities.UIComponent, error)
}