Files

105 lines
5.5 KiB
Go
Raw Permalink Normal View History

2026-08-14 13:17:03 +08:00
package model
import "gorm.io/plugin/soft_delete"
// 商品类型常量(购物车与订单明细共用)
const (
ItemTypeGame = 1 // 游戏
ItemTypeProp = 2 // 道具
)
// 订单状态常量
const (
OrderStatusDone = 1 // 已完成(积分即时支付)
OrderStatusCanceled = 2 // 已取消
)
// Cart 购物车表:加入购物车但未结算的商品
type Cart struct {
ID int `gorm:"primaryKey" json:"id"` // 购物车项ID
UserID int `gorm:"index" json:"user_id"` // 所属用户ID
ItemType int `gorm:"default:1" json:"item_type"` // 商品类型1游戏 2道具
ItemID int `json:"item_id"` // 商品ID
Quantity int `gorm:"default:1" json:"quantity"` // 数量游戏固定1
CreatedAt int64 `gorm:"autoCreateTime" json:"created_at"` // 加入时间int 时间戳)
UpdatedAt int64 `gorm:"autoUpdateTime" json:"updated_at"` // 更新时间int 时间戳)
}
// TableName 指定表名
func (Cart) TableName() string { return "carts" }
// Order 订单表:购物车结算生成,用积分支付
type Order struct {
ID int `gorm:"primaryKey" json:"id"` // 订单ID
OrderNo string `gorm:"size:32;uniqueIndex" json:"order_no"` // 订单号
UserID int `gorm:"index" json:"user_id"` // 下单用户ID
TotalPoints int `gorm:"default:0" json:"total_points"` // 订单总价(积分)
Status int `gorm:"default:1" json:"status"` // 状态1已完成 2已取消
Remark string `gorm:"size:255" json:"remark"` // 备注(商品概要)
CreatedAt int64 `gorm:"autoCreateTime" json:"created_at"` // 下单时间int 时间戳)
UpdatedAt int64 `gorm:"autoUpdateTime" json:"updated_at"` // 更新时间int 时间戳)
DeletedAt soft_delete.DeletedAt `gorm:"default:0" json:"-"` // 软删除0=未删除)
Items []OrderItem `gorm:"foreignKey:OrderID" json:"items"` // 订单明细(关联查询用)
}
// TableName 指定表名
func (Order) TableName() string { return "orders" }
// OrderItem 订单明细表:订单内每个商品一条(保存快照)
type OrderItem struct {
ID int `gorm:"primaryKey" json:"id"` // 明细ID
OrderID int `gorm:"index" json:"order_id"` // 所属订单ID
ItemType int `gorm:"default:1" json:"item_type"` // 商品类型1游戏 2道具
ItemID int `json:"item_id"` // 商品ID
ItemName string `gorm:"size:32" json:"item_name"` // 名称快照
Price int `gorm:"default:0" json:"price"` // 单价快照(积分)
Quantity int `gorm:"default:1" json:"quantity"` // 数量
CreatedAt int64 `gorm:"autoCreateTime" json:"created_at"` // 创建时间int 时间戳)
}
// TableName 指定表名
func (OrderItem) TableName() string { return "order_items" }
// UserGame 用户已购游戏表:付费游戏解锁记录
type UserGame struct {
ID int `gorm:"primaryKey" json:"id"` // 记录ID
UserID int `gorm:"index" json:"user_id"` // 用户ID
GameID int `json:"game_id"` // 已解锁游戏ID
OrderID int `gorm:"default:0" json:"order_id"` // 来源订单ID0=赠送)
CreatedAt int64 `gorm:"autoCreateTime" json:"created_at"` // 解锁时间int 时间戳)
}
// TableName 指定表名
func (UserGame) TableName() string { return "user_games" }
// Prop 道具表:局内道具商品
type Prop struct {
ID int `gorm:"primaryKey" json:"id"` // 道具ID
Code string `gorm:"size:32;uniqueIndex" json:"code"` // 道具编码(游戏内识别效果)
Name string `gorm:"size:32" json:"name"` // 道具名称
Icon string `gorm:"size:16" json:"icon"` // emoji 图标
Description string `gorm:"size:255" json:"description"` // 效果说明
Price int `gorm:"default:0" json:"price"` // 售价(积分/个)
Sort int `gorm:"default:0" json:"sort"` // 排序权重
Status int `gorm:"default:1" json:"status"` // 状态1上架 2下架
CreatedAt int64 `gorm:"autoCreateTime" json:"created_at"` // 创建时间int 时间戳)
UpdatedAt int64 `gorm:"autoUpdateTime" json:"updated_at"` // 更新时间int 时间戳)
DeletedAt soft_delete.DeletedAt `gorm:"default:0" json:"-"` // 软删除0=未删除)
}
// TableName 指定表名
func (Prop) TableName() string { return "props" }
// UserProp 用户道具背包表:持有道具及数量
type UserProp struct {
ID int `gorm:"primaryKey" json:"id"` // 记录ID
UserID int `gorm:"index" json:"user_id"` // 用户ID
PropID int `json:"prop_id"` // 道具ID
Quantity int `gorm:"default:0" json:"quantity"` // 持有数量
CreatedAt int64 `gorm:"autoCreateTime" json:"created_at"` // 创建时间int 时间戳)
UpdatedAt int64 `gorm:"autoUpdateTime" json:"updated_at"` // 更新时间int 时间戳)
}
// TableName 指定表名
func (UserProp) TableName() string { return "user_props" }