mirror of
https://ids-dev.idsbuybuybuy.com/ids-ecommerce/ids-svc-product.git
synced 2026-11-29 16:57:41 +08:00
feat: 统一商品、客户、活动页、商品分类页的状态与类型为数据库数值
This commit is contained in:
parent
d75d6e2112
commit
9e9c66fc42
@ -480,7 +480,7 @@ func (r *ProductRepository) UpdateCategoryTrees(ctx context.Context, updates []C
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if root.NodeType != 0 || root.Level != 1 || root.ParentID != "" {
|
if root.NodeType != 1 || root.Level != 1 || root.ParentID != "" {
|
||||||
return ErrCategoryTreeConflict
|
return ErrCategoryTreeConflict
|
||||||
}
|
}
|
||||||
if tree.Category != nil {
|
if tree.Category != nil {
|
||||||
@ -496,7 +496,7 @@ func (r *ProductRepository) UpdateCategoryTrees(ctx context.Context, updates []C
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if current.NodeType != 0 || current.Level != 2 || current.ParentID != tree.CategoryID {
|
if current.NodeType != 1 || current.Level != 2 || current.ParentID != tree.CategoryID {
|
||||||
return ErrCategoryTreeConflict
|
return ErrCategoryTreeConflict
|
||||||
}
|
}
|
||||||
if _, err := updateCategoryFields(ctx, tx, child); err != nil {
|
if _, err := updateCategoryFields(ctx, tx, child); err != nil {
|
||||||
@ -1652,7 +1652,7 @@ SELECT id,
|
|||||||
status,
|
status,
|
||||||
version
|
version
|
||||||
FROM product.product_category
|
FROM product.product_category
|
||||||
WHERE node_type = 0
|
WHERE node_type = 1
|
||||||
AND ($1 = false OR status = 1)
|
AND ($1 = false OR status = 1)
|
||||||
ORDER BY level ASC, sort_num ASC, id ASC
|
ORDER BY level ASC, sort_num ASC, id ASC
|
||||||
`, onlyVisible)
|
`, onlyVisible)
|
||||||
@ -1689,7 +1689,7 @@ SELECT id,
|
|||||||
status,
|
status,
|
||||||
version
|
version
|
||||||
FROM product.product_category
|
FROM product.product_category
|
||||||
WHERE node_type = 1
|
WHERE node_type = 2
|
||||||
AND ($1 = false OR status = 1)
|
AND ($1 = false OR status = 1)
|
||||||
ORDER BY sort_num ASC, id ASC
|
ORDER BY sort_num ASC, id ASC
|
||||||
`, onlyVisible)
|
`, onlyVisible)
|
||||||
@ -2625,7 +2625,7 @@ func statusFromDB(status int16) productv1.ProductStatus {
|
|||||||
case 3:
|
case 3:
|
||||||
return productv1.ProductStatus_PRODUCT_STATUS_OFF_SALE
|
return productv1.ProductStatus_PRODUCT_STATUS_OFF_SALE
|
||||||
default:
|
default:
|
||||||
return productv1.ProductStatus_PRODUCT_STATUS_UNSPECIFIED
|
return productv1.ProductStatus_PRODUCT_STATUS_NOT_FOUND
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -32,8 +32,8 @@ const (
|
|||||||
defaultPageSize = int32(20)
|
defaultPageSize = int32(20)
|
||||||
maxPageSize = int32(100)
|
maxPageSize = int32(100)
|
||||||
|
|
||||||
categoryNodeType = int32(0)
|
categoryNodeType = int32(1)
|
||||||
groupNodeType = int32(1)
|
groupNodeType = int32(2)
|
||||||
|
|
||||||
defaultNodeStatus = int32(1)
|
defaultNodeStatus = int32(1)
|
||||||
maxNodeNameLength = 100
|
maxNodeNameLength = 100
|
||||||
@ -991,9 +991,6 @@ func productFromCreateRequest(req *productv1.CreateProductRequest) (repository.P
|
|||||||
}
|
}
|
||||||
|
|
||||||
statusValue := req.GetStatus()
|
statusValue := req.GetStatus()
|
||||||
if statusValue == productv1.ProductStatus_PRODUCT_STATUS_UNSPECIFIED {
|
|
||||||
statusValue = productv1.ProductStatus_PRODUCT_STATUS_INVENTORY
|
|
||||||
}
|
|
||||||
if statusValue != productv1.ProductStatus_PRODUCT_STATUS_INVENTORY &&
|
if statusValue != productv1.ProductStatus_PRODUCT_STATUS_INVENTORY &&
|
||||||
statusValue != productv1.ProductStatus_PRODUCT_STATUS_ON_SALE &&
|
statusValue != productv1.ProductStatus_PRODUCT_STATUS_ON_SALE &&
|
||||||
statusValue != productv1.ProductStatus_PRODUCT_STATUS_OFF_SALE {
|
statusValue != productv1.ProductStatus_PRODUCT_STATUS_OFF_SALE {
|
||||||
@ -1266,9 +1263,6 @@ func skuFromCreateInput(sku *productv1.CreateProductSKU) (repository.SKURecord,
|
|||||||
name = derivedName
|
name = derivedName
|
||||||
}
|
}
|
||||||
statusValue := sku.GetStatus()
|
statusValue := sku.GetStatus()
|
||||||
if statusValue == 0 {
|
|
||||||
statusValue = 1
|
|
||||||
}
|
|
||||||
if statusValue < 0 || statusValue > 1 {
|
if statusValue < 0 || statusValue > 1 {
|
||||||
return repository.SKURecord{}, errors.New("status must be 0 or 1")
|
return repository.SKURecord{}, errors.New("status must be 0 or 1")
|
||||||
}
|
}
|
||||||
@ -1348,7 +1342,7 @@ func crossBorderJSONFromProto(info *productv1.CrossBorderInfo) (string, error) {
|
|||||||
return "", errors.New("cross_border_info.logistics_mode is invalid")
|
return "", errors.New("cross_border_info.logistics_mode is invalid")
|
||||||
}
|
}
|
||||||
|
|
||||||
marshalOptions := protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: true}
|
marshalOptions := protojson.MarshalOptions{UseProtoNames: true, UseEnumNumbers: true, EmitUnpopulated: true}
|
||||||
raw, err := marshalOptions.Marshal(info)
|
raw, err := marshalOptions.Marshal(info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -1520,7 +1514,7 @@ func toProtoCartItemProduct(lineID string, record repository.CartItemProductReco
|
|||||||
LineId: lineID,
|
LineId: lineID,
|
||||||
ProductId: record.ProductID,
|
ProductId: record.ProductID,
|
||||||
SkuId: record.SKUID,
|
SkuId: record.SKUID,
|
||||||
SpuStatus: productv1.ProductStatus_PRODUCT_STATUS_UNSPECIFIED,
|
SpuStatus: productv1.ProductStatus_PRODUCT_STATUS_NOT_FOUND,
|
||||||
}
|
}
|
||||||
if record.Product == nil {
|
if record.Product == nil {
|
||||||
return result
|
return result
|
||||||
|
|||||||
@ -111,7 +111,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS uq_products_spu_no
|
|||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS product.product_category (
|
CREATE TABLE IF NOT EXISTS product.product_category (
|
||||||
id BIGINT PRIMARY KEY,
|
id BIGINT PRIMARY KEY,
|
||||||
node_type SMALLINT NOT NULL DEFAULT 0,
|
node_type SMALLINT NOT NULL DEFAULT 1,
|
||||||
name VARCHAR(100) NOT NULL,
|
name VARCHAR(100) NOT NULL,
|
||||||
parent_id BIGINT REFERENCES product.product_category(id),
|
parent_id BIGINT REFERENCES product.product_category(id),
|
||||||
level SMALLINT NOT NULL,
|
level SMALLINT NOT NULL,
|
||||||
@ -120,7 +120,7 @@ CREATE TABLE IF NOT EXISTS product.product_category (
|
|||||||
status SMALLINT NOT NULL DEFAULT 1,
|
status SMALLINT NOT NULL DEFAULT 1,
|
||||||
version INTEGER NOT NULL DEFAULT 0,
|
version INTEGER NOT NULL DEFAULT 0,
|
||||||
CONSTRAINT chk_product_category_node_type
|
CONSTRAINT chk_product_category_node_type
|
||||||
CHECK (node_type IN (0, 1)),
|
CHECK (node_type IN (1, 2)),
|
||||||
CONSTRAINT chk_product_category_level
|
CONSTRAINT chk_product_category_level
|
||||||
CHECK (level > 0),
|
CHECK (level > 0),
|
||||||
CONSTRAINT chk_product_category_status
|
CONSTRAINT chk_product_category_status
|
||||||
@ -131,7 +131,7 @@ CREATE TABLE IF NOT EXISTS product.product_category (
|
|||||||
|
|
||||||
COMMENT ON TABLE product.product_category IS '商品类别表:存储商品分类和商品分组,通过 node_type 区分分类或分组';
|
COMMENT ON TABLE product.product_category IS '商品类别表:存储商品分类和商品分组,通过 node_type 区分分类或分组';
|
||||||
COMMENT ON COLUMN product.product_category.id IS '类别/分组节点主键';
|
COMMENT ON COLUMN product.product_category.id IS '类别/分组节点主键';
|
||||||
COMMENT ON COLUMN product.product_category.node_type IS '节点类型:0 分类,1 分组';
|
COMMENT ON COLUMN product.product_category.node_type IS '节点类型:1 分类,2 分组';
|
||||||
COMMENT ON COLUMN product.product_category.name IS '节点展示名称';
|
COMMENT ON COLUMN product.product_category.name IS '节点展示名称';
|
||||||
COMMENT ON COLUMN product.product_category.parent_id IS '上级节点 ID,顶级节点为空;子节点通过 parent_id 反向查询';
|
COMMENT ON COLUMN product.product_category.parent_id IS '上级节点 ID,顶级节点为空;子节点通过 parent_id 反向查询';
|
||||||
COMMENT ON COLUMN product.product_category.level IS '节点层级,如 1、2、3';
|
COMMENT ON COLUMN product.product_category.level IS '节点层级,如 1、2、3';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user