SuperAPI AI 工具集

stock-velocity-report

数据与分析

查看项目

更新于 10-15 09:39

技能介绍

用途

stock-velocity-report 是一个只读的 Shopify 管理技能,用于为补货计划计算每个已备货 SKU 的两项关键指标:

  • 供应天数(Days of Supply,DoS):按当前销售速度,剩余库存还能支撑多少天。
  • 售罄率(Sell-Through Rate):在统计周期内,已售数量占(已售 + 现有库存)的百分比。

该技能为只读操作,不执行任何数据变更(no mutations),可随时安全运行。

前置条件

  • 已认证的 Shopify CLI 会话: shopify store auth --store <domain> --scopes read_products,read_orders,read_inventory
  • API 权限范围:read_products、read_orders、read_inventory

参数

参数 类型 必填 默认值 说明
store string 是 — 店铺域名(例如 mystore.myshopify.com)
days_back integer 否 30 用于计算销售速度的销售窗口天数
dos_alert_threshold integer 否 14 供应天数低于此值的 SKU 会被标记
vendor_filter string 否 — 可选,按供应商限定报告范围
format string 否 human 输出格式:human 或 json

工作流程

  1. productVariants 查询:输入 first: 250、select sku、inventoryQuantity、inventoryItem { id }、分页游标;预期输出为所有变体及其现有数量,分页直到 hasNextPage: false。
  2. orders 查询:输入 query: "created_at:>='<NOW - days_back days>'"、first: 250、select lineItems { variant { id }, quantity }、分页游标;预期输出为窗口期内每个变体的售出数量。
  3. inventoryItems 查询:按已备货变体的库存项 ID 批量查询;预期输出为每个库存项的成本与是否追踪状态。

按 SKU 计算:

  • daily_velocity = units_sold / days_back
  • days_of_supply = on_hand / daily_velocity(当 velocity = 0 时为 ∞)
  • sell_through_rate = units_sold / (units_sold + on_hand) × 100

GraphQL 操作

以下查询已针对 api_version 2025-01 验证:

# productVariants:query
query VariantsForVelocity($query: String, $after: String) {
  productVariants(first: 250, after: $after, query: $query) {
    edges {
      node {
        id
        sku
        inventoryQuantity
        product {
          id
          title
          vendor
        }
        inventoryItem {
          id
        }
      }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}

# orders:query
query SalesVelocityData($query: String!, $after: String) {
  orders(first: 250, after: $after, query: $query) {
    edges {
      node {
        lineItems(first: 50) {
          edges {
            node {
              quantity
              variant {
                id
                sku
              }
            }
          }
        }
      }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}

# inventoryItems:query
query InventoryItemDetails($ids: [ID!]!) {
  nodes(ids: $ids) {
    ... on InventoryItem {
      id
      sku
      unitCost {
        amount
        currencyCode
      }
      tracked
    }
  }
}

会话跟踪

技能要求在每一阶段输出进度信息。开始时输出:

╔══════════════════════════════════════════════╗
║  SKILL: Stock Velocity Report                ║
║  Store: <store domain>                       ║
║  Started: <YYYY-MM-DD HH:MM UTC>             ║
╚══════════════════════════════════════════════╝

每步之后输出:

[N/TOTAL] <QUERY|MUTATION>  <OperationName>
          → Params: <brief summary of key inputs>
          → Result: <count or outcome>

完成时,若 format 为 human(默认):

══════════════════════════════════════════════
STOCK VELOCITY REPORT  (<days_back>-day window)
  SKUs analyzed:              <n>
  Critical (< <threshold> DoS): <n>
  Healthy (≥ <threshold> DoS):  <n>
  Zero velocity (no sales):   <n>

  Critical SKUs:
    "<product>"  SKU: <sku>  DoS: <n>d  Velocity: <n>/day
  Output: velocity_<date>.csv
══════════════════════════════════════════════

若 format 为 json,输出:

{
  "skill": "stock-velocity-report",
  "store": "<domain>",
  "period_days": 30,
  "dos_alert_threshold": 14,
  "skus_analyzed": 0,
  "critical_count": 0,
  "healthy_count": 0,
  "zero_velocity_count": 0,
  "output_file": "velocity_<date>.csv"
}

输出格式

生成 CSV 文件 velocity_<YYYY-MM-DD>.csv,包含列: variant_id, sku, product_title, vendor, on_hand, units_sold, daily_velocity, days_of_supply, sell_through_pct, alert

错误处理

错误 原因 恢复方式
THROTTLED 超出 API 速率限制 等待 2 秒,最多重试 3 次
所有 SKU 零速度 窗口期内无订单 将所有已备货 SKU 标记为“无销售”;检查日期窗口
变体没有库存项 捆绑商品或虚拟商品 跳过库存数据,仅根据订单计算速度

最佳实践

  • days_back: 30 适合快销品;对于动销较慢或季节性商品,可使用 days_back: 90。
  • DoS < 14 且正在做营销活动的 SKU 是补货最高优先级——请结合供应商交货周期交叉参考。
  • 零速度 SKU 可作为呆滞库存识别工作流的候选——如果 90 天以上无销售且仍有库存,可考虑降价或停售。
  • 旺季期间每周运行一次,以便在快速消耗的 SKU 缺货前及时发现。

限制

该技能为只读,不执行任何写操作。使用前需要已认证的 Shopify CLI 会话及相应 API 权限。其他平台支持、定价或收费信息暂未提供。