-- =====================================================
-- 会员营销模块 — 小程序完整业务链模拟数据（可重复执行）
-- 模块：business-marketing
-- 版本：1.0.0
-- 创建时间：2026-06-25
-- 依赖：
--   1. sys_tn_tenant_info 存在 tenant_id='1'、tenant_code='1' 的店铺租户
--   2. marketing.sql、marketing_coupon_scene_seed.sql 已执行
--   3. coupon_schema.sql（app_coupon_template / app_member_coupon 表）
--   4. member.sql（app_member 表）
-- 执行顺序：… → marketing_coupon_scene_seed.sql → marketing_mock_data.sql → marketing_menu_permission.sql
-- 号段：1926061330000000102～1926061330000000133（本脚本专用，101 为场景种子）
-- 清理：按固定 id 删除；remarks='marketing_mock_data'
-- 业务链：
--   扫码(cfg_marketing_tenant_qrcode.wx_scene)
--     → 落地(cfg_marketing_tenant_ext)
--     → 入会(app_member_tenant)
--     → 领券(app_coupon_template + app_member_coupon, scene=STORE_OFFLINE)
--     → 核销(app_member_coupon_verify_log + 券 status=已用)
--     → 统计(入会/领券/核销)
-- 演示账号（短信登录可用，手机号勿与生产冲突）：
--   顾客 李杏花 13900001001 | 店员 王小二 13900001002 | 店长 张掌柜 13900001003 | 顾客 赵来客 13900001004
-- =====================================================

-- ---- 清理（子表 → 主表） ----
DELETE FROM `app_member_coupon_verify_log` WHERE `id` IN ('1926061330000000113', '1926061330000000115');
DELETE FROM `app_member_coupon` WHERE `id` IN ('1926061330000000111', '1926061330000000112', '1926061330000000114', '1926061330000000116');
DELETE FROM `app_coupon_template` WHERE `id` = '1926061330000000110';
DELETE FROM `app_member_tenant` WHERE `id` IN (
  '1926061330000000130', '1926061330000000131', '1926061330000000132', '1926061330000000133'
);
DELETE FROM `cfg_marketing_tenant_qrcode` WHERE `id` IN ('1926061330000000103', '1926061330000000104');
DELETE FROM `cfg_marketing_tenant_ext` WHERE `id` = '1926061330000000102';
DELETE FROM `app_member` WHERE `id` IN (
  '1926061330000000120', '1926061330000000121', '1926061330000000122', '1926061330000000123'
);

-- ---- 1. 演示会员（C 端登录 / 店员核销） ----
INSERT INTO `app_member` (
  `id`, `member_no`, `nickname`, `real_name`, `mobile`, `gender`,
  `level_id`, `level_code`, `status`, `source`, `register_date`,
  `create_by`, `create_date`, `update_by`, `update_date`, `del_flag`, `remarks`, `tenant_code`, `tenant_id`
) VALUES
(
  '1926061330000000120', 'MKT202606250001', '李杏花', '李杏花', '13900001001', 2,
  '1', 'NORMAL', 1, 'WECHAT_MINI', DATE_SUB(NOW(), INTERVAL 25 DAY),
  'mock', DATE_SUB(NOW(), INTERVAL 25 DAY), 'mock', NOW(), '0', 'marketing_mock_data', '1', '1'
),
(
  '1926061330000000121', 'MKT202606250002', '王小二', '王小二', '13900001002', 1,
  '1', 'NORMAL', 1, 'WECHAT_MINI', DATE_SUB(NOW(), INTERVAL 30 DAY),
  'mock', DATE_SUB(NOW(), INTERVAL 30 DAY), 'mock', NOW(), '0', 'marketing_mock_data', '1', '1'
),
(
  '1926061330000000122', 'MKT202606250003', '张掌柜', '张掌柜', '13900001003', 1,
  '2', 'SILVER', 1, 'WECHAT_MINI', DATE_SUB(NOW(), INTERVAL 30 DAY),
  'mock', DATE_SUB(NOW(), INTERVAL 30 DAY), 'mock', NOW(), '0', 'marketing_mock_data', '1', '1'
),
(
  '1926061330000000123', 'MKT202606250004', '赵来客', '赵来客', '13900001004', 0,
  '1', 'NORMAL', 1, 'WECHAT_MINI', DATE_SUB(NOW(), INTERVAL 8 DAY),
  'mock', DATE_SUB(NOW(), INTERVAL 8 DAY), 'mock', NOW(), '0', 'marketing_mock_data', '1', '1'
);

