Files
ai_dianshang/server/internal/model/points.go

84 lines
3.5 KiB
Go
Raw Normal View History

2025-11-17 13:32:54 +08:00
package model
import (
"time"
)
// PointsHistory 积分历史记录
type PointsHistory struct {
ID uint `json:"id" gorm:"primaryKey"`
UserID uint `json:"user_id" gorm:"not null;index"`
Type int `json:"type" gorm:"not null;comment:类型 1=获得 2=消费"`
Points int `json:"points" gorm:"not null;comment:积分数量"`
Description string `json:"description" gorm:"size:255;comment:描述"`
OrderID *uint `json:"order_id" gorm:"index;comment:关联订单ID"`
OrderNo string `json:"order_no" gorm:"size:50;comment:订单号"`
ProductName string `json:"product_name" gorm:"size:255;comment:商品名称"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
// 关联
User User `json:"user" gorm:"foreignKey:UserID"`
Order *Order `json:"order,omitempty" gorm:"foreignKey:OrderID"`
}
// PointsRule 积分规则
type PointsRule struct {
ID uint `json:"id" gorm:"primaryKey"`
Title string `json:"title" gorm:"size:100;not null;comment:规则标题"`
Description string `json:"description" gorm:"size:500;comment:规则描述"`
Icon string `json:"icon" gorm:"size:100;comment:图标"`
Points int `json:"points" gorm:"comment:积分数量"`
Type int `json:"type" gorm:"comment:类型 1=获得 2=消费"`
Status int `json:"status" gorm:"default:1;comment:状态 0=禁用 1=启用"`
Sort int `json:"sort" gorm:"default:0;comment:排序"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// PointsExchange 积分兑换商品
type PointsExchange struct {
ID uint `json:"id" gorm:"primaryKey"`
Name string `json:"name" gorm:"size:255;not null;comment:商品名称"`
Description string `json:"description" gorm:"size:500;comment:商品描述"`
Image string `json:"image" gorm:"size:255;comment:商品图片"`
Points int `json:"points" gorm:"not null;comment:所需积分"`
Stock int `json:"stock" gorm:"default:0;comment:库存数量"`
ExchangeCount int `json:"exchange_count" gorm:"default:0;comment:兑换次数"`
Status int `json:"status" gorm:"default:1;comment:状态 0=下架 1=上架"`
Sort int `json:"sort" gorm:"default:0;comment:排序"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// PointsExchangeRecord 积分兑换记录
type PointsExchangeRecord struct {
ID uint `json:"id" gorm:"primaryKey"`
UserID uint `json:"user_id" gorm:"not null;index"`
PointsExchangeID uint `json:"points_exchange_id" gorm:"not null;index"`
Points int `json:"points" gorm:"not null;comment:消耗积分"`
Status int `json:"status" gorm:"default:1;comment:状态 1=已兑换 2=已发放"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
// 关联
User User `json:"user" gorm:"foreignKey:UserID"`
PointsExchange PointsExchange `json:"points_exchange" gorm:"foreignKey:PointsExchangeID"`
}
// TableName 设置表名
func (PointsHistory) TableName() string {
return "points_history"
}
func (PointsRule) TableName() string {
return "points_rules"
}
func (PointsExchange) TableName() string {
return "points_exchange"
}
func (PointsExchangeRecord) TableName() string {
return "points_exchange_records"
}