基础架构

This commit is contained in:
2025-07-13 16:36:20 +08:00
parent e3d64e7485
commit 807004f78d
128 changed files with 17232 additions and 11396 deletions

View File

@@ -3,6 +3,7 @@ package entities
import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
@@ -65,3 +66,11 @@ func (u *UserSecrets) Deactivate() {
func (u *UserSecrets) Activate() {
u.IsActive = true
}
// BeforeCreate GORM钩子创建前自动生成UUID
func (u *UserSecrets) BeforeCreate(tx *gorm.DB) error {
if u.ID == "" {
u.ID = uuid.New().String()
}
return nil
}

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"time"
"github.com/google/uuid"
"github.com/shopspring/decimal"
"gorm.io/gorm"
)
@@ -69,3 +70,11 @@ func (w *Wallet) SubtractBalance(amount decimal.Decimal) error {
func (w *Wallet) GetFormattedBalance() string {
return w.Balance.String()
}
// BeforeCreate GORM钩子创建前自动生成UUID
func (w *Wallet) BeforeCreate(tx *gorm.DB) error {
if w.ID == "" {
w.ID = uuid.New().String()
}
return nil
}