fix: api descript

This commit is contained in:
wwweww
2026-02-28 05:33:16 +08:00
parent 5930fb0dde
commit d2f33b4b96
243 changed files with 37065 additions and 780 deletions
+49
View File
@@ -0,0 +1,49 @@
CREATE TABLE shops (
id BIGINT PRIMARY KEY,
owner_id BIGINT NOT NULL UNIQUE,
name VARCHAR(200) NOT NULL,
banner TEXT,
description TEXT,
rating DECIMAL(3,2) DEFAULT 5.00,
total_orders INT DEFAULT 0,
player_count INT DEFAULT 0,
commission_type VARCHAR(20) NOT NULL DEFAULT 'percentage',
commission_value DECIMAL(10,2) NOT NULL,
allow_multi_shop BOOLEAN DEFAULT FALSE,
allow_independent_orders BOOLEAN DEFAULT TRUE,
dispatch_mode VARCHAR(20) NOT NULL DEFAULT 'manual',
announcements TEXT[] DEFAULT ARRAY[]::TEXT[],
template_config JSONB,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
CONSTRAINT chk_commission_type CHECK (commission_type IN ('fixed', 'percentage')),
CONSTRAINT chk_dispatch_mode CHECK (dispatch_mode IN ('manual', 'auto')),
CONSTRAINT chk_rating_range CHECK (rating >= 0 AND rating <= 5)
);
-- 基础索引
CREATE INDEX idx_shops_owner ON shops(owner_id);
CREATE INDEX idx_shops_rating ON shops(rating DESC);
-- 三元组索引用于店铺名称模糊搜索
CREATE INDEX idx_shops_name_trgm ON shops USING gin(name gin_trgm_ops);
-- 全文搜索索引
CREATE INDEX idx_shops_fulltext ON shops USING gin(
to_tsvector('simple', name || ' ' || coalesce(description, ''))
);
-- 复合索引优化排序查询
CREATE INDEX idx_shops_rating_orders ON shops(rating DESC, total_orders DESC);
-- 公告数组索引
CREATE INDEX idx_shops_announcements ON shops USING gin(announcements);
-- JSONB 索引优化模板配置查询
CREATE INDEX idx_shops_template ON shops USING gin(template_config);
CREATE TRIGGER trigger_shops_updated_at
BEFORE UPDATE ON shops
FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();
+20
View File
@@ -0,0 +1,20 @@
CREATE TABLE shop_invitations
(
id BIGINT PRIMARY KEY,
shop_id BIGINT NOT NULL REFERENCES shops (id),
player_id BIGINT NOT NULL,
status VARCHAR(20) NOT NULL DEFAULT 'pending',
invited_by BIGINT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
responded_at TIMESTAMPTZ,
CONSTRAINT chk_invitation_status CHECK (status IN ('pending', 'accepted', 'rejected', 'cancelled'))
);
CREATE UNIQUE INDEX idx_unique_pending_invitation
ON shop_invitations (shop_id, player_id)
WHERE status = 'pending';
CREATE INDEX idx_invitations_shop ON shop_invitations (shop_id);
CREATE INDEX idx_invitations_player ON shop_invitations (player_id) WHERE status = 'pending';
CREATE INDEX idx_invitations_player_status ON shop_invitations (player_id, status, created_at DESC);
CREATE INDEX idx_invitations_shop_status ON shop_invitations (shop_id, status, created_at DESC);
+20
View File
@@ -0,0 +1,20 @@
CREATE TABLE shop_players
(
shop_id BIGINT NOT NULL REFERENCES shops (id),
player_id BIGINT NOT NULL,
-- 标记是否为主店铺。用于个人主页展示和 players.shop_id 缓存源
is_primary BOOLEAN DEFAULT FALSE,
joined_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
left_at TIMESTAMPTZ, -- 软删除,表示已离职
PRIMARY KEY (shop_id, player_id)
);
-- 索引
CREATE INDEX idx_shop_players_player ON shop_players (player_id) WHERE left_at IS NULL;
CREATE INDEX idx_shop_players_shop_active ON shop_players (shop_id, joined_at DESC) WHERE left_at IS NULL;
-- [新增] 唯一索引:确保一个打手同一时间只能有一个主店铺
CREATE UNIQUE INDEX idx_shop_players_one_primary
ON shop_players (player_id) WHERE is_primary = TRUE AND left_at IS NULL;