mirror of
https://ids-dev.idsbuybuybuy.com/ids-ecommerce/ids-svc-product.git
synced 2026-11-29 16:57:41 +08:00
feat: update product status terminology from OFF_SALE to SOLD_OUT across documentation and codebase
This commit is contained in:
parent
d35d54be80
commit
791e09b35b
@ -63,7 +63,7 @@ IDS 电商矩阵中的**商品域微服务**,负责 SPU/SKU 主数据、分类
|
||||
| `group_ids` | 否 | 已存在的商品分组 ID 列表;传入后会写入全部商品分组绑定 |
|
||||
| `image_ids` | 否 | 商品图片 ID 列表 |
|
||||
| `brand_id` / `supplier_id` | 否 | 品牌、供应商 ID |
|
||||
| `status` | 否 | 未传时默认 `PRODUCT_STATUS_INVENTORY`;可取 `INVENTORY`、`ON_SALE`、`OFF_SALE`。其中 `OFF_SALE` 的数值 `3` 业务语义为“已售罄”,可保留真实库存但拒绝新锁库。 |
|
||||
| `status` | 否 | 未传时默认 `PRODUCT_STATUS_INVENTORY`;可取 `INVENTORY`、`ON_SALE`、`SOLD_OUT`。其中 `SOLD_OUT` 的数值 `3` 业务语义为“已售罄”,可保留真实库存但拒绝新锁库。 |
|
||||
| `goods_type` | 否 | 未传时默认 `1` |
|
||||
| `freight_charge_type` | 否 | 未传时默认 `1`;为 `2` 时必须传 `freight_template_id` |
|
||||
| `sale_time_type` | 否 | 未传时默认 `1`;为 `2` 时必须传 `scheduled_sale_time` |
|
||||
@ -132,7 +132,7 @@ IDS 电商矩阵中的**商品域微服务**,负责 SPU/SKU 主数据、分类
|
||||
| `category_id` | `string` | 是 | 分类/分组节点 ID,对应 `product.product_category.id` |
|
||||
| `page` | `int32` | 否 | 页码,从 `1` 开始;未传或小于 `1` 时按 `1` 处理 |
|
||||
| `page_size` | `int32` | 否 | 每页数量;未传或小于 `1` 时按 `20` 处理,大于 `100` 时截断为 `100` |
|
||||
| `only_visible` | `bool` | 否 | 为 `true` 时返回 `ON_SALE` 和 `OFF_SALE` 商品;小程序 BFF 固定传 `true`,Admin 不传以查看全部状态 |
|
||||
| `only_visible` | `bool` | 否 | 为 `true` 时返回 `ON_SALE` 和 `SOLD_OUT` 商品;小程序 BFF 固定传 `true`,Admin 不传以查看全部状态 |
|
||||
|
||||
分页响应字段:
|
||||
|
||||
@ -148,7 +148,7 @@ IDS 电商矩阵中的**商品域微服务**,负责 SPU/SKU 主数据、分类
|
||||
|
||||
### `UpdateProduct` 与 `UpdateProductStatus`
|
||||
|
||||
完整的输入输出及状态/SKU 规则见 [`docs/PRODUCT_UPDATE_AND_SKU_ARCHIVE_DESIGN.md`](docs/PRODUCT_UPDATE_AND_SKU_ARCHIVE_DESIGN.md)。重点约束:更新请求必须携带 SPU、SKU 和库存的乐观锁版本;`PATCH_EXISTING` 可更新 SKU `name`;`REPLACE_ALL` 仅允许在 `INVENTORY` 或 `OFF_SALE`(数值 `3`,已售罄)状态执行,并归档而不删除旧 SKU(即使存在锁定库存)。库存耗尽仅会自动将 `ON_SALE` 转为 `OFF_SALE`(已售罄),补库存不会自动恢复销售。
|
||||
完整的输入输出及状态/SKU 规则见 [`docs/PRODUCT_UPDATE_AND_SKU_ARCHIVE_DESIGN.md`](docs/PRODUCT_UPDATE_AND_SKU_ARCHIVE_DESIGN.md)。重点约束:更新请求必须携带 SPU、SKU 和库存的乐观锁版本;`PATCH_EXISTING` 可更新 SKU `name`;`REPLACE_ALL` 仅允许在 `INVENTORY` 或 `SOLD_OUT`(数值 `3`,已售罄)状态执行,并归档而不删除旧 SKU(即使存在锁定库存)。库存耗尽仅会自动将 `ON_SALE` 转为 `SOLD_OUT`(已售罄),补库存不会自动恢复销售。
|
||||
|
||||
`products[].created_at`、`products[].updated_at` 统一返回 13 位 Unix 毫秒时间戳字符串,前端展示时按 `Asia/Shanghai` 渲染。
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
|---:|---|---|---|
|
||||
| `1` | `PRODUCT_STATUS_INVENTORY` | 在仓库 | 不展示、不可购买 |
|
||||
| `2` | `PRODUCT_STATUS_ON_SALE` | 在销售 | 展示、可购买 |
|
||||
| `3` | `PRODUCT_STATUS_OFF_SALE` | 已售罄 | 展示已售罄状态、不可购买 |
|
||||
| `3` | `PRODUCT_STATUS_SOLD_OUT` | 已售罄 | 展示已售罄状态、不可购买 |
|
||||
|
||||
Proto 定义:
|
||||
|
||||
@ -29,7 +29,7 @@ Proto 定义:
|
||||
enum ProductStatus {
|
||||
PRODUCT_STATUS_INVENTORY = 1;
|
||||
PRODUCT_STATUS_ON_SALE = 2;
|
||||
PRODUCT_STATUS_OFF_SALE = 3;
|
||||
PRODUCT_STATUS_SOLD_OUT = 3;
|
||||
}
|
||||
```
|
||||
|
||||
@ -39,14 +39,14 @@ enum ProductStatus {
|
||||
INVENTORY -> ON_SALE
|
||||
运营人员上架;至少存在一个可售 SKU。
|
||||
|
||||
ON_SALE -> OFF_SALE
|
||||
ON_SALE -> SOLD_OUT
|
||||
所有当前可售 SKU 的 stock_quantity - locked_quantity <= 0 时系统自动标记已售罄,
|
||||
或由运营人员主动标记已售罄。状态 3 优先于真实库存,且不改写库存账实。
|
||||
|
||||
OFF_SALE -> ON_SALE
|
||||
SOLD_OUT -> ON_SALE
|
||||
仅由运营人员主动恢复销售;补货不会自动恢复销售。
|
||||
|
||||
ON_SALE 或 OFF_SALE -> INVENTORY
|
||||
ON_SALE 或 SOLD_OUT -> INVENTORY
|
||||
运营人员放回仓库。
|
||||
```
|
||||
|
||||
@ -179,7 +179,7 @@ SKU 和库存均需要版本校验,防止后台操作覆盖下单锁库存。
|
||||
5. 禁止为已归档 SKU 创建新的库存锁定;
|
||||
6. 商品版本递增,并重新计算商品是否自动售罄。
|
||||
|
||||
仅在商品处于 `INVENTORY` 或 `OFF_SALE` 时允许 `REPLACE_ALL`;商品为 `ON_SALE` 时必须返回冲突错误,避免上架中替换规格影响购物车和下单。
|
||||
仅在商品处于 `INVENTORY` 或 `SOLD_OUT` 时允许 `REPLACE_ALL`;商品为 `ON_SALE` 时必须返回冲突错误,避免上架中替换规格影响购物车和下单。
|
||||
|
||||
成功响应:
|
||||
|
||||
@ -224,7 +224,7 @@ Content-Type: application/json
|
||||
}
|
||||
```
|
||||
|
||||
运营人员可以提交 `INVENTORY`、`ON_SALE`、`OFF_SALE`。`OFF_SALE` 是数值 `3` 的旧 proto 名称,业务含义为“已售罄”。无论商品是运营人员手动标记已售罄,还是因无可售库存自动切换为 `OFF_SALE`,都只能通过本接口显式重新设置为 `ON_SALE`;库存补充本身不会改变商品状态。设置为已售罄不会清空真实库存或锁定库存,但新锁库会被拒绝。
|
||||
运营人员可以提交 `INVENTORY`、`ON_SALE`、`SOLD_OUT`。`SOLD_OUT` 是数值 `3` 的 protobuf 枚举名称,业务含义为“已售罄”。无论商品是运营人员手动标记已售罄,还是因无可售库存自动切换为 `SOLD_OUT`,都只能通过本接口显式重新设置为 `ON_SALE`;库存补充本身不会改变商品状态。设置为已售罄不会清空真实库存或锁定库存,但新锁库会被拒绝。
|
||||
|
||||
上架时必须存在至少一个启用、未归档且 `stock_quantity > locked_quantity` 的 SKU。
|
||||
|
||||
@ -232,7 +232,7 @@ Content-Type: application/json
|
||||
{
|
||||
"product_id": "726390485721088003",
|
||||
"previous_status": "PRODUCT_STATUS_ON_SALE",
|
||||
"status": "PRODUCT_STATUS_OFF_SALE",
|
||||
"status": "PRODUCT_STATUS_SOLD_OUT",
|
||||
"version": 14,
|
||||
"updated_at": "1754388000000"
|
||||
}
|
||||
@ -261,7 +261,7 @@ SKU 协议需要增加 `is_archived`、`archived_at` 与版本字段。普通接
|
||||
|---:|---|---:|---|
|
||||
| `0` | DRAFT | `1` | INVENTORY |
|
||||
| `1` | ON_SALE | `2` | ON_SALE |
|
||||
| `3` | OFF_SALE | `3` | OFF_SALE |
|
||||
| `3` | SOLD_OUT | `3` | SOLD_OUT |
|
||||
| `2` | 当前无有效语义 | `1` | INVENTORY |
|
||||
|
||||
迁移后,`status` 默认值为 `1`,约束为 `status IN (1, 2, 3)`。
|
||||
|
||||
@ -131,7 +131,7 @@ func (r *ProductRepository) BatchUpdateProductStatus(ctx context.Context, produc
|
||||
}
|
||||
if next != productv1.ProductStatus_PRODUCT_STATUS_INVENTORY &&
|
||||
next != productv1.ProductStatus_PRODUCT_STATUS_ON_SALE &&
|
||||
next != productv1.ProductStatus_PRODUCT_STATUS_OFF_SALE {
|
||||
next != productv1.ProductStatus_PRODUCT_STATUS_SOLD_OUT {
|
||||
return 0, fmt.Errorf("unsupported product status")
|
||||
}
|
||||
parsed, originals, err := parseBatchProductIDs(productIDs)
|
||||
|
||||
@ -2062,7 +2062,7 @@ func (r *ProductRepository) UpdateProductStatus(ctx context.Context, productID s
|
||||
if expectedVersion < 0 {
|
||||
return nil, fmt.Errorf("expected product version must be non-negative")
|
||||
}
|
||||
if next != productv1.ProductStatus_PRODUCT_STATUS_INVENTORY && next != productv1.ProductStatus_PRODUCT_STATUS_ON_SALE && next != productv1.ProductStatus_PRODUCT_STATUS_OFF_SALE {
|
||||
if next != productv1.ProductStatus_PRODUCT_STATUS_INVENTORY && next != productv1.ProductStatus_PRODUCT_STATUS_ON_SALE && next != productv1.ProductStatus_PRODUCT_STATUS_SOLD_OUT {
|
||||
return nil, fmt.Errorf("unsupported product status")
|
||||
}
|
||||
id, err := parseID(productID, "product id")
|
||||
@ -2391,8 +2391,8 @@ SELECT EXISTS(
|
||||
return exists, nil
|
||||
}
|
||||
|
||||
// autoMarkProductSoldOut transitions an on-sale product to status 3 (the legacy
|
||||
// proto identifier is OFF_SALE) when no SKU can be sold. It never auto-relists:
|
||||
// autoMarkProductSoldOut transitions an on-sale product to SOLD_OUT (status 3)
|
||||
// when no SKU can be sold. It never auto-relists:
|
||||
// replenishment alone must not undo an explicit or automatic sold-out state.
|
||||
func autoMarkProductSoldOut(ctx context.Context, tx *sql.Tx, productID int64) error {
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
@ -2411,7 +2411,7 @@ WHERE p.id = $1
|
||||
AND pi.status = 1
|
||||
AND inv.stock_quantity > inv.locked_quantity
|
||||
)
|
||||
`, productID, statusToDB(productv1.ProductStatus_PRODUCT_STATUS_OFF_SALE), statusToDB(productv1.ProductStatus_PRODUCT_STATUS_ON_SALE))
|
||||
`, productID, statusToDB(productv1.ProductStatus_PRODUCT_STATUS_SOLD_OUT), statusToDB(productv1.ProductStatus_PRODUCT_STATUS_ON_SALE))
|
||||
if err != nil {
|
||||
return fmt.Errorf("auto mark product sold out %s: %w", formatID(productID), err)
|
||||
}
|
||||
@ -2582,7 +2582,7 @@ FOR UPDATE OF p
|
||||
return nil, fmt.Errorf("lock product for inventory %s: %w", skuID, err)
|
||||
}
|
||||
productLifecycleStatus := statusFromDB(productStatus)
|
||||
if productLifecycleStatus == productv1.ProductStatus_PRODUCT_STATUS_OFF_SALE {
|
||||
if productLifecycleStatus == productv1.ProductStatus_PRODUCT_STATUS_SOLD_OUT {
|
||||
return nil, fmt.Errorf("lock inventory %s: %w", skuID, ErrProductSoldOut)
|
||||
}
|
||||
if productLifecycleStatus != productv1.ProductStatus_PRODUCT_STATUS_ON_SALE {
|
||||
@ -3252,7 +3252,7 @@ func (r *ProductRepository) BatchGetStorefrontProductSKUs(ctx context.Context, p
|
||||
}
|
||||
args = append(args, scope.StoreID,
|
||||
statusToDB(productv1.ProductStatus_PRODUCT_STATUS_ON_SALE),
|
||||
statusToDB(productv1.ProductStatus_PRODUCT_STATUS_OFF_SALE),
|
||||
statusToDB(productv1.ProductStatus_PRODUCT_STATUS_SOLD_OUT),
|
||||
)
|
||||
storeArg := len(args) - 2
|
||||
onSaleArg := len(args) - 1
|
||||
@ -3491,7 +3491,7 @@ func (r *ProductRepository) SearchProducts(ctx context.Context, keyword string,
|
||||
containsPattern := "%" + escapedKeyword + "%"
|
||||
prefixPattern := escapedKeyword + "%"
|
||||
onSaleStatus := statusToDB(productv1.ProductStatus_PRODUCT_STATUS_ON_SALE)
|
||||
offSaleStatus := statusToDB(productv1.ProductStatus_PRODUCT_STATUS_OFF_SALE)
|
||||
soldOutStatus := statusToDB(productv1.ProductStatus_PRODUCT_STATUS_SOLD_OUT)
|
||||
|
||||
var total int64
|
||||
if err := r.db.QueryRowContext(ctx, `
|
||||
@ -3509,7 +3509,7 @@ WHERE p.deleted_at IS NULL
|
||||
AND pi.status = 1
|
||||
)
|
||||
AND p.title ILIKE $1 ESCAPE '\'
|
||||
`, containsPattern, onSaleStatus, offSaleStatus, scope.StoreID).Scan(&total); err != nil {
|
||||
`, containsPattern, onSaleStatus, soldOutStatus, scope.StoreID).Scan(&total); err != nil {
|
||||
return nil, 0, fmt.Errorf("count searched products: %w", err)
|
||||
}
|
||||
if total == 0 {
|
||||
@ -3564,7 +3564,7 @@ ORDER BY CASE
|
||||
p.updated_at DESC,
|
||||
p.id DESC
|
||||
LIMIT $6 OFFSET $7
|
||||
`, containsPattern, onSaleStatus, offSaleStatus, keyword, prefixPattern, pageSize, offset, scope.StoreID)
|
||||
`, containsPattern, onSaleStatus, soldOutStatus, keyword, prefixPattern, pageSize, offset, scope.StoreID)
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("query searched products: %w", err)
|
||||
}
|
||||
@ -3665,7 +3665,7 @@ WHERE ($6 = 2 OR b.category_id IN (
|
||||
AND pi.is_archived = FALSE
|
||||
AND pi.status = 1
|
||||
))
|
||||
`, parsedCategoryID, onlyVisible, statusToDB(productv1.ProductStatus_PRODUCT_STATUS_ON_SALE), statusToDB(productv1.ProductStatus_PRODUCT_STATUS_OFF_SALE), scope.StoreID, targetNodeType).Scan(&total); err != nil {
|
||||
`, parsedCategoryID, onlyVisible, statusToDB(productv1.ProductStatus_PRODUCT_STATUS_ON_SALE), statusToDB(productv1.ProductStatus_PRODUCT_STATUS_SOLD_OUT), scope.StoreID, targetNodeType).Scan(&total); err != nil {
|
||||
return nil, nil, 0, fmt.Errorf("count category products: %w", err)
|
||||
}
|
||||
if total == 0 {
|
||||
@ -3700,7 +3700,7 @@ WHERE ($6 = 2 OR b.category_id IN (
|
||||
))
|
||||
GROUP BY p.id
|
||||
ORDER BY MAX(p.created_at) DESC, p.id DESC
|
||||
`, parsedCategoryID, onlyVisible, statusToDB(productv1.ProductStatus_PRODUCT_STATUS_ON_SALE), statusToDB(productv1.ProductStatus_PRODUCT_STATUS_OFF_SALE), scope.StoreID, targetNodeType)
|
||||
`, parsedCategoryID, onlyVisible, statusToDB(productv1.ProductStatus_PRODUCT_STATUS_ON_SALE), statusToDB(productv1.ProductStatus_PRODUCT_STATUS_SOLD_OUT), scope.StoreID, targetNodeType)
|
||||
if err != nil {
|
||||
return nil, nil, 0, fmt.Errorf("query category product ids: %w", err)
|
||||
}
|
||||
@ -3770,7 +3770,7 @@ WHERE ($8 = 2 OR b.category_id IN (
|
||||
))
|
||||
ORDER BY p.created_at DESC, p.id DESC
|
||||
LIMIT $3 OFFSET $4
|
||||
`, parsedCategoryID, onlyVisible, pageSize, offset, statusToDB(productv1.ProductStatus_PRODUCT_STATUS_ON_SALE), statusToDB(productv1.ProductStatus_PRODUCT_STATUS_OFF_SALE), scope.StoreID, targetNodeType)
|
||||
`, parsedCategoryID, onlyVisible, pageSize, offset, statusToDB(productv1.ProductStatus_PRODUCT_STATUS_ON_SALE), statusToDB(productv1.ProductStatus_PRODUCT_STATUS_SOLD_OUT), scope.StoreID, targetNodeType)
|
||||
if err != nil {
|
||||
return nil, nil, 0, fmt.Errorf("query category products: %w", err)
|
||||
}
|
||||
@ -5099,7 +5099,7 @@ func statusToDB(status productv1.ProductStatus) int16 {
|
||||
return 1
|
||||
case productv1.ProductStatus_PRODUCT_STATUS_ON_SALE:
|
||||
return 2
|
||||
case productv1.ProductStatus_PRODUCT_STATUS_OFF_SALE:
|
||||
case productv1.ProductStatus_PRODUCT_STATUS_SOLD_OUT:
|
||||
return 3
|
||||
default:
|
||||
return 1
|
||||
@ -5113,7 +5113,7 @@ func statusFromDB(status int16) productv1.ProductStatus {
|
||||
case 2:
|
||||
return productv1.ProductStatus_PRODUCT_STATUS_ON_SALE
|
||||
case 3:
|
||||
return productv1.ProductStatus_PRODUCT_STATUS_OFF_SALE
|
||||
return productv1.ProductStatus_PRODUCT_STATUS_SOLD_OUT
|
||||
default:
|
||||
return productv1.ProductStatus_PRODUCT_STATUS_UNSPECIFIED
|
||||
}
|
||||
|
||||
@ -864,7 +864,7 @@ func productListFilterFromRequest(req *productv1.ListProductsRequest) (repositor
|
||||
statusValue := req.GetStatus()
|
||||
if statusValue != productv1.ProductStatus_PRODUCT_STATUS_INVENTORY &&
|
||||
statusValue != productv1.ProductStatus_PRODUCT_STATUS_ON_SALE &&
|
||||
statusValue != productv1.ProductStatus_PRODUCT_STATUS_OFF_SALE {
|
||||
statusValue != productv1.ProductStatus_PRODUCT_STATUS_SOLD_OUT {
|
||||
return repository.ProductListFilter{}, errors.New("status must be 1, 2, or 3")
|
||||
}
|
||||
filter.Status = &statusValue
|
||||
@ -2166,7 +2166,7 @@ func productFromCreateRequest(req *productv1.CreateProductRequest) (repository.P
|
||||
}
|
||||
if statusValue != productv1.ProductStatus_PRODUCT_STATUS_INVENTORY &&
|
||||
statusValue != productv1.ProductStatus_PRODUCT_STATUS_ON_SALE &&
|
||||
statusValue != productv1.ProductStatus_PRODUCT_STATUS_OFF_SALE {
|
||||
statusValue != productv1.ProductStatus_PRODUCT_STATUS_SOLD_OUT {
|
||||
return repository.ProductRecord{}, nil, errors.New("unsupported product status")
|
||||
}
|
||||
crossBorderJSON, err := crossBorderJSONFromProto(req.GetCrossBorderInfo())
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
-- One-time migration for product lifecycle statuses and SKU archival.
|
||||
-- Run during a maintenance window before deploying the product-service code
|
||||
-- that uses PRODUCT_STATUS_INVENTORY / ON_SALE / OFF_SALE.
|
||||
-- that uses PRODUCT_STATUS_INVENTORY / ON_SALE / SOLD_OUT.
|
||||
|
||||
BEGIN;
|
||||
|
||||
@ -20,7 +20,7 @@ ALTER TABLE product.product_items
|
||||
ALTER TABLE product.products
|
||||
DROP CONSTRAINT IF EXISTS chk_products_status;
|
||||
|
||||
-- Current values are 0=DRAFT, 1=ON_SALE, 3=OFF_SALE. Value 2 has no
|
||||
-- Current values are 0=DRAFT, 1=ON_SALE, 3=SOLD_OUT. Value 2 has no
|
||||
-- supported current meaning and is moved to INVENTORY as the safe state.
|
||||
UPDATE product.products
|
||||
SET status = CASE status
|
||||
|
||||
Loading…
Reference in New Issue
Block a user