feat(consignment): 寄卖规格与价格动态配置重构

This commit is contained in:
2026-11-05 17:09:05 +08:00
parent 2ef16ddcc7
commit d41ec44679
22 changed files with 3761 additions and 621 deletions
@@ -0,0 +1,111 @@
-- 130_consignment_dynamic_specs.sql
-- 寄卖动态规格:提报/库存增加 spec_values_json、spec_key、spec_text 与改价上限。
-- 全部语句幂等,可安全重跑;不改动历史迁移。
-- ===========================================================================
-- 1. 提报:动态规格值、匹配 key、展示文本、改价上限
-- ===========================================================================
ALTER TABLE consignment_submissions
ADD COLUMN IF NOT EXISTS spec_values_json JSONB NOT NULL DEFAULT '{}'::jsonb,
ADD COLUMN IF NOT EXISTS spec_key TEXT NOT NULL DEFAULT '',
ADD COLUMN IF NOT EXISTS spec_text TEXT NOT NULL DEFAULT '',
ADD COLUMN IF NOT EXISTS price_cap_fen BIGINT NOT NULL DEFAULT 0;
-- ===========================================================================
-- 2. 库存:同提报;入库后规格值继续随库存走
-- ===========================================================================
ALTER TABLE consignment_inventories
ADD COLUMN IF NOT EXISTS spec_values_json JSONB NOT NULL DEFAULT '{}'::jsonb,
ADD COLUMN IF NOT EXISTS spec_key TEXT NOT NULL DEFAULT '',
ADD COLUMN IF NOT EXISTS spec_text TEXT NOT NULL DEFAULT '',
ADD COLUMN IF NOT EXISTS price_cap_fen BIGINT NOT NULL DEFAULT 0;
-- ===========================================================================
-- 3. 存量回填:内置 5 规格 -> JSON / key / 文本;改价上限取当前售价
-- ===========================================================================
UPDATE consignment_submissions
SET
spec_values_json = jsonb_strip_nulls(
jsonb_build_object(
'system', NULLIF(BTRIM(system), ''),
'serverZone', NULLIF(BTRIM(server_zone), ''),
'series', NULLIF(BTRIM(series), ''),
'diamondLevel', diamond_level,
'brillianceCount', brilliance_count
)
),
spec_key = NULLIF(
concat_ws(
'|',
CASE WHEN COALESCE(NULLIF(BTRIM(system), ''), '') <> '' THEN 'system=' || BTRIM(system) END,
CASE WHEN COALESCE(NULLIF(BTRIM(server_zone), ''), '') <> '' THEN 'serverZone=' || BTRIM(server_zone) END,
CASE WHEN COALESCE(NULLIF(BTRIM(series), ''), '') <> '' THEN 'series=' || BTRIM(series) END,
CASE WHEN diamond_level IS NOT NULL THEN 'diamondLevel=' || diamond_level::text END,
CASE WHEN brilliance_count IS NOT NULL THEN 'brillianceCount=' || brilliance_count::text END
),
''
),
spec_text = COALESCE(NULLIF(BTRIM(item_name), ''), ''),
price_cap_fen = CASE
WHEN COALESCE(requested_sale_price_fen, 0) > 0 THEN requested_sale_price_fen
WHEN COALESCE(asking_price_fen, 0) > 0 THEN asking_price_fen
ELSE 0
END
WHERE spec_key = '';
UPDATE consignment_inventories
SET
spec_values_json = jsonb_strip_nulls(
jsonb_build_object(
'system', NULLIF(BTRIM(system), ''),
'serverZone', NULLIF(BTRIM(server_zone), ''),
'series', NULLIF(BTRIM(series), ''),
'diamondLevel', diamond_level,
'brillianceCount', brilliance_count
)
),
spec_key = NULLIF(
concat_ws(
'|',
CASE WHEN COALESCE(NULLIF(BTRIM(system), ''), '') <> '' THEN 'system=' || BTRIM(system) END,
CASE WHEN COALESCE(NULLIF(BTRIM(server_zone), ''), '') <> '' THEN 'serverZone=' || BTRIM(server_zone) END,
CASE WHEN COALESCE(NULLIF(BTRIM(series), ''), '') <> '' THEN 'series=' || BTRIM(series) END,
CASE WHEN diamond_level IS NOT NULL THEN 'diamondLevel=' || diamond_level::text END,
CASE WHEN brilliance_count IS NOT NULL THEN 'brillianceCount=' || brilliance_count::text END
),
''
),
spec_text = COALESCE(NULLIF(BTRIM(item_name), ''), ''),
price_cap_fen = COALESCE(sale_price_fen, 0)
WHERE spec_key = '';
-- ===========================================================================
-- 4. 索引:按配置 + 规格 key 快速筛选在库可匹配库存
-- ===========================================================================
CREATE INDEX IF NOT EXISTS idx_consignment_inventories_spec_key
ON consignment_inventories (profile_id, spec_key)
WHERE status = 'in_stock' AND allow_matching;
CREATE INDEX IF NOT EXISTS idx_consignment_submissions_spec_key
ON consignment_submissions (profile_id, spec_key)
WHERE status = 'pending_review';
-- ===========================================================================
-- 5. 注释
-- ===========================================================================
COMMENT ON COLUMN consignment_submissions.spec_values_json IS
'动态规格字段值(key -> 选项值/数字/文本),随配置版本快照固化';
COMMENT ON COLUMN consignment_submissions.spec_key IS
'参与匹配的规格字段稳定 key(按字段 key 排序的 key=value 串),用于候选筛选';
COMMENT ON COLUMN consignment_submissions.spec_text IS
'规格展示/搜索文本(字段名称 + 选项名称拼接)';
COMMENT ON COLUMN consignment_submissions.price_cap_fen IS
'打手改价上限(分):默认取接单模板价/系统建议价;0 = 不限制';
COMMENT ON COLUMN consignment_inventories.spec_values_json IS
'动态规格字段值(key -> 选项值/数字/文本),随配置版本快照固化';
COMMENT ON COLUMN consignment_inventories.spec_key IS
'参与匹配的规格字段稳定 key(按字段 key 排序的 key=value 串),用于候选筛选';
COMMENT ON COLUMN consignment_inventories.spec_text IS
'规格展示/搜索文本(字段名称 + 选项名称拼接)';
COMMENT ON COLUMN consignment_inventories.price_cap_fen IS
'打手改价上限(分):默认取接单模板价/系统建议价;0 = 不限制';
@@ -0,0 +1,203 @@
-- 131_consignment_surnan_default_profile.sql
-- 苏尔南手枪默认寄卖配置:五个规格字段(与旧发布页一致),直接发布 v1。
-- 幂等:该分类已有寄卖配置时不做任何事,避免覆盖运营已保存/已发布的配置。
DO $migration$
DECLARE
v_category_id BIGINT;
v_profile_id BIGINT;
v_version_id BIGINT;
v_config JSONB;
BEGIN
SELECT id INTO v_category_id
FROM work_categories
WHERE category_key = 'shouqiang'
LIMIT 1;
IF v_category_id IS NULL THEN
RETURN;
END IF;
IF EXISTS (SELECT 1 FROM consignment_profiles WHERE category_id = v_category_id) THEN
RETURN;
END IF;
v_config := $config${
"version": 1,
"tabTitle": "苏尔南寄卖",
"tabDescription": "苏尔南手枪寄卖:选择规格后按接单模板价带出建议价",
"specs": [
{
"key": "system",
"label": "操作系统",
"type": "radio",
"required": true,
"options": [
{ "label": "苹果", "value": "苹果", "enabled": true },
{ "label": "安卓", "value": "安卓", "enabled": true }
],
"placeholder": "",
"helpText": "",
"matchMode": "exact",
"wildcardValues": [],
"showInItemName": true,
"sortOrder": 10
},
{
"key": "serverZone",
"label": "游戏区服",
"type": "radio",
"required": true,
"options": [
{ "label": "互通(QQ/微信)", "value": "互通", "enabled": true }
],
"placeholder": "",
"helpText": "苏尔南手枪当前统一为互通区服,旧库存的微信区/QQ区仍可参与匹配",
"matchMode": "wildcard",
"wildcardValues": ["互通", "通用", "全区", "不限"],
"showInItemName": false,
"sortOrder": 20
},
{
"key": "series",
"label": "系列 / 枪系",
"type": "radio",
"required": true,
"options": [
{ "label": "暗潮", "value": "暗潮", "enabled": true },
{ "label": "怒嚎", "value": "怒嚎", "enabled": true },
{ "label": "血宴", "value": "血宴", "enabled": true }
],
"placeholder": "",
"helpText": "",
"matchMode": "exact",
"wildcardValues": [],
"showInItemName": true,
"sortOrder": 30
},
{
"key": "diamondLevel",
"label": "钻石等级",
"type": "radio",
"required": true,
"options": [
{ "label": "1钻", "value": "1", "enabled": true },
{ "label": "2钻", "value": "2", "enabled": true },
{ "label": "3钻", "value": "3", "enabled": true },
{ "label": "4钻", "value": "4", "enabled": true },
{ "label": "5钻", "value": "5", "enabled": true },
{ "label": "6钻", "value": "6", "enabled": true },
{ "label": "7钻", "value": "7", "enabled": true }
],
"placeholder": "",
"helpText": "",
"matchMode": "minimum",
"wildcardValues": [],
"showInItemName": true,
"sortOrder": 40
},
{
"key": "brillianceCount",
"label": "璀璨数",
"type": "radio",
"required": true,
"options": [
{ "label": "无", "value": "0", "enabled": true },
{ "label": "1璀", "value": "1", "enabled": true },
{ "label": "2璀", "value": "2", "enabled": true },
{ "label": "3璀", "value": "3", "enabled": true },
{ "label": "4璀", "value": "4", "enabled": true },
{ "label": "5璀", "value": "5", "enabled": true },
{ "label": "6璀", "value": "6", "enabled": true },
{ "label": "7璀", "value": "7", "enabled": true }
],
"placeholder": "",
"helpText": "",
"matchMode": "minimum",
"wildcardValues": [],
"showInItemName": true,
"sortOrder": 50
}
],
"nameTemplate": "{system}{series}{diamondLevel}钻{brillianceCount}璀璨 苏尔南",
"pricing": {
"priceType": "template_discount",
"discount": 10,
"fixedPriceFen": 0,
"allowWorkerPrice": true,
"minPriceFen": 0,
"missingPricePolicy": "manual"
},
"fields": {
"system": true,
"serverZone": true,
"series": true,
"diamondLevel": true,
"brillianceCount": true,
"quantity": true
},
"deposit": {
"enabled": false,
"mode": "fixed",
"fixedAmountFen": 0,
"unitAmountFen": 0
},
"serviceFee": {
"enabled": false,
"mode": "percent",
"percent": 0,
"amountFen": 0
},
"inventoryLimit": {
"enabled": false,
"maxActiveQuantity": 0
},
"matching": {
"mode": "manual",
"autoMatchEnabled": false,
"exactOnly": true,
"preferLowReward": true
},
"internalMatch": {
"delayMinutes": 30,
"fallbackToHall": true
},
"timeout": {
"minutes": 30,
"policy": "reopen"
},
"priceDrop": {
"enabled": false,
"hours": 72,
"mode": "percent",
"value": 10
}
}$config$::jsonb;
INSERT INTO consignment_profiles (
category_id, name, title, description, tab_title, config_json, status, created_at, updated_at
) VALUES (
v_category_id,
'苏尔南手枪寄卖',
'苏尔南手枪寄卖',
'苏尔南手枪默认配置:选择规格后按接单模板价带出建议价',
'苏尔南寄卖',
v_config,
'published',
now(),
now()
)
RETURNING id INTO v_profile_id;
INSERT INTO consignment_profile_versions (
profile_id, version_no, config_json, published_at, created_at
) VALUES (
v_profile_id, 1, v_config, now(), now()
)
RETURNING id INTO v_version_id;
UPDATE consignment_profiles
SET current_version_id = v_version_id, updated_at = now()
WHERE id = v_profile_id;
END
$migration$;