This commit is contained in:
nepiedg
2025-12-29 09:32:44 +00:00
commit a5a24562b2
13 changed files with 722 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
package model
import (
"time"
"gorm.io/gorm"
)
type Product struct {
ID uint `gorm:"primarykey" json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
Name string `gorm:"size:200;not null" json:"name"`
Description string `gorm:"type:text" json:"description"`
Price float64 `gorm:"type:decimal(10,2);not null" json:"price"`
Stock int `gorm:"default:0" json:"stock"`
ImageURL string `gorm:"size:500" json:"image_url"`
Category string `gorm:"size:50" json:"category"`
Status int `gorm:"default:1" json:"status"`
}
func (Product) TableName() string {
return "products"
}
+22
View File
@@ -0,0 +1,22 @@
package model
type Response struct {
Code int `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
}
func Success(data interface{}) Response {
return Response{
Code: 200,
Message: "success",
Data: data,
}
}
func Error(code int, message string) Response {
return Response{
Code: code,
Message: message,
}
}
+27
View File
@@ -0,0 +1,27 @@
package model
import (
"time"
"gorm.io/gorm"
)
type User struct {
ID uint `gorm:"primarykey" json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
OpenID string `gorm:"uniqueIndex;size:100" json:"open_id"`
UnionID string `gorm:"size:100" json:"union_id,omitempty"`
NickName string `gorm:"size:100" json:"nickname"`
AvatarURL string `gorm:"size:500" json:"avatar_url"`
Gender int `gorm:"default:0" json:"gender"`
Phone string `gorm:"size:20" json:"phone,omitempty"`
SessionKey string `gorm:"size:100" json:"-"`
}
func (User) TableName() string {
return "users"
}