CREATE TABLE IF NOT EXISTS app_popup_config (
  id BIGINT NOT NULL PRIMARY KEY,
  sys_origin VARCHAR(32) NOT NULL DEFAULT '' COMMENT '来源系统',
  popup_key VARCHAR(64) NOT NULL COMMENT '弹窗业务key，例如 invite/game',
  name VARCHAR(128) NOT NULL DEFAULT '' COMMENT '后台展示名称',
  scene VARCHAR(32) NOT NULL DEFAULT 'APP_ENTER' COMMENT '弹窗场景',
  enabled TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否启用',
  limit_days INT NOT NULL DEFAULT 0 COMMENT '返回给App的展示间隔建议值，0=每次都弹',
  priority INT NOT NULL DEFAULT 0 COMMENT '优先级，越大越靠前',
  version INT NOT NULL DEFAULT 1 COMMENT '配置版本',
  start_time DATETIME(3) DEFAULT NULL COMMENT '开始时间',
  end_time DATETIME(3) DEFAULT NULL COMMENT '结束时间',
  platforms_json JSON DEFAULT NULL COMMENT '平台白名单，例如 ["ios","android"]',
  min_app_version VARCHAR(32) NOT NULL DEFAULT '' COMMENT '最低App版本',
  max_app_version VARCHAR(32) NOT NULL DEFAULT '' COMMENT '最高App版本',
  user_scope_type VARCHAR(32) NOT NULL DEFAULT 'ALL' COMMENT '人群规则：ALL/WHITELIST/BLACKLIST',
  user_scope_json JSON DEFAULT NULL COMMENT '人群配置，一期可为空',
  content_json JSON DEFAULT NULL COMMENT '弹窗内容：标题、图片、按钮、多语言',
  jump_type VARCHAR(32) NOT NULL DEFAULT '' COMMENT 'H5/APP_ROUTE/GAME/NOOP',
  jump_url VARCHAR(512) NOT NULL DEFAULT '' COMMENT '跳转地址',
  remark VARCHAR(255) NOT NULL DEFAULT '' COMMENT '备注',
  create_time DATETIME(3) DEFAULT NULL,
  update_time DATETIME(3) DEFAULT NULL,
  UNIQUE KEY uk_app_popup_config_key (sys_origin, scene, popup_key),
  KEY idx_app_popup_config_scene (sys_origin, scene, enabled, priority)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='APP弹窗配置';

INSERT INTO app_popup_config
(id, sys_origin, popup_key, name, scene, enabled, limit_days, priority, version,
 content_json, jump_type, jump_url, create_time, update_time)
VALUES
(1001, 'LIKEI', 'invite', '邀请活动弹窗', 'APP_ENTER', 1, 7, 100, 1,
 JSON_OBJECT('title', 'Invite friends', 'image', 'https://cdn.example.com/popup/invite.png'),
 'H5', '/h5/app-invite/landing.html', NOW(3), NOW(3)),
(1002, 'LIKEI', 'game', '游戏引导弹窗', 'APP_ENTER', 1, 7, 90, 1,
 JSON_OBJECT('title', 'Play games', 'image', 'https://cdn.example.com/popup/game.png'),
 'APP_ROUTE', '/game-center', NOW(3), NOW(3))
ON DUPLICATE KEY UPDATE
  name = VALUES(name),
  enabled = VALUES(enabled),
  limit_days = VALUES(limit_days),
  priority = VALUES(priority),
  version = VALUES(version),
  content_json = VALUES(content_json),
  jump_type = VALUES(jump_type),
  jump_url = VALUES(jump_url),
  update_time = NOW(3);

