重构后端服务架构并优化前端错误处理

This commit is contained in:
ylweng
2025-09-12 01:21:43 +08:00
parent d550a8ed51
commit 3a48a67757
53 changed files with 3925 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
package models
import (
"time"
"gorm.io/gorm"
)
type OrderStatus string
const (
OrderStatusPending OrderStatus = "pending"
OrderStatusConfirmed OrderStatus = "confirmed"
OrderStatusProcessing OrderStatus = "processing"
OrderStatusShipped OrderStatus = "shipped"
OrderStatusDelivered OrderStatus = "delivered"
OrderStatusCancelled OrderStatus = "cancelled"
OrderStatusCompleted OrderStatus = "completed"
)
type Order struct {
ID uint `gorm:"primaryKey" json:"id"`
OrderNo string `gorm:"uniqueIndex;not null" json:"order_no"`
BuyerID uint `gorm:"not null" json:"buyer_id"`
SellerID uint `gorm:"not null" json:"seller_id"`
VarietyType string `gorm:"not null" json:"variety_type"`
WeightRange string `gorm:"not null" json:"weight_range"`
WeightActual float64 `json:"weight_actual"`
PricePerUnit float64 `gorm:"not null" json:"price_per_unit"`
TotalPrice float64 `gorm:"not null" json:"total_price"`
AdvancePayment float64 `gorm:"default:0.0" json:"advance_payment"`
FinalPayment float64 `gorm:"default:0.0" json:"final_payment"`
Status OrderStatus `gorm:"default:pending" json:"status"`
DeliveryAddress string `json:"delivery_address"`
DeliveryTime *time.Time `json:"delivery_time"`
Remark string `json:"remark"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (Order) TableName() string {
return "orders"
}

View File

@@ -0,0 +1,44 @@
package models
import (
"time"
"gorm.io/gorm"
)
type PaymentType string
type PaymentMethod string
type PaymentStatus string
const (
PaymentTypeAdvance PaymentType = "advance"
PaymentTypeFinal PaymentType = "final"
PaymentMethodWechat PaymentMethod = "wechat"
PaymentMethodAlipay PaymentMethod = "alipay"
PaymentMethodBank PaymentMethod = "bank"
PaymentStatusPending PaymentStatus = "pending"
PaymentStatusSuccess PaymentStatus = "success"
PaymentStatusFailed PaymentStatus = "failed"
PaymentStatusRefunded PaymentStatus = "refunded"
)
type Payment struct {
ID uint `gorm:"primaryKey" json:"id"`
PaymentNo string `gorm:"uniqueIndex;not null" json:"payment_no"`
OrderID uint `gorm:"not null" json:"order_id"`
UserID uint `gorm:"not null" json:"user_id"`
Amount float64 `gorm:"not null" json:"amount"`
PaymentType PaymentType `gorm:"not null" json:"payment_type"`
PaymentMethod PaymentMethod `gorm:"not null" json:"payment_method"`
Status PaymentStatus `gorm:"default:pending" json:"status"`
TransactionID string `json:"transaction_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (Payment) TableName() string {
return "payments"
}

38
go-backend/models/user.go Normal file
View File

@@ -0,0 +1,38 @@
package models
import (
"time"
"gorm.io/gorm"
)
type UserType string
type UserStatus string
const (
UserTypeClient UserType = "client"
UserTypeSupplier UserType = "supplier"
UserTypeDriver UserType = "driver"
UserTypeStaff UserType = "staff"
UserTypeAdmin UserType = "admin"
UserStatusActive UserStatus = "active"
UserStatusInactive UserStatus = "inactive"
UserStatusLocked UserStatus = "locked"
)
type User struct {
ID uint `gorm:"primaryKey" json:"id"`
UUID string `gorm:"uniqueIndex;not null" json:"uuid"`
Username string `gorm:"not null" json:"username"`
Password string `gorm:"not null" json:"-"`
UserType UserType `gorm:"default:client" json:"user_type"`
Status UserStatus `gorm:"default:active" json:"status"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (User) TableName() string {
return "users"
}