-- =====================================================================================
-- 补充缺失分类的测试商品数据 (修正版：忽略已存在的 Product Code)
-- 说明：为用户提到的缺失分类各生成6个商品数据，如果商品已存在则跳过
-- =====================================================================================

DO $$
DECLARE
    -- 商家ID
    v_merchant_id UUID;
    
    -- 分类ID变量
    cat_kitchen UUID;       -- 厨具
    cat_books UUID;         -- 图书文娱
    cat_wshoes UUID;        -- 女鞋
    cat_furniture UUID;     -- 家具
    cat_home UUID;          -- 家居用品
    cat_decoration UUID;    -- 家装
    cat_accessories UUID;   -- 数码配件
    cat_clothing UUID;      -- 服装鞋帽
    cat_baby UUID;          -- 母婴用品
    cat_daily UUID;         -- 生活用品
    cat_mshoes UUID;        -- 男鞋
    cat_beauty UUID;        -- 美容护肤 (美妆护肤)
    cat_meat UUID;          -- 肉禽蛋类
    cat_sports UUID;        -- 运动户外
    cat_drinks UUID;        -- 酒水饮料
    cat_food UUID;          -- 食品饮料

BEGIN
    -- 1. 获取商家ID
    SELECT id INTO v_merchant_id FROM public.ak_users WHERE role = 'merchant' LIMIT 1;
    IF v_merchant_id IS NULL THEN
        SELECT id INTO v_merchant_id FROM public.ak_users LIMIT 1;
    END IF;

    -- 2. 获取分类ID (尝试匹配名称)
    SELECT id INTO cat_kitchen FROM public.ml_categories WHERE name = '厨具' LIMIT 1;
    SELECT id INTO cat_books FROM public.ml_categories WHERE name = '图书文娱' LIMIT 1;
    SELECT id INTO cat_wshoes FROM public.ml_categories WHERE name = '女鞋' LIMIT 1;
    SELECT id INTO cat_furniture FROM public.ml_categories WHERE name = '家具' LIMIT 1;
    SELECT id INTO cat_home FROM public.ml_categories WHERE name = '家居用品' LIMIT 1;
    SELECT id INTO cat_decoration FROM public.ml_categories WHERE name = '家装' OR name = '家装建材' LIMIT 1;
    SELECT id INTO cat_accessories FROM public.ml_categories WHERE name = '数码配件' LIMIT 1;
    SELECT id INTO cat_clothing FROM public.ml_categories WHERE name = '服装鞋帽' LIMIT 1;
    SELECT id INTO cat_baby FROM public.ml_categories WHERE name = '母婴用品' LIMIT 1;
    SELECT id INTO cat_daily FROM public.ml_categories WHERE name = '生活用品' LIMIT 1;
    SELECT id INTO cat_mshoes FROM public.ml_categories WHERE name = '男鞋' LIMIT 1;
    SELECT id INTO cat_beauty FROM public.ml_categories WHERE name = '美容护肤' OR name = '美妆护肤' LIMIT 1;
    SELECT id INTO cat_meat FROM public.ml_categories WHERE name = '肉禽蛋类' LIMIT 1;
    SELECT id INTO cat_sports FROM public.ml_categories WHERE name = '运动户外' LIMIT 1;
    SELECT id INTO cat_drinks FROM public.ml_categories WHERE name = '酒水饮料' LIMIT 1;
    SELECT id INTO cat_food FROM public.ml_categories WHERE name = '食品饮料' LIMIT 1;

    -- 3. 插入数据 (添加 ON CONFLICT DO NOTHING)

    -- ---------------------------------------------------------------------------------
    -- 厨具
    -- ---------------------------------------------------------------------------------
    IF cat_kitchen IS NOT NULL THEN
        INSERT INTO public.ml_products (merchant_id, category_id, product_code, name, description, main_image_url, base_price, total_stock, available_stock, status, sale_count) VALUES 
        (v_merchant_id, cat_kitchen, 'KIT001', '苏泊尔红点不粘锅炒锅', '少油烟，易清洗，30cm', '/static/images/demo/p1.jpg', 199.00, 200, 200, 1, 800),
        (v_merchant_id, cat_kitchen, 'KIT002', '十八子作切片刀', '家用菜刀，不锈钢', '/static/images/demo/p2.jpg', 89.00, 300, 300, 1, 1200),
        (v_merchant_id, cat_kitchen, 'KIT003', '双立人刀具套装', '德国工艺，多功能', '/static/images/demo/p3.jpg', 699.00, 100, 100, 1, 300),
        (v_merchant_id, cat_kitchen, 'KIT004', '楠竹防霉菜板', '整竹加厚，双面可用', '/static/images/demo/p4.jpg', 49.00, 500, 500, 1, 2000),
        (v_merchant_id, cat_kitchen, 'KIT005', '不锈钢厨房置物架', '多层收纳，节省空间', '/static/images/demo/p5.jpg', 129.00, 150, 150, 1, 600),
        (v_merchant_id, cat_kitchen, 'KIT006', '硅胶锅铲套装', '耐高温，不伤锅', '/static/images/demo/p6.jpg', 39.00, 400, 400, 1, 1500)
        ON CONFLICT (product_code) DO NOTHING;
    END IF;

    -- ---------------------------------------------------------------------------------
    -- 图书文娱
    -- ---------------------------------------------------------------------------------
    IF cat_books IS NOT NULL THEN
        INSERT INTO public.ml_products (merchant_id, category_id, product_code, name, description, main_image_url, base_price, total_stock, available_stock, status, sale_count) VALUES 
        (v_merchant_id, cat_books, 'BOOK001', '《三体》全集 刘慈欣著', '中国科幻基石', '/static/images/demo/p1.jpg', 68.00, 500, 500, 1, 5000),
        (v_merchant_id, cat_books, 'BOOK002', '尤克里里初学者套装', '23寸桃花芯木', '/static/images/demo/p2.jpg', 199.00, 200, 200, 1, 800),
        (v_merchant_id, cat_books, 'BOOK003', '儿童绘画套装礼盒', '水彩笔蜡笔，安全无毒', '/static/images/demo/p3.jpg', 59.00, 300, 300, 1, 1500),
        (v_merchant_id, cat_books, 'BOOK004', '《活着》 余华著', '当代文学经典', '/static/images/demo/p4.jpg', 35.00, 600, 600, 1, 3000),
        (v_merchant_id, cat_books, 'BOOK005', '乐高积木 机械组', '跑车模型，益智拼装', '/static/images/demo/p5.jpg', 899.00, 100, 100, 1, 400),
        (v_merchant_id, cat_books, 'BOOK006', '雅马哈民谣吉他', 'F310，新手入门推荐', '/static/images/demo/p6.jpg', 999.00, 50, 50, 1, 200)
        ON CONFLICT (product_code) DO NOTHING;
    END IF;

    -- ---------------------------------------------------------------------------------
    -- 女鞋
    -- ---------------------------------------------------------------------------------
    IF cat_wshoes IS NOT NULL THEN
        INSERT INTO public.ml_products (merchant_id, category_id, product_code, name, description, main_image_url, base_price, total_stock, available_stock, status, sale_count) VALUES 
        (v_merchant_id, cat_wshoes, 'WSHOE001', '法式尖头高跟鞋', '细跟浅口，气质通勤', '/static/images/demo/p1.jpg', 299.00, 100, 100, 1, 500),
        (v_merchant_id, cat_wshoes, 'WSHOE002', '百搭小白鞋', '真皮休闲，舒适透气', '/static/images/demo/p2.jpg', 159.00, 300, 300, 1, 1200),
        (v_merchant_id, cat_wshoes, 'WSHOE003', '英伦风马丁靴', '厚底增高，帅气机车', '/static/images/demo/p3.jpg', 359.00, 150, 150, 1, 800),
        (v_merchant_id, cat_wshoes, 'WSHOE004', '平底乐福鞋', '金属扣装饰，软底', '/static/images/demo/p4.jpg', 199.00, 200, 200, 1, 600),
        (v_merchant_id, cat_wshoes, 'WSHOE005', '夏季凉鞋', '一字扣带，粗跟', '/static/images/demo/p5.jpg', 129.00, 400, 400, 1, 900),
        (v_merchant_id, cat_wshoes, 'WSHOE006', '秋冬过膝长靴', '弹力绒面，显瘦修腿', '/static/images/demo/p6.jpg', 499.00, 80, 80, 1, 300)
        ON CONFLICT (product_code) DO NOTHING;
    END IF;

    -- ---------------------------------------------------------------------------------
    -- 家具
    -- ---------------------------------------------------------------------------------
    IF cat_furniture IS NOT NULL THEN
        INSERT INTO public.ml_products (merchant_id, category_id, product_code, name, description, main_image_url, base_price, total_stock, available_stock, status, sale_count) VALUES 
        (v_merchant_id, cat_furniture, 'FURN001', '北欧布艺沙发', '三人位，可拆洗，小户型', '/static/images/demo/p1.jpg', 2999.00, 50, 50, 1, 100),
        (v_merchant_id, cat_furniture, 'FURN002', '实木双人床', '1.8米大床，现代简约', '/static/images/demo/p2.jpg', 3599.00, 30, 30, 1, 80),
        (v_merchant_id, cat_furniture, 'FURN003', '岩板餐桌椅组合', '轻奢风，耐磨耐高温', '/static/images/demo/p3.jpg', 1999.00, 40, 40, 1, 120),
        (v_merchant_id, cat_furniture, 'FURN004', '人体工学电脑椅', '可升降，护腰透气', '/static/images/demo/p4.jpg', 699.00, 100, 100, 1, 500),
        (v_merchant_id, cat_furniture, 'FURN005', '简约衣柜', '推拉门，大容量储物', '/static/images/demo/p5.jpg', 2599.00, 20, 20, 1, 60),
        (v_merchant_id, cat_furniture, 'FURN006', '多层简易鞋柜', '门口家用，防尘大容量', '/static/images/demo/p6.jpg', 199.00, 200, 200, 1, 800)
        ON CONFLICT (product_code) DO NOTHING;
    END IF;

    -- ---------------------------------------------------------------------------------
    -- 家居用品
    -- ---------------------------------------------------------------------------------
    IF cat_home IS NOT NULL THEN
        INSERT INTO public.ml_products (merchant_id, category_id, product_code, name, description, main_image_url, base_price, total_stock, available_stock, status, sale_count) VALUES 
        (v_merchant_id, cat_home, 'HOME001', '纯棉四件套', '60支长绒棉，亲肤裸睡', '/static/images/demo/p1.jpg', 299.00, 300, 300, 1, 900),
        (v_merchant_id, cat_home, 'HOME002', '乳胶枕头', '泰国天然乳胶，护颈椎', '/static/images/demo/p2.jpg', 159.00, 400, 400, 1, 1500),
        (v_merchant_id, cat_home, 'HOME003', '全棉加厚浴巾', '吸水速干，不掉毛', '/static/images/demo/p3.jpg', 59.00, 500, 500, 1, 2000),
        (v_merchant_id, cat_home, 'HOME004', '布艺收纳箱', '可折叠，衣物整理', '/static/images/demo/p4.jpg', 39.00, 600, 600, 1, 3000),
        (v_merchant_id, cat_home, 'HOME005', '防滑无痕衣架', '干湿两用，20个装', '/static/images/demo/p5.jpg', 29.90, 800, 800, 1, 5000),
        (v_merchant_id, cat_home, 'HOME006', '平板拖把', '免手洗，家用一拖净', '/static/images/demo/p6.jpg', 49.00, 300, 300, 1, 1200)
        ON CONFLICT (product_code) DO NOTHING;
    END IF;

    -- ---------------------------------------------------------------------------------
    -- 家装
    -- ---------------------------------------------------------------------------------
    IF cat_decoration IS NOT NULL THEN
        INSERT INTO public.ml_products (merchant_id, category_id, product_code, name, description, main_image_url, base_price, total_stock, available_stock, status, sale_count) VALUES 
        (v_merchant_id, cat_decoration, 'DECO001', '吸顶灯LED', '简约现代，客厅卧室通用', '/static/images/demo/p1.jpg', 199.00, 200, 200, 1, 500),
        (v_merchant_id, cat_decoration, 'DECO002', '3D立体墙贴', '自粘壁纸，防水防潮', '/static/images/demo/p2.jpg', 29.00, 1000, 1000, 1, 3000),
        (v_merchant_id, cat_decoration, 'DECO003', '全遮光窗帘', '成品定制，隔热防晒', '/static/images/demo/p3.jpg', 89.00, 300, 300, 1, 800),
        (v_merchant_id, cat_decoration, 'DECO004', '北欧风地毯', '客厅茶几垫，可水洗', '/static/images/demo/p4.jpg', 129.00, 150, 150, 1, 400),
        (v_merchant_id, cat_decoration, 'DECO005', '装饰挂画', '三联画，现代简约晶瓷画', '/static/images/demo/p5.jpg', 159.00, 200, 200, 1, 600),
        (v_merchant_id, cat_decoration, 'DECO006', '静音挂钟', '创意艺术，时尚时钟', '/static/images/demo/p6.jpg', 69.00, 400, 400, 1, 900)
        ON CONFLICT (product_code) DO NOTHING;
    END IF;

    -- ---------------------------------------------------------------------------------
    -- 数码配件
    -- ---------------------------------------------------------------------------------
    IF cat_accessories IS NOT NULL THEN
        INSERT INTO public.ml_products (merchant_id, category_id, product_code, name, description, main_image_url, base_price, total_stock, available_stock, status, sale_count) VALUES 
        (v_merchant_id, cat_accessories, 'ACC001', '20W快充充电头', 'Type-C接口，PD协议', '/static/images/demo/p1.jpg', 59.00, 1000, 1000, 1, 5000),
        (v_merchant_id, cat_accessories, 'ACC002', '液态硅胶手机壳', '全包防摔，手感亲肤', '/static/images/demo/p2.jpg', 29.00, 2000, 2000, 1, 8000),
        (v_merchant_id, cat_accessories, 'ACC003', '钢化膜 2片装', '高清防指纹，自动贴膜', '/static/images/demo/p3.jpg', 19.90, 3000, 3000, 1, 10000),
        (v_merchant_id, cat_accessories, 'ACC004', '10000mAh充电宝', '迷你便携，双向快充', '/static/images/demo/p4.jpg', 99.00, 500, 500, 1, 2000),
        (v_merchant_id, cat_accessories, 'ACC005', '桌面手机支架', '可折叠升降，金属底座', '/static/images/demo/p5.jpg', 39.00, 800, 800, 1, 3000),
        (v_merchant_id, cat_accessories, 'ACC006', '数据线三合一', '耐用编织，苹果安卓通用于', '/static/images/demo/p6.jpg', 25.00, 1500, 1500, 1, 4000)
        ON CONFLICT (product_code) DO NOTHING;
    END IF;

    -- ---------------------------------------------------------------------------------
    -- 服装鞋帽 (General / Accessories)
    -- ---------------------------------------------------------------------------------
    IF cat_clothing IS NOT NULL THEN
        INSERT INTO public.ml_products (merchant_id, category_id, product_code, name, description, main_image_url, base_price, total_stock, available_stock, status, sale_count) VALUES 
        (v_merchant_id, cat_clothing, 'CLOTH001', '鸭舌帽', '韩版百搭，刺绣棒球帽', '/static/images/demo/p1.jpg', 39.00, 500, 500, 1, 1200),
        (v_merchant_id, cat_clothing, 'CLOTH002', '纯棉袜子 5双装', '中筒袜，吸汗防臭', '/static/images/demo/p2.jpg', 29.90, 1000, 1000, 1, 5000),
        (v_merchant_id, cat_clothing, 'CLOTH003', '真皮皮带', '自动扣，商务休闲', '/static/images/demo/p3.jpg', 99.00, 300, 300, 1, 800),
        (v_merchant_id, cat_clothing, 'CLOTH004', '羊毛围巾', '冬季保暖，经典格子', '/static/images/demo/p4.jpg', 129.00, 200, 200, 1, 600),
        (v_merchant_id, cat_clothing, 'CLOTH005', '触屏手套', '加绒保暖，骑行防风', '/static/images/demo/p5.jpg', 49.00, 400, 400, 1, 900),
        (v_merchant_id, cat_clothing, 'CLOTH006', '防晒衣', 'UPF50+，轻薄透气', '/static/images/demo/p6.jpg', 79.00, 600, 600, 1, 2000)
        ON CONFLICT (product_code) DO NOTHING;
    END IF;

    -- ---------------------------------------------------------------------------------
    -- 母婴用品
    -- ---------------------------------------------------------------------------------
    IF cat_baby IS NOT NULL THEN
        INSERT INTO public.ml_products (merchant_id, category_id, product_code, name, description, main_image_url, base_price, total_stock, available_stock, status, sale_count) VALUES 
        (v_merchant_id, cat_baby, 'BABY001', '婴儿纸尿裤 L码', '超薄透气，干爽瞬吸', '/static/images/demo/p1.jpg', 129.00, 500, 500, 1, 3000),
        (v_merchant_id, cat_baby, 'BABY002', '婴儿配方奶粉 3段', '进口奶源，DHA添加', '/static/images/demo/p2.jpg', 299.00, 200, 200, 1, 1500),
        (v_merchant_id, cat_baby, 'BABY003', 'PPSU奶瓶', '宽口径，防胀气', '/static/images/demo/p3.jpg', 89.00, 300, 300, 1, 800),
        (v_merchant_id, cat_baby, 'BABY004', '婴儿湿巾 80抽*5', '纯水无添加，手口专用', '/static/images/demo/p4.jpg', 49.90, 1000, 1000, 1, 5000),
        (v_merchant_id, cat_baby, 'BABY005', '轻便折叠婴儿推车', '可坐可躺，一键收车', '/static/images/demo/p5.jpg', 599.00, 100, 100, 1, 400),
        (v_merchant_id, cat_baby, 'BABY006', '益智积木桌', '多功能游戏桌，大颗粒', '/static/images/demo/p6.jpg', 199.00, 150, 150, 1, 600)
        ON CONFLICT (product_code) DO NOTHING;
    END IF;

    -- ---------------------------------------------------------------------------------
    -- 生活用品
    -- ---------------------------------------------------------------------------------
    IF cat_daily IS NOT NULL THEN
        INSERT INTO public.ml_products (merchant_id, category_id, product_code, name, description, main_image_url, base_price, total_stock, available_stock, status, sale_count) VALUES 
        (v_merchant_id, cat_daily, 'DAILY001', '抽纸 24包整箱', '4层加厚，原生木浆', '/static/images/demo/p1.jpg', 59.90, 800, 800, 1, 6000),
        (v_merchant_id, cat_daily, 'DAILY002', '洗衣液 3kg+2kg', '深层洁净，薰衣草香', '/static/images/demo/p2.jpg', 49.90, 600, 600, 1, 4000),
        (v_merchant_id, cat_daily, 'DAILY003', '洗发水套装', '去屑止痒，柔顺丝滑', '/static/images/demo/p3.jpg', 79.00, 400, 400, 1, 2000),
        (v_merchant_id, cat_daily, 'DAILY004', '加厚垃圾袋', '手提式，承重力强', '/static/images/demo/p4.jpg', 19.90, 1000, 1000, 1, 8000),
        (v_merchant_id, cat_daily, 'DAILY005', '按压式牙膏', '美白去黄，清新口气', '/static/images/demo/p5.jpg', 29.90, 500, 500, 1, 3000),
        (v_merchant_id, cat_daily, 'DAILY006', '透明收纳箱', '特大号，带轮滑', '/static/images/demo/p6.jpg', 45.00, 300, 300, 1, 1200)
        ON CONFLICT (product_code) DO NOTHING;
    END IF;

     -- ---------------------------------------------------------------------------------
    -- 男鞋
    -- ---------------------------------------------------------------------------------
    IF cat_mshoes IS NOT NULL THEN
        INSERT INTO public.ml_products (merchant_id, category_id, product_code, name, description, main_image_url, base_price, total_stock, available_stock, status, sale_count) VALUES 
        (v_merchant_id, cat_mshoes, 'MSHOE001', '商务正装皮鞋', '头层牛皮，透气舒适', '/static/images/demo/p1.jpg', 399.00, 100, 100, 1, 400),
        (v_merchant_id, cat_mshoes, 'MSHOE002', '运动跑步鞋', '减震气垫，轻便防滑', '/static/images/demo/p2.jpg', 299.00, 300, 300, 1, 1500),
        (v_merchant_id, cat_mshoes, 'MSHOE003', '休闲板鞋', '百搭小白鞋，耐磨', '/static/images/demo/p3.jpg', 159.00, 400, 400, 1, 2000),
        (v_merchant_id, cat_mshoes, 'MSHOE004', '高帮工装靴', '复古马丁靴，硬汉风', '/static/images/demo/p4.jpg', 459.00, 150, 150, 1, 600),
        (v_merchant_id, cat_mshoes, 'MSHOE005', '夏季网面透气鞋', '镂空飞织，一脚蹬', '/static/images/demo/p5.jpg', 129.00, 500, 500, 1, 1000),
        (v_merchant_id, cat_mshoes, 'MSHOE006', '居家防滑拖鞋', 'EVA材质，软底静音', '/static/images/demo/p6.jpg', 19.90, 1000, 1000, 1, 5000)
        ON CONFLICT (product_code) DO NOTHING;
    END IF;

    -- ---------------------------------------------------------------------------------
    -- 美容护肤
    -- ---------------------------------------------------------------------------------
    IF cat_beauty IS NOT NULL THEN
        INSERT INTO public.ml_products (merchant_id, category_id, product_code, name, description, main_image_url, base_price, total_stock, available_stock, status, sale_count) VALUES 
        (v_merchant_id, cat_beauty, 'BEAUTY001', '小灯泡美白精华', '提亮肤色，淡化斑点', '/static/images/demo/p1.jpg', 1299.00, 100, 100, 1, 500),
        (v_merchant_id, cat_beauty, 'BEAUTY002', '哑光雾面口红', '显白烂番茄色，不拔干', '/static/images/demo/p2.jpg', 299.00, 300, 300, 1, 2000),
        (v_merchant_id, cat_beauty, 'BEAUTY003', '氨基酸洗面奶', '温和清洁，敏感肌可用', '/static/images/demo/p3.jpg', 89.00, 1000, 1000, 1, 5000),
        (v_merchant_id, cat_beauty, 'BEAUTY004', '补水保湿面膜 10片', '深层补水，急救修护', '/static/images/demo/p4.jpg', 99.00, 800, 800, 1, 4000),
        (v_merchant_id, cat_beauty, 'BEAUTY005', '持妆粉底液', '遮瑕控油，不脱妆', '/static/images/demo/p5.jpg', 399.00, 200, 200, 1, 900),
        (v_merchant_id, cat_beauty, 'BEAUTY006', '爽肤水', '二次清洁，收缩毛孔', '/static/images/demo/p6.jpg', 159.00, 400, 400, 1, 1200)
        ON CONFLICT (product_code) DO NOTHING;
    END IF;

    -- ---------------------------------------------------------------------------------
    -- 肉禽蛋类
    -- ---------------------------------------------------------------------------------
    IF cat_meat IS NOT NULL THEN
        INSERT INTO public.ml_products (merchant_id, category_id, product_code, name, description, main_image_url, base_price, total_stock, available_stock, status, sale_count) VALUES 
        (v_merchant_id, cat_meat, 'MEAT001', '原切牛排 10片', '整肉原切，眼肉西冷', '/static/images/demo/p1.jpg', 199.00, 500, 500, 1, 2500),
        (v_merchant_id, cat_meat, 'MEAT002', '散养土鸡蛋 30枚', '农家散养，营养丰富', '/static/images/demo/p2.jpg', 39.90, 800, 800, 1, 3000),
        (v_merchant_id, cat_meat, 'MEAT003', '新鲜五花肉 500g', '肥瘦相间，适合红烧', '/static/images/demo/p3.jpg', 25.00, 300, 300, 1, 1500),
        (v_merchant_id, cat_meat, 'MEAT004', '清远鸡 1只', '走地鸡，肉质紧实', '/static/images/demo/p4.jpg', 59.00, 200, 200, 1, 800),
        (v_merchant_id, cat_meat, 'MEAT005', '冷冻鸡胸肉 1kg', '低脂高蛋白，健身代餐', '/static/images/demo/p5.jpg', 19.90, 1000, 1000, 1, 5000),
        (v_merchant_id, cat_meat, 'MEAT006', '羔羊肉卷 500g', '火锅食材，不膻不腻', '/static/images/demo/p6.jpg', 39.00, 600, 600, 1, 2000)
        ON CONFLICT (product_code) DO NOTHING;
    END IF;

    -- ---------------------------------------------------------------------------------
    -- 运动户外
    -- ---------------------------------------------------------------------------------
    IF cat_sports IS NOT NULL THEN
        INSERT INTO public.ml_products (merchant_id, category_id, product_code, name, description, main_image_url, base_price, total_stock, available_stock, status, sale_count) VALUES 
        (v_merchant_id, cat_sports, 'SPORT001', 'TPE瑜伽垫', '加宽加厚，防滑无味', '/static/images/demo/p1.jpg', 59.00, 500, 500, 1, 2000),
        (v_merchant_id, cat_sports, 'SPORT002', '全碳素羽毛球拍', '单拍，超轻进攻型', '/static/images/demo/p2.jpg', 199.00, 200, 200, 1, 600),
        (v_merchant_id, cat_sports, 'SPORT003', '标准篮球 7号', '耐磨防滑，室外水泥地', '/static/images/demo/p3.jpg', 89.00, 300, 300, 1, 1000),
        (v_merchant_id, cat_sports, 'SPORT004', '可调节哑铃', '家用健身，男女通用', '/static/images/demo/p4.jpg', 129.00, 150, 150, 1, 500),
        (v_merchant_id, cat_sports, 'SPORT005', '户外速开帐篷', '防雨防晒，3-4人', '/static/images/demo/p5.jpg', 299.00, 100, 100, 1, 300),
        (v_merchant_id, cat_sports, 'SPORT006', '跳绳', '专业计数，燃脂减肥', '/static/images/demo/p6.jpg', 29.00, 1000, 1000, 1, 5000)
        ON CONFLICT (product_code) DO NOTHING;
    END IF;

    -- ---------------------------------------------------------------------------------
    -- 酒水饮料
    -- ---------------------------------------------------------------------------------
    IF cat_drinks IS NOT NULL THEN
        INSERT INTO public.ml_products (merchant_id, category_id, product_code, name, description, main_image_url, base_price, total_stock, available_stock, status, sale_count) VALUES 
        (v_merchant_id, cat_drinks, 'DRINK001', '可口可乐 330ml*24', '经典原味，快乐肥宅水', '/static/images/demo/p1.jpg', 45.00, 500, 500, 1, 3000),
        (v_merchant_id, cat_drinks, 'DRINK002', '青岛啤酒 500ml*12', '经典10度，聚会畅饮', '/static/images/demo/p2.jpg', 59.00, 400, 400, 1, 2000),
        (v_merchant_id, cat_drinks, 'DRINK003', '法国进口红酒', '干红葡萄酒，整箱装', '/static/images/demo/p3.jpg', 299.00, 100, 100, 1, 500),
        (v_merchant_id, cat_drinks, 'DRINK004', '纯牛奶 250ml*24', '全脂灭菌乳，早餐奶', '/static/images/demo/p4.jpg', 69.00, 600, 600, 1, 4000),
        (v_merchant_id, cat_drinks, 'DRINK005', '矿泉水 550ml*24', '天然弱碱性，饮用水', '/static/images/demo/p5.jpg', 29.00, 800, 800, 1, 5000),
        (v_merchant_id, cat_drinks, 'DRINK006', '无糖乌龙茶', '0糖0脂，解腻茶饮料', '/static/images/demo/p6.jpg', 55.00, 300, 300, 1, 1500)
        ON CONFLICT (product_code) DO NOTHING;
    END IF;

    -- ---------------------------------------------------------------------------------
    -- 食品饮料 (General)
    -- ---------------------------------------------------------------------------------
    IF cat_food IS NOT NULL THEN
        INSERT INTO public.ml_products (merchant_id, category_id, product_code, name, description, main_image_url, base_price, total_stock, available_stock, status, sale_count) VALUES 
        (v_merchant_id, cat_food, 'FOOD001', '五常大米 5kg', '东北香米，软糯香甜', '/static/images/demo/p1.jpg', 59.90, 500, 500, 1, 2500),
        (v_merchant_id, cat_food, 'FOOD002', '金龙鱼调和油 5L', '家用食用油，非转基因', '/static/images/demo/p2.jpg', 69.90, 400, 400, 1, 3000),
        (v_merchant_id, cat_food, 'FOOD003', '方便面整箱 24袋', '红烧牛肉味，夜宵速食', '/static/images/demo/p3.jpg', 45.00, 600, 600, 1, 5000),
        (v_merchant_id, cat_food, 'FOOD004', '老干妈风味豆豉', '下饭菜，拌面酱', '/static/images/demo/p4.jpg', 12.90, 1000, 1000, 1, 8000),
        (v_merchant_id, cat_food, 'FOOD005', '螺蛳粉 300g*3', '广西特产，酸辣爽口', '/static/images/demo/p5.jpg', 39.90, 800, 800, 1, 6000),
        (v_merchant_id, cat_food, 'FOOD006', '广式腊肠 500g', '正宗风味，也是二八肥瘦', '/static/images/demo/p6.jpg', 35.00, 300, 300, 1, 1200)
        ON CONFLICT (product_code) DO NOTHING;
    END IF;

    RAISE NOTICE '数据生成完成：已为缺失分类插入测试商品 (跳过重复)';
END $$;
