feat: 分类管理添加是否可跨分类购物选项
This commit is contained in:
@@ -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})
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user