From e7fdf6cc190bf269a9af8b7c76dd9eb977240452 Mon Sep 17 00:00:00 2001 From: BXY <103352887+BXY0414@users.noreply.github.com> Date: Thu, 13 Aug 2026 17:44:14 +0800 Subject: [PATCH] =?UTF-8?q?feat(product):=20=E5=88=86=E7=B1=BB=E5=95=86?= =?UTF-8?q?=E5=93=81=E5=88=97=E8=A1=A8=E8=BF=94=E5=9B=9E=E5=BA=93=E5=AD=98?= =?UTF-8?q?=E6=B1=87=E6=80=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/repository/product_repository.go | 38 +++++++++++++++-------- internal/server/product_server.go | 20 ++++++------ 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/internal/repository/product_repository.go b/internal/repository/product_repository.go index 473db80..f69b037 100644 --- a/internal/repository/product_repository.go +++ b/internal/repository/product_repository.go @@ -195,15 +195,17 @@ type ProductStatusUpdate struct { // CategoryProductRecord is the product summary returned by product list endpoints. type CategoryProductRecord struct { - ID string - SPUNo string - Title string - Status productv1.ProductStatus - ImageIDs []string - Price int64 - SoldQuantity int64 - CreatedAt time.Time - UpdatedAt time.Time + ID string + SPUNo string + Title string + Status productv1.ProductStatus + ImageIDs []string + Price int64 + SoldQuantity int64 + AvailableQuantity int64 + LockedQuantity int64 + CreatedAt time.Time + UpdatedAt time.Time } // CategoryRecord is the persistence model for product.product_category. @@ -1505,11 +1507,15 @@ SELECT p.updated_at, p.status, COALESCE(to_json(p.image_ids)::text, '[]'), 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 LEFT JOIN LATERAL ( 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 LEFT JOIN product.product_item_inventory inv ON inv.sku_id = pi.id WHERE pi.product_id = p.id @@ -1602,12 +1608,16 @@ SELECT p.updated_at, p.status, COALESCE(to_json(p.image_ids)::text, '[]'), 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 JOIN product.product_category_bindings b ON b.product_id = p.id LEFT JOIN LATERAL ( 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 LEFT JOIN product.product_item_inventory inv ON inv.sku_id = pi.id WHERE pi.product_id = p.id @@ -2207,6 +2217,8 @@ func scanCategoryProduct(scanner rowScanner) (*CategoryProductRecord, error) { &imageIDsJSON, &rec.Price, &rec.SoldQuantity, + &rec.AvailableQuantity, + &rec.LockedQuantity, ); err != nil { return nil, fmt.Errorf("scan category product: %w", err) } diff --git a/internal/server/product_server.go b/internal/server/product_server.go index 6dfde7b..a8c1972 100644 --- a/internal/server/product_server.go +++ b/internal/server/product_server.go @@ -1543,15 +1543,17 @@ func toProtoCategoryProduct(product *repository.CategoryProductRecord) *productv return nil } return &productv1.CategoryProduct{ - UpdatedAt: timeToMillisString(product.UpdatedAt), - CreatedAt: timeToMillisString(product.CreatedAt), - Title: product.Title, - ProductId: product.ID, - SpuNo: product.SPUNo, - Status: product.Status, - ImageIds: product.ImageIDs, - Price: product.Price, - SoldQuantity: product.SoldQuantity, + UpdatedAt: timeToMillisString(product.UpdatedAt), + CreatedAt: timeToMillisString(product.CreatedAt), + Title: product.Title, + ProductId: product.ID, + SpuNo: product.SPUNo, + Status: product.Status, + ImageIds: product.ImageIDs, + Price: product.Price, + SoldQuantity: product.SoldQuantity, + AvailableQuantity: product.AvailableQuantity, + LockedQuantity: product.LockedQuantity, } }