‹ 首页

domain-ecommerce

@signalpilot-labs · 收录于 5 天前 · 上游提交 6 天前

E-commerce domain knowledge: transaction lifecycle, driving tables, status filtering.

适合你,如果需要了解电商交易流程和状态过滤规则

/ 通过 npx 安装 校验哈希
npx oh-my-skill add signalpilot-labs/signalpilot/domain-ecommerce
/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- signalpilot-labs/signalpilot/domain-ecommerce
/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify signalpilot-labs/signalpilot/domain-ecommerce
安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
473GitHub stars
~1.1K上下文体积 · 单文件
索引托管

怎么用

商店整理自技能原文 · 版本 436a4c4 · 表述以原文为准
它做什么

Claude 在回答电商数据分析问题时,会遵循交易生命周期规则:只将已履行或已发货的订单计为收入,排除已退货、已退款和已取消的订单;在聚合数据时始终从事实表驱动,并正确使用 WHERE 过滤而非 CASE WHEN;如果存在单独的退货源表,则不添加退货过滤;客户健康评分使用等宽百分比带。

什么时候触发

当用户要求计算电商收入、销售额、订单数、客户健康评分等指标,或要求编写 SQL 分析电商交易数据时触发。

装好后可以这样说
Claude 会自动排除退货、退款和取消的订单。
技能原文 SKILL.md作者撰写 · Apache-2.0 · 436a4c4

E-Commerce Domain Knowledge

WARNING: Return Filtering

BEFORE writing any purchase or revenue metric, check: does a separate returns source table exist? A "separate returns table" means a distinct raw source table (not a dbt model or ref) that records returns independently. A downstream dbt model like lost_revenue that aggregates returns FROM the same fact table is NOT a separate returns table.

IF YES (a raw source table for returns exists, separate from the main fact table) - the main fact table records only sales. Do NOT add a return filter. Filtering drops valid sales rows that are tracked in the other table.

IF NO (returns are rows in the same fact table via a status/flag column, even if a dbt model aggregates those returns separately) - Exclude them with WHERE status_col NOT IN (...) BEFORE any GROUP BY. Use WHERE, not CASE WHEN - CASE WHEN zeroes out return rows but keeps return-only entities in the output with fake purchase_total=0. A customer who bought 5 items and returned 3 made 2 purchases - not 5.

Driving Table

When a model computes metrics by aggregating a fact table (SUM, COUNT, AVG on transactions), the fact aggregation MUST be the FROM clause - driving from the dimension table and LEFT JOINing facts produces rows for entities with zero activity, inflating row counts with NULL or zero metrics.

LEFT JOIN the dimension table onto the fact aggregation for enrichment (names, addresses). The dimension does NOT control which entities appear - the fact table does. If a customer has no qualifying rows in the fact table after status filtering, that customer has no data to report and MUST NOT appear in the output.

Exception - calendar-spine models (daily/weekly/monthly reports): When a model CROSS JOINs a date spine with a shop/entity, the date spine drives the FROM clause - NOT the fact table. Days with zero activity MUST appear in the output with metric columns COALESCE'd to 0. This is the opposite of the fact-drives rule above. The calendar ensures every date appears regardless of whether transactions occurred. Identify calendar-spine models by: CROSS JOIN with a date/calendar table, or YML description mentioning "daily", "weekly", or "per day."

Transaction Lifecycle

An order moves through stages. Not every row in a transaction table is a completed sale:

  1. Placed → customer submits an order
  2. Authorized → payment is approved but not yet captured
  3. Fulfilled / Shipped / Delivered → goods sent or received - this is revenue
  4. Returned → customer sends goods back - this offsets revenue
  5. Refunded → money returned to customer - this offsets revenue
  6. Cancelled / Voided → order was abandoned or reversed before fulfillment - not revenue

A fact table may contain rows from ALL of these stages. Only fulfilled/delivered rows count as revenue. Returns and refunds are separate metrics. Cancelled orders are neither.

Revenue Metrics MUST Exclude Non-Sale Events

A purchase or revenue total counts ONLY completed sales. Returned, refunded, and cancelled items are NOT revenue - they are reversals or abandonments. If a transaction table has a status/flag column, revenue metrics MUST exclude these negative event types.

BEFORE writing any SUM for a revenue metric, run SELECT DISTINCT <status_col> on the table in your FROM clause - not its raw source (intermediate models rename columns). Find which values represent returns, refunds, or cancellations from sibling models or existing WHERE clauses. Then exclude them with WHERE status_col NOT IN (...). Keep ALL other values - they are valid sales regardless of what their codes mean.

Customer Health Scoring

When categorizing entities into health tiers (green/yellow/orange/red, good/fair/poor, A/B/C/D), use equal-width percentage bands unless the YML description specifies different thresholds - guessing custom breakpoints from data distributions produces arbitrary boundaries that vary between runs. For a 0-100% range with 4 tiers: 0-25%, 25-50%, 50-75%, 75-100%.

If a computed metric exceeds 100% (e.g., returns exceed purchases), that entity is an anomaly. Set its category to NULL - it does not belong in any defined tier.

Common Traps
  1. Guessing the purchase value: Status columns often have codes or abbreviations. If you only include the one value you THINK means "purchase," you miss other valid purchase states. Exclude the known negative values instead.
  2. No filter at all: Summing all rows mixes purchases + returns + cancellations. Return-only customers appear in purchase reports with fake amounts.
  3. CASE WHEN instead of WHERE: Zeroing out return rows with CASE WHEN keeps return-only entities in the GROUP BY with purchase_total=0. Use WHERE to exclude them from the FROM entirely.
按 Apache-2.0 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。