-- ---- 2. 店铺营销扩展（须为 cfg_marketing_tenant_ext 首条，统计 resolveCurrentTenantId 取 tenant_id） ----
INSERT INTO `cfg_marketing_tenant_ext` (
  `id`, `marketing_enabled`, `auto_join_on_qr`, `welcome_title`, `welcome_subtitle`, `logo_url`,
  `create_by`, `create_date`, `update_by`, `update_date`, `del_flag`, `remarks`, `tenant_code`, `tenant_id`
) VALUES (
  '1926061330000000102',
  1,
  1,
  '欢迎加入杏花村·晋味小馆会员',
  '扫码领券 · 到店核销 · 会员专享',
  'https://picsum.photos/seed/marketing-store-logo/200/200',
  'mock',
  DATE_SUB(NOW(), INTERVAL 30 DAY),
  'mock',
  NOW(),
  '0',
  'marketing_mock_data',
  '1',
  '1'
);

-- ---- 3. 推广二维码（scene 供 /mobile/noAuth/marketing/tenant/landing?scene= 解析） ----
INSERT INTO `cfg_marketing_tenant_qrcode` (
  `id`, `channel_code`, `channel_name`, `wx_scene`, `qrcode_url`, `page_path`, `status`, `scan_count`,
  `create_by`, `create_date`, `update_by`, `update_date`, `del_flag`, `remarks`, `tenant_code`, `tenant_id`
) VALUES
(
  '1926061330000000103',
  'DEFAULT',
  '门店默认码',
  '1_DEFAULT',
  'https://picsum.photos/seed/marketing-qr-default/430/430',
  'pages/home/index',
  1,
  128,
  'mock',
  DATE_SUB(NOW(), INTERVAL 30 DAY),
  'mock',
  NOW(),
  '0',
  'marketing_mock_data',
  '1',
  '1'
),
(
  '1926061330000000104',
  'POSTER',
  '海报推广',
  '1_POSTER',
  'https://picsum.photos/seed/marketing-qr-poster/430/430',
  'pages/home/index',
  1,
  56,
  'mock',
  DATE_SUB(NOW(), INTERVAL 20 DAY),
  'mock',
  NOW(),
  '0',
  'marketing_mock_data',
  '1',
  '1'
);

-- ---- 4. 会员-店铺关系（含角色：CUSTOMER / CLERK / MANAGER） ----
INSERT INTO `app_member_tenant` (
  `id`, `member_id`, `member_no`, `bind_status`, `join_source`, `channel_code`, `member_role`, `join_date`,
  `create_by`, `create_date`, `update_by`, `update_date`, `del_flag`, `remarks`, `tenant_code`, `tenant_id`
) VALUES
(
  '1926061330000000130', '1926061330000000120', 'MKT202606250001', 1, 'QR_SCAN', 'DEFAULT', 'CUSTOMER',
  DATE_SUB(NOW(), INTERVAL 25 DAY),
  'mock', DATE_SUB(NOW(), INTERVAL 25 DAY), 'mock', NOW(), '0', 'marketing_mock_data', '1', '1'
),
(
  '1926061330000000131', '1926061330000000121', 'MKT202606250002', 1, 'QR_SCAN', 'DEFAULT', 'CLERK',
  DATE_SUB(NOW(), INTERVAL 30 DAY),
  'mock', DATE_SUB(NOW(), INTERVAL 30 DAY), 'mock', NOW(), '0', 'marketing_mock_data', '1', '1'
),
(
  '1926061330000000132', '1926061330000000122', 'MKT202606250003', 1, 'ADMIN', 'DEFAULT', 'MANAGER',
  DATE_SUB(NOW(), INTERVAL 30 DAY),
  'mock', DATE_SUB(NOW(), INTERVAL 30 DAY), 'mock', NOW(), '0', 'marketing_mock_data', '1', '1'
),
(
  '1926061330000000133', '1926061330000000123', 'MKT202606250004', 1, 'QR_SCAN', 'POSTER', 'CUSTOMER',
  DATE_SUB(NOW(), INTERVAL 8 DAY),
  'mock', DATE_SUB(NOW(), INTERVAL 8 DAY), 'mock', NOW(), '0', 'marketing_mock_data', '1', '1'
);

