cangku/backend/model/KpiItems.js

205 lines
4.0 KiB
JavaScript

// Cube.js 数据模型 - 业绩与退款 KPI
// 基于 jst_goods_profit_kpi_items_afs 表
cube(`KpiItems`, {
sql: `SELECT * FROM rpt.jst_goods_profit_kpi_items_afs`,
measures: {
count: {
type: `count`,
title: `总记录数`
},
// --- 销售相关 ---
totalGoodsAmount: {
sql: `undefined21`, // 商品金额
type: `sum`,
format: `currency`,
title: `商品总金额`
},
totalPayment: {
sql: `undefined26`, // 付款金额
type: `sum`,
format: `currency`,
title: `总付款金额`
},
totalCost: {
sql: `undefined22`, // 商品成本
type: `sum`,
format: `currency`,
title: `总成本`
},
totalRealSendAmount: {
sql: `undefined29`, // 实发金额
type: `sum`,
format: `currency`,
title: `实发总金额`
},
totalRealSendCount: {
sql: `undefined30`, // 实发数量
type: `sum`,
title: `实发总数量`
},
totalFreightIncome: {
sql: `undefined25`, // 运费收入
type: `sum`,
format: `currency`,
title: `运费收入`
},
// --- 退款相关 ---
totalRefundAmountBeforeSend: {
sql: `undefined43`, // 发货前退款金额
type: `sum`,
format: `currency`,
title: `发货前退款金额`
},
totalRefundAmountAfterSend: {
sql: `undefined52`, // 发货后退款金额
type: `sum`,
format: `currency`,
title: `发货后退款金额`
},
totalRefundAmount: {
sql: `${totalRefundAmountBeforeSend} + ${totalRefundAmountAfterSend}`,
type: `number`,
format: `currency`,
title: `总退款金额`
},
// --- 利润相关 (估算) ---
grossProfit: {
sql: `${totalPayment} - ${totalCost}`,
type: `number`,
format: `currency`,
title: `毛利`
}
},
dimensions: {
// --- 标识符 ---
id: {
sql: `undefined1`, // 内部订单号作为主键假设
type: `string`,
primaryKey: true,
title: `内部订单号`
},
onlineOrderId: {
sql: `undefined2`, // 线上订单号
type: `string`,
title: `线上订单号`
},
subOrderId: {
sql: `undefined3`, // 子订单号
type: `string`,
title: `子订单号`
},
refundId: {
sql: `undefined4`, // 售后单号
type: `string`,
title: `售后单号`
},
// --- 时间维度 ---
payTime: {
sql: `undefined5`, // 支付时间
type: `time`,
title: `支付时间`
},
sendTime: {
sql: `undefined6`, // 发货时间
type: `time`,
title: `发货时间`
},
orderTime: {
sql: `undefined7`, // 订单时间
type: `time`,
title: `订单时间`
},
// --- 商品维度 ---
skuId: {
sql: `undefined10`, // 商品编码
type: `string`,
title: `商品编码`
},
iId: {
sql: `undefined11`, // 款式编码
type: `string`,
title: `款式编码`
},
brand: {
sql: `undefined15`, // 品牌
type: `string`,
title: `品牌`
},
category: {
sql: `undefined16`, // 分类
type: `string`,
title: `分类`
},
productName: {
sql: `undefined36`, // 线上商品名称
type: `string`,
title: `商品名称`
},
// --- 店铺/渠道维度 ---
shopName: {
sql: `undefined8`, // 店铺名称
type: `string`,
title: `店铺名称`
},
// --- 地理维度 ---
province: {
sql: `undefined74`, // 省
type: `string`,
title: `省份`
},
city: {
sql: `undefined75`, // 市
type: `string`,
title: `城市`
},
// --- 物流维度 ---
expressCompany: {
sql: `undefined73`, // 快递公司
type: `string`,
title: `快递公司`
},
warehouse: {
sql: `undefined66`, // 发货仓库
type: `string`,
title: `发货仓库`
}
}
});