From b26fea9621e3e317378f670f8fa717bcea7eec7c Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 5 Jul 2026 20:18:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=86=E7=B1=BB=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=98=AF=E5=90=A6=E5=8F=AF=E8=B7=A8=E5=88=86?= =?UTF-8?q?=E7=B1=BB=E8=B4=AD=E7=89=A9=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/internal/api/handlers/product.go | 24 ++++++++------ backend/internal/models/category.go | 33 ++++++++++--------- backend/internal/schemas/product.go | 42 +++++++++++++----------- frontend/src/views/admin/Categories.vue | 16 +++++++-- 4 files changed, 66 insertions(+), 49 deletions(-) diff --git a/backend/internal/api/handlers/product.go b/backend/internal/api/handlers/product.go index 8fe6338..43c7813 100644 --- a/backend/internal/api/handlers/product.go +++ b/backend/internal/api/handlers/product.go @@ -49,16 +49,17 @@ func (h *CategoryHandler) Create(c *gin.Context) { } category := models.Category{ - Name: req.Name, - Description: req.Description, - ParentID: req.ParentID, - MinAmount: req.MinAmount, - MaxAmount: req.MaxAmount, - MinQuantity: req.MinQuantity, - MaxQuantity: req.MaxQuantity, - MinWeight: req.MinWeight, - MaxWeight: req.MaxWeight, - SortOrder: req.SortOrder, + Name: req.Name, + Description: req.Description, + ParentID: req.ParentID, + MinAmount: req.MinAmount, + MaxAmount: req.MaxAmount, + MinQuantity: req.MinQuantity, + MaxQuantity: req.MaxQuantity, + MinWeight: req.MinWeight, + MaxWeight: req.MaxWeight, + AllowCrossCategory: req.AllowCrossCategory != nil && *req.AllowCrossCategory, + SortOrder: req.SortOrder, } if err := utils.DB.Create(&category).Error; err != nil { @@ -122,6 +123,9 @@ func (h *CategoryHandler) Update(c *gin.Context) { if req.SortOrder != nil { updates["sort_order"] = *req.SortOrder } + if req.AllowCrossCategory != nil { + updates["allow_cross_category"] = *req.AllowCrossCategory + } utils.DB.Model(&category).Updates(updates) c.JSON(http.StatusOK, gin.H{"data": category}) diff --git a/backend/internal/models/category.go b/backend/internal/models/category.go index 62af1fa..d35ba24 100644 --- a/backend/internal/models/category.go +++ b/backend/internal/models/category.go @@ -7,22 +7,23 @@ import ( ) type Category struct { - ID uint `gorm:"primaryKey" json:"id"` - Name string `gorm:"size:100;not null;uniqueIndex" 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:"-"` - ProductCount int64 `gorm:"-" json:"product_count"` - Children []Category `gorm:"foreignKey:ParentID" json:"children,omitempty"` + ID uint `gorm:"primaryKey" json:"id"` + Name string `gorm:"size:100;not null;uniqueIndex" 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"` + AllowCrossCategory bool `gorm:"default:false" json:"allow_cross_category"` + 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:"-"` + ProductCount int64 `gorm:"-" json:"product_count"` + Children []Category `gorm:"foreignKey:ParentID" json:"children,omitempty"` } func (Category) TableName() string { diff --git a/backend/internal/schemas/product.go b/backend/internal/schemas/product.go index 9cfd4e0..0de40e7 100644 --- a/backend/internal/schemas/product.go +++ b/backend/internal/schemas/product.go @@ -1,29 +1,31 @@ package schemas type CreateCategoryRequest struct { - Name string `json:"name" binding:"required"` - 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 `json:"sort_order"` + Name string `json:"name" binding:"required"` + 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"` + AllowCrossCategory *bool `json:"allow_cross_category"` + SortOrder int `json:"sort_order"` } type UpdateCategoryRequest struct { - Name *string `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 `json:"sort_order"` + Name *string `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"` + AllowCrossCategory *bool `json:"allow_cross_category"` + SortOrder *int `json:"sort_order"` } type CreateProductRequest struct { diff --git a/frontend/src/views/admin/Categories.vue b/frontend/src/views/admin/Categories.vue index 46bee47..51cbe02 100644 --- a/frontend/src/views/admin/Categories.vue +++ b/frontend/src/views/admin/Categories.vue @@ -14,6 +14,13 @@ - + + +