-- ---- 5. 店铺线下券模板（scene_code=STORE_OFFLINE，tenant_id 与店铺一致） ----
INSERT INTO `app_coupon_template` (
  `id`, `coupon_code`, `coupon_name`, `coupon_type`, `coupon_image`,
  `discount_type`, `discount_value`, `min_consume_amount`, `max_discount_amount`,
  `use_scope`, `scope_ids`, `exclude_scope_ids`,
  `total_count`, `issued_count`, `used_count`, `per_member_limit`, `get_type`, `exchange_points`,
  `validity_type`, `valid_start_date`, `valid_end_date`, `valid_days`,
  `get_start_date`, `get_end_date`,
  `use_platforms`, `member_levels`, `can_overlay`, `status`, `description`, `scene_code`,
  `create_by`, `create_date`, `update_by`, `update_date`, `del_flag`, `remarks`, `tenant_code`, `tenant_id`
) VALUES (
  '1926061330000000110',
  'MKT_STORE_50_10',
  '到店满50减10',
  1,
  'https://picsum.photos/seed/marketing-coupon/400/200',
  1, 10.00, 50.00, NULL,
  1, NULL, NULL,
  500, 4, 2, 3, 1, NULL,
  1, DATE_SUB(CURDATE(), INTERVAL 30 DAY), DATE_ADD(CURDATE(), INTERVAL 180 DAY), NULL,
  DATE_SUB(CURDATE(), INTERVAL 30 DAY), DATE_ADD(CURDATE(), INTERVAL 180 DAY),
  '["MINI"]', NULL, 0, 1,
  '本券仅限本店线下到店核销，单笔满50元可用，不可与其他优惠叠加。',
  'STORE_OFFLINE',
  'mock', DATE_SUB(NOW(), INTERVAL 30 DAY), 'mock', NOW(), '0', 'marketing_mock_data', '1', '1'
);

