CREATE TABLE IF NOT EXISTS douyin_reward_logs (
    id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT '主键ID',
    shop_order_id VARCHAR(64) NOT NULL DEFAULT '' COMMENT '抖店订单号',
    douyin_user_id VARCHAR(128) NOT NULL DEFAULT '' COMMENT '抖音用户ID',
    local_user_id BIGINT NOT NULL DEFAULT 0 COMMENT '本地用户ID',
    douyin_product_id VARCHAR(64) NOT NULL DEFAULT '' COMMENT '抖店商品ID',
    prize_id BIGINT NOT NULL DEFAULT 0 COMMENT '直播奖品ID(可选)',
    source VARCHAR(32) NOT NULL DEFAULT '' COMMENT '来源: auto/manual/dispatch',
    status VARCHAR(32) NOT NULL DEFAULT '' COMMENT '状态: success/failed/skipped',
    message VARCHAR(255) NOT NULL DEFAULT '' COMMENT '说明信息',
    extra JSON NULL COMMENT '扩展信息',
    created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT '创建时间'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='抖店发奖日志';

CREATE INDEX idx_douyin_reward_logs_order ON douyin_reward_logs (shop_order_id, created_at);
