feat(consignment): 新增和平精英寄卖库存管理、定向收集审核与工单智能匹配履约
This commit is contained in:
@@ -0,0 +1,162 @@
|
||||
-- 077_consignment_inventory.sql —— 和平精英寄售仓库、定向收集链接、用户提报与内部履约支持。
|
||||
|
||||
CREATE TABLE IF NOT EXISTS consignment_inventories (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
inventory_no TEXT NOT NULL UNIQUE,
|
||||
game_name TEXT NOT NULL DEFAULT '和平精英',
|
||||
category_id BIGINT REFERENCES work_categories(id) ON DELETE SET NULL,
|
||||
item_name TEXT NOT NULL,
|
||||
system TEXT NOT NULL DEFAULT '',
|
||||
server_zone TEXT NOT NULL DEFAULT '',
|
||||
series TEXT NOT NULL DEFAULT '',
|
||||
diamond_level INTEGER NOT NULL DEFAULT 1,
|
||||
brilliance_count INTEGER NOT NULL DEFAULT 0,
|
||||
cost_price_fen INTEGER NOT NULL DEFAULT 0,
|
||||
buyer_name TEXT NOT NULL DEFAULT '',
|
||||
inbound_batch TEXT NOT NULL DEFAULT '',
|
||||
seller_contact TEXT NOT NULL DEFAULT '',
|
||||
seller_game_id TEXT NOT NULL DEFAULT '',
|
||||
seller_payment_info TEXT NOT NULL DEFAULT '',
|
||||
seller_phone TEXT NOT NULL DEFAULT '',
|
||||
credentials_json JSONB NOT NULL DEFAULT '{}'::jsonb,
|
||||
screenshots_json JSONB NOT NULL DEFAULT '[]'::jsonb,
|
||||
remark TEXT NOT NULL DEFAULT '',
|
||||
allow_matching BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
status TEXT NOT NULL DEFAULT 'in_stock'
|
||||
CHECK (status IN ('in_stock', 'consumed', 'archived')),
|
||||
allocation_status TEXT NOT NULL DEFAULT '待安排',
|
||||
bound_order_id BIGINT REFERENCES orders(id) ON DELETE SET NULL,
|
||||
bound_work_order_id BIGINT REFERENCES work_orders(id) ON DELETE SET NULL,
|
||||
bound_platform_order_id TEXT NOT NULL DEFAULT '',
|
||||
shop_name TEXT NOT NULL DEFAULT '',
|
||||
source_type TEXT NOT NULL DEFAULT 'manual'
|
||||
CHECK (source_type IN ('manual', 'collection_link', 'recycle')),
|
||||
source_submission_id BIGINT,
|
||||
inbound_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
consumed_at TIMESTAMPTZ,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS consignment_collect_links (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
token TEXT NOT NULL UNIQUE,
|
||||
title TEXT NOT NULL,
|
||||
game_name TEXT NOT NULL DEFAULT '和平精英',
|
||||
category_id BIGINT REFERENCES work_categories(id) ON DELETE SET NULL,
|
||||
system TEXT NOT NULL DEFAULT '',
|
||||
server_zone TEXT NOT NULL DEFAULT '',
|
||||
series TEXT NOT NULL DEFAULT '',
|
||||
diamond_level INTEGER NOT NULL DEFAULT 1,
|
||||
brilliance_count INTEGER NOT NULL DEFAULT 0,
|
||||
preset_price_fen INTEGER NOT NULL DEFAULT 0,
|
||||
inbound_batch TEXT NOT NULL DEFAULT '',
|
||||
buyer_name TEXT NOT NULL DEFAULT '',
|
||||
template_json JSONB NOT NULL DEFAULT '{}'::jsonb,
|
||||
is_multi_use BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
expires_at TIMESTAMPTZ,
|
||||
enabled BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
created_by TEXT NOT NULL DEFAULT '',
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS consignment_submissions (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
submission_no TEXT NOT NULL UNIQUE,
|
||||
link_id BIGINT REFERENCES consignment_collect_links(id) ON DELETE SET NULL,
|
||||
game_name TEXT NOT NULL DEFAULT '和平精英',
|
||||
category_id BIGINT REFERENCES work_categories(id) ON DELETE SET NULL,
|
||||
item_name TEXT NOT NULL,
|
||||
system TEXT NOT NULL DEFAULT '',
|
||||
server_zone TEXT NOT NULL DEFAULT '',
|
||||
series TEXT NOT NULL DEFAULT '',
|
||||
diamond_level INTEGER NOT NULL DEFAULT 1,
|
||||
brilliance_count INTEGER NOT NULL DEFAULT 0,
|
||||
seller_game_id TEXT NOT NULL DEFAULT '',
|
||||
seller_payment_info TEXT NOT NULL DEFAULT '',
|
||||
seller_phone TEXT NOT NULL DEFAULT '',
|
||||
contact_info TEXT NOT NULL DEFAULT '',
|
||||
content_json JSONB NOT NULL DEFAULT '{}'::jsonb,
|
||||
screenshots_json JSONB NOT NULL DEFAULT '[]'::jsonb,
|
||||
asking_price_fen INTEGER NOT NULL DEFAULT 0,
|
||||
status TEXT NOT NULL DEFAULT 'pending_review'
|
||||
CHECK (status IN ('pending_review', 'approved', 'rejected')),
|
||||
review_note TEXT NOT NULL DEFAULT '',
|
||||
reviewer_name TEXT NOT NULL DEFAULT '',
|
||||
reviewed_at TIMESTAMPTZ,
|
||||
result_inventory_id BIGINT REFERENCES consignment_inventories(id) ON DELETE SET NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
ALTER TABLE consignment_inventories
|
||||
ADD CONSTRAINT fk_consignment_inventories_submission
|
||||
FOREIGN KEY (source_submission_id) REFERENCES consignment_submissions(id) ON DELETE SET NULL;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_consignment_inventories_status_matching
|
||||
ON consignment_inventories(status, allow_matching, id DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_consignment_inventories_game_category
|
||||
ON consignment_inventories(game_name, category_id, status);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_consignment_inventories_specs
|
||||
ON consignment_inventories(system, server_zone, series, diamond_level, status);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_consignment_inventories_buyer
|
||||
ON consignment_inventories(buyer_name, status);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_consignment_inventories_shop
|
||||
ON consignment_inventories(shop_name, status);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_consignment_inventories_batch
|
||||
ON consignment_inventories(inbound_batch);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_consignment_submissions_status_created
|
||||
ON consignment_submissions(status, created_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_consignment_submissions_link
|
||||
ON consignment_submissions(link_id, created_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_consignment_collect_links_token
|
||||
ON consignment_collect_links(token)
|
||||
WHERE enabled = TRUE;
|
||||
|
||||
-- RBAC 权限分配
|
||||
INSERT INTO admin_permissions (permission_key, permission_name, permission_group, description)
|
||||
VALUES
|
||||
('consignment.view', '查看寄卖库存', '寄卖管理', '查看寄售仓库、收集链接与提报单'),
|
||||
('consignment.manage', '管理寄卖库存', '寄卖管理', '录入、修改、下架寄售物品与管理收集链接'),
|
||||
('consignment.review', '审核寄卖提报', '寄卖管理', '审核玩家提交的寄卖回收申请并入库'),
|
||||
('consignment.fulfill', '寄卖内部履约', '寄卖管理', '使用内部寄卖库存直接履约工单与撤销重选')
|
||||
ON CONFLICT (permission_key) DO UPDATE SET
|
||||
permission_name = EXCLUDED.permission_name,
|
||||
permission_group = EXCLUDED.permission_group,
|
||||
description = EXCLUDED.description,
|
||||
updated_at = NOW();
|
||||
|
||||
-- 管理员与运营拥有全部寄卖权限
|
||||
INSERT INTO admin_role_permissions (role_key, permission_key)
|
||||
SELECT 'admin', permission_key
|
||||
FROM admin_permissions
|
||||
WHERE permission_key LIKE 'consignment.%'
|
||||
ON CONFLICT DO NOTHING;
|
||||
|
||||
INSERT INTO admin_role_permissions (role_key, permission_key)
|
||||
SELECT 'operator', permission_key
|
||||
FROM admin_permissions
|
||||
WHERE permission_key LIKE 'consignment.%'
|
||||
ON CONFLICT DO NOTHING;
|
||||
|
||||
-- 客服拥有查看、管理、审核与履约权限
|
||||
INSERT INTO admin_role_permissions (role_key, permission_key)
|
||||
VALUES
|
||||
('support', 'consignment.view'),
|
||||
('support', 'consignment.manage'),
|
||||
('support', 'consignment.review'),
|
||||
('support', 'consignment.fulfill')
|
||||
ON CONFLICT DO NOTHING;
|
||||
|
||||
COMMENT ON TABLE consignment_inventories IS '和平精英寄售仓库库存台账';
|
||||
COMMENT ON TABLE consignment_collect_links IS '对外定向收集链接与规格配置';
|
||||
COMMENT ON TABLE consignment_submissions IS '玩家通过收集链接提交的寄卖提报审核单';
|
||||
Reference in New Issue
Block a user