admin接入数据库
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
-- =====================================================================================
|
||||
-- Schema: 分销代理商申请表
|
||||
-- 位置:docs/sql/10_schema/distribution/ak_distribution_agent_applications_v1.sql
|
||||
-- 对象类型:TABLE
|
||||
-- 版本:v1
|
||||
-- 依赖:ak_users, ak_distribution_divisions
|
||||
-- =====================================================================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.ak_distribution_agent_applications (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
uid UUID NOT NULL REFERENCES public.ak_users(id) ON DELETE CASCADE,
|
||||
division_uid UUID NOT NULL REFERENCES public.ak_distribution_divisions(uid),
|
||||
|
||||
agent_name TEXT NOT NULL,
|
||||
agent_phone TEXT NULL,
|
||||
|
||||
proof_images JSONB NULL, -- 申请凭证图片列表
|
||||
|
||||
status TEXT NOT NULL DEFAULT 'pending', -- pending/approved/rejected
|
||||
refusal_reason TEXT NULL,
|
||||
|
||||
approved_at TIMESTAMPTZ NULL,
|
||||
approved_by UUID NULL REFERENCES public.ak_users(id),
|
||||
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_dist_agent_applications_uid ON public.ak_distribution_agent_applications(uid);
|
||||
CREATE INDEX IF NOT EXISTS idx_dist_agent_applications_division_uid ON public.ak_distribution_agent_applications(division_uid);
|
||||
CREATE INDEX IF NOT EXISTS idx_dist_agent_applications_status ON public.ak_distribution_agent_applications(status);
|
||||
|
||||
COMMENT ON TABLE public.ak_distribution_agent_applications IS '分销代理商申请记录表';
|
||||
COMMENT ON COLUMN public.ak_distribution_agent_applications.proof_images IS '申请图片列表(JSON)';
|
||||
@@ -1,41 +1,29 @@
|
||||
-- =====================================================================================
|
||||
-- Schema: 分销代理商管理表
|
||||
-- 位置:docs/sql/10_schema/distribution/ak_distribution_agents_v1.sql
|
||||
-- 说明:管理事业部旗下的代理商,按商家隔离。
|
||||
-- 对象类型:TABLE
|
||||
-- 版本:v1
|
||||
-- 依赖:ak_users, ak_distribution_divisions
|
||||
-- =====================================================================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.ak_distribution_agents (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
merchant_id UUID NOT NULL REFERENCES public.ak_users(id) ON DELETE CASCADE,
|
||||
division_id UUID NOT NULL REFERENCES public.ak_distribution_divisions(id) ON DELETE CASCADE,
|
||||
uid UUID NOT NULL REFERENCES public.ak_users(id) ON DELETE CASCADE,
|
||||
|
||||
name TEXT NOT NULL, -- 代理商名称(或备注名)
|
||||
status BOOLEAN DEFAULT true, -- 状态: true开启, false关闭
|
||||
|
||||
uid UUID PRIMARY KEY REFERENCES public.ak_users(id) ON DELETE CASCADE,
|
||||
division_uid UUID NOT NULL REFERENCES public.ak_distribution_divisions(uid), -- 所属事业部
|
||||
name TEXT NOT NULL,
|
||||
commission_ratio NUMERIC(5,2) DEFAULT 0 CHECK (commission_ratio >= 0 AND commission_ratio <= 100),
|
||||
is_enabled BOOLEAN DEFAULT TRUE,
|
||||
end_time TIMESTAMPTZ,
|
||||
created_at TIMESTAMPTZ DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ DEFAULT now(),
|
||||
|
||||
-- 约束:一个用户在一个商家下只能成为一个代理商
|
||||
UNIQUE(merchant_id, uid)
|
||||
created_by UUID REFERENCES public.ak_users(id),
|
||||
updated_by UUID REFERENCES public.ak_users(id)
|
||||
);
|
||||
|
||||
-- 启用 RLS
|
||||
ALTER TABLE public.ak_distribution_agents ENABLE ROW LEVEL SECURITY;
|
||||
|
||||
-- 权限策略:商家仅能管理自己的代理商
|
||||
CREATE POLICY "Merchants manage their own agents"
|
||||
ON public.ak_distribution_agents FOR ALL
|
||||
TO authenticated
|
||||
USING (merchant_id = auth.uid())
|
||||
WITH CHECK (merchant_id = auth.uid());
|
||||
|
||||
-- 允许查看
|
||||
CREATE POLICY "Authenticated users view active agents"
|
||||
ON public.ak_distribution_agents FOR SELECT
|
||||
TO authenticated
|
||||
USING (status = true);
|
||||
|
||||
-- 索引
|
||||
CREATE INDEX IF NOT EXISTS idx_agents_merchant ON public.ak_distribution_agents(merchant_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_agents_division ON public.ak_distribution_agents(division_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_distribution_agents_division_uid ON public.ak_distribution_agents(division_uid);
|
||||
|
||||
-- 注释
|
||||
COMMENT ON TABLE public.ak_distribution_agents IS '分销代理商信息表';
|
||||
COMMENT ON COLUMN public.ak_distribution_agents.uid IS '用户ID(关联代理商本人)';
|
||||
COMMENT ON COLUMN public.ak_distribution_agents.division_uid IS '所属事业部UID';
|
||||
COMMENT ON COLUMN public.ak_distribution_agents.commission_ratio IS '代理商固定分佣比例(%)';
|
||||
|
||||
@@ -1,46 +1,30 @@
|
||||
-- =====================================================================================
|
||||
-- Schema: 分销事业部管理表
|
||||
-- 位置:docs/sql/10_schema/distribution/ak_distribution_divisions_v1.sql
|
||||
-- 说明:管理分销体系中的事业部,支持独立分销比例、邀请码及有效期,按商家隔离。
|
||||
-- 对象类型:TABLE
|
||||
-- 版本:v1
|
||||
-- 依赖:ak_users
|
||||
-- =====================================================================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.ak_distribution_divisions (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
merchant_id UUID NOT NULL REFERENCES public.ak_users(id) ON DELETE CASCADE,
|
||||
|
||||
uid UUID NOT NULL REFERENCES public.ak_users(id), -- 事业部负责人UID
|
||||
name TEXT NOT NULL, -- 事业部名称
|
||||
invite_code TEXT UNIQUE NOT NULL, -- 事业部专属邀请码
|
||||
|
||||
ratio DECIMAL(5,2) DEFAULT 0, -- 事业部额外分销比例 (%)
|
||||
agent_count INTEGER DEFAULT 0, -- 下属代理商数量 (由程序或触发器维护)
|
||||
|
||||
end_time TIMESTAMPTZ, -- 协议截止时间
|
||||
status BOOLEAN DEFAULT true, -- 状态: true开启, false关闭
|
||||
|
||||
uid UUID PRIMARY KEY REFERENCES public.ak_users(id) ON DELETE CASCADE,
|
||||
name TEXT NOT NULL,
|
||||
invite_code TEXT UNIQUE NOT NULL,
|
||||
commission_ratio NUMERIC(5,2) DEFAULT 0 CHECK (commission_ratio >= 0 AND commission_ratio <= 100),
|
||||
is_enabled BOOLEAN DEFAULT TRUE,
|
||||
end_time TIMESTAMPTZ,
|
||||
created_at TIMESTAMPTZ DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ DEFAULT now(),
|
||||
|
||||
-- 约束:一个用户在一个商家下只能负责一个事业部
|
||||
UNIQUE(merchant_id, uid)
|
||||
created_by UUID REFERENCES public.ak_users(id),
|
||||
updated_by UUID REFERENCES public.ak_users(id)
|
||||
);
|
||||
|
||||
-- 启用 RLS
|
||||
ALTER TABLE public.ak_distribution_divisions ENABLE ROW LEVEL SECURITY;
|
||||
|
||||
-- 权限策略
|
||||
CREATE POLICY "Merchants manage their own divisions"
|
||||
ON public.ak_distribution_divisions FOR ALL
|
||||
TO authenticated
|
||||
USING (merchant_id = auth.uid())
|
||||
WITH CHECK (merchant_id = auth.uid());
|
||||
|
||||
-- 允许查看
|
||||
CREATE POLICY "Authenticated users view active divisions"
|
||||
ON public.ak_distribution_divisions FOR SELECT
|
||||
TO authenticated
|
||||
USING (status = true);
|
||||
|
||||
-- 索引
|
||||
CREATE INDEX IF NOT EXISTS idx_divisions_merchant ON public.ak_distribution_divisions(merchant_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_divisions_uid ON public.ak_distribution_divisions(uid);
|
||||
CREATE INDEX IF NOT EXISTS idx_distribution_divisions_invite_code ON public.ak_distribution_divisions(invite_code);
|
||||
|
||||
-- 注释
|
||||
COMMENT ON TABLE public.ak_distribution_divisions IS '分销事业部信息表';
|
||||
COMMENT ON COLUMN public.ak_distribution_divisions.uid IS '用户ID(关联事业部负责人)';
|
||||
COMMENT ON COLUMN public.ak_distribution_divisions.invite_code IS '事业部专属邀请码';
|
||||
COMMENT ON COLUMN public.ak_distribution_divisions.commission_ratio IS '事业部固定分佣比例(%)';
|
||||
COMMENT ON COLUMN public.ak_distribution_divisions.end_time IS '事业部有效截止时间';
|
||||
|
||||
52
docs/sql/20_rls/distribution/ml_distribution_rls_v1.sql
Normal file
52
docs/sql/20_rls/distribution/ml_distribution_rls_v1.sql
Normal file
@@ -0,0 +1,52 @@
|
||||
-- =====================================================================================
|
||||
-- RLS: 分销模块安全策略
|
||||
-- 位置:docs/sql/20_rls/distribution/ml_distribution_rls_v1.sql
|
||||
-- 对象类型:RLS 策略
|
||||
-- 版本:v1
|
||||
-- 说明:管理端全量权限通过 SECURITY DEFINER RPC 执行;用户仅能访问个人关联数据
|
||||
-- =====================================================================================
|
||||
|
||||
-- 启用 RLS
|
||||
ALTER TABLE public.ak_distribution_config ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.ak_distribution_level ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.ak_promoter_relations ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.ak_commission_logs ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.ak_distribution_divisions ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.ak_distribution_agents ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.ak_distribution_agent_applications ENABLE ROW LEVEL SECURITY;
|
||||
|
||||
-- 1. 分销配置:允许所有登录用户读取(消费者端展示逻辑需要)
|
||||
DROP POLICY IF EXISTS dist_config_select_policy ON public.ak_distribution_config;
|
||||
CREATE POLICY dist_config_select_policy ON public.ak_distribution_config
|
||||
FOR SELECT TO authenticated USING (true);
|
||||
|
||||
-- 2. 分销等级:允许所有登录用户读取可见等级
|
||||
DROP POLICY IF EXISTS dist_level_select_policy ON public.ak_distribution_level;
|
||||
CREATE POLICY dist_level_select_policy ON public.ak_distribution_level
|
||||
FOR SELECT TO authenticated USING (is_visible = true);
|
||||
|
||||
-- 3. 推广员关系:用户仅能查看与自己相关的记录
|
||||
DROP POLICY IF EXISTS promoter_relations_select_policy ON public.ak_promoter_relations;
|
||||
CREATE POLICY promoter_relations_select_policy ON public.ak_promoter_relations
|
||||
FOR SELECT TO authenticated USING (uid = auth.uid() OR inviter_uid = auth.uid());
|
||||
|
||||
-- 4. 佣金日志:用户仅能查看自己的佣金记录
|
||||
DROP POLICY IF EXISTS commission_logs_select_policy ON public.ak_commission_logs;
|
||||
CREATE POLICY commission_logs_select_policy ON public.ak_commission_logs
|
||||
FOR SELECT TO authenticated USING (uid = auth.uid());
|
||||
|
||||
-- 5. 事业部与代理商:允许登录用户查看启用的记录
|
||||
DROP POLICY IF EXISTS dist_divisions_select_policy ON public.ak_distribution_divisions;
|
||||
CREATE POLICY dist_divisions_select_policy ON public.ak_distribution_divisions
|
||||
FOR SELECT TO authenticated USING (is_enabled = true);
|
||||
|
||||
DROP POLICY IF EXISTS dist_agents_select_policy ON public.ak_distribution_agents;
|
||||
CREATE POLICY dist_agents_select_policy ON public.ak_distribution_agents
|
||||
FOR SELECT TO authenticated USING (is_enabled = true);
|
||||
|
||||
-- 6. 代理商申请:用户仅能管理自己的申请记录
|
||||
DROP POLICY IF EXISTS dist_apply_user_policy ON public.ak_distribution_agent_applications;
|
||||
CREATE POLICY dist_apply_user_policy ON public.ak_distribution_agent_applications
|
||||
FOR ALL TO authenticated USING (uid = auth.uid()) WITH CHECK (uid = auth.uid());
|
||||
|
||||
-- 管理端全量管理将通过 SECURITY DEFINER 的 RPC 接口执行,此处不再额外开放直接表操作
|
||||
31
docs/sql/30_rpc/distribution/rpc_admin_delete_agent_v1.sql
Normal file
31
docs/sql/30_rpc/distribution/rpc_admin_delete_agent_v1.sql
Normal file
@@ -0,0 +1,31 @@
|
||||
-- RPC: rpc_admin_delete_agent
|
||||
-- 管理端删除代理商
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.rpc_admin_delete_agent(
|
||||
p_uid uuid
|
||||
)
|
||||
RETURNS boolean
|
||||
LANGUAGE plpgsql
|
||||
SECURITY DEFINER
|
||||
SET search_path = public
|
||||
AS $$
|
||||
DECLARE
|
||||
v_ok boolean;
|
||||
BEGIN
|
||||
-- 仅管理员可操作
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM public.ak_users u
|
||||
WHERE u.id = auth.uid() AND u.role = 'admin'
|
||||
) THEN
|
||||
RAISE EXCEPTION 'permission denied';
|
||||
END IF;
|
||||
|
||||
DELETE FROM public.ak_distribution_agents WHERE uid = p_uid;
|
||||
|
||||
GET DIAGNOSTICS v_ok = ROW_COUNT;
|
||||
RETURN v_ok;
|
||||
END;
|
||||
$$;
|
||||
|
||||
REVOKE ALL ON FUNCTION public.rpc_admin_delete_agent(uuid) FROM PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION public.rpc_admin_delete_agent(uuid) TO authenticated;
|
||||
@@ -0,0 +1,38 @@
|
||||
-- RPC: rpc_admin_delete_division
|
||||
-- 管理端删除事业部
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.rpc_admin_delete_division(
|
||||
p_uid uuid
|
||||
)
|
||||
RETURNS boolean
|
||||
LANGUAGE plpgsql
|
||||
SECURITY DEFINER
|
||||
SET search_path = public
|
||||
AS $$
|
||||
DECLARE
|
||||
v_ok boolean;
|
||||
BEGIN
|
||||
-- 仅管理员可操作
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM public.ak_users u
|
||||
WHERE u.id = auth.uid() AND u.role = 'admin'
|
||||
) THEN
|
||||
RAISE EXCEPTION 'permission denied';
|
||||
END IF;
|
||||
|
||||
-- 检查是否有关联代理商
|
||||
IF EXISTS (
|
||||
SELECT 1 FROM public.ak_distribution_agents WHERE division_uid = p_uid
|
||||
) THEN
|
||||
RAISE EXCEPTION 'cannot delete division with associated agents';
|
||||
END IF;
|
||||
|
||||
DELETE FROM public.ak_distribution_divisions WHERE uid = p_uid;
|
||||
|
||||
GET DIAGNOSTICS v_ok = ROW_COUNT;
|
||||
RETURN v_ok;
|
||||
END;
|
||||
$$;
|
||||
|
||||
REVOKE ALL ON FUNCTION public.rpc_admin_delete_division(uuid) FROM PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION public.rpc_admin_delete_division(uuid) TO authenticated;
|
||||
@@ -0,0 +1,68 @@
|
||||
-- RPC: rpc_admin_get_agent_apply_list
|
||||
-- 管理端获取代理商申请列表
|
||||
-- 支持按状态过滤:all, pending, approved, rejected
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.rpc_admin_get_agent_apply_list(
|
||||
p_status text DEFAULT 'all',
|
||||
p_search text DEFAULT NULL,
|
||||
p_page integer DEFAULT 1,
|
||||
p_page_size integer DEFAULT 20
|
||||
)
|
||||
RETURNS TABLE (
|
||||
id uuid,
|
||||
uid uuid,
|
||||
name text,
|
||||
phone text,
|
||||
dept_uid uuid,
|
||||
dept_name text,
|
||||
proof_images jsonb,
|
||||
status text,
|
||||
refusal_reason text,
|
||||
time timestamptz,
|
||||
invite_code text
|
||||
)
|
||||
LANGUAGE plpgsql
|
||||
SECURITY DEFINER
|
||||
SET search_path = public
|
||||
AS $$
|
||||
DECLARE
|
||||
v_page integer := GREATEST(1, COALESCE(p_page, 1));
|
||||
v_page_size integer := LEAST(200, GREATEST(1, COALESCE(p_page_size, 20)));
|
||||
v_offset integer := (v_page - 1) * v_page_size;
|
||||
BEGIN
|
||||
-- 权限检查
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM public.ak_users u
|
||||
WHERE u.id = auth.uid() AND u.role IN ('admin', 'analytics')
|
||||
) THEN
|
||||
RAISE EXCEPTION 'permission denied';
|
||||
END IF;
|
||||
|
||||
RETURN QUERY
|
||||
SELECT
|
||||
a.id,
|
||||
a.uid,
|
||||
a.agent_name AS name,
|
||||
a.agent_phone AS phone,
|
||||
a.division_uid AS dept_uid,
|
||||
d.name AS dept_name,
|
||||
a.proof_images,
|
||||
a.status,
|
||||
a.refusal_reason,
|
||||
a.created_at AS time,
|
||||
d.invite_code
|
||||
FROM public.ak_distribution_agent_applications a
|
||||
JOIN public.ak_distribution_divisions d ON d.uid = a.division_uid
|
||||
WHERE (p_status = 'all' OR a.status = p_status)
|
||||
AND (
|
||||
p_search IS NULL OR p_search = ''
|
||||
OR a.agent_name ILIKE ('%' || p_search || '%')
|
||||
OR a.uid::text ILIKE ('%' || p_search || '%')
|
||||
)
|
||||
ORDER BY a.created_at DESC
|
||||
LIMIT v_page_size OFFSET v_offset;
|
||||
END;
|
||||
$$;
|
||||
|
||||
REVOKE ALL ON FUNCTION public.rpc_admin_get_agent_apply_list(text, text, integer, integer) FROM PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION public.rpc_admin_get_agent_apply_list(text, text, integer, integer) TO authenticated;
|
||||
62
docs/sql/30_rpc/distribution/rpc_admin_get_agent_list_v1.sql
Normal file
62
docs/sql/30_rpc/distribution/rpc_admin_get_agent_list_v1.sql
Normal file
@@ -0,0 +1,62 @@
|
||||
-- RPC: rpc_admin_get_agent_list
|
||||
-- 管理端获取代理商列表
|
||||
-- 支持搜索代理商名称或负责人UID,并关联显示所属事业部信息
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.rpc_admin_get_agent_list(
|
||||
p_search text DEFAULT NULL,
|
||||
p_page integer DEFAULT 1,
|
||||
p_page_size integer DEFAULT 20
|
||||
)
|
||||
RETURNS TABLE (
|
||||
uid uuid,
|
||||
name text,
|
||||
division_uid uuid,
|
||||
division_name text,
|
||||
commission_ratio numeric,
|
||||
is_enabled boolean,
|
||||
end_time timestamptz,
|
||||
created_at timestamptz,
|
||||
"staffCount" bigint
|
||||
)
|
||||
LANGUAGE plpgsql
|
||||
SECURITY DEFINER
|
||||
SET search_path = public
|
||||
AS $$
|
||||
DECLARE
|
||||
v_page integer := GREATEST(1, COALESCE(p_page, 1));
|
||||
v_page_size integer := LEAST(200, GREATEST(1, COALESCE(p_page_size, 20)));
|
||||
v_offset integer := (v_page - 1) * v_page_size;
|
||||
BEGIN
|
||||
-- 权限检查
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM public.ak_users u
|
||||
WHERE u.id = auth.uid() AND u.role IN ('admin', 'analytics')
|
||||
) THEN
|
||||
RAISE EXCEPTION 'permission denied';
|
||||
END IF;
|
||||
|
||||
RETURN QUERY
|
||||
SELECT
|
||||
a.uid,
|
||||
a.name,
|
||||
a.division_uid,
|
||||
d.name AS division_name,
|
||||
a.commission_ratio,
|
||||
a.is_enabled,
|
||||
a.end_time,
|
||||
a.created_at,
|
||||
(SELECT COUNT(*) FROM public.ak_promoter_relations r WHERE r.inviter_uid = a.uid)::bigint AS "staffCount"
|
||||
FROM public.ak_distribution_agents a
|
||||
JOIN public.ak_distribution_divisions d ON d.uid = a.division_uid
|
||||
WHERE (
|
||||
p_search IS NULL OR p_search = ''
|
||||
OR a.name ILIKE ('%' || p_search || '%')
|
||||
OR a.uid::text ILIKE ('%' || p_search || '%')
|
||||
)
|
||||
ORDER BY a.created_at DESC
|
||||
LIMIT v_page_size OFFSET v_offset;
|
||||
END;
|
||||
$$;
|
||||
|
||||
REVOKE ALL ON FUNCTION public.rpc_admin_get_agent_list(text, integer, integer) FROM PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION public.rpc_admin_get_agent_list(text, integer, integer) TO authenticated;
|
||||
@@ -0,0 +1,59 @@
|
||||
-- RPC: rpc_admin_get_division_list
|
||||
-- 管理端获取事业部列表
|
||||
-- 支持搜索事业部名称或负责人UID
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.rpc_admin_get_division_list(
|
||||
p_search text DEFAULT NULL,
|
||||
p_page integer DEFAULT 1,
|
||||
p_page_size integer DEFAULT 20
|
||||
)
|
||||
RETURNS TABLE (
|
||||
uid uuid,
|
||||
name text,
|
||||
invite_code text,
|
||||
commission_ratio numeric,
|
||||
is_enabled boolean,
|
||||
end_time timestamptz,
|
||||
created_at timestamptz,
|
||||
"agentCount" bigint
|
||||
)
|
||||
LANGUAGE plpgsql
|
||||
SECURITY DEFINER
|
||||
SET search_path = public
|
||||
AS $$
|
||||
DECLARE
|
||||
v_page integer := GREATEST(1, COALESCE(p_page, 1));
|
||||
v_page_size integer := LEAST(200, GREATEST(1, COALESCE(p_page_size, 20)));
|
||||
v_offset integer := (v_page - 1) * v_page_size;
|
||||
BEGIN
|
||||
-- 仅管理员或分析员可调用
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM public.ak_users u
|
||||
WHERE u.id = auth.uid() AND u.role IN ('admin', 'analytics')
|
||||
) THEN
|
||||
RAISE EXCEPTION 'permission denied';
|
||||
END IF;
|
||||
|
||||
RETURN QUERY
|
||||
SELECT
|
||||
d.uid,
|
||||
d.name,
|
||||
d.invite_code,
|
||||
d.commission_ratio,
|
||||
d.is_enabled,
|
||||
d.end_time,
|
||||
d.created_at,
|
||||
(SELECT COUNT(*) FROM public.ak_distribution_agents a WHERE a.division_uid = d.uid)::bigint AS "agentCount"
|
||||
FROM public.ak_distribution_divisions d
|
||||
WHERE (
|
||||
p_search IS NULL OR p_search = ''
|
||||
OR d.name ILIKE ('%' || p_search || '%')
|
||||
OR d.uid::text ILIKE ('%' || p_search || '%')
|
||||
)
|
||||
ORDER BY d.created_at DESC
|
||||
LIMIT v_page_size OFFSET v_offset;
|
||||
END;
|
||||
$$;
|
||||
|
||||
REVOKE ALL ON FUNCTION public.rpc_admin_get_division_list(text, integer, integer) FROM PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION public.rpc_admin_get_division_list(text, integer, integer) TO authenticated;
|
||||
@@ -0,0 +1,69 @@
|
||||
-- RPC: rpc_admin_process_agent_apply
|
||||
-- 管理端审核代理商申请
|
||||
-- 若通过(approved),则同步在 ak_distribution_agents 中创建或更新记录
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.rpc_admin_process_agent_apply(
|
||||
p_id uuid,
|
||||
p_status text, -- approved / rejected
|
||||
p_refusal_reason text DEFAULT NULL
|
||||
)
|
||||
RETURNS boolean
|
||||
LANGUAGE plpgsql
|
||||
SECURITY DEFINER
|
||||
SET search_path = public
|
||||
AS $$
|
||||
DECLARE
|
||||
v_uid uuid;
|
||||
v_division_uid uuid;
|
||||
v_agent_name text;
|
||||
BEGIN
|
||||
-- 仅管理员可审核
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM public.ak_users u
|
||||
WHERE u.id = auth.uid() AND u.role = 'admin'
|
||||
) THEN
|
||||
RAISE EXCEPTION 'permission denied';
|
||||
END IF;
|
||||
|
||||
-- 1. 获取并锁定申请记录
|
||||
SELECT uid, division_uid, agent_name
|
||||
INTO v_uid, v_division_uid, v_agent_name
|
||||
FROM public.ak_distribution_agent_applications
|
||||
WHERE id = p_id;
|
||||
|
||||
IF v_uid IS NULL THEN
|
||||
RAISE EXCEPTION 'application record not found';
|
||||
END IF;
|
||||
|
||||
-- 2. 更新申请状态
|
||||
UPDATE public.ak_distribution_agent_applications
|
||||
SET
|
||||
status = p_status,
|
||||
refusal_reason = CASE WHEN p_status = 'rejected' THEN p_refusal_reason ELSE NULL END,
|
||||
approved_at = now(),
|
||||
approved_by = auth.uid(),
|
||||
updated_at = now()
|
||||
WHERE id = p_id;
|
||||
|
||||
-- 3. 如果通过,则同步到代理商正式表
|
||||
IF p_status = 'approved' THEN
|
||||
INSERT INTO public.ak_distribution_agents (
|
||||
uid, division_uid, name, commission_ratio, is_enabled, updated_at, updated_by
|
||||
)
|
||||
VALUES (
|
||||
v_uid, v_division_uid, v_agent_name, 0, true, now(), auth.uid()
|
||||
)
|
||||
ON CONFLICT (uid) DO UPDATE
|
||||
SET
|
||||
division_uid = EXCLUDED.division_uid,
|
||||
name = EXCLUDED.name,
|
||||
updated_at = now(),
|
||||
updated_by = auth.uid();
|
||||
END IF;
|
||||
|
||||
RETURN true;
|
||||
END;
|
||||
$$;
|
||||
|
||||
REVOKE ALL ON FUNCTION public.rpc_admin_process_agent_apply(uuid, text, text) FROM PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION public.rpc_admin_process_agent_apply(uuid, text, text) TO authenticated;
|
||||
54
docs/sql/30_rpc/distribution/rpc_admin_save_agent_v1.sql
Normal file
54
docs/sql/30_rpc/distribution/rpc_admin_save_agent_v1.sql
Normal file
@@ -0,0 +1,54 @@
|
||||
-- RPC: rpc_admin_save_agent
|
||||
-- 管理端新增或更新代理商
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.rpc_admin_save_agent(
|
||||
p_uid uuid,
|
||||
p_division_uid uuid,
|
||||
p_name text,
|
||||
p_commission_ratio numeric,
|
||||
p_is_enabled boolean DEFAULT true,
|
||||
p_end_time timestamptz DEFAULT NULL
|
||||
)
|
||||
RETURNS uuid
|
||||
LANGUAGE plpgsql
|
||||
SECURITY DEFINER
|
||||
SET search_path = public
|
||||
AS $$
|
||||
BEGIN
|
||||
-- 仅管理员可操作
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM public.ak_users u
|
||||
WHERE u.id = auth.uid() AND u.role = 'admin'
|
||||
) THEN
|
||||
RAISE EXCEPTION 'permission denied';
|
||||
END IF;
|
||||
|
||||
-- 确保事业部存在
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM public.ak_distribution_divisions WHERE uid = p_division_uid
|
||||
) THEN
|
||||
RAISE EXCEPTION 'parent division not found';
|
||||
END IF;
|
||||
|
||||
INSERT INTO public.ak_distribution_agents (
|
||||
uid, division_uid, name, commission_ratio, is_enabled, end_time, updated_at, updated_by
|
||||
)
|
||||
VALUES (
|
||||
p_uid, p_division_uid, p_name, p_commission_ratio, p_is_enabled, p_end_time, now(), auth.uid()
|
||||
)
|
||||
ON CONFLICT (uid) DO UPDATE
|
||||
SET
|
||||
division_uid = EXCLUDED.division_uid,
|
||||
name = EXCLUDED.name,
|
||||
commission_ratio = EXCLUDED.commission_ratio,
|
||||
is_enabled = EXCLUDED.is_enabled,
|
||||
end_time = EXCLUDED.end_time,
|
||||
updated_at = now(),
|
||||
updated_by = auth.uid();
|
||||
|
||||
RETURN p_uid;
|
||||
END;
|
||||
$$;
|
||||
|
||||
REVOKE ALL ON FUNCTION public.rpc_admin_save_agent(uuid, uuid, text, numeric, boolean, timestamptz) FROM PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION public.rpc_admin_save_agent(uuid, uuid, text, numeric, boolean, timestamptz) TO authenticated;
|
||||
47
docs/sql/30_rpc/distribution/rpc_admin_save_division_v1.sql
Normal file
47
docs/sql/30_rpc/distribution/rpc_admin_save_division_v1.sql
Normal file
@@ -0,0 +1,47 @@
|
||||
-- RPC: rpc_admin_save_division
|
||||
-- 管理端新增或更新事业部
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.rpc_admin_save_division(
|
||||
p_uid uuid,
|
||||
p_name text,
|
||||
p_invite_code text,
|
||||
p_commission_ratio numeric,
|
||||
p_is_enabled boolean DEFAULT true,
|
||||
p_end_time timestamptz DEFAULT NULL
|
||||
)
|
||||
RETURNS uuid
|
||||
LANGUAGE plpgsql
|
||||
SECURITY DEFINER
|
||||
SET search_path = public
|
||||
AS $$
|
||||
BEGIN
|
||||
-- 仅管理员可操作
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM public.ak_users u
|
||||
WHERE u.id = auth.uid() AND u.role = 'admin'
|
||||
) THEN
|
||||
RAISE EXCEPTION 'permission denied';
|
||||
END IF;
|
||||
|
||||
INSERT INTO public.ak_distribution_divisions (
|
||||
uid, name, invite_code, commission_ratio, is_enabled, end_time, updated_at, updated_by
|
||||
)
|
||||
VALUES (
|
||||
p_uid, p_name, p_invite_code, p_commission_ratio, p_is_enabled, p_end_time, now(), auth.uid()
|
||||
)
|
||||
ON CONFLICT (uid) DO UPDATE
|
||||
SET
|
||||
name = EXCLUDED.name,
|
||||
invite_code = EXCLUDED.invite_code,
|
||||
commission_ratio = EXCLUDED.commission_ratio,
|
||||
is_enabled = EXCLUDED.is_enabled,
|
||||
end_time = EXCLUDED.end_time,
|
||||
updated_at = now(),
|
||||
updated_by = auth.uid();
|
||||
|
||||
RETURN p_uid;
|
||||
END;
|
||||
$$;
|
||||
|
||||
REVOKE ALL ON FUNCTION public.rpc_admin_save_division(uuid, text, text, numeric, boolean, timestamptz) FROM PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION public.rpc_admin_save_division(uuid, text, text, numeric, boolean, timestamptz) TO authenticated;
|
||||
@@ -4,32 +4,36 @@
|
||||
<view class="filter-row">
|
||||
<view class="filter-item">
|
||||
<text class="label">代理商查询:</text>
|
||||
<input class="filter-input" placeholder="请输入姓名、手机号或UID" v-model="searchQuery" @confirm="onSearch" />
|
||||
<input class="filter-input" placeholder="请输入姓名或UID" v-model="searchQuery" @confirm="onSearch" />
|
||||
</view>
|
||||
<view class="filter-btns">
|
||||
<button class="btn primary" @click="onSearch">查询</button>
|
||||
<button class="btn" @click="onReset">重置</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="content-card">
|
||||
<view class="action-bar">
|
||||
<button class="btn primary small" @click="onAdd">添加代理商</button>
|
||||
</view>
|
||||
<view class="table-container">
|
||||
<!-- Loading 遮罩 -->
|
||||
<view v-if="isLoading" class="loading-mask">
|
||||
<text class="loading-text">加载中...</text>
|
||||
<text class="loading-text">数据加载中...</text>
|
||||
</view>
|
||||
|
||||
<view class="table-header">
|
||||
<view class="col col-uid"><text>用户UID</text></view>
|
||||
<view class="col col-avatar"><text>头像</text></view>
|
||||
<view class="col col-name"><text>名称</text></view>
|
||||
<view class="col col-ratio"><text>所属事业部</text></view>
|
||||
<view class="col col-time"><text>加入时间</text></view>
|
||||
<view class="col col-ratio"><text>分佣比例</text></view>
|
||||
<view class="col col-dept"><text>所属事业部</text></view>
|
||||
<view class="col col-count"><text>员工数量</text></view>
|
||||
<view class="col col-time"><text>过期时间</text></view>
|
||||
<view class="col col-status"><text>状态</text></view>
|
||||
<view class="col col-ops"><text>操作</text></view>
|
||||
</view>
|
||||
|
||||
<view class="table-body">
|
||||
<view v-if="agentList.length === 0 && !isLoading" class="empty-row">
|
||||
<text>暂无代理商数据</text>
|
||||
@@ -37,18 +41,20 @@
|
||||
<view v-for="item in agentList" :key="item.uid" class="table-row">
|
||||
<view class="col col-uid"><text class="td-txt-small">{{ item.uid }}</text></view>
|
||||
<view class="col col-avatar">
|
||||
<image class="avatar-img" :src="item.avatar_url || '/static/logo.png'" mode="aspectFill" />
|
||||
<image class="avatar-img" src="/static/logo.png" mode="aspectFill" />
|
||||
</view>
|
||||
<view class="col col-name"><text>{{ item.name || item.nickname }}</text></view>
|
||||
<view class="col col-ratio"><text>{{ item.division_name || '-' }}</text></view>
|
||||
<view class="col col-time"><text>{{ formatDateTime(item.created_at) }}</text></view>
|
||||
<view class="col col-name"><text>{{ item.name }}</text></view>
|
||||
<view class="col col-ratio"><text>{{ item.commission_ratio }}%</text></view>
|
||||
<view class="col col-dept"><text>{{ item.division_name || '-' }}</text></view>
|
||||
<view class="col col-count"><text>{{ item.staffCount }}</text></view>
|
||||
<view class="col col-time"><text>{{ item.end_time ? item.end_time.substring(0, 10) : '-' }}</text></view>
|
||||
<view class="col col-status">
|
||||
<switch :checked="item.status" color="#1890ff" scale="0.8" @change="toggleStatus(item)" />
|
||||
<switch :checked="item.is_enabled" color="#1890ff" scale="0.8" @change="() => onToggleStatus(item)" />
|
||||
</view>
|
||||
<view class="col col-ops">
|
||||
<text class="op-link">详情</text>
|
||||
<text class="op-link" @click="onEdit(item)">编辑</text>
|
||||
<text class="op-divider">|</text>
|
||||
<text class="op-link danger" @click="onDelete(item.id)">删除</text>
|
||||
<text class="op-link danger" @click="onDelete(item.uid)">删除</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -60,36 +66,100 @@
|
||||
<text class="page-num">第 {{ page }} 页</text>
|
||||
<button class="btn small" :disabled="agentList.length < pageSize" @click="onNextPage">下一页</button>
|
||||
</view>
|
||||
<text class="page-info">共 {{ total }} 条记录</text>
|
||||
<text class="page-info">共 {{ agentList.length }} 条记录</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 添加/编辑 弹窗 -->
|
||||
<view v-if="editPopupVisible" class="popup-mask" @click="closeEditModal">
|
||||
<view class="popup-card" @click.stop>
|
||||
<view class="popup-header">
|
||||
<text class="popup-title">{{ isEdit ? '编辑代理商' : '添加代理商' }}</text>
|
||||
<text class="popup-close" @click="closeEditModal">×</text>
|
||||
</view>
|
||||
|
||||
<view class="popup-body">
|
||||
<view class="popup-item" v-if="!isEdit">
|
||||
<text class="popup-label">用户 UID</text>
|
||||
<input v-model="editForm.uid" class="popup-input" placeholder="请输入代理商 UID" />
|
||||
</view>
|
||||
|
||||
<view class="popup-item">
|
||||
<text class="popup-label">所属事业部</text>
|
||||
<picker :value="divisionIndex" :range="divisionOptions" range-key="name" @change="onDivisionChange">
|
||||
<view class="select-box">
|
||||
<text>{{ divisionOptions[divisionIndex]?.name || '请选择事业部' }}</text>
|
||||
<text class="arrow">▼</text>
|
||||
</view>
|
||||
</picker>
|
||||
</view>
|
||||
|
||||
<view class="popup-item">
|
||||
<text class="popup-label">代理商名称</text>
|
||||
<input v-model="editForm.name" class="popup-input" placeholder="请输入名称" />
|
||||
</view>
|
||||
|
||||
<view class="popup-item">
|
||||
<text class="popup-label">分佣比例 (%)</text>
|
||||
<input v-model="editForm.commission_ratio" type="digit" class="popup-input" placeholder="0 - 100" />
|
||||
</view>
|
||||
|
||||
<view class="popup-item">
|
||||
<text class="popup-label">过期时间</text>
|
||||
<input v-model="editForm.end_time" class="popup-input" placeholder="YYYY-MM-DD" />
|
||||
</view>
|
||||
|
||||
<view class="popup-item popup-row">
|
||||
<text class="popup-label">启用状态</text>
|
||||
<switch :checked="editForm.is_enabled" color="#1890ff" scale="0.8" @change="(e : any) => editForm.is_enabled = e.detail.value" />
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="popup-footer">
|
||||
<button class="btn" @click="closeEditModal">取消</button>
|
||||
<button class="btn primary" @click="handleSave">保存</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
<script setup lang="uts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { fetchAgents, saveAgent, DistributionAgent } from '@/services/admin/distributionService.uts'
|
||||
|
||||
const agentList = ref<DistributionAgent[]>([])
|
||||
<script setup lang="uts">
|
||||
import { ref, onMounted, reactive } from 'vue'
|
||||
import { getAgentList, saveAgent, deleteAgent, getDivisionList, type Agent, type Division } from '@/services/admin/distributionService.uts'
|
||||
|
||||
const agentList = ref<Agent[]>([])
|
||||
const isLoading = ref(false)
|
||||
const searchQuery = ref('')
|
||||
const total = ref(0)
|
||||
const page = ref(1)
|
||||
const pageSize = 20
|
||||
|
||||
onMounted(() => {
|
||||
loadData()
|
||||
// 事业部选项 (供选择器使用)
|
||||
const divisionOptions = ref<Division[]>([])
|
||||
const divisionIndex = ref(0)
|
||||
|
||||
// 弹窗状态
|
||||
const editPopupVisible = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const editForm = reactive({
|
||||
uid: '',
|
||||
division_uid: '',
|
||||
name: '',
|
||||
commission_ratio: 0,
|
||||
is_enabled: true,
|
||||
end_time: ''
|
||||
})
|
||||
|
||||
async function loadData() {
|
||||
onMounted(() => {
|
||||
loadAgents()
|
||||
loadDivisions()
|
||||
})
|
||||
|
||||
async function loadAgents() {
|
||||
isLoading.value = true
|
||||
try {
|
||||
const res = await fetchAgents({
|
||||
search: searchQuery.value,
|
||||
page: page.value,
|
||||
pageSize: pageSize
|
||||
})
|
||||
agentList.value = res.items
|
||||
total.value = res.total
|
||||
const res = await getAgentList(searchQuery.value || null, page.value, pageSize)
|
||||
agentList.value = res
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '加载失败', icon: 'none' })
|
||||
} finally {
|
||||
@@ -97,55 +167,168 @@ async function loadData() {
|
||||
}
|
||||
}
|
||||
|
||||
async function loadDivisions() {
|
||||
const res = await getDivisionList(null, 1, 100)
|
||||
divisionOptions.value = res
|
||||
}
|
||||
|
||||
function onSearch() {
|
||||
page.value = 1
|
||||
loadData()
|
||||
loadAgents()
|
||||
}
|
||||
|
||||
function onReset() {
|
||||
searchQuery.value = ''
|
||||
page.value = 1
|
||||
loadAgents()
|
||||
}
|
||||
|
||||
function onAdd() {
|
||||
uni.showToast({ title: '添加代理商功能开发中', icon: 'none' })
|
||||
isEdit.value = false
|
||||
Object.assign(editForm, {
|
||||
uid: '',
|
||||
division_uid: '',
|
||||
name: '',
|
||||
commission_ratio: 0,
|
||||
is_enabled: true,
|
||||
end_time: ''
|
||||
})
|
||||
divisionIndex.value = 0
|
||||
editPopupVisible.value = true
|
||||
}
|
||||
|
||||
async function toggleStatus(item : DistributionAgent) {
|
||||
if (item.id == null) return
|
||||
const nextStatus = !item.status
|
||||
const success = await saveAgent({ ...item, status: nextStatus } as DistributionAgent)
|
||||
function onEdit(item : Agent) {
|
||||
isEdit.value = true
|
||||
Object.assign(editForm, {
|
||||
uid: item.uid,
|
||||
division_uid: item.division_uid,
|
||||
name: item.name,
|
||||
commission_ratio: item.commission_ratio,
|
||||
is_enabled: item.is_enabled,
|
||||
end_time: item.end_time || ''
|
||||
})
|
||||
|
||||
const idx = divisionOptions.value.findIndex(d => d.uid === item.division_uid)
|
||||
divisionIndex.value = idx > -1 ? idx : 0
|
||||
|
||||
editPopupVisible.value = true
|
||||
}
|
||||
|
||||
function closeEditModal() {
|
||||
editPopupVisible.value = false
|
||||
}
|
||||
|
||||
function onDivisionChange(e : any) {
|
||||
divisionIndex.value = e.detail.value as number
|
||||
editForm.division_uid = divisionOptions.value[divisionIndex.value].uid
|
||||
}
|
||||
|
||||
async function handleSave() {
|
||||
if (!editForm.uid || !editForm.division_uid || !editForm.name) {
|
||||
uni.showToast({ title: '请完善信息', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
isLoading.value = true
|
||||
try {
|
||||
const success = await saveAgent(editForm)
|
||||
if (success) {
|
||||
uni.showToast({ title: '保存成功', icon: 'success' })
|
||||
editPopupVisible.value = false
|
||||
loadAgents()
|
||||
}
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function onDelete(uid : string) {
|
||||
uni.showModal({
|
||||
title: '确认删除',
|
||||
content: '确定要删除该代理商吗?',
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
isLoading.value = true
|
||||
try {
|
||||
const success = await deleteAgent(uid)
|
||||
if (success) {
|
||||
uni.showToast({ title: '删除成功' })
|
||||
loadAgents()
|
||||
}
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function onToggleStatus(item : Agent) {
|
||||
const updated = { ...item, is_enabled: !item.is_enabled }
|
||||
const success = await saveAgent(updated)
|
||||
if (success) {
|
||||
item.status = nextStatus
|
||||
uni.showToast({ title: '状态修改成功', icon: 'success' })
|
||||
item.is_enabled = !item.is_enabled
|
||||
uni.showToast({ title: '状态已更新' })
|
||||
}
|
||||
}
|
||||
|
||||
function onPrevPage() {
|
||||
if (page.value > 1) {
|
||||
page.value--
|
||||
loadData()
|
||||
loadAgents()
|
||||
}
|
||||
}
|
||||
|
||||
function onNextPage() {
|
||||
if (agentList.value.length >= pageSize) {
|
||||
page.value++
|
||||
loadData()
|
||||
}
|
||||
if (agentList.value.length < pageSize) return
|
||||
page.value++
|
||||
loadAgents()
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.admin-page { padding: 0; }
|
||||
.filter-card { background: #fff; padding: 24px; margin-bottom: 16px; border-radius: 4px; }
|
||||
.filter-row { display: flex; flex-direction: row; align-items: center; gap: 24px; }
|
||||
.label { font-size: 14px; color: #333; }
|
||||
.filter-input { border: 1px solid #d9d9d9; height: 32px; width: 220px; padding: 0 12px; font-size: 14px; }
|
||||
.btn { height: 32px; padding: 0 16px; font-size: 14px; border: 1px solid #d9d9d9; background: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer; }
|
||||
.filter-input { border: 1px solid #d9d9d9; height: 32px; width: 220px; padding: 0 12px; font-size: 14px; border-radius: 4px; }
|
||||
.btn { height: 32px; padding: 0 16px; font-size: 14px; border: 1px solid #d9d9d9; background: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer; border-radius: 4px; }
|
||||
.btn.primary { background: #1890ff; border-color: #1890ff; color: #fff; }
|
||||
.content-card { background: #fff; border-radius: 4px; }
|
||||
.btn.small { height: 28px; padding: 0 12px; font-size: 13px; }
|
||||
|
||||
.content-card { background: #fff; border-radius: 4px; position: relative; }
|
||||
.action-bar { padding: 16px 24px; }
|
||||
.table-container { padding: 0 24px 24px; }
|
||||
.table-container { padding: 0 24px 24px; min-height: 200px; }
|
||||
.table-header { display: flex; flex-direction: row; background: #f8faff; border-bottom: 1px solid #f0f0f0; padding: 12px 0; }
|
||||
.table-row { display: flex; flex-direction: row; border-bottom: 1px solid #f0f0f0; padding: 12px 0; align-items: center; &:hover { background: #fafafa; } }
|
||||
.col { padding: 0 8px; font-size: 14px; color: #333; display: flex; align-items: center; }
|
||||
.col-uid { width: 80px; } .col-avatar { width: 80px; justify-content: center; } .col-name { width: 120px; } .col-ratio { width: 100px; justify-content: center; } .col-count { width: 100px; justify-content: center; } .col-time { width: 120px; justify-content: center; } .col-status { width: 80px; justify-content: center; } .col-ops { flex: 1; justify-content: flex-end; }
|
||||
|
||||
.col-uid { width: 80px; } .col-avatar { width: 80px; justify-content: center; } .col-name { width: 120px; } .col-ratio { width: 100px; justify-content: center; } .col-dept { width: 140px; } .col-count { width: 100px; justify-content: center; } .col-time { width: 120px; justify-content: center; } .col-status { width: 80px; justify-content: center; } .col-ops { flex: 1; justify-content: flex-end; }
|
||||
|
||||
.avatar-img { width: 32px; height: 32px; border-radius: 2px; }
|
||||
.op-link { color: #1890ff; cursor: pointer; }
|
||||
.op-link { color: #1890ff; cursor: pointer; &.danger { color: #ff4d4f; } }
|
||||
.op-divider { color: #e8e8e8; margin: 0 8px; }
|
||||
|
||||
.pagination { padding: 16px 24px; border-top: 1px solid #f0f0f0; display: flex; flex-direction: row; align-items: center; justify-content: space-between; }
|
||||
.pager-btns { display: flex; flex-direction: row; align-items: center; gap: 12px; }
|
||||
.page-num { font-size: 14px; color: #333; }
|
||||
.page-info { font-size: 14px; color: #999; }
|
||||
|
||||
.loading-mask { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(255,255,255,0.7); display: flex; align-items: center; justify-content: center; z-index: 10; }
|
||||
.loading-text { color: #1890ff; font-size: 14px; }
|
||||
.empty-row { padding: 40px 0; text-align: center; color: #999; font-size: 14px; }
|
||||
|
||||
/* 弹窗样式 */
|
||||
.popup-mask { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0, 0, 0, 0.5); display: flex; align-items: center; justify-content: center; z-index: 999; }
|
||||
.popup-card { width: 500px; background-color: #fff; border-radius: 8px; display: flex; flex-direction: column; overflow: hidden; }
|
||||
.popup-header { display: flex; flex-direction: row; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid #f0f0f0; }
|
||||
.popup-title { font-size: 16px; font-weight: bold; color: #333; }
|
||||
.popup-close { font-size: 20px; color: #999; cursor: pointer; padding: 4px; }
|
||||
.popup-body { padding: 24px; display: flex; flex-direction: column; gap: 16px; }
|
||||
.popup-item { display: flex; flex-direction: column; gap: 8px; }
|
||||
.popup-row { flex-direction: row; align-items: center; justify-content: space-between; }
|
||||
.popup-label { font-size: 14px; color: #666; }
|
||||
.popup-input { border: 1px solid #d9d9d9; border-radius: 4px; height: 36px; padding: 0 12px; font-size: 14px; width: 100%; }
|
||||
.select-box { border: 1px solid #d9d9d9; border-radius: 4px; height: 36px; padding: 0 12px; display: flex; flex-direction: row; align-items: center; justify-content: space-between; text { font-size: 14px; color: #333; } .arrow { font-size: 10px; color: #bfbfbf; } }
|
||||
.popup-footer { padding: 16px 24px; border-top: 1px solid #f0f0f0; display: flex; flex-direction: row; justify-content: flex-end; gap: 12px; }
|
||||
</style>
|
||||
@@ -4,23 +4,24 @@
|
||||
<view class="filter-row">
|
||||
<view class="filter-item">
|
||||
<text class="label">搜索:</text>
|
||||
<input class="filter-input" placeholder="请输入姓名、UID" />
|
||||
<input class="filter-input" placeholder="请输入姓名、UID" v-model="searchQuery" @confirm="onSearch" />
|
||||
</view>
|
||||
<view class="filter-btns">
|
||||
<button class="btn primary" @click="onSearch">查询</button>
|
||||
<button class="btn" @click="onReset">重置</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="content-card">
|
||||
<view class="tabs-row">
|
||||
<view v-for="(tab, index) in tabs" :key="index" class="tab-item" :class="{ active: activeTab === index }" @click="activeTab = index">
|
||||
<text>{{ tab }}</text>
|
||||
<view v-for="(tab, index) in tabOptions" :key="index" class="tab-item" :class="{ active: activeTabIndex === index }" @click="onTabChange(index)">
|
||||
<text>{{ tab.label }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="table-container">
|
||||
<!-- Loading 遮罩 -->
|
||||
<view v-if="isLoading" class="loading-mask">
|
||||
<text class="loading-text">加载中...</text>
|
||||
<text class="loading-text">数据加载中...</text>
|
||||
</view>
|
||||
|
||||
<view class="table-header">
|
||||
@@ -41,75 +42,70 @@
|
||||
<view v-for="item in applyList" :key="item.id" class="table-row">
|
||||
<view class="col col-uid"><text class="td-txt-small">{{ item.uid }}</text></view>
|
||||
<view class="col col-name"><text>{{ item.name }}</text></view>
|
||||
<view class="col col-phone"><text>{{ item.phone }}</text></view>
|
||||
<view class="col col-dept"><text>{{ item.division_name || '-' }}</text></view>
|
||||
<view class="col col-phone"><text>{{ item.phone || '-' }}</text></view>
|
||||
<view class="col col-dept"><text>{{ item.dept_name }}</text></view>
|
||||
<view class="col col-img">
|
||||
<image class="table-img" :src="item.images[0] || '/static/logo.png'" mode="aspectFill" />
|
||||
<image v-if="item.proof_images != null && item.proof_images!.length > 0" class="table-img" :src="item.proof_images![0]" mode="aspectFill" />
|
||||
<view v-else class="img-placeholder"><text>无</text></view>
|
||||
</view>
|
||||
<view class="col col-time"><text class="td-txt-small">{{ formatTime(item.created_at) }}</text></view>
|
||||
<view class="col col-time"><text class="td-txt-small">{{ formatDateTime(item.time) }}</text></view>
|
||||
<view class="col col-status">
|
||||
<view class="status-tag"><text>{{ getStatusLabel(item.status) }}</text></view>
|
||||
<view class="status-tag" :class="getStatusClass(item.status)"><text>{{ getStatusText(item.status) }}</text></view>
|
||||
</view>
|
||||
<view class="col col-code"><view class="code-box"><text>{{ item.invite_code || '-' }}</text></view></view>
|
||||
<view class="col col-code"><view class="code-box"><text>{{ item.invite_code }}</text></view></view>
|
||||
<view class="col col-ops">
|
||||
<template v-if="item.status === 1">
|
||||
<text class="op-link" @click="handleAudit(item, 2)">同意</text>
|
||||
<text class="op-divider">|</text>
|
||||
<text class="op-link" @click="handleAudit(item, 3)">拒绝</text>
|
||||
<template v-if="item.status === 'pending'">
|
||||
<text class="op-link" @click="handleProcess(item, 'approved')">同意</text>
|
||||
<text class="op-divider">|</text>
|
||||
<text class="op-link danger" @click="handleProcess(item, 'rejected')">拒绝</text>
|
||||
</template>
|
||||
<text class="op-link danger" @click="onDelete(item.id)">删除</text>
|
||||
<text v-else class="op-disabled">-</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="pagination" style="padding: 16px 24px;">
|
||||
<!-- 分页 -->
|
||||
<view class="pagination">
|
||||
<view class="pager-btns">
|
||||
<button class="btn small" :disabled="page <= 1" @click="onPrevPage">上一页</button>
|
||||
<text class="page-num">第 {{ page }} 页</text>
|
||||
<button class="btn small" :disabled="applyList.length < pageSize" @click="onNextPage">下一页</button>
|
||||
</view>
|
||||
<text class="page-info">共 {{ total }} 条记录</text>
|
||||
<text class="page-info">共 {{ applyList.length }} 条记录</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref, onMounted, watch } from 'vue'
|
||||
import { fetchApplications, auditApplication, DistributionApplication } from '@/services/admin/distributionService.uts'
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { getAgentApplyList, processAgentApply, type AgentApply } from '@/services/admin/distributionService.uts'
|
||||
|
||||
const activeTab = ref(0)
|
||||
const tabs = ['全部', '申请中', '已同意', '已拒绝']
|
||||
const statusMap = [0, 1, 2, 3] // 映射到接口状态: 0:全部, 1:待审核, 2:已同意, 3:已拒绝
|
||||
|
||||
const applyList = ref<DistributionApplication[]>([])
|
||||
const isLoading = ref(false)
|
||||
const applyList = ref<AgentApply[]>([])
|
||||
const searchQuery = ref('')
|
||||
const total = ref(0)
|
||||
const page = ref(1)
|
||||
const pageSize = 20
|
||||
|
||||
onMounted(() => {
|
||||
loadData()
|
||||
})
|
||||
const activeTabIndex = ref(0)
|
||||
const tabOptions = [
|
||||
{ label: '全部', value: 'all' },
|
||||
{ label: '申请中', value: 'pending' },
|
||||
{ label: '已同意', value: 'approved' },
|
||||
{ label: '已拒绝', value: 'rejected' }
|
||||
]
|
||||
|
||||
watch(activeTab, () => {
|
||||
page.value = 1
|
||||
onMounted(() => {
|
||||
loadData()
|
||||
})
|
||||
|
||||
async function loadData() {
|
||||
isLoading.value = true
|
||||
try {
|
||||
const res = await fetchApplications({
|
||||
search: searchQuery.value,
|
||||
status: statusMap[activeTab.value],
|
||||
page: page.value,
|
||||
pageSize: pageSize
|
||||
})
|
||||
applyList.value = res.items
|
||||
total.value = res.total
|
||||
const status = tabOptions[activeTabIndex.value].value
|
||||
const res = await getAgentApplyList(status, searchQuery.value || null, page.value, pageSize)
|
||||
applyList.value = res
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '加载失败', icon: 'none' })
|
||||
} finally {
|
||||
@@ -122,36 +118,56 @@ function onSearch() {
|
||||
loadData()
|
||||
}
|
||||
|
||||
async function handleAudit(item : DistributionApplication, status : number) {
|
||||
if (item.id == null) return
|
||||
const actionText = status === 2 ? '同意' : '拒绝'
|
||||
uni.showModal({
|
||||
title: '确认操作',
|
||||
content: `确定要${actionText}该申请吗?`,
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
const success = await auditApplication(item.id!, status)
|
||||
if (success) {
|
||||
uni.showToast({ title: '操作成功', icon: 'success' })
|
||||
loadData()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
function onReset() {
|
||||
searchQuery.value = ''
|
||||
page.value = 1
|
||||
loadData()
|
||||
}
|
||||
|
||||
async function onDelete(id : string | undefined) {
|
||||
if (id == null) return
|
||||
uni.showModal({
|
||||
title: '确认删除',
|
||||
content: '确定要删除该申请记录吗?',
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
// 暂用审核接口或补充删除接口,此处示例为提示
|
||||
uni.showToast({ title: '删除功能开发中', icon: 'none' })
|
||||
function onTabChange(index : number) {
|
||||
activeTabIndex.value = index
|
||||
page.value = 1
|
||||
loadData()
|
||||
}
|
||||
|
||||
async function handleProcess(item : AgentApply, status : string) {
|
||||
const actionText = status === 'approved' ? '同意' : '拒绝'
|
||||
|
||||
if (status === 'rejected') {
|
||||
uni.showModal({
|
||||
title: '拒绝申请',
|
||||
editable: true,
|
||||
placeholderText: '请输入拒绝原因',
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
await doProcess(item.id, status, res.content)
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: `确定要 ${actionText} 该申请吗?`,
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
await doProcess(item.id, status, null)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async function doProcess(id : string, status : string, reason : string | null) {
|
||||
isLoading.value = true
|
||||
try {
|
||||
const success = await processAgentApply(id, status, reason)
|
||||
if (success) {
|
||||
uni.showToast({ title: '处理成功', icon: 'success' })
|
||||
loadData()
|
||||
}
|
||||
})
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function onPrevPage() {
|
||||
@@ -162,46 +178,72 @@ function onPrevPage() {
|
||||
}
|
||||
|
||||
function onNextPage() {
|
||||
if (applyList.value.length >= pageSize) {
|
||||
page.value++
|
||||
loadData()
|
||||
}
|
||||
if (applyList.value.length < pageSize) return
|
||||
page.value++
|
||||
loadData()
|
||||
}
|
||||
|
||||
function formatTime(iso : string | null | undefined) : string {
|
||||
if (iso == null) return '-'
|
||||
return iso.substring(0, 16).replace('T', ' ')
|
||||
function getStatusText(status : string) : string {
|
||||
if (status === 'pending') return '申请中'
|
||||
if (status === 'approved') return '已同意'
|
||||
if (status === 'rejected') return '已拒绝'
|
||||
return status
|
||||
}
|
||||
|
||||
function getStatusLabel(status : number) : string {
|
||||
switch (status) {
|
||||
case 1: return '申请中'
|
||||
case 2: return '已同意'
|
||||
case 3: return '已拒绝'
|
||||
default: return '未知'
|
||||
}
|
||||
function getStatusClass(status : string) : string {
|
||||
if (status === 'pending') return 'pending'
|
||||
if (status === 'approved') return 'approved'
|
||||
if (status === 'rejected') return 'rejected'
|
||||
return ''
|
||||
}
|
||||
|
||||
function formatDateTime(dateStr : string) : string {
|
||||
return dateStr.substring(0, 16).replace('T', ' ')
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.admin-page { padding: 0; }
|
||||
.filter-card { background: #fff; padding: 24px; margin-bottom: 16px; border-radius: 4px; }
|
||||
.filter-row { display: flex; flex-direction: row; align-items: center; gap: 24px; }
|
||||
.label { font-size: 14px; color: #333; }
|
||||
.filter-input { border: 1px solid #d9d9d9; height: 32px; width: 220px; padding: 0 12px; font-size: 14px; }
|
||||
.btn { height: 32px; padding: 0 16px; font-size: 14px; border: 1px solid #d9d9d9; background: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer; }
|
||||
.filter-input { border: 1px solid #d9d9d9; height: 32px; width: 220px; padding: 0 12px; font-size: 14px; border-radius: 4px; }
|
||||
.btn { height: 32px; padding: 0 16px; font-size: 14px; border: 1px solid #d9d9d9; background: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer; border-radius: 4px; }
|
||||
.btn.primary { background: #1890ff; border-color: #1890ff; color: #fff; }
|
||||
.content-card { background: #fff; border-radius: 4px; }
|
||||
.btn.small { height: 28px; padding: 0 12px; font-size: 13px; }
|
||||
|
||||
.content-card { background: #fff; border-radius: 4px; position: relative; }
|
||||
.tabs-row { display: flex; flex-direction: row; padding: 0 24px; border-bottom: 1px solid #f0f0f0; }
|
||||
.tab-item { padding: 16px 20px; cursor: pointer; position: relative; text { font-size: 15px; color: #666; } &.active { text { color: #1890ff; font-weight: 500; } &::after { content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 2px; background: #1890ff; } } }
|
||||
.table-container { padding: 24px; }
|
||||
|
||||
.table-container { padding: 24px; min-height: 200px; }
|
||||
.table-header { display: flex; flex-direction: row; background: #f8faff; border-bottom: 1px solid #f0f0f0; padding: 12px 0; }
|
||||
.table-row { display: flex; flex-direction: row; border-bottom: 1px solid #f0f0f0; padding: 12px 0; align-items: center; &:hover { background: #fafafa; } }
|
||||
.col { padding: 0 8px; font-size: 14px; color: #333; display: flex; align-items: center; }
|
||||
|
||||
.col-uid { width: 80px; } .col-name { width: 120px; } .col-phone { width: 120px; } .col-dept { width: 120px; } .col-img { width: 80px; justify-content: center; } .col-time { width: 160px; justify-content: center; } .col-status { width: 100px; justify-content: center; } .col-code { width: 100px; justify-content: center; } .col-ops { flex: 1; justify-content: flex-end; }
|
||||
.table-img { width: 32px; height: 32px; border-radius: 2px; }
|
||||
.status-tag { border: 1px solid #1890ff; color: #1890ff; padding: 2px 8px; border-radius: 4px; font-size: 12px; }
|
||||
|
||||
.td-txt-small { font-size: 12px; color: #666; }
|
||||
.table-img { width: 32px; height: 32px; border-radius: 2px; background: #f5f5f5; }
|
||||
.img-placeholder { width: 32px; height: 32px; background: #f5f5f5; display: flex; align-items: center; justify-content: center; text { font-size: 12px; color: #ccc; } }
|
||||
|
||||
.status-tag { border: 1px solid #d9d9d9; color: #666; padding: 2px 8px; border-radius: 4px; font-size: 12px; background: #fafafa;
|
||||
&.pending { border-color: #1890ff; color: #1890ff; background: #e6f7ff; }
|
||||
&.approved { border-color: #52c41a; color: #52c41a; background: #f6ffed; }
|
||||
&.rejected { border-color: #f5222d; color: #f5222d; background: #fff1f0; }
|
||||
}
|
||||
|
||||
.code-box { border: 1px solid #d9d9d9; padding: 2px 8px; border-radius: 4px; font-size: 12px; background: #fafafa; }
|
||||
.op-link { color: #1890ff; cursor: pointer; }
|
||||
.op-link { color: #1890ff; cursor: pointer; &.danger { color: #ff4d4f; } }
|
||||
.op-divider { color: #e8e8e8; margin: 0 8px; }
|
||||
</style>
|
||||
.op-disabled { color: #ccc; font-size: 14px; }
|
||||
|
||||
.pagination { padding: 16px 24px; border-top: 1px solid #f0f0f0; display: flex; flex-direction: row; align-items: center; justify-content: space-between; }
|
||||
.pager-btns { display: flex; flex-direction: row; align-items: center; gap: 12px; }
|
||||
.page-num { font-size: 14px; color: #333; }
|
||||
.page-info { font-size: 14px; color: #999; }
|
||||
|
||||
.loading-mask { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(255,255,255,0.7); display: flex; align-items: center; justify-content: center; z-index: 10; }
|
||||
.loading-text { color: #1890ff; font-size: 14px; }
|
||||
.empty-row { padding: 40px 0; text-align: center; color: #999; font-size: 14px; }
|
||||
</style>
|
||||
@@ -1,5 +1,6 @@
|
||||
<template>
|
||||
<view class="admin-page">
|
||||
<!-- 过滤器区域 -->
|
||||
<view class="filter-card">
|
||||
<view class="filter-row">
|
||||
<view class="filter-item">
|
||||
@@ -8,9 +9,12 @@
|
||||
</view>
|
||||
<view class="filter-btns">
|
||||
<button class="btn primary" @click="onSearch">查询</button>
|
||||
<button class="btn" @click="onReset">重置</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 内容区域 -->
|
||||
<view class="content-card">
|
||||
<view class="action-bar">
|
||||
<button class="btn primary small" @click="onAdd">添加事业部</button>
|
||||
@@ -18,7 +22,7 @@
|
||||
<view class="table-container">
|
||||
<!-- Loading 遮罩 -->
|
||||
<view v-if="isLoading" class="loading-mask">
|
||||
<text class="loading-text">加载中...</text>
|
||||
<text class="loading-text">数据加载中...</text>
|
||||
</view>
|
||||
|
||||
<view class="table-header">
|
||||
@@ -37,63 +41,113 @@
|
||||
<text>暂无事业部数据</text>
|
||||
</view>
|
||||
<view v-for="item in divisionList" :key="item.uid" class="table-row">
|
||||
<view class="col col-uid"><text class="td-txt-small">{{ item.uid }}</text></view>
|
||||
<view class="col col-uid"><text>{{ item.uid }}</text></view>
|
||||
<view class="col col-avatar">
|
||||
<image class="avatar-img" :src="item.avatar_url || '/static/logo.png'" mode="aspectFill" />
|
||||
<image class="avatar-img" src="/static/logo.png" mode="aspectFill" />
|
||||
</view>
|
||||
<view class="col col-name"><text>{{ item.name || item.nickname }}</text></view>
|
||||
<view class="col col-name"><text>{{ item.name }}</text></view>
|
||||
<view class="col col-code"><text>{{ item.invite_code }}</text></view>
|
||||
<view class="col col-ratio"><text>{{ item.ratio }}%</text></view>
|
||||
<view class="col col-count"><text>{{ item.agent_count }}</text></view>
|
||||
<view class="col col-time"><text>{{ formatTime(item.end_time) }}</text></view>
|
||||
<view class="col col-ratio"><text>{{ item.commission_ratio }}%</text></view>
|
||||
<view class="col col-count"><text>{{ item.agentCount }}</text></view>
|
||||
<view class="col col-time"><text>{{ item.end_time ? item.end_time.substring(0, 10) : '-' }}</text></view>
|
||||
<view class="col col-status">
|
||||
<switch :checked="item.status" color="#1890ff" scale="0.8" @change="toggleStatus(item)" />
|
||||
<switch :checked="item.is_enabled" color="#1890ff" scale="0.8" @change="() => onToggleStatus(item)" />
|
||||
</view>
|
||||
<view class="col col-ops">
|
||||
<text class="op-link">查看代理商</text>
|
||||
<text class="op-link" @click="onEdit(item)">编辑</text>
|
||||
<text class="op-divider">|</text>
|
||||
<text class="op-link" @click="onDelete(item.id)">删除</text>
|
||||
<text class="op-link danger" @click="onDelete(item.uid)">删除</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 分页区域 -->
|
||||
<view class="pagination">
|
||||
<view class="pager-btns">
|
||||
<button class="btn small" :disabled="page <= 1" @click="onPrevPage">上一页</button>
|
||||
<text class="page-num">第 {{ page }} 页</text>
|
||||
<button class="btn small" :disabled="divisionList.length < pageSize" @click="onNextPage">下一页</button>
|
||||
</view>
|
||||
<text class="page-info">共 {{ total }} 条记录</text>
|
||||
<text class="page-info">共 {{ divisionList.length }} 条记录</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 添加/编辑 弹窗 -->
|
||||
<view v-if="editPopupVisible" class="popup-mask" @click="closeEditModal">
|
||||
<view class="popup-card" @click.stop>
|
||||
<view class="popup-header">
|
||||
<text class="popup-title">{{ isEdit ? '编辑事业部' : '添加事业部' }}</text>
|
||||
<text class="popup-close" @click="closeEditModal">×</text>
|
||||
</view>
|
||||
|
||||
<view class="popup-body">
|
||||
<view class="popup-item" v-if="!isEdit">
|
||||
<text class="popup-label">用户 UID</text>
|
||||
<input v-model="editForm.uid" class="popup-input" placeholder="请输入负责人 UID" />
|
||||
</view>
|
||||
<view class="popup-item">
|
||||
<text class="popup-label">事业部名称</text>
|
||||
<input v-model="editForm.name" class="popup-input" placeholder="如:华东事业部" />
|
||||
</view>
|
||||
<view class="popup-item">
|
||||
<text class="popup-label">邀请码</text>
|
||||
<input v-model="editForm.invite_code" class="popup-input" placeholder="请输入唯一邀请码" />
|
||||
</view>
|
||||
<view class="popup-item">
|
||||
<text class="popup-label">分佣比例 (%)</text>
|
||||
<input v-model="editForm.commission_ratio" type="digit" class="popup-input" placeholder="0 - 100" />
|
||||
</view>
|
||||
<view class="popup-item">
|
||||
<text class="popup-label">截止时间</text>
|
||||
<input v-model="editForm.end_time" class="popup-input" placeholder="YYYY-MM-DD" />
|
||||
</view>
|
||||
<view class="popup-item popup-row">
|
||||
<text class="popup-label">启用状态</text>
|
||||
<switch :checked="editForm.is_enabled" color="#1890ff" scale="0.8" @change="(e : any) => editForm.is_enabled = e.detail.value" />
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="popup-footer">
|
||||
<button class="btn" @click="closeEditModal">取消</button>
|
||||
<button class="btn primary" @click="handleSave">保存</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
<script setup lang="uts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { fetchDivisions, saveDivision, deleteDivision, DistributionDivision } from '@/services/admin/distributionService.uts'
|
||||
|
||||
const divisionList = ref<DistributionDivision[]>([])
|
||||
<script setup lang="uts">
|
||||
import { ref, onMounted, reactive } from 'vue'
|
||||
import { getDivisionList, saveDivision, deleteDivision, type Division } from '@/services/admin/distributionService.uts'
|
||||
|
||||
const divisionList = ref<Division[]>([])
|
||||
const isLoading = ref(false)
|
||||
const searchQuery = ref('')
|
||||
const total = ref(0)
|
||||
const page = ref(1)
|
||||
const pageSize = 20
|
||||
|
||||
onMounted(() => {
|
||||
loadData()
|
||||
// 弹窗表单状态
|
||||
const editPopupVisible = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const editForm = reactive({
|
||||
uid: '',
|
||||
name: '',
|
||||
invite_code: '',
|
||||
commission_ratio: 0,
|
||||
is_enabled: true,
|
||||
end_time: ''
|
||||
})
|
||||
|
||||
async function loadData() {
|
||||
onMounted(() => {
|
||||
loadDivisions()
|
||||
})
|
||||
|
||||
async function loadDivisions() {
|
||||
isLoading.value = true
|
||||
try {
|
||||
const res = await fetchDivisions({
|
||||
search: searchQuery.value,
|
||||
page: page.value,
|
||||
pageSize: pageSize
|
||||
})
|
||||
divisionList.value = res.items
|
||||
total.value = res.total
|
||||
const res = await getDivisionList(searchQuery.value || null, page.value, pageSize)
|
||||
divisionList.value = res
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '加载失败', icon: 'none' })
|
||||
} finally {
|
||||
@@ -103,75 +157,152 @@ async function loadData() {
|
||||
|
||||
function onSearch() {
|
||||
page.value = 1
|
||||
loadData()
|
||||
loadDivisions()
|
||||
}
|
||||
|
||||
function onReset() {
|
||||
searchQuery.value = ''
|
||||
page.value = 1
|
||||
loadDivisions()
|
||||
}
|
||||
|
||||
function onAdd() {
|
||||
uni.showToast({ title: '添加事业部功能开发中', icon: 'none' })
|
||||
isEdit.value = false
|
||||
Object.assign(editForm, {
|
||||
uid: '',
|
||||
name: '',
|
||||
invite_code: Math.random().toString(36).slice(2, 10).toUpperCase(),
|
||||
commission_ratio: 0,
|
||||
is_enabled: true,
|
||||
end_time: ''
|
||||
})
|
||||
editPopupVisible.value = true
|
||||
}
|
||||
|
||||
async function toggleStatus(item : DistributionDivision) {
|
||||
if (item.id == null) return
|
||||
const nextStatus = !item.status
|
||||
const success = await saveDivision({ ...item, status: nextStatus } as DistributionDivision)
|
||||
if (success) {
|
||||
item.status = nextStatus
|
||||
uni.showToast({ title: '状态修改成功', icon: 'success' })
|
||||
function onEdit(item : Division) {
|
||||
isEdit.value = true
|
||||
Object.assign(editForm, {
|
||||
uid: item.uid,
|
||||
name: item.name,
|
||||
invite_code: item.invite_code,
|
||||
commission_ratio: item.commission_ratio,
|
||||
is_enabled: item.is_enabled,
|
||||
end_time: item.end_time || ''
|
||||
})
|
||||
editPopupVisible.value = true
|
||||
}
|
||||
|
||||
function closeEditModal() {
|
||||
editPopupVisible.value = false
|
||||
}
|
||||
|
||||
async function handleSave() {
|
||||
if (!editForm.uid || !editForm.name) {
|
||||
uni.showToast({ title: '请填写必要信息', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
isLoading.value = true
|
||||
try {
|
||||
const success = await saveDivision(editForm)
|
||||
if (success) {
|
||||
uni.showToast({ title: '保存成功', icon: 'success' })
|
||||
editPopupVisible.value = false
|
||||
loadDivisions()
|
||||
} else {
|
||||
uni.showToast({ title: '保存失败', icon: 'none' })
|
||||
}
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function onDelete(id : string | undefined) {
|
||||
if (id == null) return
|
||||
async function onDelete(uid : string) {
|
||||
uni.showModal({
|
||||
title: '确认删除',
|
||||
content: '确定要删除该事业部吗?',
|
||||
title: '提示',
|
||||
content: '确定要删除该事业部吗?(若有关联代理商将无法删除)',
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
const success = await deleteDivision(id!)
|
||||
if (success) {
|
||||
uni.showToast({ title: '删除成功' })
|
||||
loadData()
|
||||
isLoading.value = true
|
||||
try {
|
||||
const success = await deleteDivision(uid)
|
||||
if (success) {
|
||||
uni.showToast({ title: '删除成功' })
|
||||
loadDivisions()
|
||||
}
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function onToggleStatus(item : Division) {
|
||||
const updated = { ...item, is_enabled: !item.is_enabled }
|
||||
const success = await saveDivision(updated)
|
||||
if (success) {
|
||||
item.is_enabled = !item.is_enabled
|
||||
uni.showToast({ title: '状态已更新' })
|
||||
}
|
||||
}
|
||||
|
||||
function onPrevPage() {
|
||||
if (page.value > 1) {
|
||||
page.value--
|
||||
loadData()
|
||||
loadDivisions()
|
||||
}
|
||||
}
|
||||
|
||||
function onNextPage() {
|
||||
if (divisionList.value.length >= pageSize) {
|
||||
page.value++
|
||||
loadData()
|
||||
}
|
||||
}
|
||||
|
||||
function formatTime(iso : string | null) : string {
|
||||
if (!iso) return '-'
|
||||
return iso.substring(0, 10)
|
||||
if (divisionList.value.length < pageSize) return
|
||||
page.value++
|
||||
loadDivisions()
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.admin-page { padding: 0; }
|
||||
.filter-card { background: #fff; padding: 24px; margin-bottom: 16px; border-radius: 4px; }
|
||||
.filter-row { display: flex; flex-direction: row; align-items: center; gap: 24px; }
|
||||
.label { font-size: 14px; color: #333; }
|
||||
.filter-input { border: 1px solid #d9d9d9; height: 32px; width: 220px; padding: 0 12px; font-size: 14px; }
|
||||
.btn { height: 32px; padding: 0 16px; font-size: 14px; border: 1px solid #d9d9d9; background: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer; }
|
||||
.filter-input { border: 1px solid #d9d9d9; height: 32px; width: 220px; padding: 0 12px; font-size: 14px; border-radius: 4px; }
|
||||
.btn { height: 32px; padding: 0 16px; font-size: 14px; border: 1px solid #d9d9d9; background: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer; border-radius: 4px; }
|
||||
.btn.primary { background: #1890ff; border-color: #1890ff; color: #fff; }
|
||||
.content-card { background: #fff; border-radius: 4px; }
|
||||
.btn.small { height: 28px; padding: 0 12px; font-size: 13px; }
|
||||
|
||||
.content-card { background: #fff; border-radius: 4px; position: relative; }
|
||||
.action-bar { padding: 16px 24px; }
|
||||
.table-container { padding: 0 24px 24px; }
|
||||
.table-container { padding: 0 24px 24px; min-height: 200px; }
|
||||
.table-header { display: flex; flex-direction: row; background: #f8faff; border-bottom: 1px solid #f0f0f0; padding: 12px 0; }
|
||||
.table-row { display: flex; flex-direction: row; border-bottom: 1px solid #f0f0f0; padding: 12px 0; align-items: center; &:hover { background: #fafafa; } }
|
||||
.col { padding: 0 8px; font-size: 14px; color: #333; display: flex; align-items: center; }
|
||||
|
||||
.col-uid { width: 80px; } .col-avatar { width: 80px; justify-content: center; } .col-name { width: 120px; } .col-code { width: 100px; justify-content: center; } .col-ratio { width: 100px; justify-content: center; } .col-count { width: 100px; justify-content: center; } .col-time { width: 120px; justify-content: center; } .col-status { width: 80px; justify-content: center; } .col-ops { flex: 1; justify-content: flex-end; }
|
||||
|
||||
.avatar-img { width: 32px; height: 32px; border-radius: 2px; }
|
||||
.op-link { color: #1890ff; cursor: pointer; }
|
||||
.op-link { color: #1890ff; cursor: pointer; &.danger { color: #ff4d4f; } }
|
||||
.op-divider { color: #e8e8e8; margin: 0 8px; }
|
||||
|
||||
.pagination { padding: 16px 24px; border-top: 1px solid #f0f0f0; display: flex; flex-direction: row; align-items: center; justify-content: space-between; }
|
||||
.pager-btns { display: flex; flex-direction: row; align-items: center; gap: 12px; }
|
||||
.page-num { font-size: 14px; color: #333; }
|
||||
.page-info { font-size: 14px; color: #999; }
|
||||
|
||||
.loading-mask { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(255,255,255,0.7); display: flex; align-items: center; justify-content: center; z-index: 10; }
|
||||
.loading-text { color: #1890ff; font-size: 14px; }
|
||||
.empty-row { padding: 40px 0; text-align: center; color: #999; font-size: 14px; }
|
||||
|
||||
/* 弹窗样式 */
|
||||
.popup-mask { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0, 0, 0, 0.5); display: flex; align-items: center; justify-content: center; z-index: 999; }
|
||||
.popup-card { width: 500px; background-color: #fff; border-radius: 8px; display: flex; flex-direction: column; overflow: hidden; }
|
||||
.popup-header { display: flex; flex-direction: row; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid #f0f0f0; }
|
||||
.popup-title { font-size: 16px; font-weight: bold; color: #333; }
|
||||
.popup-close { font-size: 20px; color: #999; cursor: pointer; padding: 4px; }
|
||||
.popup-body { padding: 24px; display: flex; flex-direction: column; gap: 16px; }
|
||||
.popup-item { display: flex; flex-direction: column; gap: 8px; }
|
||||
.popup-row { flex-direction: row; align-items: center; justify-content: space-between; }
|
||||
.popup-label { font-size: 14px; color: #666; }
|
||||
.popup-input { border: 1px solid #d9d9d9; border-radius: 4px; height: 36px; padding: 0 12px; font-size: 14px; width: 100%; }
|
||||
.popup-footer { padding: 16px 24px; border-top: 1px solid #f0f0f0; display: flex; flex-direction: row; justify-content: flex-end; gap: 12px; }
|
||||
</style>
|
||||
@@ -1,27 +1,296 @@
|
||||
<template>
|
||||
<AdminLayout :currentPage="currentPage">
|
||||
<view class="page">
|
||||
<view class="header">
|
||||
<text class="title">{{ title }}</text>
|
||||
<text class="sub-title">页面占位 (自动生成)</text>
|
||||
<view class="marketing-groupbuy-list">
|
||||
<!-- 1. 过滤搜索栏 -->
|
||||
<view class="filter-card border-shadow">
|
||||
<view class="filter-row">
|
||||
<view class="filter-item">
|
||||
<text class="label">活动搜索:</text>
|
||||
<input class="input-mock" placeholder="请输入活动名称" v-model="searchQuery" @confirm="handleSearch" />
|
||||
</view>
|
||||
<view class="filter-btns">
|
||||
<button class="btn-query" @click="handleSearch">查询</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 2. 操作栏 -->
|
||||
<view class="action-bar">
|
||||
<button class="btn-add" @click="handleAdd">添加团购活动</button>
|
||||
</view>
|
||||
|
||||
<!-- 3. 数据表格 -->
|
||||
<view class="table-card border-shadow">
|
||||
<view class="table-container">
|
||||
<!-- Loading 遮罩 -->
|
||||
<view v-if="isLoading" class="loading-mask">
|
||||
<text class="loading-text">数据加载中...</text>
|
||||
</view>
|
||||
|
||||
<view class="table-head">
|
||||
<view class="th cell-id">ID</view>
|
||||
<view class="th cell-product">关联商品</view>
|
||||
<view class="th cell-title">活动标题</view>
|
||||
<view class="th cell-price">团购价</view>
|
||||
<view class="th cell-people">成团人数</view>
|
||||
<view class="th cell-stock">库存</view>
|
||||
<view class="th cell-time">有效期</view>
|
||||
<view class="th cell-status">状态</view>
|
||||
<view class="th cell-op">操作</view>
|
||||
</view>
|
||||
|
||||
<view class="table-body">
|
||||
<view v-if="dataList.length === 0 && !isLoading" class="empty-row">
|
||||
<text>暂无团购活动记录</text>
|
||||
</view>
|
||||
<view v-for="item in dataList" :key="item.id" class="table-row">
|
||||
<view class="td cell-id">
|
||||
<text class="td-txt-small">{{ item.id }}</text>
|
||||
</view>
|
||||
<view class="td cell-product">
|
||||
<view class="p-info">
|
||||
<image class="p-img" :src="item.product_image || '/static/logo.png'" mode="aspectFill" />
|
||||
<text class="p-name line-clamp-1">{{ item.product_name || '未知商品' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="td cell-title">
|
||||
<text class="td-txt">{{ item.title }}</text>
|
||||
</view>
|
||||
<view class="td cell-price">
|
||||
<text class="td-txt danger">¥{{ item.price }}</text>
|
||||
</view>
|
||||
<view class="td cell-people">
|
||||
<text class="td-txt">{{ item.people }}人</text>
|
||||
</view>
|
||||
<view class="td cell-stock">
|
||||
<text class="td-txt">{{ item.stock }}</text>
|
||||
</view>
|
||||
<view class="td cell-time">
|
||||
<text class="td-txt-small">始: {{ formatTime(item.start_time) }}</text>
|
||||
<text class="td-txt-small">终: {{ formatTime(item.stop_time) }}</text>
|
||||
</view>
|
||||
<view class="td cell-status">
|
||||
<view class="switch-mock" :class="{ active: item.status }" @click="toggleStatus(item)">
|
||||
<view class="switch-dot"></view>
|
||||
<text class="switch-txt">{{ item.status ? '开启' : '关闭' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="td cell-op">
|
||||
<view class="op-links">
|
||||
<text class="op-link" @click="handleEdit(item)">编辑</text>
|
||||
<text class="op-split">|</text>
|
||||
<text class="op-link danger" @click="handleDelete(item)">删除</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 4. 分页控制 -->
|
||||
<view class="pagination-footer">
|
||||
<view class="page-total">
|
||||
<text class="total-txt">共 {{ total }} 条</text>
|
||||
</view>
|
||||
<view class="page-btns">
|
||||
<text class="p-btn" :class="{ disabled: page <= 1 }" @click="onPrevPage">‹</text>
|
||||
<text class="p-btn active">{{ page }}</text>
|
||||
<text class="p-btn" :class="{ disabled: dataList.length < pageSize }" @click="onNextPage">›</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</AdminLayout>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref } from 'vue'
|
||||
import { ref, onMounted } from 'vue'
|
||||
import AdminLayout from '@/layouts/admin/AdminLayout.uvue'
|
||||
const currentPage = ref<string>('groupbuy-list')
|
||||
const title = ref<string>('list')
|
||||
import { fetchGroupbuyActivities, saveGroupbuyActivity, deleteGroupbuyActivity, GroupbuyActivity } from '@/services/admin/marketingService.uts'
|
||||
|
||||
const currentPage = ref('groupbuy-list')
|
||||
const dataList = ref<GroupbuyActivity[]>([])
|
||||
const isLoading = ref(false)
|
||||
const searchQuery = ref('')
|
||||
const page = ref(1)
|
||||
const pageSize = 15
|
||||
const total = ref(0)
|
||||
|
||||
onMounted(() => {
|
||||
loadData()
|
||||
})
|
||||
|
||||
async function loadData() {
|
||||
isLoading.value = true
|
||||
try {
|
||||
const res = await fetchGroupbuyActivities({
|
||||
search: searchQuery.value,
|
||||
page: page.value,
|
||||
pageSize: pageSize
|
||||
})
|
||||
dataList.value = res.items
|
||||
total.value = res.total
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '加载数据失败', icon: 'none' })
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function handleSearch() {
|
||||
page.value = 1
|
||||
loadData()
|
||||
}
|
||||
|
||||
async function toggleStatus(item : GroupbuyActivity) {
|
||||
if (item.id == null) return
|
||||
const nextStatus = !item.status
|
||||
const success = await saveGroupbuyActivity({ ...item, status: nextStatus } as GroupbuyActivity)
|
||||
if (success) {
|
||||
item.status = nextStatus
|
||||
uni.showToast({ title: '修改成功', icon: 'success' })
|
||||
}
|
||||
}
|
||||
|
||||
function handleAdd() {
|
||||
uni.showToast({ title: '添加功能开发中', icon: 'none' })
|
||||
}
|
||||
|
||||
function handleEdit(item : GroupbuyActivity) {
|
||||
uni.showToast({ title: '编辑功能开发中', icon: 'none' })
|
||||
}
|
||||
|
||||
async function handleDelete(item : GroupbuyActivity) {
|
||||
if (item.id == null) return
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要删除该团购活动吗?',
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
const success = await deleteGroupbuyActivity(item.id!)
|
||||
if (success) {
|
||||
uni.showToast({ title: '删除成功' })
|
||||
loadData()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function onPrevPage() {
|
||||
if (page.value > 1) {
|
||||
page.value--
|
||||
loadData()
|
||||
}
|
||||
}
|
||||
|
||||
function onNextPage() {
|
||||
if (dataList.value.length >= pageSize) {
|
||||
page.value++
|
||||
loadData()
|
||||
}
|
||||
}
|
||||
|
||||
function formatTime(iso: string): string {
|
||||
if (!iso) return '-'
|
||||
return iso.substring(0, 10)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@import '@/uni.scss';
|
||||
.page { padding: $space-lg; }
|
||||
.header { padding: $space-lg; border-radius: $radius; background: $background-primary; box-shadow: $shadow-xs; }
|
||||
.title { font-size: $font-size-lg; font-weight: $font-weight-bold; color: $text-primary; }
|
||||
.sub-title { margin-top: $space-xs; font-size: $font-size-md; color: $text-secondary; }
|
||||
.marketing-groupbuy-list {
|
||||
min-height: 100vh;
|
||||
background: #f0f2f5;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.border-shadow {
|
||||
background: #fff;
|
||||
border-radius: 4px;
|
||||
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.filter-card { padding: 24px; margin-bottom: 16px; }
|
||||
.filter-row { display: flex; flex-direction: row; align-items: center; gap: 24px; }
|
||||
.filter-item { display: flex; flex-direction: row; align-items: center; }
|
||||
.label { font-size: 14px; color: #606266; }
|
||||
.input-mock {
|
||||
width: 240px; height: 32px; border: 1px solid #dcdfe6; border-radius: 4px;
|
||||
padding: 0 12px; font-size: 13px;
|
||||
}
|
||||
.btn-query {
|
||||
width: 64px; height: 32px; background-color: #1890ff; color: #fff;
|
||||
font-size: 14px; border: none; border-radius: 4px; cursor: pointer;
|
||||
}
|
||||
|
||||
.action-bar { margin-bottom: 16px; }
|
||||
.btn-add {
|
||||
padding: 0 16px; height: 32px; background-color: #1890ff; color: #fff;
|
||||
font-size: 14px; border: none; border-radius: 4px; cursor: pointer;
|
||||
}
|
||||
|
||||
.table-card { padding: 24px; position: relative; }
|
||||
.table-container { min-height: 400px; position: relative; }
|
||||
.loading-mask {
|
||||
position: absolute; top: 0; left: 0; right: 0; bottom: 0;
|
||||
background: rgba(255,255,255,0.7); display: flex; align-items: center; justify-content: center; z-index: 10;
|
||||
}
|
||||
.loading-text { color: #1890ff; font-size: 14px; }
|
||||
|
||||
.table-head {
|
||||
display: flex; flex-direction: row; background-color: #f8faff;
|
||||
border-bottom: 1px solid #e8eaec;
|
||||
}
|
||||
.th { padding: 12px 8px; font-size: 13px; color: #515a6e; font-weight: bold; text-align: center; }
|
||||
|
||||
.table-row {
|
||||
display: flex; flex-direction: row; border-bottom: 1px solid #e8eaec; align-items: center;
|
||||
&:hover { background-color: #fafafa; }
|
||||
}
|
||||
.td { padding: 16px 8px; text-align: center; display: flex; align-items: center; justify-content: center; }
|
||||
.td-txt { font-size: 13px; color: #515a6e; }
|
||||
.td-txt-small { font-size: 12px; color: #999; display: block; }
|
||||
.danger { color: #f5222d; }
|
||||
|
||||
.cell-id { width: 60px; }
|
||||
.cell-product { flex: 1.5; justify-content: flex-start; }
|
||||
.cell-title { flex: 1; }
|
||||
.cell-price { width: 100px; }
|
||||
.cell-people { width: 100px; }
|
||||
.cell-stock { width: 80px; }
|
||||
.cell-time { width: 160px; }
|
||||
.cell-status { width: 100px; }
|
||||
.cell-op { width: 120px; }
|
||||
|
||||
.p-info { display: flex; flex-direction: row; align-items: center; gap: 8px; }
|
||||
.p-img { width: 32px; height: 32px; border-radius: 4px; background: #f5f5f5; }
|
||||
.p-name { font-size: 12px; color: #1890ff; text-align: left; }
|
||||
.line-clamp-1 { display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
|
||||
|
||||
.switch-mock {
|
||||
width: 44px; height: 20px; background-color: #bfbfbf; border-radius: 10px;
|
||||
position: relative; transition: all 0.3s;
|
||||
&.active { background-color: #1890ff; }
|
||||
}
|
||||
.switch-dot {
|
||||
width: 16px; height: 16px; background-color: #fff; border-radius: 50%;
|
||||
position: absolute; top: 2px; left: 2px; transition: left 0.3s;
|
||||
}
|
||||
.active .switch-dot { left: 26px; }
|
||||
.switch-txt { font-size: 10px; color: #fff; position: absolute; right: 6px; top: 2px; }
|
||||
.active .switch-txt { left: 6px; right: auto; }
|
||||
|
||||
.op-links { display: flex; flex-direction: row; gap: 8px; }
|
||||
.op-link { font-size: 13px; color: #1890ff; cursor: pointer; &.danger { color: #f5222d; } }
|
||||
.op-split { color: #eee; }.pagination-footer {
|
||||
margin-top: 24px; display: flex; flex-direction: row; align-items: center; justify-content: flex-end; gap: 12px;
|
||||
}
|
||||
.total-txt { font-size: 13px; color: #999; }
|
||||
.page-btns { display: flex; flex-direction: row; gap: 8px; }
|
||||
.p-btn {
|
||||
width: 28px; height: 28px; border: 1px solid #dcdfe6; border-radius: 4px;
|
||||
display: flex; align-items: center; justify-content: center; font-size: 14px;
|
||||
&.active { background: #1890ff; color: #fff; border-color: #1890ff; }
|
||||
&.disabled { opacity: 0.5; cursor: not-allowed; }
|
||||
}
|
||||
.empty-row { padding: 60px 0; text-align: center; color: #999; }
|
||||
</style>
|
||||
|
||||
|
||||
|
||||
@@ -1,27 +1,240 @@
|
||||
<template>
|
||||
<AdminLayout :currentPage="currentPage">
|
||||
<view class="page">
|
||||
<view class="header">
|
||||
<text class="title">{{ title }}</text>
|
||||
<text class="sub-title">页面占位 (自动生成)</text>
|
||||
<view class="marketing-recharge-record">
|
||||
<!-- 1. 搜索过滤栏 -->
|
||||
<view class="filter-card border-shadow">
|
||||
<view class="filter-row">
|
||||
<view class="filter-item">
|
||||
<text class="label">搜索记录:</text>
|
||||
<input class="input-mock" placeholder="订单号/用户名" v-model="searchQuery" @confirm="handleSearch" />
|
||||
</view>
|
||||
<view class="filter-btns">
|
||||
<button class="btn-query" @click="handleSearch">查询</button>
|
||||
<button class="btn-reset" @click="handleReset">重置</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 2. 数据表格 -->
|
||||
<view class="table-card border-shadow">
|
||||
<view class="table-container">
|
||||
<view v-if="isLoading" class="loading-mask">
|
||||
<text class="loading-text">加载中...</text>
|
||||
</view>
|
||||
|
||||
<view class="table-head">
|
||||
<view class="th cell-id">ID</view>
|
||||
<view class="th cell-user">用户信息</view>
|
||||
<view class="th cell-no">充值订单号</view>
|
||||
<view class="th cell-price">实际充值</view>
|
||||
<view class="th cell-price">赠送金额</view>
|
||||
<view class="th cell-type">支付渠道</view>
|
||||
<view class="th cell-status">支付状态</view>
|
||||
<view class="th cell-time">充值时间</view>
|
||||
</view>
|
||||
|
||||
<view class="table-body">
|
||||
<view v-if="recordList.length === 0 && !isLoading" class="empty-row">
|
||||
<text>暂无充值记录</text>
|
||||
</view>
|
||||
<view v-for="item in recordList" :key="item.id" class="table-row">
|
||||
<view class="td cell-id">
|
||||
<text class="td-txt-small">{{ item.id }}</text>
|
||||
</view>
|
||||
<view class="td cell-user">
|
||||
<view class="u-info">
|
||||
<image class="u-avatar" :src="item.avatar || '/static/logo.png'" mode="aspectFill" />
|
||||
<text class="u-nick">{{ item.nickname || '未知用户' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="td cell-no">
|
||||
<text class="td-txt">{{ item.order_no }}</text>
|
||||
</view>
|
||||
<view class="td cell-price">
|
||||
<text class="td-txt-bold">¥{{ item.price.toFixed(2) }}</text>
|
||||
</view>
|
||||
<view class="td cell-price">
|
||||
<text class="td-txt color-orange">¥{{ item.give_price.toFixed(2) }}</text>
|
||||
</view>
|
||||
<view class="td cell-type">
|
||||
<text class="td-txt">{{ formatRechargeType(item.recharge_type) }}</text>
|
||||
</view>
|
||||
<view class="td cell-status">
|
||||
<text class="status-tag" :class="item.paid === 1 ? 'paid' : 'unpaid'">
|
||||
{{ item.paid === 1 ? '已支付' : '未支付' }}
|
||||
</text>
|
||||
</view>
|
||||
<view class="td cell-time">
|
||||
<text class="td-txt-small">{{ formatDateTime(item.created_at) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 3. 分页控制 -->
|
||||
<view class="pagination-footer">
|
||||
<view class="page-total">
|
||||
<text class="total-txt">共 {{ total }} 条</text>
|
||||
</view>
|
||||
<view class="page-btns">
|
||||
<text class="p-btn" :class="{ disabled: page <= 1 }" @click="onPrevPage">‹</text>
|
||||
<text class="p-btn active">{{ page }}</text>
|
||||
<text class="p-btn" :class="{ disabled: recordList.length < pageSize }" @click="onNextPage">›</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</AdminLayout>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref } from 'vue'
|
||||
import { ref, onMounted } from 'vue'
|
||||
import AdminLayout from '@/layouts/admin/AdminLayout.uvue'
|
||||
const currentPage = ref<string>('recharge-record')
|
||||
const title = ref<string>('record')
|
||||
import { fetchRechargeRecords, RechargeRecord } from '@/services/admin/marketingService.uts'
|
||||
|
||||
const currentPage = ref('recharge-record')
|
||||
const recordList = ref<RechargeRecord[]>([])
|
||||
const isLoading = ref(false)
|
||||
const searchQuery = ref('')
|
||||
const page = ref(1)
|
||||
const pageSize = 15
|
||||
const total = ref(0)
|
||||
|
||||
onMounted(() => {
|
||||
loadData()
|
||||
})
|
||||
|
||||
async function loadData() {
|
||||
isLoading.value = true
|
||||
try {
|
||||
const res = await fetchRechargeRecords({
|
||||
search: searchQuery.value,
|
||||
page: page.value,
|
||||
pageSize: pageSize
|
||||
})
|
||||
recordList.value = res.items
|
||||
total.value = res.total
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '加载失败', icon: 'none' })
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function handleSearch() {
|
||||
page.value = 1
|
||||
loadData()
|
||||
}
|
||||
|
||||
function handleReset() {
|
||||
searchQuery.value = ''
|
||||
page.value = 1
|
||||
loadData()
|
||||
}
|
||||
|
||||
function onPrevPage() {
|
||||
if (page.value > 1) {
|
||||
page.value--
|
||||
loadData()
|
||||
}
|
||||
}
|
||||
|
||||
function onNextPage() {
|
||||
if (recordList.value.length >= pageSize) {
|
||||
page.value++
|
||||
loadData()
|
||||
}
|
||||
}
|
||||
|
||||
function formatRechargeType(type : string) : string {
|
||||
switch (type) {
|
||||
case 'wechat': return '微信支付'
|
||||
case 'alipay': return '支付宝'
|
||||
case 'system': return '系统补单'
|
||||
default: return type
|
||||
}
|
||||
}
|
||||
|
||||
function formatDateTime(iso : string) : string {
|
||||
return iso.substring(0, 16).replace('T', ' ')
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@import '@/uni.scss';
|
||||
.page { padding: $space-lg; }
|
||||
.header { padding: $space-lg; border-radius: $radius; background: $background-primary; box-shadow: $shadow-xs; }
|
||||
.title { font-size: $font-size-lg; font-weight: $font-weight-bold; color: $text-primary; }
|
||||
.sub-title { margin-top: $space-xs; font-size: $font-size-md; color: $text-secondary; }
|
||||
.marketing-recharge-record {
|
||||
min-height: 100vh;
|
||||
background: #f0f2f5;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.border-shadow {
|
||||
background: #fff;
|
||||
border-radius: 4px;
|
||||
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.filter-card { padding: 24px; margin-bottom: 16px; }
|
||||
.filter-row { display: flex; flex-direction: row; align-items: center; gap: 24px; }
|
||||
.filter-item { display: flex; flex-direction: row; align-items: center; }
|
||||
.label { font-size: 14px; color: #606266; }
|
||||
.input-mock {
|
||||
width: 240px; height: 32px; border: 1px solid #dcdfe6; border-radius: 4px;
|
||||
padding: 0 12px; font-size: 13px;
|
||||
}
|
||||
.filter-btns { display: flex; flex-direction: row; gap: 12px; }
|
||||
.btn-query { background: #1890ff; color: #fff; height: 32px; padding: 0 16px; border-radius: 4px; font-size: 14px; border: none; cursor: pointer; }
|
||||
.btn-reset { background: #fff; color: #666; height: 32px; padding: 0 16px; border-radius: 4px; font-size: 14px; border: 1px solid #dcdfe6; cursor: pointer; }
|
||||
|
||||
.table-card { padding: 24px; position: relative; }
|
||||
.table-container { min-height: 400px; position: relative; }
|
||||
.loading-mask {
|
||||
position: absolute; top: 0; left: 0; right: 0; bottom: 0;
|
||||
background: rgba(255,255,255,0.7); display: flex; align-items: center; justify-content: center; z-index: 10;
|
||||
}
|
||||
.loading-text { color: #1890ff; font-size: 14px; }
|
||||
|
||||
.table-head {
|
||||
display: flex; flex-direction: row; background-color: #f8faff;
|
||||
border-bottom: 1px solid #e8eaec;
|
||||
}
|
||||
.th { padding: 12px 8px; font-size: 13px; color: #515a6e; font-weight: bold; text-align: center; }
|
||||
|
||||
.table-row {
|
||||
display: flex; flex-direction: row; border-bottom: 1px solid #e8eaec; align-items: center;
|
||||
&:hover { background-color: #fafafa; }
|
||||
}
|
||||
.td { padding: 12px 8px; text-align: center; display: flex; align-items: center; justify-content: center; }
|
||||
.td-txt { font-size: 13px; color: #515a6e; }
|
||||
.td-txt-bold { font-size: 14px; color: #333; font-weight: bold; }
|
||||
.td-txt-small { font-size: 12px; color: #999; }
|
||||
.color-orange { color: #ff9900; }
|
||||
|
||||
.cell-id { width: 60px; }
|
||||
.cell-user { flex: 1; justify-content: flex-start; }
|
||||
.cell-no { width: 200px; }
|
||||
.cell-price { width: 100px; }
|
||||
.cell-type { width: 100px; }
|
||||
.cell-status { width: 100px; }
|
||||
.cell-time { width: 160px; }
|
||||
|
||||
.u-info { display: flex; flex-direction: row; align-items: center; gap: 8px; }
|
||||
.u-avatar { width: 32px; height: 32px; border-radius: 16px; background: #f5f5f5; }
|
||||
.u-nick { font-size: 13px; color: #333; }
|
||||
|
||||
.status-tag {
|
||||
padding: 2px 8px; border-radius: 4px; font-size: 12px;
|
||||
&.paid { background: #f6ffed; color: #52c41a; border: 1px solid #b7eb8f; }
|
||||
&.unpaid { background: #fff7e6; color: #faad14; border: 1px solid #ffe7ba; }
|
||||
}.pagination-footer {
|
||||
margin-top: 24px; display: flex; flex-direction: row; align-items: center; justify-content: flex-end; gap: 12px;
|
||||
}
|
||||
.total-txt { font-size: 13px; color: #999; }
|
||||
.page-btns { display: flex; flex-direction: row; gap: 8px; }
|
||||
.p-btn {
|
||||
width: 28px; height: 28px; border: 1px solid #dcdfe6; border-radius: 4px;
|
||||
display: flex; align-items: center; justify-content: center; font-size: 14px;
|
||||
&.active { background: #1890ff; color: #fff; border-color: #1890ff; }
|
||||
&.disabled { opacity: 0.5; cursor: not-allowed; }
|
||||
}
|
||||
.empty-row { padding: 60px 0; text-align: center; color: #999; }
|
||||
</style>
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import supa from '@/components/supadb/aksupainstance.uts'
|
||||
|
||||
/**
|
||||
* 分销配置模型 (与 ak_distribution_config 表对齐)
|
||||
* 分销配置模型
|
||||
*/
|
||||
export type DistributionConfig = {
|
||||
id?: string
|
||||
// 分销模式
|
||||
is_enabled: boolean
|
||||
extract_type: string
|
||||
bind_type: string
|
||||
@@ -15,8 +14,6 @@ export type DistributionConfig = {
|
||||
is_area_manager: boolean
|
||||
is_agent_apply: boolean
|
||||
is_commission_window: boolean
|
||||
|
||||
// 返佣设置
|
||||
is_self_brokerage: boolean
|
||||
is_member_brokerage: boolean
|
||||
brokerage_type: string
|
||||
@@ -26,17 +23,13 @@ export type DistributionConfig = {
|
||||
store_brokerage_ratio: number
|
||||
store_brokerage_two_ratio: number
|
||||
extract_frozen_time: number
|
||||
|
||||
// 提现设置
|
||||
user_extract_min_price: number
|
||||
extract_bank_list: string
|
||||
extract_type_list: string[]
|
||||
wechat_extract_type: string
|
||||
alipay_extract_type: string
|
||||
user_extract_fee: number
|
||||
|
||||
updated_at?: string
|
||||
updated_by?: string
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,6 +51,52 @@ export type Promoter = {
|
||||
unwithdrawnAmount: number
|
||||
}
|
||||
|
||||
/**
|
||||
* 事业部模型
|
||||
*/
|
||||
export type Division = {
|
||||
uid: string
|
||||
name: string
|
||||
invite_code: string
|
||||
commission_ratio: number
|
||||
is_enabled: boolean
|
||||
end_time: string | null
|
||||
created_at: string
|
||||
agentCount: number
|
||||
}
|
||||
|
||||
/**
|
||||
* 代理商模型
|
||||
*/
|
||||
export type Agent = {
|
||||
uid: string
|
||||
name: string
|
||||
division_uid: string
|
||||
division_name: string
|
||||
commission_ratio: number
|
||||
is_enabled: boolean
|
||||
end_time: string | null
|
||||
created_at: string
|
||||
staffCount: number
|
||||
}
|
||||
|
||||
/**
|
||||
* 代理商申请模型
|
||||
*/
|
||||
export type AgentApply = {
|
||||
id: string
|
||||
uid: string
|
||||
name: string
|
||||
phone: string
|
||||
dept_uid: string
|
||||
dept_name: string
|
||||
proof_images: string[] | null
|
||||
status: string
|
||||
refusal_reason: string | null
|
||||
time: string
|
||||
invite_code: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销全局配置
|
||||
*/
|
||||
@@ -89,11 +128,7 @@ export async function saveDistributionConfig(config: DistributionConfig): Promis
|
||||
})
|
||||
.execute()
|
||||
|
||||
if (error != null) {
|
||||
console.error('保存分销配置失败:', error)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
return error == null
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,8 +143,6 @@ export type DistributionLevel = {
|
||||
task_total: number
|
||||
task_finish: number
|
||||
is_visible: boolean
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,30 +155,18 @@ export async function getDistributionLevelList(): Promise<DistributionLevel[]> {
|
||||
.order('level', { ascending: true })
|
||||
.execute()
|
||||
|
||||
if (error != null) {
|
||||
console.error('获取分销等级列表失败:', error)
|
||||
return [] as DistributionLevel[]
|
||||
}
|
||||
return data as DistributionLevel[]
|
||||
return (data ?? []) as DistributionLevel[]
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存/更新分销等级
|
||||
* 保存分销等级
|
||||
*/
|
||||
export async function saveDistributionLevel(level: DistributionLevel): Promise<boolean> {
|
||||
const { error } = await supa
|
||||
.from('ak_distribution_level')
|
||||
.upsert({
|
||||
...level,
|
||||
updated_at: new Date().toISOString()
|
||||
})
|
||||
.upsert(level)
|
||||
.execute()
|
||||
|
||||
if (error != null) {
|
||||
console.error('保存分销等级失败:', error)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
return error == null
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,16 +178,11 @@ export async function deleteDistributionLevel(id: string): Promise<boolean> {
|
||||
.delete()
|
||||
.eq('id', id)
|
||||
.execute()
|
||||
|
||||
if (error != null) {
|
||||
console.error('删除分销等级失败:', error)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
return error == null
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取推广员列表
|
||||
* 推广员列表参数
|
||||
*/
|
||||
export type PromoterListParams = {
|
||||
search?: string | null
|
||||
@@ -177,185 +193,111 @@ export type PromoterListParams = {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取推广员列表(聚合统计)
|
||||
* 获取推广员列表
|
||||
*/
|
||||
export async function getPromoterList(params?: PromoterListParams): Promise<Promoter[]> {
|
||||
const payload = {
|
||||
const { data, error } = await supa.rpc('rpc_admin_get_promoter_list', {
|
||||
p_search: params?.search ?? null,
|
||||
p_page: params?.page ?? 1,
|
||||
p_page_size: params?.pageSize ?? 20,
|
||||
p_start_time: params?.startTime ?? null,
|
||||
p_end_time: params?.endTime ?? null
|
||||
} as any
|
||||
} as any)
|
||||
|
||||
const { data, error } = await supa
|
||||
.rpc('rpc_admin_get_promoter_list', payload as any)
|
||||
|
||||
if (error != null) {
|
||||
console.error('获取推广员列表失败:', error)
|
||||
return [] as Promoter[]
|
||||
}
|
||||
return (data ?? []) as Promoter[]
|
||||
}
|
||||
|
||||
/**
|
||||
* 事业部模型
|
||||
*/
|
||||
export type DistributionDivision = {
|
||||
id?: string
|
||||
merchant_id?: string
|
||||
uid: string
|
||||
name: string
|
||||
invite_code: string
|
||||
ratio: number
|
||||
agent_count: number
|
||||
end_time: string | null
|
||||
status: boolean
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
// 关联字段
|
||||
nickname?: string
|
||||
avatar_url?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 代理商模型
|
||||
*/
|
||||
export type DistributionAgent = {
|
||||
id?: string
|
||||
merchant_id?: string
|
||||
uid: string
|
||||
division_id: string
|
||||
name: string
|
||||
status: boolean
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
// 关联字段
|
||||
nickname?: string
|
||||
avatar_url?: string
|
||||
division_name?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取事业部列表
|
||||
*/
|
||||
export async function fetchDivisions(query?: { search?: string, page?: number, pageSize?: number }): Promise<{ total: number, items: DistributionDivision[] }> {
|
||||
let q = supa.from('ak_distribution_divisions').select('*, ak_users!uid(username, avatar_url)', { count: 'exact' })
|
||||
|
||||
if (query?.search != null && query.search !== '') {
|
||||
q = q.or(`name.ilike.%${query.search}%,ak_users.username.ilike.%${query.search}%`)
|
||||
}
|
||||
|
||||
const p = query?.page ?? 1
|
||||
const ps = query?.pageSize ?? 20
|
||||
const from = (p - 1) * ps
|
||||
const to = from + ps - 1
|
||||
|
||||
const { data, error, count } = await q
|
||||
.order('created_at', { ascending: false })
|
||||
.range(from, to)
|
||||
.execute()
|
||||
|
||||
if (error != null) {
|
||||
console.error('获取事业部列表失败:', error)
|
||||
return { total: 0, items: [] as DistributionDivision[] }
|
||||
}
|
||||
|
||||
const items = (data ?? []).map((item: any): DistributionDivision => {
|
||||
return {
|
||||
...item,
|
||||
nickname: item.ak_users?.username,
|
||||
avatar_url: item.ak_users?.avatar_url
|
||||
} as DistributionDivision
|
||||
})
|
||||
|
||||
return { total: count ?? 0, items }
|
||||
export async function getDivisionList(search: string | null, page: number, pageSize: number): Promise<Division[]> {
|
||||
const { data, error } = await supa.rpc('rpc_admin_get_division_list', {
|
||||
p_search: search,
|
||||
p_page: page,
|
||||
p_page_size: pageSize
|
||||
} as any)
|
||||
return (data ?? []) as Division[]
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存事业部(新增/更新)
|
||||
* 保存事业部
|
||||
*/
|
||||
export async function saveDivision(division: DistributionDivision): Promise<boolean> {
|
||||
const session = supa.getSession()
|
||||
const mid = session?.user?.getString('id')
|
||||
if (mid == null) return false
|
||||
|
||||
const { error } = await supa
|
||||
.from('ak_distribution_divisions')
|
||||
.upsert({
|
||||
...division,
|
||||
merchant_id: mid,
|
||||
updated_at: new Date().toISOString()
|
||||
})
|
||||
.execute()
|
||||
|
||||
export async function saveDivision(division: any): Promise<boolean> {
|
||||
const { error } = await supa.rpc('rpc_admin_save_division', {
|
||||
p_uid: division.uid,
|
||||
p_name: division.name,
|
||||
p_invite_code: division.invite_code,
|
||||
p_commission_ratio: division.commission_ratio,
|
||||
p_is_enabled: division.is_enabled,
|
||||
p_end_time: division.end_time
|
||||
} as any)
|
||||
return error == null
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除事业部
|
||||
*/
|
||||
export async function deleteDivision(id: string): Promise<boolean> {
|
||||
const { error } = await supa.from('ak_distribution_divisions').delete().eq('id', id).execute()
|
||||
return error == null
|
||||
export async function deleteDivision(uid: string): Promise<boolean> {
|
||||
const { data, error } = await supa.rpc('rpc_admin_delete_division', { p_uid: uid } as any)
|
||||
return error == null && data === true
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取代理商列表
|
||||
*/
|
||||
export async function fetchAgents(query?: { search?: string, divisionId?: string, page?: number, pageSize?: number }): Promise<{ total: number, items: DistributionAgent[] }> {
|
||||
let q = supa.from('ak_distribution_agents').select('*, ak_users!uid(username, avatar_url), ak_distribution_divisions!division_id(name)', { count: 'exact' })
|
||||
|
||||
if (query?.search != null && query.search !== '') {
|
||||
q = q.or(`name.ilike.%${query.search}%,ak_users.username.ilike.%${query.search}%`)
|
||||
}
|
||||
if (query?.divisionId != null) {
|
||||
q = q.eq('division_id', query.divisionId)
|
||||
}
|
||||
|
||||
const p = query?.page ?? 1
|
||||
const ps = query?.pageSize ?? 20
|
||||
const from = (p - 1) * ps
|
||||
const to = from + ps - 1
|
||||
|
||||
const { data, error, count } = await q
|
||||
.order('created_at', { ascending: false })
|
||||
.range(from, to)
|
||||
.execute()
|
||||
|
||||
if (error != null) {
|
||||
console.error('获取代理商列表失败:', error)
|
||||
return { total: 0, items: [] as DistributionAgent[] }
|
||||
}
|
||||
|
||||
const items = (data ?? []).map((item: any): DistributionAgent => {
|
||||
return {
|
||||
...item,
|
||||
nickname: item.ak_users?.username,
|
||||
avatar_url: item.ak_users?.avatar_url,
|
||||
division_name: item.ak_distribution_divisions?.name
|
||||
} as DistributionAgent
|
||||
})
|
||||
|
||||
return { total: count ?? 0, items }
|
||||
export async function getAgentList(search: string | null, page: number, pageSize: number): Promise<Agent[]> {
|
||||
const { data, error } = await supa.rpc('rpc_admin_get_agent_list', {
|
||||
p_search: search,
|
||||
p_page: page,
|
||||
p_page_size: pageSize
|
||||
} as any)
|
||||
return (data ?? []) as Agent[]
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存代理商
|
||||
*/
|
||||
export async function saveAgent(agent: DistributionAgent): Promise<boolean> {
|
||||
const session = supa.getSession()
|
||||
const mid = session?.user?.getString('id')
|
||||
if (mid == null) return false
|
||||
|
||||
const { error } = await supa
|
||||
.from('ak_distribution_agents')
|
||||
.upsert({
|
||||
...agent,
|
||||
merchant_id: mid,
|
||||
updated_at: new Date().toISOString()
|
||||
})
|
||||
.execute()
|
||||
|
||||
export async function saveAgent(agent: any): Promise<boolean> {
|
||||
const { error } = await supa.rpc('rpc_admin_save_agent', {
|
||||
p_uid: agent.uid,
|
||||
p_division_uid: agent.division_uid,
|
||||
p_name: agent.name,
|
||||
p_commission_ratio: agent.commission_ratio,
|
||||
p_is_enabled: agent.is_enabled,
|
||||
p_end_time: agent.end_time
|
||||
} as any)
|
||||
return error == null
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除代理商
|
||||
*/
|
||||
export async function deleteAgent(uid: string): Promise<boolean> {
|
||||
const { data, error } = await supa.rpc('rpc_admin_delete_agent', { p_uid: uid } as any)
|
||||
return error == null && data === true
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取代理商申请列表
|
||||
*/
|
||||
export async function getAgentApplyList(status: string, search: string | null, page: number, pageSize: number): Promise<AgentApply[]> {
|
||||
const { data, error } = await supa.rpc('rpc_admin_get_agent_apply_list', {
|
||||
p_status: status,
|
||||
p_search: search,
|
||||
p_page: page,
|
||||
p_page_size: pageSize
|
||||
} as any)
|
||||
return (data ?? []) as AgentApply[]
|
||||
}
|
||||
|
||||
/**
|
||||
* 审核代理商申请
|
||||
*/
|
||||
export async function processAgentApply(id: string, status: string, reason: string | null): Promise<boolean> {
|
||||
const { data, error } = await supa.rpc('rpc_admin_process_agent_apply', {
|
||||
p_id: id,
|
||||
p_status: status,
|
||||
p_refusal_reason: reason
|
||||
} as any)
|
||||
return error == null && data === true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user