mirror of
https://ids-dev.idsbuybuybuy.com/ids-ecommerce/ids-svc-product.git
synced 2026-11-29 16:57:41 +08:00
feat(product): 分类商品列表返回库存汇总
This commit is contained in:
parent
9e9c66fc42
commit
e7fdf6cc19
@ -202,6 +202,8 @@ type CategoryProductRecord struct {
|
|||||||
ImageIDs []string
|
ImageIDs []string
|
||||||
Price int64
|
Price int64
|
||||||
SoldQuantity int64
|
SoldQuantity int64
|
||||||
|
AvailableQuantity int64
|
||||||
|
LockedQuantity int64
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
}
|
}
|
||||||
@ -1505,11 +1507,15 @@ SELECT p.updated_at,
|
|||||||
p.status,
|
p.status,
|
||||||
COALESCE(to_json(p.image_ids)::text, '[]'),
|
COALESCE(to_json(p.image_ids)::text, '[]'),
|
||||||
COALESCE(sku_summary.price, 0),
|
COALESCE(sku_summary.price, 0),
|
||||||
COALESCE(sku_summary.sold_quantity, 0)
|
COALESCE(sku_summary.sold_quantity, 0),
|
||||||
|
COALESCE(sku_summary.available_quantity, 0),
|
||||||
|
COALESCE(sku_summary.locked_quantity, 0)
|
||||||
FROM product.products p
|
FROM product.products p
|
||||||
LEFT JOIN LATERAL (
|
LEFT JOIN LATERAL (
|
||||||
SELECT MIN(pi.price) AS price,
|
SELECT MIN(pi.price) AS price,
|
||||||
SUM(COALESCE(inv.sold_quantity, 0)) AS sold_quantity
|
SUM(COALESCE(inv.sold_quantity, 0)) AS sold_quantity,
|
||||||
|
SUM(COALESCE(inv.available_quantity, 0)) AS available_quantity,
|
||||||
|
SUM(COALESCE(inv.locked_quantity, 0)) AS locked_quantity
|
||||||
FROM product.product_items pi
|
FROM product.product_items pi
|
||||||
LEFT JOIN product.product_item_inventory inv ON inv.sku_id = pi.id
|
LEFT JOIN product.product_item_inventory inv ON inv.sku_id = pi.id
|
||||||
WHERE pi.product_id = p.id
|
WHERE pi.product_id = p.id
|
||||||
@ -1602,12 +1608,16 @@ SELECT p.updated_at,
|
|||||||
p.status,
|
p.status,
|
||||||
COALESCE(to_json(p.image_ids)::text, '[]'),
|
COALESCE(to_json(p.image_ids)::text, '[]'),
|
||||||
COALESCE(sku_summary.price, 0),
|
COALESCE(sku_summary.price, 0),
|
||||||
COALESCE(sku_summary.sold_quantity, 0)
|
COALESCE(sku_summary.sold_quantity, 0),
|
||||||
|
COALESCE(sku_summary.available_quantity, 0),
|
||||||
|
COALESCE(sku_summary.locked_quantity, 0)
|
||||||
FROM product.products p
|
FROM product.products p
|
||||||
JOIN product.product_category_bindings b ON b.product_id = p.id
|
JOIN product.product_category_bindings b ON b.product_id = p.id
|
||||||
LEFT JOIN LATERAL (
|
LEFT JOIN LATERAL (
|
||||||
SELECT MIN(pi.price) AS price,
|
SELECT MIN(pi.price) AS price,
|
||||||
SUM(COALESCE(inv.sold_quantity, 0)) AS sold_quantity
|
SUM(COALESCE(inv.sold_quantity, 0)) AS sold_quantity,
|
||||||
|
SUM(COALESCE(inv.available_quantity, 0)) AS available_quantity,
|
||||||
|
SUM(COALESCE(inv.locked_quantity, 0)) AS locked_quantity
|
||||||
FROM product.product_items pi
|
FROM product.product_items pi
|
||||||
LEFT JOIN product.product_item_inventory inv ON inv.sku_id = pi.id
|
LEFT JOIN product.product_item_inventory inv ON inv.sku_id = pi.id
|
||||||
WHERE pi.product_id = p.id
|
WHERE pi.product_id = p.id
|
||||||
@ -2207,6 +2217,8 @@ func scanCategoryProduct(scanner rowScanner) (*CategoryProductRecord, error) {
|
|||||||
&imageIDsJSON,
|
&imageIDsJSON,
|
||||||
&rec.Price,
|
&rec.Price,
|
||||||
&rec.SoldQuantity,
|
&rec.SoldQuantity,
|
||||||
|
&rec.AvailableQuantity,
|
||||||
|
&rec.LockedQuantity,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, fmt.Errorf("scan category product: %w", err)
|
return nil, fmt.Errorf("scan category product: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1552,6 +1552,8 @@ func toProtoCategoryProduct(product *repository.CategoryProductRecord) *productv
|
|||||||
ImageIds: product.ImageIDs,
|
ImageIds: product.ImageIDs,
|
||||||
Price: product.Price,
|
Price: product.Price,
|
||||||
SoldQuantity: product.SoldQuantity,
|
SoldQuantity: product.SoldQuantity,
|
||||||
|
AvailableQuantity: product.AvailableQuantity,
|
||||||
|
LockedQuantity: product.LockedQuantity,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user