创建分类
This commit is contained in:
parent
67df27ae49
commit
872e028e0d
|
@ -12,7 +12,7 @@ import (
|
|||
|
||||
type CreateCategoryRequest struct {
|
||||
Name string `json:"name" validate:"required"` //名称
|
||||
ParentId string `json:"parent_id"` //父分类编号
|
||||
ParentId uint32 `json:"parent_id"` //父分类id
|
||||
}
|
||||
|
||||
// CreateCategory 创建分类
|
||||
|
|
|
@ -12,7 +12,7 @@ type Category struct {
|
|||
Name string `json:"name"` // 分类名称
|
||||
Number string `json:"number"` //编号
|
||||
Display int8 `json:"state"` // 1 展示 0 隐藏
|
||||
Pid string `json:"pid" gorm:"index"` //父分类的编号
|
||||
Pid uint32 `json:"pid" gorm:"index"` //父分类的编号
|
||||
CooperativeBusinessId uint32 `json:"cooperative_business_id"` //合作商id
|
||||
}
|
||||
|
||||
|
@ -24,11 +24,13 @@ func (c *Category) BeforeCreate(tx *gorm.DB) error {
|
|||
if c.Number == "" {
|
||||
var count int64
|
||||
var err error
|
||||
if c.Pid == "" {
|
||||
if c.Pid == 0 {
|
||||
err = tx.Model(c).
|
||||
Unscoped().
|
||||
Scopes(common.ScopeCooperativeBusiness(c.CooperativeBusinessId)).
|
||||
Where("pid", "").
|
||||
Count(&count).Error
|
||||
Count(&count).
|
||||
Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -37,12 +39,13 @@ func (c *Category) BeforeCreate(tx *gorm.DB) error {
|
|||
var parent Category
|
||||
err = tx.
|
||||
Scopes(common.ScopeCooperativeBusiness(c.CooperativeBusinessId)).
|
||||
Where("number", c.Pid).
|
||||
Where("id", c.Pid).
|
||||
First(&parent).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = tx.Model(c).
|
||||
Unscoped().
|
||||
Scopes(common.ScopeCooperativeBusiness(c.CooperativeBusinessId)).
|
||||
Where("pid", c.Pid).
|
||||
Count(&count).
|
||||
|
|
Loading…
Reference in New Issue
Block a user