wood chen aeb05f790a 重构数据库层并迁移到 GORM
- 将数据库操作从原生 SQL 迁移到 GORM ORM
- 更新模型定义,添加 GORM 标签和关系
- 移除手动创建表的 SQL 方法,改用 AutoMigrate
- 更新所有数据库相关处理逻辑以适配 GORM
- 升级 Go 版本和依赖库
- 移除数据库和路由中间件,简化项目结构
2025-03-06 23:32:18 +08:00

40 lines
2.0 KiB
Go

package models
import (
"time"
"gorm.io/gorm"
)
type Price struct {
ID uint `json:"id" gorm:"primaryKey"`
Model string `json:"model" gorm:"not null"`
ModelType string `json:"model_type" gorm:"not null"` // text2text, text2image, etc.
BillingType string `json:"billing_type" gorm:"not null"` // tokens or times
ChannelType uint `json:"channel_type" gorm:"not null"`
Currency string `json:"currency" gorm:"not null"` // USD or CNY
InputPrice float64 `json:"input_price" gorm:"not null"`
OutputPrice float64 `json:"output_price" gorm:"not null"`
PriceSource string `json:"price_source" gorm:"not null"`
Status string `json:"status" gorm:"not null;default:pending"` // pending, approved, rejected
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
CreatedBy string `json:"created_by" gorm:"not null"`
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
// 临时字段,用于存储待审核的更新
TempModel *string `json:"temp_model,omitempty" gorm:"column:temp_model"`
TempModelType *string `json:"temp_model_type,omitempty" gorm:"column:temp_model_type"`
TempBillingType *string `json:"temp_billing_type,omitempty" gorm:"column:temp_billing_type"`
TempChannelType *uint `json:"temp_channel_type,omitempty" gorm:"column:temp_channel_type"`
TempCurrency *string `json:"temp_currency,omitempty" gorm:"column:temp_currency"`
TempInputPrice *float64 `json:"temp_input_price,omitempty" gorm:"column:temp_input_price"`
TempOutputPrice *float64 `json:"temp_output_price,omitempty" gorm:"column:temp_output_price"`
TempPriceSource *string `json:"temp_price_source,omitempty" gorm:"column:temp_price_source"`
UpdatedBy *string `json:"updated_by,omitempty" gorm:"column:updated_by"`
}
// TableName 指定表名
func (Price) TableName() string {
return "price"
}