Compare commits

...

3 Commits

Author SHA1 Message Date
lixu 856b81125c Merge PR #34: public MSRP display
CI / Go (api) (push) Successful in 54s
CI / Python (ingestion) (push) Successful in 16s
CI / Migrations (postgres) (push) Successful in 26s
feat: embed MSRP in public product detail (hide zero amounts)
2026-06-25 08:59:21 +08:00
busenalbantoglu51424 5fe5774251 feat(public): 商品详情页展示厂商建议零售价(MSRP)
CI / Go (api) (pull_request) Successful in 1m59s
CI / Python (ingestion) (pull_request) Successful in 1m13s
CI / Migrations (postgres) (pull_request) Successful in 27s
后端 ProductByID/ProductByGTIN 在商品详情 JSON 中内嵌 msrp 字段(按 effective_date 倒序,过滤 amount=0 的无效快照);公开前台详情页新增「建议零售价」展示。

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-06-25 00:42:18 +00:00
lixu 0da57a2fb3 Merge pull request 'feat(admin): 新增 /api/import/bypos 导入接口(修复采集器导入失败)' (#33) from devin/1782307670-bypos-import-endpoint into main
CI / Go (api) (push) Successful in 53s
CI / Python (ingestion) (push) Successful in 16s
CI / Migrations (postgres) (push) Successful in 28s
2026-06-24 21:33:02 +08:00
4 changed files with 53 additions and 3 deletions
+16 -1
View File
@@ -208,7 +208,22 @@
"nutriments": { "type": "object", "additionalProperties": true, "nullable": true },
"nutrition_basis": { "type": "string", "nullable": true },
"nutri_score": { "type": "string", "nullable": true },
"ingredients_text": { "type": "string", "nullable": true }
"ingredients_text": { "type": "string", "nullable": true },
"msrp": {
"type": "array",
"description": "Manufacturer suggested retail price snapshots (reference only, newest first; zero-amount entries omitted).",
"items": {
"type": "object",
"properties": {
"amount": { "type": "number" },
"currency": { "type": "string" },
"region": { "type": "string" },
"effective_date": { "type": "string", "nullable": true },
"source_url": { "type": "string", "nullable": true },
"note": { "type": "string", "nullable": true }
}
}
}
}
}
}
+10 -2
View File
@@ -126,6 +126,7 @@ type Product struct {
Ingredients *string `json:"ingredients_text,omitempty"`
Allergens []string `json:"allergens,omitempty"`
Additives []string `json:"additives,omitempty"`
MSRP []MSRP `json:"msrp,omitempty"`
}
// ProductBarcodes returns every barcode attached to a product, primary first.
@@ -280,6 +281,9 @@ func (s *Store) ProductByGTIN(ctx context.Context, gtin string) (*Product, error
if p.Specs, err = s.buildSpecs(ctx, p.ArchiveKind, attrs); err != nil {
return nil, err
}
if p.MSRP, err = s.ListMSRP(ctx, p.ID); err != nil {
return nil, err
}
s.cacheSet(ctx, suffix+gtin, p, productCacheTTL)
return p, nil
}
@@ -301,6 +305,9 @@ func (s *Store) ProductByID(ctx context.Context, id string) (*Product, error) {
if p.Specs, err = s.buildSpecs(ctx, p.ArchiveKind, attrs); err != nil {
return nil, err
}
if p.MSRP, err = s.ListMSRP(ctx, p.ID); err != nil {
return nil, err
}
s.cacheSet(ctx, suffix+id, p, productCacheTTL)
return p, nil
}
@@ -445,11 +452,12 @@ type MSRP struct {
Note *string `json:"note"`
}
// ListMSRP returns all MSRP snapshots for a product.
// ListMSRP returns a product's suggested-retail-price snapshots, newest first.
// Zero-amount entries are excluded as they carry no price information.
func (s *Store) ListMSRP(ctx context.Context, id string) ([]MSRP, error) {
rows, err := s.pool.Query(ctx,
`SELECT amount, currency, region, effective_date::text, source_url, note
FROM product_msrp WHERE product_id = $1 ORDER BY effective_date DESC NULLS LAST`, id)
FROM product_msrp WHERE product_id = $1 AND amount > 0 ORDER BY effective_date DESC NULLS LAST`, id)
if err != nil {
return nil, err
}
@@ -42,6 +42,12 @@ export default function ProductView({ id, onBack }: { id: string; onBack: () =>
const nutriEntries = Object.entries(p.nutriments || {}).filter(
([, v]) => v !== null && v !== undefined,
);
const latestMsrp = (p.msrp || [])[0];
const msrpText = latestMsrp
? latestMsrp.currency === "CNY"
? `¥${latestMsrp.amount.toFixed(2)}`
: `${latestMsrp.amount.toFixed(2)} ${latestMsrp.currency}`
: null;
return (
<div>
@@ -93,6 +99,17 @@ export default function ProductView({ id, onBack }: { id: string; onBack: () =>
}
/>
<Row label="产地" value={p.country_of_origin} />
<Row
label="建议零售价"
value={
msrpText ? (
<span className="inline-flex items-baseline gap-2">
<span className="font-medium text-gray-900">{msrpText}</span>
<span className="text-xs text-gray-400"></span>
</span>
) : null
}
/>
<Row label="Nutri-Score" value={p.nutri_score} />
<Row label="配料" value={p.ingredients_text} />
<Row
+10
View File
@@ -24,6 +24,15 @@ export interface ProductSpec {
unit?: string;
}
export interface Msrp {
amount: number;
currency: string;
region: string;
effective_date?: string | null;
source_url?: string | null;
note?: string | null;
}
export interface Product {
id: string;
gtin: string | null;
@@ -43,6 +52,7 @@ export interface Product {
ingredients_text?: string | null;
allergens?: string[] | null;
additives?: string[] | null;
msrp?: Msrp[] | null;
}
export interface Category {