SuperAPI AI 工具集

shopify-admin-stock-velocity-report

办公与效率

查看项目

更新于 10-15 10:43

技能介绍

用途

本技能为补货规划计算两个关键指标,覆盖每一个有库存的 SKU:

  • Days of Supply (DoS,库存可用天数):按当前销售速度,现有库存还能支撑多少天。
  • Sell-Through Rate (售出率):期间内已售出库存占总到货库存的百分比。

该技能为只读,不执行任何变更操作。

前提条件

  • 已认证的 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 — query

    • 输入:first: 250,选择 sku、inventoryQuantity、inventoryItem { id }、分页游标
    • 预期输出:所有变体及其在手数量;分页直到 hasNextPage: false
  2. orders — query

    • 输入:query: "created_at:>='<NOW - days_back days>'",first: 250,选择 lineItems { variant { id }, quantity }、分页游标
    • 预期输出:窗口内每个变体的售出数量
  3. inventoryItems — query

    • 输入:按有库存变体的 inventory item ID 分批请求
    • 预期输出:每个条目的成本与追踪状态

按 SKU 计算:

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

GraphQL 操作

# productVariants:query — 已针对 api_version 2025-01 验证
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 — 已针对 api_version 2025-01 验证
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 — 已针对 api_version 2025-01 验证
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 标记为 "no sales",检查日期窗口
变体没有库存条目 捆绑或虚拟商品 跳过库存数据,仅根据订单计算速度

最佳实践

  • days_back: 30 适合快消品;慢销或季节性商品可用 days_back: 90。
  • DoS < 14 且正在做营销活动的 SKU 是最高优先级补货对象——需与供应商交期交叉核对。
  • 零速度 SKU 是属于 dead-stock-identifier 工作流的候选:若 90 天以上无销售且仍有库存,可考虑降价或停售。
  • 旺季每周运行一次,可在快销 SKU 断货前及时发现。