-- Audit log for earnings backfill executions

CREATE TABLE IF NOT EXISTS `play_earnings_backfill_log` (
  `id` varchar(32) NOT NULL COMMENT 'UUID',
  `tenant_id` varchar(32) NOT NULL COMMENT '租户ID',
  `operator_id` varchar(32) DEFAULT NULL COMMENT '操作人ID',
  `operator_name` varchar(64) DEFAULT NULL COMMENT '操作人名称',
  `backfill_begin_time` datetime DEFAULT NULL COMMENT '查询起始时间',
  `backfill_end_time` datetime DEFAULT NULL COMMENT '查询结束时间',
  `clerk_ids` text COMMENT '指定店员ID集合(JSON)',
  `dry_run` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否试运行',
  `orders_checked` int NOT NULL DEFAULT '0' COMMENT '检查订单数',
  `created_count` int NOT NULL DEFAULT '0' COMMENT '新增收益条目数',
  `skipped_existing` int NOT NULL DEFAULT '0' COMMENT '跳过已存在收益条目数',
  `warning_count` int NOT NULL DEFAULT '0' COMMENT '警告数量',
  `warnings` text COMMENT '警告明细(JSON)',
  `comment` varchar(255) DEFAULT NULL COMMENT '备注',
  `created_time` datetime DEFAULT CURRENT_TIMESTAMP,
  `created_by` varchar(32) DEFAULT NULL,
  `updated_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_by` varchar(32) DEFAULT NULL,
  `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '逻辑删除 1已删除 0未删除',
  `version` int NOT NULL DEFAULT '1' COMMENT '数据版本',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_backfill_tenant_time` (`tenant_id`, `created_time`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=DYNAMIC COMMENT='收益补算执行记录';
    
