CREATE TABLE `sys_user_qy_user` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '关联ID',
  `sys_user_id` bigint NOT NULL COMMENT '系统用户ID',
  `qy_user_id` int NOT NULL COMMENT '企业微信用户ID',
  `creator_id` bigint NULL DEFAULT '0' COMMENT '创建者ID',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updater_id` bigint NULL DEFAULT '0' COMMENT '更新者ID',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `remark` varchar(512) DEFAULT NULL COMMENT '备注',
  `deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '删除标志(0存在 1删除)',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_sys_user_qy_user` (`sys_user_id`,`qy_user_id`) COMMENT '防止重复绑定',
  KEY `idx_sys_user_id` (`sys_user_id`),
  KEY `idx_qy_user_id` (`qy_user_id`),
  CONSTRAINT `fk_sys_user_qy_user_sys` FOREIGN KEY (`sys_user_id`) REFERENCES `sys_user` (`user_id`) ON DELETE CASCADE,
  CONSTRAINT `fk_sys_user_qy_user_qy` FOREIGN KEY (`qy_user_id`) REFERENCES `qy_user` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='系统用户与企业微信用户关联表';

ALTER TABLE qy_user
ADD COLUMN `balance` DECIMAL(15,2) NOT NULL DEFAULT 0.00 COMMENT '用户余额（精度与商品价格对齐）';