CREATE TABLE `user_balance_log` (
  `log_id` bigint NOT NULL AUTO_INCREMENT COMMENT '日志ID',
  `user_balance_id` bigint NOT NULL COMMENT '用户余额ID',
  
  -- 余额变更信息
  `change_type` tinyint NOT NULL COMMENT '变更类型(1-消费 2-审批归还 3-系统调整)',
  `change_amount` bigint NOT NULL COMMENT '变更金额（单位：分，正数表示增加，负数表示减少）',
  `use_balance_before` bigint NOT NULL COMMENT '变更前已用余额',
  `use_balance_after` bigint NOT NULL COMMENT '变更后已用余额',
  
  -- 关联表信息
  `order_id` bigint DEFAULT NULL COMMENT '关联订单ID',
  `approval_id` bigint DEFAULT NULL COMMENT '关联审批ID',
  `order_goods_id` bigint DEFAULT NULL COMMENT '关联订单商品ID',
  
  -- 系统字段
  `creator_id` bigint NOT NULL DEFAULT 0 COMMENT '创建者ID',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updater_id` bigint NOT NULL DEFAULT 0 COMMENT '更新者ID',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '删除标志（0存在 1删除）',
  
  PRIMARY KEY (`log_id`),
  KEY `idx_user_balance` (`user_balance_id`),
  KEY `idx_order` (`order_id`),
  KEY `idx_approval` (`approval_id`),
  KEY `idx_change_type` (`change_type`),
  KEY `idx_create_time` (`create_time`),
  KEY `idx_order_goods` (`order_goods_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户余额变更日志表';
