Files
backend/cloudprint-backend/internal/model/model.go

225 lines
9.1 KiB
Go

package model
import (
"time"
)
// User 用户表
type User struct {
ID int32 `gorm:"primaryKey;autoIncrement" json:"id"`
Openid string `gorm:"uniqueIndex;size:64;not null" json:"openid"` // 微信OpenID
Nickname string `gorm:"size:128;default:''" json:"nickname"`
Avatar string `gorm:"size:512;default:''" json:"avatar"`
Balance float64 `gorm:"type:decimal(10,2);default:0.00" json:"balance"` // 余额
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
Orders []Order `gorm:"foreignKey:UserID" json:"orders,omitempty"`
}
func (User) TableName() string {
return "user"
}
// Admin 管理员表
type Admin struct {
ID int32 `gorm:"primaryKey;autoIncrement" json:"id"`
Username string `gorm:"uniqueIndex;size:64;not null" json:"username"`
PasswordHash string `gorm:"size:256;not null" json:"-"`
Nickname string `gorm:"size:128;default:''" json:"nickname"`
Role int8 `gorm:"default:1" json:"role"` // 1:普通管理员 2:超级管理员
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
}
func (Admin) TableName() string {
return "admin"
}
// Printer 打印机表
type Printer struct {
ID int32 `gorm:"primaryKey;autoIncrement" json:"id"`
Name string `gorm:"uniqueIndex;size:128;not null" json:"name"` // 系统打印机名
DisplayName string `gorm:"size:128;not null" json:"display_name"` // 显示名称
APIKey string `gorm:"uniqueIndex;size:64;not null" json:"api_key"` // 客户端认证Key
IsActive bool `gorm:"default:true" json:"is_active"`
Status int8 `gorm:"default:0" json:"status"` // 0:空闲 1:打印中 2:离线
LastHeartbeat *time.Time `json:"last_heartbeat"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
PrintJobs []PrintJob `gorm:"foreignKey:PrinterID" json:"print_jobs,omitempty"`
}
func (Printer) TableName() string {
return "printer"
}
// Order 订单表
type Order struct {
ID int32 `gorm:"primaryKey;autoIncrement" json:"id"`
OrderNo string `gorm:"uniqueIndex;size:32;not null" json:"order_no"` // 订单号
UserID int32 `gorm:"not null;index" json:"user_id"`
Status int8 `gorm:"default:0" json:"status"` // 0:待支付 1:已支付 2:打印中 3:已完成 4:已取消
TotalAmount float64 `gorm:"type:decimal(10,2);not null" json:"total_amount"`
Remark string `gorm:"size:512;default:''" json:"remark"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
PaidAt *time.Time `json:"paid_at"`
User *User `gorm:"foreignKey:UserID" json:"user,omitempty"`
Items []OrderItem `gorm:"foreignKey:OrderID" json:"items,omitempty"`
Payment *Payment `gorm:"foreignKey:OrderNo;references:OrderNo" json:"payment,omitempty"`
}
func (Order) TableName() string {
return "order"
}
// OrderItem 订单明细表
type OrderItem struct {
ID int32 `gorm:"primaryKey;autoIncrement" json:"id"`
OrderID int32 `gorm:"not null;index" json:"order_id"`
FileID int32 `gorm:"not null" json:"file_id"`
PrinterID *int32 `json:"printer_id"`
Copies int `gorm:"default:1" json:"copies"`
Color bool `gorm:"default:false" json:"color"`
Duplex bool `gorm:"default:false" json:"duplex"`
PageRange string `gorm:"size:64;default:'all'" json:"page_range"`
Price float64 `gorm:"type:decimal(10,2);not null" json:"price"`
Order *Order `gorm:"foreignKey:OrderID" json:"order,omitempty"`
File *File `gorm:"foreignKey:FileID" json:"file,omitempty"`
Printer *Printer `gorm:"foreignKey:PrinterID" json:"printer,omitempty"`
PrintJobs []PrintJob `gorm:"foreignKey:OrderItemID" json:"print_jobs,omitempty"`
}
func (OrderItem) TableName() string {
return "order_item"
}
// File 文件表
type File struct {
ID int32 `gorm:"primaryKey;autoIncrement" json:"id"`
FileName string `gorm:"size:256;not null" json:"file_name"`
FilePath string `gorm:"size:512;not null" json:"file_path"`
FileType string `gorm:"size:32;not null" json:"file_type"` // pdf/doc/docx/xls/xlsx/ppt/pptx/txt/jpg/png/zip
FileSize int64 `gorm:"not null" json:"file_size"` // 字节
UploaderType string `gorm:"size:16;not null" json:"uploader_type"` // user/admin/system
UploaderID int32 `gorm:"not null" json:"uploader_id"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
}
func (File) TableName() string {
return "file"
}
// LibraryCategory 文库分类表
type LibraryCategory struct {
ID int32 `gorm:"primaryKey;autoIncrement" json:"id"`
Name string `gorm:"size:128;not null" json:"name"`
Icon string `gorm:"size:128;default:''" json:"icon"`
SortOrder int `gorm:"default:0" json:"sort_order"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
Files []LibraryFile `gorm:"foreignKey:CategoryID" json:"files,omitempty"`
}
func (LibraryCategory) TableName() string {
return "library_category"
}
// LibraryFile 文库文件表
type LibraryFile struct {
ID int32 `gorm:"primaryKey;autoIncrement" json:"id"`
CategoryID int32 `gorm:"not null;index" json:"category_id"`
FileID int32 `gorm:"not null" json:"file_id"`
Title string `gorm:"size:256;not null" json:"title"`
Description string `gorm:"size:512;default:''" json:"description"`
PageCount int `gorm:"default:0" json:"page_count"`
DownloadCount int `gorm:"default:0" json:"download_count"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
Category *LibraryCategory `gorm:"foreignKey:CategoryID" json:"category,omitempty"`
File *File `gorm:"foreignKey:FileID" json:"file,omitempty"`
}
func (LibraryFile) TableName() string {
return "library_file"
}
// PrintJob 打印任务表
type PrintJob struct {
ID int32 `gorm:"primaryKey;autoIncrement" json:"id"`
JobNo string `gorm:"uniqueIndex;size:32;not null" json:"job_no"`
PrinterID int32 `gorm:"not null;index" json:"printer_id"`
OrderItemID int32 `gorm:"not null;index" json:"order_item_id"`
Status string `gorm:"size:16;default:'pending'" json:"status"` // pending/printing/completed/failed/cancelled
Progress int `gorm:"default:0" json:"progress"`
ErrorMsg string `gorm:"size:512;default:''" json:"error_msg"`
StartedAt *time.Time `json:"started_at"`
CompletedAt *time.Time `json:"completed_at"`
Printer *Printer `gorm:"foreignKey:PrinterID" json:"printer,omitempty"`
OrderItem *OrderItem `gorm:"foreignKey:OrderItemID" json:"order_item,omitempty"`
}
func (PrintJob) TableName() string {
return "print_job"
}
// PriceList 价目表
type PriceList struct {
ID int32 `gorm:"primaryKey;autoIncrement" json:"id"`
Name string `gorm:"size:128;not null" json:"name"` // 项目名称
Type string `gorm:"size:32;not null" json:"type"` // 纸张类型: A4/A3/照片纸
Price float64 `gorm:"type:decimal(10,2);not null" json:"price"` // 单价
Unit string `gorm:"size:16;not null" json:"unit"` // 单位: 页/张/份
ColorEnabled bool `gorm:"default:true" json:"color_enabled"` // 是否支持彩色
IsActive bool `gorm:"default:true" json:"is_active"`
SortOrder int `gorm:"default:0" json:"sort_order"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
}
func (PriceList) TableName() string {
return "price_list"
}
// Payment 支付记录表
type Payment struct {
ID int32 `gorm:"primaryKey;autoIncrement" json:"id"`
OrderNo string `gorm:"uniqueIndex;size:32;not null" json:"order_no"`
PayType string `gorm:"size:16;default:'wechat'" json:"pay_type"` // wechat/balance
PayStatus int8 `gorm:"default:0" json:"pay_status"` // 0:待支付 1:支付中 2:成功 3:失败
TransactionID string `gorm:"size:64;default:''" json:"transaction_id"`
PaidAt *time.Time `json:"paid_at"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
}
func (Payment) TableName() string {
return "payment"
}
// OrderStatus 订单状态常量
const (
OrderStatusPending = 0 // 待支付
OrderStatusPaid = 1 // 已支付
OrderStatusPrinting = 2 // 打印中
OrderStatusCompleted = 3 // 已完成
OrderStatusCancelled = 4 // 已取消
)
// PayStatus 支付状态常量
const (
PayStatusPending = 0 // 待支付
PayStatusPaying = 1 // 支付中
PayStatusSuccess = 2 // 成功
PayStatusFailed = 3 // 失败
)
// PrinterStatus 打印机状态常量
const (
PrinterStatusIdle = 0 // 空闲
PrinterStatusPrinting = 1 // 打印中
PrinterStatusOffline = 2 // 离线
)
// PrintJobStatus 打印任务状态常量
const (
PrintJobStatusPending = "pending"
PrintJobStatusPrinting = "printing"
PrintJobStatusCompleted = "completed"
PrintJobStatusFailed = "failed"
PrintJobStatusCancelled = "cancelled"
)