Initial commit: 商品售卖网站

This commit is contained in:
2026-04-13 07:20:09 +08:00
commit c6154273f2
865 changed files with 26573 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
package models
import (
"time"
)
type Address struct {
ID uint `gorm:"primaryKey" json:"id"`
UserID uint `gorm:"index;not null" json:"user_id"`
Name string `gorm:"size:50;not null" json:"name"`
Phone string `gorm:"size:20;not null" json:"phone"`
Province string `gorm:"size:50" json:"province"`
City string `gorm:"size:50" json:"city"`
District string `gorm:"size:50" json:"district"`
Address string `gorm:"type:text;not null" json:"address"`
IsDefault bool `gorm:"default:false" json:"is_default"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (Address) TableName() string {
return "addresses"
}
+27
View File
@@ -0,0 +1,27 @@
package models
import (
"time"
"gorm.io/gorm"
)
type Article struct {
ID uint `gorm:"primaryKey" json:"id"`
Title string `gorm:"size:255;not null" json:"title"`
Content string `gorm:"type:text;not null" json:"content"`
Summary string `gorm:"size:500" json:"summary"`
CoverImage string `gorm:"size:500" json:"cover_image"`
IsPinned bool `gorm:"default:false" json:"is_pinned"`
IsPublished bool `gorm:"default:true" json:"is_published"`
SortOrder int `gorm:"default:0" json:"sort_order"`
AuthorID *uint `json:"author_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
Author *User `gorm:"foreignKey:AuthorID" json:"author,omitempty"`
}
func (Article) TableName() string {
return "articles"
}
+22
View File
@@ -0,0 +1,22 @@
package models
import (
"time"
"gorm.io/gorm"
)
type Brand struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"size:255;not null;uniqueIndex" json:"name"`
Description string `json:"description"`
Logo string `json:"logo"`
SortOrder int `gorm:"default:0" json:"sort_order"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (Brand) TableName() string {
return "brands"
}
+19
View File
@@ -0,0 +1,19 @@
package models
import (
"time"
)
type Cart struct {
ID uint `gorm:"primaryKey" json:"id"`
UserID uint `gorm:"index;not null" json:"user_id"`
ProductID uint `gorm:"index;not null" json:"product_id"`
Quantity int `gorm:"not null" json:"quantity"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Product Product `json:"product,omitempty"`
}
func (Cart) TableName() string {
return "carts"
}
+29
View File
@@ -0,0 +1,29 @@
package models
import (
"time"
"gorm.io/gorm"
)
type Category struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"size:100;not null" json:"name"`
Description string `json:"description"`
ParentID *uint `json:"parent_id"`
MinAmount *float64 `json:"min_amount"`
MaxAmount *float64 `json:"max_amount"`
MinQuantity *int `json:"min_quantity"`
MaxQuantity *int `json:"max_quantity"`
MinWeight *float64 `json:"min_weight"`
MaxWeight *float64 `json:"max_weight"`
SortOrder int `gorm:"default:0" json:"sort_order"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
Children []Category `gorm:"foreignKey:ParentID" json:"children,omitempty"`
}
func (Category) TableName() string {
return "categories"
}
+17
View File
@@ -0,0 +1,17 @@
package models
import (
"time"
)
type Inventory struct {
ID uint `gorm:"primaryKey" json:"id"`
ProductID uint `gorm:"index;not null" json:"product_id"`
SupplierID uint `gorm:"index;not null" json:"supplier_id"`
Quantity int `gorm:"default:0" json:"quantity"`
UpdatedAt time.Time `json:"updated_at"`
}
func (Inventory) TableName() string {
return "inventory"
}
+80
View File
@@ -0,0 +1,80 @@
package models
import (
"time"
"gorm.io/gorm"
)
type Lottery struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"size:100;not null" json:"name"`
Description string `json:"description"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Cycle string `gorm:"size:20" json:"cycle"`
DailyQuota *int `json:"daily_quota"`
TotalQuota *int `json:"total_quota"`
RegistrationValidity *int `json:"registration_validity"`
IsActive bool `gorm:"default:true" json:"is_active"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
Prizes []LotteryPrize `json:"prizes,omitempty"`
}
func (Lottery) TableName() string {
return "lotteries"
}
type LotteryPrize struct {
ID uint `gorm:"primaryKey" json:"id"`
LotteryID uint `gorm:"index;not null" json:"lottery_id"`
Name string `gorm:"size:100;not null" json:"name"`
Type string `gorm:"size:20;not null" json:"type"`
Quantity int `gorm:"not null" json:"quantity"`
Weight int `gorm:"default:1" json:"weight"`
CreditReward *int `json:"credit_reward"`
DrawMode string `gorm:"size:20;default:'random'" json:"draw_mode"`
}
func (LotteryPrize) TableName() string {
return "lottery_prizes"
}
type LotteryParticipant struct {
ID uint `gorm:"primaryKey" json:"id"`
LotteryID uint `gorm:"index;not null" json:"lottery_id"`
UserID uint `gorm:"index;not null" json:"user_id"`
PurchaseWeight int `gorm:"default:0" json:"purchase_weight"`
RegisteredAt time.Time `json:"registered_at"`
}
func (LotteryParticipant) TableName() string {
return "lottery_participants"
}
type LotteryWinner struct {
ID uint `gorm:"primaryKey" json:"id"`
LotteryID uint `gorm:"index;not null" json:"lottery_id"`
PrizeID uint `gorm:"index;not null" json:"prize_id"`
UserID uint `gorm:"index;not null" json:"user_id"`
DrawnAt time.Time `json:"drawn_at"`
}
func (LotteryWinner) TableName() string {
return "lottery_winners"
}
const (
PrizeTypePhysical = "physical"
PrizeTypeVirtual = "virtual"
PrizeTypeCredit = "credit"
DrawModeRandom = "random"
DrawModeWeight = "weight"
CycleDaily = "daily"
CycleWeekly = "weekly"
CycleMonthly = "monthly"
)
+70
View File
@@ -0,0 +1,70 @@
package models
import (
"time"
"gorm.io/gorm"
)
type Order struct {
ID uint `gorm:"primaryKey" json:"id"`
UserID uint `gorm:"index;not null" json:"user_id"`
SupplierID *uint `gorm:"index" json:"supplier_id"`
Subtotal float64 `gorm:"type:decimal(10,2);not null" json:"subtotal"`
ShippingFee float64 `gorm:"type:decimal(10,2);default:0" json:"shipping_fee"`
ServiceFee float64 `gorm:"type:decimal(10,2);default:0" json:"service_fee"`
Tax float64 `gorm:"type:decimal(10,2);default:0" json:"tax"`
TotalAmount float64 `gorm:"type:decimal(10,2);not null" json:"total_amount"`
RefundAmount *float64 `gorm:"type:decimal(10,2)" json:"refund_amount"`
RefundStatus string `gorm:"size:20" json:"refund_status"`
RefundReason string `json:"refund_reason"`
Status string `gorm:"size:20;not null;default:'pending_payment'" json:"status"`
ShippingAddressID *uint `json:"shipping_address_id"`
TrackingNumber string `gorm:"size:100" json:"tracking_number"`
ShippingPhoto string `gorm:"type:text" json:"shipping_photo"`
ExpressPhoto string `gorm:"type:text" json:"express_photo"`
CustomsPhoto string `gorm:"type:text" json:"customs_photo"`
PaymentMethod string `gorm:"size:50" json:"payment_method"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
OrderItems []OrderItem `json:"order_items,omitempty"`
ShippingAddress *Address `json:"shipping_address,omitempty"`
User User `json:"user,omitempty"`
}
func (Order) TableName() string {
return "orders"
}
type OrderItem struct {
ID uint `gorm:"primaryKey" json:"id"`
OrderID uint `gorm:"index;not null" json:"order_id"`
ProductID uint `gorm:"index;not null" json:"product_id"`
Quantity int `gorm:"not null" json:"quantity"`
Price float64 `gorm:"type:decimal(10,2);not null" json:"price"`
Product Product `json:"product,omitempty"`
}
func (OrderItem) TableName() string {
return "order_items"
}
const (
OrderStatusPendingPayment = "pending_payment"
OrderStatusPendingConfirm = "pending_confirm"
OrderStatusPendingShip = "pending_ship"
OrderStatusShipped = "shipped"
OrderStatusCompleted = "completed"
OrderStatusRefunding = "refunding"
OrderStatusRefunded = "refunded"
OrderStatusCancelled = "cancelled"
)
const (
RefundStatusNone = ""
RefundStatusPending = "pending"
RefundStatusApproved = "approved"
RefundStatusRejected = "rejected"
RefundStatusCompleted = "completed"
)
+48
View File
@@ -0,0 +1,48 @@
package models
import (
"time"
"gorm.io/gorm"
)
type Product struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"size:255;not null" json:"name"`
Description string `json:"description"`
Price float64 `gorm:"type:decimal(10,2);not null" json:"price"`
MinPurchase int `gorm:"default:1" json:"min_purchase"`
MaxPurchase *int `json:"max_purchase"`
MinWeight *float64 `json:"min_weight"`
MaxWeight *float64 `json:"max_weight"`
MinAmount *float64 `json:"min_amount"`
MaxAmount *float64 `json:"max_amount"`
RequireCredit bool `gorm:"default:false" json:"require_credit"`
CreditCost int `gorm:"default:0" json:"credit_cost"`
CreditReward int `gorm:"default:0" json:"credit_reward"`
Images string `gorm:"type:text" json:"images"`
IsActive bool `gorm:"default:true" json:"is_active"`
BrandID *uint `json:"brand_id"`
Brand *Brand `json:"brand,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
Categories []Category `gorm:"many2many:product_categories;" json:"categories,omitempty"`
CustomFields []ProductCustomField `json:"custom_fields,omitempty"`
}
func (Product) TableName() string {
return "products"
}
type ProductCustomField struct {
ID uint `gorm:"primaryKey" json:"id"`
ProductID uint `gorm:"index;not null" json:"product_id"`
FieldName string `gorm:"size:100;not null" json:"field_name"`
FieldValue string `json:"field_value"`
CreatedAt time.Time `json:"created_at"`
}
func (ProductCustomField) TableName() string {
return "product_custom_fields"
}
+32
View File
@@ -0,0 +1,32 @@
package models
import (
"time"
)
type SystemSetting struct {
ID uint `gorm:"primaryKey" json:"id"`
Key string `gorm:"uniqueIndex;size:100;not null" json:"key"`
Value string `gorm:"type:text" json:"value"`
UpdatedAt time.Time `json:"updated_at"`
}
func (SystemSetting) TableName() string {
return "system_settings"
}
type SupplierAuthorization struct {
ID uint `gorm:"primaryKey" json:"id"`
SupplierID uint `gorm:"index;not null" json:"supplier_id"`
Type string `gorm:"size:20;not null" json:"type"`
RefID uint `gorm:"not null" json:"ref_id"`
}
func (SupplierAuthorization) TableName() string {
return "supplier_authorizations"
}
const (
AuthTypeCategory = "category"
AuthTypeProduct = "product"
)
+39
View File
@@ -0,0 +1,39 @@
package models
import (
"time"
"gorm.io/gorm"
)
type Ticket struct {
ID uint `gorm:"primaryKey" json:"id"`
UserID uint `gorm:"index;not null" json:"user_id"`
Title string `gorm:"size:200;not null" json:"title"`
Content string `gorm:"type:text;not null" json:"content"`
Category string `gorm:"size:50" json:"category"`
Status string `gorm:"size:20;not null;default:'pending'" json:"status"`
AssignedTo *uint `json:"assigned_to"`
Reply string `gorm:"type:text" json:"reply"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
User User `gorm:"foreignKey:UserID" json:"user,omitempty"`
Assignee *User `gorm:"foreignKey:AssignedTo" json:"assignee,omitempty"`
}
func (Ticket) TableName() string {
return "tickets"
}
const (
TicketStatusPending = "pending"
TicketStatusProcessing = "processing"
TicketStatusResolved = "resolved"
TicketStatusClosed = "closed"
TicketCategoryOrder = "order"
TicketCategoryAccount = "account"
TicketCategoryProduct = "product"
TicketCategoryOther = "other"
)
+27
View File
@@ -0,0 +1,27 @@
package models
import (
"time"
"gorm.io/gorm"
)
type User struct {
ID uint `gorm:"primaryKey" json:"id"`
Username string `gorm:"uniqueIndex;size:50;not null" json:"username"`
Email string `gorm:"uniqueIndex;size:100;not null" json:"email"`
PasswordHash string `gorm:"size:255;not null" json:"-"`
Role string `gorm:"size:20;not null;default:'user'" json:"role"`
PurchaseCredits int `gorm:"default:0" json:"purchase_credits"`
InviteCode string `gorm:"uniqueIndex;size:20" json:"invite_code"`
ReferredBy *uint `json:"referred_by"`
EmailVerified bool `gorm:"default:false" json:"email_verified"`
IsActive bool `gorm:"default:true" json:"is_active"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (User) TableName() string {
return "users"
}