feat(ai-image): AI生图开发
This commit is contained in:
@@ -321,12 +321,14 @@ export class ExtensionService {
|
||||
await tx.query(
|
||||
`UPDATE atlas.product_variants
|
||||
SET source_sku = $1, display_name = $2, sort_order = $3,
|
||||
purchase_cost_cny = COALESCE(ROUND($4::numeric, 2), purchase_cost_cny),
|
||||
deleted_at = NULL, updated_at = now()
|
||||
WHERE id = $4`,
|
||||
WHERE id = $5`,
|
||||
[
|
||||
variant.sourceSku ?? null,
|
||||
variant.displayName,
|
||||
index,
|
||||
sourcePurchaseCost(payload.source.platform, variant),
|
||||
variantId,
|
||||
],
|
||||
);
|
||||
@@ -334,8 +336,8 @@ export class ExtensionService {
|
||||
} else {
|
||||
const inserted = await tx.query<{ id: string }>(
|
||||
`INSERT INTO atlas.product_variants
|
||||
(workspace_id, product_id, source_variant_key, source_sku, display_name, sort_order)
|
||||
VALUES ($1, $2, $3, $4, $5, $6) RETURNING id`,
|
||||
(workspace_id, product_id, source_variant_key, source_sku, display_name, sort_order, purchase_cost_cny)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, ROUND($7::numeric, 2)) RETURNING id`,
|
||||
[
|
||||
workspaceId,
|
||||
productId,
|
||||
@@ -343,6 +345,7 @@ export class ExtensionService {
|
||||
variant.sourceSku ?? null,
|
||||
variant.displayName,
|
||||
index,
|
||||
sourcePurchaseCost(payload.source.platform, variant),
|
||||
],
|
||||
);
|
||||
variantId = inserted.rows[0].id;
|
||||
@@ -486,3 +489,13 @@ function sourceState(payload: CollectedProductPayload) {
|
||||
sourcePrice: payload.common.sourcePrice,
|
||||
};
|
||||
}
|
||||
|
||||
/** 仅将 1688 明确标为人民币的逐 SKU 来源价写入采购价。 */
|
||||
function sourcePurchaseCost(
|
||||
platform: CollectedProductPayload['source']['platform'],
|
||||
variant: CollectedProductPayload['variants'][number] | { sourceVariantKey: null },
|
||||
) {
|
||||
return platform === '1688' && 'sourcePrice' in variant && variant.sourcePrice?.currencyCode === 'CNY'
|
||||
? variant.sourcePrice.amount
|
||||
: null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user