-- ---- 6. 会员券（2 张未用 + 2 张已核销） ----
INSERT INTO `app_member_coupon` (
  `id`, `coupon_sn`, `member_id`, `member_no`, `member_mobile`,
  `template_id`, `coupon_code`, `coupon_name`, `coupon_type`,
  `discount_type`, `discount_value`, `min_consume_amount`, `max_discount_amount`,
  `scene_code`, `use_scope`, `scope_ids`, `exclude_scope_ids`,
  `get_type`, `get_date`, `get_source`, `activity_id`, `exchange_points`,
  `valid_start_date`, `valid_end_date`,
  `status`, `use_date`, `use_order_id`, `use_order_no`, `use_amount`, `order_amount`,
  `return_date`, `return_reason`, `is_returned`,
  `freeze_date`, `freeze_reason`, `freeze_order_id`,
  `create_by`, `create_date`, `update_by`, `update_date`, `del_flag`, `remarks`, `tenant_code`, `tenant_id`
) VALUES
(
  '1926061330000000111',
  'CPNMKT192606133000001',
  '1926061330000000120', 'MKT202606250001', '13900001001',
  '1926061330000000110', 'MKT_STORE_50_10', '到店满50减10', 1,
  1, 10.00, 50.00, NULL,
  'STORE_OFFLINE', 1, NULL, NULL,
  1, DATE_SUB(NOW(), INTERVAL 5 DAY), 'MINI', NULL, NULL,
  DATE_SUB(CURDATE(), INTERVAL 30 DAY), DATE_ADD(CURDATE(), INTERVAL 180 DAY),
  0, NULL, NULL, NULL, NULL, NULL,
  NULL, NULL, 0,
  NULL, NULL, NULL,
  'mock', DATE_SUB(NOW(), INTERVAL 5 DAY), 'mock', NOW(), '0', 'marketing_mock_data', '1', '1'
),
(
  '1926061330000000112',
  'CPNMKT192606133000002',
  '1926061330000000120', 'MKT202606250001', '13900001001',
  '1926061330000000110', 'MKT_STORE_50_10', '到店满50减10', 1,
  1, 10.00, 50.00, NULL,
  'STORE_OFFLINE', 1, NULL, NULL,
  1, DATE_SUB(NOW(), INTERVAL 10 DAY), 'MINI', NULL, NULL,
  DATE_SUB(CURDATE(), INTERVAL 30 DAY), DATE_ADD(CURDATE(), INTERVAL 180 DAY),
  1, DATE_SUB(NOW(), INTERVAL 3 DAY), NULL, 'MKT_OFFLINE_001', 10.00, 68.00,
  NULL, NULL, 0,
  NULL, NULL, NULL,
  'mock', DATE_SUB(NOW(), INTERVAL 10 DAY), 'mock', NOW(), '0', 'marketing_mock_data', '1', '1'
),
(
  '1926061330000000114',
  'CPNMKT192606133000003',
  '1926061330000000123', 'MKT202606250004', '13900001004',
  '1926061330000000110', 'MKT_STORE_50_10', '到店满50减10', 1,
  1, 10.00, 50.00, NULL,
  'STORE_OFFLINE', 1, NULL, NULL,
  1, DATE_SUB(NOW(), INTERVAL 7 DAY), 'MINI', NULL, NULL,
  DATE_SUB(CURDATE(), INTERVAL 30 DAY), DATE_ADD(CURDATE(), INTERVAL 180 DAY),
  1, DATE_SUB(NOW(), INTERVAL 1 DAY), NULL, 'MKT_OFFLINE_002', 10.00, 88.00,
  NULL, NULL, 0,
  NULL, NULL, NULL,
  'mock', DATE_SUB(NOW(), INTERVAL 7 DAY), 'mock', NOW(), '0', 'marketing_mock_data', '1', '1'
),
(
  '1926061330000000116',
  'CPNMKT192606133000004',
  '1926061330000000123', 'MKT202606250004', '13900001004',
  '1926061330000000110', 'MKT_STORE_50_10', '到店满50减10', 1,
  1, 10.00, 50.00, NULL,
  'STORE_OFFLINE', 1, NULL, NULL,
  1, DATE_SUB(NOW(), INTERVAL 2 DAY), 'MINI', NULL, NULL,
  DATE_SUB(CURDATE(), INTERVAL 30 DAY), DATE_ADD(CURDATE(), INTERVAL 180 DAY),
  0, NULL, NULL, NULL, NULL, NULL,
  NULL, NULL, 0,
  NULL, NULL, NULL,
  'mock', DATE_SUB(NOW(), INTERVAL 2 DAY), 'mock', NOW(), '0', 'marketing_mock_data', '1', '1'
);

-- ---- 7. 线下核销流水（与已用券 112、114 对应） ----
INSERT INTO `app_member_coupon_verify_log` (
  `id`, `member_coupon_id`, `coupon_template_id`, `coupon_name`, `member_id`,
  `verify_type`, `verify_time`, `operator_id`, `operator_name`, `verify_token`,
  `verify_tenant_id`, `verify_tenant_code`,
  `create_by`, `create_date`, `update_by`, `update_date`, `del_flag`, `remarks`, `tenant_code`, `tenant_id`
) VALUES
(
  '1926061330000000113',
  '1926061330000000112',
  '1926061330000000110',
  '到店满50减10',
  '1926061330000000120',
  'OFFLINE_SCAN',
  DATE_SUB(NOW(), INTERVAL 3 DAY),
  '1926061330000000121',
  '王小二',
  'MKTVFY19260613300000101',
  '1',
  '1',
  'mock',
  DATE_SUB(NOW(), INTERVAL 3 DAY),
  'mock',
  NOW(),
  '0',
  'marketing_mock_data',
  '1',
  '1'
),
(
  '1926061330000000115',
  '1926061330000000114',
  '1926061330000000110',
  '到店满50减10',
  '1926061330000000123',
  'OFFLINE_SCAN',
  DATE_SUB(NOW(), INTERVAL 1 DAY),
  '1926061330000000121',
  '王小二',
  'MKTVFY19260613300000102',
  '1',
  '1',
  'mock',
  DATE_SUB(NOW(), INTERVAL 1 DAY),
  'mock',
  NOW(),
  '0',
  'marketing_mock_data',
  '1',
  '1'
);
