refactor(finance): 成本模型与履约方式正交,拆分成本中心巨型文件
后端: - 删除 services/admin/admin-cost-center-service.ts(4,248 行),拆为 services/cost-center/ 下 5 个模块: cost-center-shared(类型/枚举/归一化/映射/costModelScopeSql)、 cost-center-overview(总览与选项)、 product-catalog(商品与渠道映射)、 template-bootstrap(模板引导、自动发货同步、工单证据回填)、 cost-definition(成本项/版本/异常/预览/快照) - cost_items.carrier_type / cost_type 改为单一 cost_model;专属模型只对 对应履约方式生效,通用模型对所有履约方式生效 - cost_snapshots / cost_exceptions 删除载体列;按履约方式筛异常改用 IN 半连接(248k 异常下 EXISTS 逐行回表 2.7s -> 170ms) - sales_daily_facts.carrier_type -> fulfillment_mode - 人工支出按 cost_model 归类;履约方式只读 order_items.fulfillment_mode - 移除 syncOpenCostExceptionCarrierTypes:异常表已无载体列可同步 前端: - AdminCostCenterPage.tsx(2,887 行 -> 18 行转发),拆为 pages/admin/cost-center/ 下 8 个 Panel + shared + CostCenterContext - CostCarrierType 删除;新增 FulfillmentMode / ProductSource / CostModel - 销售毛利页 carrierType -> fulfillmentMode 同步补两个索引:idx_order_items_fulfillment_id(异常半连接)、 idx_work_categories_name(商品目录分类 lateral join)。
This commit is contained in:
@@ -32,22 +32,21 @@ import { ADMIN_DEFAULT_PAGE_SIZE, buildAdminTablePagination } from '@/utils/admi
|
||||
import { hasAdminPermission } from '@/utils/admin-auth'
|
||||
import { formatMoney } from './panels/shared'
|
||||
|
||||
type FilterForm = { dateRange?: unknown; provider?: string; carrierType?: string }
|
||||
type FilterForm = { dateRange?: unknown; provider?: string; fulfillmentMode?: string }
|
||||
|
||||
const CARRIER_OPTIONS = [
|
||||
{ value: '', label: '全部载体' },
|
||||
{ value: 'affiliate_dash', label: '自动发货' },
|
||||
const FULFILLMENT_MODE_OPTIONS = [
|
||||
{ value: '', label: '全部履约方式' },
|
||||
{ value: 'work_order', label: '接单平台' },
|
||||
{ value: 'affiliate_dash', label: '自动发货' },
|
||||
{ value: 'legacy_platform', label: '历史平台' },
|
||||
{ value: 'manual', label: '人工客服' },
|
||||
{ value: 'shared', label: '共用' },
|
||||
]
|
||||
|
||||
const CARRIER_LABEL: Record<string, string> = {
|
||||
affiliate_dash: '自动发货',
|
||||
const FULFILLMENT_MODE_LABEL: Record<string, string> = {
|
||||
work_order: '接单平台',
|
||||
affiliate_dash: '自动发货',
|
||||
legacy_platform: '历史平台',
|
||||
manual: '人工客服',
|
||||
shared: '共用',
|
||||
unknown: '未知',
|
||||
}
|
||||
|
||||
const COST_STAGE_LABEL: Record<string, { label: string; color: string }> = {
|
||||
@@ -65,8 +64,8 @@ export default function AdminSalesProfitPage() {
|
||||
dateFrom: string
|
||||
dateTo: string
|
||||
provider: string
|
||||
carrierType: string
|
||||
}>({ dateFrom: '', dateTo: '', provider: '', carrierType: '' })
|
||||
fulfillmentMode: string
|
||||
}>({ dateFrom: '', dateTo: '', provider: '', fulfillmentMode: '' })
|
||||
const [page, setPage] = useState(1)
|
||||
const [pageSize, setPageSize] = useState(ADMIN_DEFAULT_PAGE_SIZE)
|
||||
const [rebuilding, setRebuilding] = useState(false)
|
||||
@@ -90,14 +89,14 @@ export default function AdminSalesProfitPage() {
|
||||
dateFrom: range[0] ? dayjs(range[0]).format('YYYY-MM-DD') : '',
|
||||
dateTo: range[1] ? dayjs(range[1]).format('YYYY-MM-DD') : '',
|
||||
provider: values.provider || '',
|
||||
carrierType: values.carrierType || '',
|
||||
fulfillmentMode: values.fulfillmentMode || '',
|
||||
})
|
||||
}
|
||||
|
||||
function resetFilters() {
|
||||
form.resetFields()
|
||||
setPage(1)
|
||||
setFilters({ dateFrom: '', dateTo: '', provider: '', carrierType: '' })
|
||||
setFilters({ dateFrom: '', dateTo: '', provider: '', fulfillmentMode: '' })
|
||||
}
|
||||
|
||||
async function rebuildFacts() {
|
||||
@@ -169,11 +168,13 @@ export default function AdminSalesProfitPage() {
|
||||
},
|
||||
]
|
||||
|
||||
const carrierColumns: TableColumnsType<NonNullable<typeof overview>['byCarrier'][number]> = [
|
||||
const fulfillmentModeColumns: TableColumnsType<
|
||||
NonNullable<typeof overview>['byFulfillmentMode'][number]
|
||||
> = [
|
||||
{
|
||||
title: '履约载体',
|
||||
dataIndex: 'carrierType',
|
||||
render: (value: string) => CARRIER_LABEL[value] || value,
|
||||
title: '履约方式',
|
||||
dataIndex: 'fulfillmentMode',
|
||||
render: (value: string) => FULFILLMENT_MODE_LABEL[value] || value,
|
||||
},
|
||||
{ title: '订单项', dataIndex: 'itemCount', width: 90 },
|
||||
{ title: '销售收入', dataIndex: 'grossRevenueFen', render: formatMoney },
|
||||
@@ -209,10 +210,10 @@ export default function AdminSalesProfitPage() {
|
||||
row.canonicalProductId ? value : <Tag color="orange">未归一</Tag>,
|
||||
},
|
||||
{
|
||||
title: '载体',
|
||||
dataIndex: 'carrierType',
|
||||
title: '履约方式',
|
||||
dataIndex: 'fulfillmentMode',
|
||||
width: 100,
|
||||
render: (value: string) => CARRIER_LABEL[value] || value,
|
||||
render: (value: string) => FULFILLMENT_MODE_LABEL[value] || value,
|
||||
},
|
||||
{ title: '订单项', dataIndex: 'itemCount', width: 80 },
|
||||
{ title: '销售收入', dataIndex: 'grossRevenueFen', width: 120, render: formatMoney },
|
||||
@@ -254,7 +255,7 @@ export default function AdminSalesProfitPage() {
|
||||
initialValues={{
|
||||
dateRange: [dayjs().subtract(29, 'day'), dayjs()],
|
||||
provider: '',
|
||||
carrierType: '',
|
||||
fulfillmentMode: '',
|
||||
}}
|
||||
>
|
||||
<Form.Item name="dateRange" label="销售日期">
|
||||
@@ -271,8 +272,8 @@ export default function AdminSalesProfitPage() {
|
||||
]}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item name="carrierType" label="载体">
|
||||
<Select style={{ width: 150 }} options={CARRIER_OPTIONS} />
|
||||
<Form.Item name="fulfillmentMode" label="履约方式">
|
||||
<Select style={{ width: 150 }} options={FULFILLMENT_MODE_OPTIONS} />
|
||||
</Form.Item>
|
||||
<Form.Item>
|
||||
<Space>
|
||||
@@ -412,14 +413,14 @@ export default function AdminSalesProfitPage() {
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'carrier',
|
||||
label: '载体',
|
||||
key: 'fulfillment-mode',
|
||||
label: '履约方式',
|
||||
children: (
|
||||
<Table
|
||||
rowKey="carrierType"
|
||||
rowKey="fulfillmentMode"
|
||||
size="small"
|
||||
columns={carrierColumns}
|
||||
dataSource={overview?.byCarrier || []}
|
||||
columns={fulfillmentModeColumns}
|
||||
dataSource={overview?.byFulfillmentMode || []}
|
||||
loading={overviewQuery.isLoading}
|
||||
pagination={false}
|
||||
scroll={{ x: 800 }}
|
||||
|
||||
Reference in New Issue
Block a user