优化寄售仓库现货统计与可匹配矩阵
This commit is contained in:
@@ -72,6 +72,14 @@ import {
|
||||
resolveConsignmentSpecValueText,
|
||||
} from '@/utils/consignment-spec-display'
|
||||
import { CONSIGNMENT_SYSTEM_OPTIONS, CONSIGNMENT_ZONE_OPTIONS } from '@/utils/consignment-spec'
|
||||
import {
|
||||
buildConsignmentStockSpecFilter,
|
||||
buildConsignmentStockSpecMatrix,
|
||||
formatConsignmentStockSpecLabel,
|
||||
formatConsignmentStockSpecSummary,
|
||||
isSameConsignmentStockSpec,
|
||||
type ConsignmentStockSpecSummaryItem,
|
||||
} from '@/utils/consignment-stock-summary'
|
||||
import { formatDateTime } from '@/utils/date-time'
|
||||
|
||||
const { Text } = Typography
|
||||
@@ -148,6 +156,10 @@ export default function ConsignmentInventoryPanel() {
|
||||
const [categoryId, setCategoryId] = useState<number | null>(null)
|
||||
const [categoryExpandedKeys, setCategoryExpandedKeys] = useState<Array<string | number>>([])
|
||||
const [specFilters, setSpecFilters] = useState<Record<string, string>>({})
|
||||
/** 点击现货汇总标签产生的列表筛选;不参与顶部统计和汇总本身。 */
|
||||
const [stockSpecFilter, setStockSpecFilter] = useState<ConsignmentStockSpecSummaryItem | null>(
|
||||
null,
|
||||
)
|
||||
const [allowMatching, setAllowMatching] = useState<string>('')
|
||||
// 对接客服多选:0 作为「未指定」哨兵值,与真实客服 id 分开。
|
||||
const [contactSupporterIds, setContactSupporterIds] = useState<number[]>([])
|
||||
@@ -297,11 +309,22 @@ export default function ConsignmentInventoryPanel() {
|
||||
}, [dynamicFilters, specFilters])
|
||||
const specFilterParams =
|
||||
Object.keys(specFilterPayload).length > 0 ? JSON.stringify(specFilterPayload) : undefined
|
||||
const stockSpecFilterPayload = useMemo(
|
||||
() => (stockSpecFilter ? buildConsignmentStockSpecFilter(stockSpecFilter) : {}),
|
||||
[stockSpecFilter],
|
||||
)
|
||||
// 现货汇总标签只筛选下方列表;统计和汇总继续显示当前分类下的完整现货分布。
|
||||
const listSpecFilterPayload = { ...specFilterPayload, ...stockSpecFilterPayload }
|
||||
const listSpecFilterParams =
|
||||
Object.keys(listSpecFilterPayload).length > 0
|
||||
? JSON.stringify(listSpecFilterPayload)
|
||||
: undefined
|
||||
// 对接客服筛选只按 id 传参;未指定单独标记,后端与多选 id 取并集。
|
||||
const contactSupporterIdsParam = contactSupporterIds.filter((id) => id > 0).join(',') || undefined
|
||||
const includeUnassignedContactSupporter = contactSupporterIds.includes(0)
|
||||
|
||||
function updateSpecFilter(field: ConsignmentInventoryFilterField, value: string) {
|
||||
setStockSpecFilter(null)
|
||||
setSpecFilters((current) => {
|
||||
const next = { ...current }
|
||||
if (value) next[field.key] = value
|
||||
@@ -311,13 +334,24 @@ export default function ConsignmentInventoryPanel() {
|
||||
setPage(1)
|
||||
}
|
||||
|
||||
function handleStockSpecClick(item: ConsignmentStockSpecSummaryItem) {
|
||||
if (isSameConsignmentStockSpec(stockSpecFilter, item)) {
|
||||
setStockSpecFilter(null)
|
||||
} else {
|
||||
setStockSpecFilter(item)
|
||||
setAllowMatching('yes')
|
||||
setStatus('in_stock')
|
||||
}
|
||||
setPage(1)
|
||||
}
|
||||
|
||||
// 数据查询
|
||||
const inventoriesQuery = useQuery({
|
||||
queryKey: [
|
||||
'admin-consignment-inventories',
|
||||
status,
|
||||
categoryId,
|
||||
specFilterParams,
|
||||
listSpecFilterParams,
|
||||
allowMatching,
|
||||
contactSupporterIdsParam,
|
||||
includeUnassignedContactSupporter,
|
||||
@@ -331,7 +365,7 @@ export default function ConsignmentInventoryPanel() {
|
||||
fetchAdminConsignmentInventories({
|
||||
status: status === 'all' ? undefined : status,
|
||||
categoryId: categoryId ?? undefined,
|
||||
specFilters: specFilterParams,
|
||||
specFilters: listSpecFilterParams,
|
||||
allowMatching: allowMatching === 'yes' ? true : allowMatching === 'no' ? false : undefined,
|
||||
contactSupporterIds: contactSupporterIdsParam,
|
||||
contactSupporterUnassigned: includeUnassignedContactSupporter || undefined,
|
||||
@@ -364,6 +398,42 @@ export default function ConsignmentInventoryPanel() {
|
||||
const items = inventoriesQuery.data?.data.items || []
|
||||
const total = inventoriesQuery.data?.data.total || 0
|
||||
const stats = statsQuery.data?.data
|
||||
const stockSpecMatrixRows = useMemo(
|
||||
() => buildConsignmentStockSpecMatrix(stats?.byStockSpec),
|
||||
[stats],
|
||||
)
|
||||
const stockSpecMatrixGroups = useMemo(() => {
|
||||
const groups = new Map<string, typeof stockSpecMatrixRows>()
|
||||
for (const row of stockSpecMatrixRows) {
|
||||
const group = groups.get(row.system) || []
|
||||
group.push(row)
|
||||
groups.set(row.system, group)
|
||||
}
|
||||
return [...groups.entries()].map(([system, rows]) => ({ system, rows }))
|
||||
}, [stockSpecMatrixRows])
|
||||
|
||||
function resolveStockSpecSystemPalette(system: string) {
|
||||
if (system === '苹果') {
|
||||
return { background: '#e6f4ff', border: '#91caff', color: '#0958d9' }
|
||||
}
|
||||
if (system === '安卓') {
|
||||
return { background: '#f6ffed', border: '#b7eb8f', color: '#389e0d' }
|
||||
}
|
||||
return { background: '#f9f0ff', border: '#d3adf7', color: '#531dab' }
|
||||
}
|
||||
|
||||
function resolveStockSpecSeriesPalette(series: string) {
|
||||
if (series === '暗潮') {
|
||||
return { background: '#e6f4ff', color: '#0958d9' }
|
||||
}
|
||||
if (series === '怒嚎') {
|
||||
return { background: '#fff7e6', color: '#d46b08' }
|
||||
}
|
||||
if (series === '血宴') {
|
||||
return { background: '#fff0f6', color: '#c41d7f' }
|
||||
}
|
||||
return { background: '#f9f0ff', color: '#531dab' }
|
||||
}
|
||||
|
||||
async function refresh() {
|
||||
await Promise.all([inventoriesQuery.refetch(), statsQuery.refetch()])
|
||||
@@ -956,7 +1026,7 @@ export default function ConsignmentInventoryPanel() {
|
||||
<div style={{ marginTop: 4, display: 'flex', flexWrap: 'wrap', gap: 6 }}>
|
||||
{(stats?.byBuyer || []).map((b) => (
|
||||
<Tag key={b.buyer_name} color={BUYER_COLORS[b.buyer_name] || 'blue'}>
|
||||
{b.buyer_name}: {b.count}件 (在库) / ¥{(b.total_cost_fen / 100).toFixed(0)}
|
||||
{b.buyer_name}: {b.count}件 (在库) / ¥{(b.total_cost_fen / 100).toFixed(2)}
|
||||
</Tag>
|
||||
))}
|
||||
</div>
|
||||
@@ -965,6 +1035,209 @@ export default function ConsignmentInventoryPanel() {
|
||||
</Row>
|
||||
</Card>
|
||||
|
||||
{/* 现货分布:只统计在库剩余数量;璀璨数合并计入,不单独拆分。 */}
|
||||
<Card
|
||||
size="small"
|
||||
bordered={false}
|
||||
className="platform-summary-strip-card"
|
||||
styles={{ body: { padding: '6px 10px' } }}
|
||||
>
|
||||
<Space direction="vertical" size={4} style={{ width: '100%' }}>
|
||||
<Space size={6} wrap style={{ width: '100%', justifyContent: 'space-between' }}>
|
||||
<Space size={8} wrap>
|
||||
<Text strong>现货库存</Text>
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>
|
||||
仅统计在库且允许匹配的剩余数量,璀璨已合并计入,不单独拆分
|
||||
</Text>
|
||||
{stockSpecFilter ? (
|
||||
<Tag
|
||||
color="orange"
|
||||
closable
|
||||
onClose={(event) => {
|
||||
event.preventDefault()
|
||||
setStockSpecFilter(null)
|
||||
setPage(1)
|
||||
}}
|
||||
>
|
||||
列表筛选:{formatConsignmentStockSpecLabel(stockSpecFilter)}(在库可匹配)
|
||||
</Tag>
|
||||
) : null}
|
||||
</Space>
|
||||
<Button
|
||||
size="small"
|
||||
icon={<ReloadOutlined />}
|
||||
loading={statsQuery.isFetching}
|
||||
onClick={() => void refresh()}
|
||||
>
|
||||
刷新
|
||||
</Button>
|
||||
</Space>
|
||||
{stockSpecMatrixGroups.length > 0 ? (
|
||||
<div style={{ width: '100%', overflowX: 'auto' }}>
|
||||
<table
|
||||
style={{
|
||||
width: '100%',
|
||||
minWidth: 1220,
|
||||
borderCollapse: 'separate',
|
||||
borderSpacing: 0,
|
||||
tableLayout: 'fixed',
|
||||
}}
|
||||
>
|
||||
<colgroup>
|
||||
<col style={{ width: 66 }} />
|
||||
<col style={{ width: 90 }} />
|
||||
{Array.from({ length: 7 }, (_, index) => (
|
||||
<col key={index} style={{ width: 150 }} />
|
||||
))}
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
{['系统', '系列', '1钻', '2钻', '3钻', '4钻', '5钻', '6钻', '7钻'].map(
|
||||
(label, index) => (
|
||||
<th
|
||||
key={label}
|
||||
style={{
|
||||
padding: '3px 6px',
|
||||
textAlign: 'center',
|
||||
fontSize: 12,
|
||||
color: '#595959',
|
||||
fontWeight: 600,
|
||||
background: '#fafafa',
|
||||
borderTop: '1px solid #f0f0f0',
|
||||
borderBottom: '1px solid #f0f0f0',
|
||||
borderRight: index < 8 ? '1px solid #f0f0f0' : undefined,
|
||||
}}
|
||||
>
|
||||
{label}
|
||||
</th>
|
||||
),
|
||||
)}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{stockSpecMatrixGroups.map((group, groupIndex) => {
|
||||
const systemPalette = resolveStockSpecSystemPalette(group.system)
|
||||
return group.rows.map((row, rowIndex) => {
|
||||
const seriesPalette = resolveStockSpecSeriesPalette(row.series)
|
||||
return (
|
||||
<tr key={`${row.system}-${row.series}`}>
|
||||
{rowIndex === 0 ? (
|
||||
<td
|
||||
rowSpan={group.rows.length}
|
||||
style={{
|
||||
padding: '3px 6px',
|
||||
textAlign: 'center',
|
||||
fontWeight: 600,
|
||||
color: systemPalette.color,
|
||||
background: systemPalette.background,
|
||||
borderTop: groupIndex > 0 ? '4px solid #f5f7fb' : undefined,
|
||||
borderRight: '1px solid #f0f0f0',
|
||||
borderBottom: '1px solid #f0f0f0',
|
||||
}}
|
||||
>
|
||||
{group.system}
|
||||
</td>
|
||||
) : null}
|
||||
<td
|
||||
style={{
|
||||
padding: '3px 6px',
|
||||
textAlign: 'center',
|
||||
fontWeight: 600,
|
||||
color: seriesPalette.color,
|
||||
background: seriesPalette.background,
|
||||
borderTop:
|
||||
rowIndex === 0 && groupIndex > 0 ? '4px solid #f5f7fb' : undefined,
|
||||
borderRight: '1px solid #f0f0f0',
|
||||
borderBottom: '1px solid #f0f0f0',
|
||||
}}
|
||||
>
|
||||
{row.series}
|
||||
</td>
|
||||
{row.cells.map((cell, cellIndex) => {
|
||||
const item = cell.item
|
||||
const selected = isSameConsignmentStockSpec(stockSpecFilter, item)
|
||||
const displayItem = item || {
|
||||
system: row.system,
|
||||
series: row.series,
|
||||
diamond_level: cell.diamond_level,
|
||||
quantity: 0,
|
||||
}
|
||||
const displayLabel = formatConsignmentStockSpecSummary(displayItem)
|
||||
return (
|
||||
<td
|
||||
key={cell.diamond_level}
|
||||
style={{
|
||||
padding: 2,
|
||||
textAlign: 'center',
|
||||
borderTop:
|
||||
rowIndex === 0 && groupIndex > 0
|
||||
? '4px solid #f5f7fb'
|
||||
: undefined,
|
||||
borderRight:
|
||||
cellIndex < row.cells.length - 1
|
||||
? '1px solid #f0f0f0'
|
||||
: undefined,
|
||||
borderBottom: '1px solid #f0f0f0',
|
||||
}}
|
||||
>
|
||||
{item ? (
|
||||
<button
|
||||
type="button"
|
||||
title={`点击筛选:${displayLabel}`}
|
||||
onClick={() => handleStockSpecClick(item)}
|
||||
style={{
|
||||
width: '100%',
|
||||
minHeight: 20,
|
||||
padding: '0 4px',
|
||||
borderRadius: 4,
|
||||
cursor: 'pointer',
|
||||
fontSize: 12,
|
||||
lineHeight: '20px',
|
||||
textAlign: 'center',
|
||||
whiteSpace: 'nowrap',
|
||||
fontWeight: selected ? 700 : 500,
|
||||
color: selected ? '#ad4e00' : systemPalette.color,
|
||||
background: selected ? '#fff7e6' : systemPalette.background,
|
||||
border: `1px solid ${selected ? '#fa8c16' : systemPalette.border}`,
|
||||
}}
|
||||
>
|
||||
{displayLabel}
|
||||
</button>
|
||||
) : (
|
||||
<span
|
||||
style={{
|
||||
display: 'block',
|
||||
minHeight: 20,
|
||||
padding: '0 4px',
|
||||
borderRadius: 4,
|
||||
color: '#bfbfbf',
|
||||
background: '#fafafa',
|
||||
border: '1px solid #f0f0f0',
|
||||
fontSize: 12,
|
||||
lineHeight: '20px',
|
||||
textAlign: 'center',
|
||||
whiteSpace: 'nowrap',
|
||||
}}
|
||||
>
|
||||
{displayLabel}
|
||||
</span>
|
||||
)}
|
||||
</td>
|
||||
)
|
||||
})}
|
||||
</tr>
|
||||
)
|
||||
})
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
) : (
|
||||
<Text type="secondary">暂无在库现货</Text>
|
||||
)}
|
||||
</Space>
|
||||
</Card>
|
||||
|
||||
{/* 筛选过滤工具条 */}
|
||||
<Card size="small">
|
||||
<Space direction="vertical" size={12} style={{ width: '100%' }}>
|
||||
@@ -1031,6 +1304,7 @@ export default function ConsignmentInventoryPanel() {
|
||||
if (typeof value !== 'number' || value <= 0) return
|
||||
setCategoryId(value)
|
||||
setSpecFilters({})
|
||||
setStockSpecFilter(null)
|
||||
setPage(1)
|
||||
}}
|
||||
/>
|
||||
@@ -1112,6 +1386,7 @@ export default function ConsignmentInventoryPanel() {
|
||||
? [dates[0].format(ADMIN_DATE_FORMAT), dates[1].format(ADMIN_DATE_FORMAT)]
|
||||
: null,
|
||||
)
|
||||
setStockSpecFilter(null)
|
||||
setPage(1)
|
||||
}}
|
||||
/>
|
||||
@@ -1664,13 +1939,16 @@ export default function ConsignmentInventoryPanel() {
|
||||
inventoryId={manualMatchItem?.id ?? null}
|
||||
inventoryLabel={manualMatchItem?.itemName}
|
||||
onClose={() => setManualMatchItem(null)}
|
||||
onMatched={() => void inventoriesQuery.refetch()}
|
||||
onMatched={() => void refresh()}
|
||||
/>
|
||||
|
||||
{/* 一键查询待匹配订单:简单只读的待抢单手枪 × 在库手枪看板 */}
|
||||
<ConsignmentPendingMatchModal
|
||||
open={pendingMatchOpen}
|
||||
onClose={() => setPendingMatchOpen(false)}
|
||||
onClose={() => {
|
||||
setPendingMatchOpen(false)
|
||||
void refresh()
|
||||
}}
|
||||
/>
|
||||
|
||||
<ConsignmentMatchLogsModal open={matchLogsOpen} onClose={() => setMatchLogsOpen(false)} />
|
||||
|
||||
@@ -279,6 +279,13 @@ export type ConsignmentStatsSummary = {
|
||||
byShop: Array<{ shop_name: string; count: number }>
|
||||
byBatch: Array<{ inbound_batch: string; count: number; total_cost_fen: number }>
|
||||
bySeries: Array<{ series: string; diamond_level: number; count: number }>
|
||||
/** 现货分布:系统 + 系列 + 钻级 -> 剩余可匹配件数;璀璨数不参与分组。 */
|
||||
byStockSpec: Array<{
|
||||
system: string
|
||||
series: string
|
||||
diamond_level: number
|
||||
quantity: number
|
||||
}>
|
||||
}
|
||||
|
||||
export type ConsignmentMatchResult = {
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
export type ConsignmentStockSpecSummaryItem = {
|
||||
system: string
|
||||
series: string
|
||||
diamond_level: number
|
||||
quantity: number
|
||||
}
|
||||
|
||||
export type ConsignmentStockSpecMatrixCell = {
|
||||
diamond_level: number
|
||||
item?: ConsignmentStockSpecSummaryItem
|
||||
}
|
||||
|
||||
export type ConsignmentStockSpecMatrixRow = {
|
||||
system: string
|
||||
series: string
|
||||
cells: ConsignmentStockSpecMatrixCell[]
|
||||
}
|
||||
|
||||
export const CONSIGNMENT_STOCK_SERIES_ORDER = ['暗潮', '怒嚎', '血宴'] as const
|
||||
export const CONSIGNMENT_STOCK_SYSTEM_ORDER = ['苹果', '安卓'] as const
|
||||
export const CONSIGNMENT_STOCK_DIAMOND_LEVELS = [1, 2, 3, 4, 5, 6, 7] as const
|
||||
|
||||
const UNKNOWN_SPEC_LABEL = '未注明'
|
||||
|
||||
function normalizeText(value: unknown) {
|
||||
const text = String(value ?? '').trim()
|
||||
return text || UNKNOWN_SPEC_LABEL
|
||||
}
|
||||
|
||||
function formatDiamondLevel(value: unknown) {
|
||||
const level = Number(value)
|
||||
return Number.isFinite(level) && level > 0 ? `${Math.round(level)}钻` : '未知钻级'
|
||||
}
|
||||
|
||||
/** 现货汇总标签:系统 + 系列 + 钻级;璀璨数和区服不参与。 */
|
||||
export function formatConsignmentStockSpecLabel(item: ConsignmentStockSpecSummaryItem) {
|
||||
return `${normalizeText(item.system)}${normalizeText(item.series)}${formatDiamondLevel(
|
||||
item.diamond_level,
|
||||
)}`
|
||||
}
|
||||
|
||||
/** 页面展示格式,例如「安卓怒嚎3钻-2件」。 */
|
||||
export function formatConsignmentStockSpecSummary(item: ConsignmentStockSpecSummaryItem) {
|
||||
const quantity = Math.max(0, Math.round(Number(item.quantity) || 0))
|
||||
return `${formatConsignmentStockSpecLabel(item)}-${quantity}件`
|
||||
}
|
||||
|
||||
/** 汇总总件数,用于与顶部「在库数量」做同口径校验。 */
|
||||
export function sumConsignmentStockSpecQuantity(
|
||||
items: ConsignmentStockSpecSummaryItem[] | undefined,
|
||||
) {
|
||||
return (items || []).reduce(
|
||||
(total, item) => total + Math.max(0, Math.round(Number(item.quantity) || 0)),
|
||||
0,
|
||||
)
|
||||
}
|
||||
|
||||
export function isSameConsignmentStockSpec(
|
||||
left: ConsignmentStockSpecSummaryItem | null | undefined,
|
||||
right: ConsignmentStockSpecSummaryItem | null | undefined,
|
||||
) {
|
||||
if (!left || !right) return false
|
||||
return (
|
||||
normalizeText(left.system) === normalizeText(right.system) &&
|
||||
normalizeText(left.series) === normalizeText(right.series) &&
|
||||
Number(left.diamond_level) === Number(right.diamond_level)
|
||||
)
|
||||
}
|
||||
|
||||
/** 点击现货汇总后用于过滤下方列表;璀璨数和区服不进入筛选条件。 */
|
||||
export function buildConsignmentStockSpecFilter(item: ConsignmentStockSpecSummaryItem) {
|
||||
return {
|
||||
system: { value: normalizeText(item.system), match: 'exact' as const },
|
||||
series: { value: normalizeText(item.series), match: 'exact' as const },
|
||||
diamondLevel: {
|
||||
value: String(Math.round(Number(item.diamond_level) || 0)),
|
||||
match: 'exact' as const,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
function sortByKnownOrder(values: string[], order: readonly string[]) {
|
||||
const rank = new Map(order.map((value, index) => [value, index]))
|
||||
return values.sort((left, right) => {
|
||||
const leftRank = rank.get(left)
|
||||
const rightRank = rank.get(right)
|
||||
if (leftRank !== undefined || rightRank !== undefined) {
|
||||
return (leftRank ?? Number.MAX_SAFE_INTEGER) - (rightRank ?? Number.MAX_SAFE_INTEGER)
|
||||
}
|
||||
return left.localeCompare(right, 'zh-CN')
|
||||
})
|
||||
}
|
||||
|
||||
/** 按图片结构生成矩阵:系统分组(苹果在前)→ 系列(暗潮/怒嚎/血宴)→ 1~7 钻。 */
|
||||
export function buildConsignmentStockSpecMatrix(
|
||||
items: ConsignmentStockSpecSummaryItem[] | undefined,
|
||||
): ConsignmentStockSpecMatrixRow[] {
|
||||
const normalizedItems = (items || []).map((item) => ({
|
||||
...item,
|
||||
system: normalizeText(item.system),
|
||||
series: normalizeText(item.series),
|
||||
diamond_level: Math.round(Number(item.diamond_level) || 0),
|
||||
}))
|
||||
const systems = sortByKnownOrder(
|
||||
[...new Set(normalizedItems.map((item) => item.system))],
|
||||
CONSIGNMENT_STOCK_SYSTEM_ORDER,
|
||||
)
|
||||
const seriesList = sortByKnownOrder(
|
||||
[...new Set(normalizedItems.map((item) => item.series))],
|
||||
CONSIGNMENT_STOCK_SERIES_ORDER,
|
||||
)
|
||||
const itemByKey = new Map(
|
||||
normalizedItems.map((item) => [
|
||||
`${item.system}\u0000${item.series}\u0000${item.diamond_level}`,
|
||||
item,
|
||||
]),
|
||||
)
|
||||
|
||||
return systems.flatMap((system) =>
|
||||
seriesList.map((series) => ({
|
||||
system,
|
||||
series,
|
||||
cells: CONSIGNMENT_STOCK_DIAMOND_LEVELS.map((diamondLevel) => ({
|
||||
diamond_level: diamondLevel,
|
||||
item: itemByKey.get(`${system}\u0000${series}\u0000${diamondLevel}`),
|
||||
})),
|
||||
})),
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import test from 'node:test'
|
||||
|
||||
import {
|
||||
buildConsignmentStockSpecFilter,
|
||||
buildConsignmentStockSpecMatrix,
|
||||
formatConsignmentStockSpecLabel,
|
||||
formatConsignmentStockSpecSummary,
|
||||
isSameConsignmentStockSpec,
|
||||
sumConsignmentStockSpecQuantity,
|
||||
} from '../src/utils/consignment-stock-summary.ts'
|
||||
|
||||
test('现货汇总标签按 系统+系列+钻级 输出,不包含璀璨和区服', () => {
|
||||
assert.equal(
|
||||
formatConsignmentStockSpecSummary({
|
||||
system: '安卓',
|
||||
series: '怒嚎',
|
||||
diamond_level: 3,
|
||||
quantity: 2,
|
||||
}),
|
||||
'安卓怒嚎3钻-2件',
|
||||
)
|
||||
assert.equal(
|
||||
formatConsignmentStockSpecLabel({
|
||||
system: '苹果',
|
||||
series: '暗潮',
|
||||
diamond_level: 2,
|
||||
quantity: 3,
|
||||
}),
|
||||
'苹果暗潮2钻',
|
||||
)
|
||||
})
|
||||
|
||||
test('现货汇总对缺失规格和异常数量做安全展示', () => {
|
||||
assert.equal(
|
||||
formatConsignmentStockSpecSummary({
|
||||
system: '',
|
||||
series: ' ',
|
||||
diamond_level: 0,
|
||||
quantity: -2,
|
||||
}),
|
||||
'未注明未注明未知钻级-0件',
|
||||
)
|
||||
assert.equal(
|
||||
formatConsignmentStockSpecSummary({
|
||||
system: '苹果',
|
||||
series: '怒嚎',
|
||||
diamond_level: 2,
|
||||
quantity: 0,
|
||||
}),
|
||||
'苹果怒嚎2钻-0件',
|
||||
)
|
||||
})
|
||||
|
||||
test('现货汇总总件数按数量相加,不按行数相加', () => {
|
||||
assert.equal(
|
||||
sumConsignmentStockSpecQuantity([
|
||||
{ system: '苹果', series: '暗潮', diamond_level: 2, quantity: 3 },
|
||||
{ system: '安卓', series: '怒嚎', diamond_level: 3, quantity: 2 },
|
||||
]),
|
||||
5,
|
||||
)
|
||||
})
|
||||
|
||||
test('点击现货汇总只生成系统+系列+钻级三个精确筛选条件', () => {
|
||||
assert.deepEqual(
|
||||
buildConsignmentStockSpecFilter({
|
||||
system: '安卓',
|
||||
series: '怒嚎',
|
||||
diamond_level: 3,
|
||||
quantity: 2,
|
||||
}),
|
||||
{
|
||||
system: { value: '安卓', match: 'exact' },
|
||||
series: { value: '怒嚎', match: 'exact' },
|
||||
diamondLevel: { value: '3', match: 'exact' },
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
test('现货汇总筛选只比较系统、系列和钻级,忽略数量和璀璨差异', () => {
|
||||
assert.equal(
|
||||
isSameConsignmentStockSpec(
|
||||
{ system: '苹果', series: '暗潮', diamond_level: 2, quantity: 3 },
|
||||
{ system: '苹果', series: '暗潮', diamond_level: 2, quantity: 8 },
|
||||
),
|
||||
true,
|
||||
)
|
||||
assert.equal(
|
||||
isSameConsignmentStockSpec(
|
||||
{ system: '苹果', series: '暗潮', diamond_level: 2, quantity: 3 },
|
||||
{ system: '安卓', series: '暗潮', diamond_level: 2, quantity: 3 },
|
||||
),
|
||||
false,
|
||||
)
|
||||
})
|
||||
|
||||
test('现货矩阵按苹果在前、安卓在后,系列按 暗潮 → 怒嚎 → 血宴 排列', () => {
|
||||
const rows = buildConsignmentStockSpecMatrix([
|
||||
{ system: '苹果', series: '血宴', diamond_level: 1, quantity: 4 },
|
||||
{ system: '安卓', series: '怒嚎', diamond_level: 5, quantity: 13 },
|
||||
{ system: '安卓', series: '暗潮', diamond_level: 3, quantity: 1 },
|
||||
{ system: '苹果', series: '暗潮', diamond_level: 2, quantity: 9 },
|
||||
{ system: '安卓', series: '暗潮', diamond_level: 1, quantity: 3 },
|
||||
{ system: '苹果', series: '暗潮', diamond_level: 1, quantity: 3 },
|
||||
])
|
||||
|
||||
assert.deepEqual(
|
||||
rows.map((row) => `${row.system}/${row.series}`),
|
||||
['苹果/暗潮', '苹果/怒嚎', '苹果/血宴', '安卓/暗潮', '安卓/怒嚎', '安卓/血宴'],
|
||||
)
|
||||
assert.ok(
|
||||
rows.every((row) => row.cells.length === 7),
|
||||
'每行必须固定 1~7 钻七列',
|
||||
)
|
||||
const appleDarkTide = rows.find((row) => row.system === '苹果' && row.series === '暗潮')
|
||||
assert.equal(appleDarkTide?.cells[0]?.item?.quantity, 3)
|
||||
assert.equal(appleDarkTide?.cells[1]?.item?.quantity, 9)
|
||||
const androidRage = rows.find((row) => row.system === '安卓' && row.series === '怒嚎')
|
||||
assert.equal(androidRage?.cells[4]?.item?.quantity, 13)
|
||||
})
|
||||
|
||||
test('寄售仓库页面必须渲染后端现货汇总并展示口径提示', () => {
|
||||
const source = readFileSync(
|
||||
fileURLToPath(
|
||||
new URL('../src/pages/admin/panels/ConsignmentInventoryPanel.tsx', import.meta.url),
|
||||
),
|
||||
'utf8',
|
||||
).replace(/\r\n/g, '\n')
|
||||
|
||||
assert.ok(source.includes('stats?.byStockSpec'), '页面必须读取服务端现货汇总')
|
||||
assert.ok(source.includes('formatConsignmentStockSpecSummary'), '页面必须使用统一汇总格式')
|
||||
assert.ok(source.includes('璀璨已合并计入'), '页面必须说明璀璨不单独拆分')
|
||||
assert.ok(source.includes('loading={statsQuery.isFetching}'), '现货库存必须提供手动刷新状态')
|
||||
assert.ok(!source.includes('refetchInterval'), '现货库存不得自动轮询,只保留手动刷新')
|
||||
assert.ok(
|
||||
source.includes('onClick={() => handleStockSpecClick(item)}'),
|
||||
'点击现货标签必须筛选列表',
|
||||
)
|
||||
assert.ok(source.includes("setAllowMatching('yes')"), '点击矩阵必须同时筛选允许匹配库存')
|
||||
assert.ok(source.includes("setStatus('in_stock')"), '点击矩阵必须回到在库列表')
|
||||
assert.ok(source.includes('stockSpecFilter'), '页面必须维护现货标签筛选状态')
|
||||
assert.ok(source.includes('buildConsignmentStockSpecMatrix'), '现货汇总必须按图片生成矩阵')
|
||||
assert.ok(source.includes('systemPalette.background'), '矩阵必须用颜色区分系统')
|
||||
assert.ok(source.includes('seriesPalette.background'), '枪系颜色只能标记系列列')
|
||||
assert.ok(
|
||||
source.includes("background: selected ? '#fff7e6' : systemPalette.background"),
|
||||
'钻级库存格必须继续跟随系统颜色,不受枪系颜色影响',
|
||||
)
|
||||
assert.ok(source.includes('#fff7e6'), '矩阵必须用颜色区分选中状态')
|
||||
assert.ok(
|
||||
!source.includes("textAlign: index < 2 ? 'left' : 'center'"),
|
||||
'列头和所有表格内容必须统一居中',
|
||||
)
|
||||
assert.ok(
|
||||
source.includes('{displayLabel}'),
|
||||
'每个矩阵格子必须显示完整规格和数量,例如 苹果怒嚎2钻-9件',
|
||||
)
|
||||
assert.ok(
|
||||
source.includes('const displayItem = item || {'),
|
||||
'无库存格子也必须生成对应规格的 0 件展示',
|
||||
)
|
||||
assert.ok(!source.includes(": '无'"), '无库存不能只显示“无”,必须显示对应规格的 -0件')
|
||||
})
|
||||
Reference in New Issue
Block a user