|
|
@@ -8353,5 +8353,76 @@ private void runMigration100() {
|
|
|
} catch (Exception e) {
|
|
|
log.warn("tasks.status枚举修改失败(可能已修改): " + e.getMessage());
|
|
|
}
|
|
|
+
|
|
|
+ // 迁移196: 创建 user_platform_balance 表(CF值余额)
|
|
|
+ try {
|
|
|
+ jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS user_platform_balance (" +
|
|
|
+ "id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
|
|
|
+ "user_id BIGINT NOT NULL COMMENT '用户ID', " +
|
|
|
+ "family_id BIGINT COMMENT '归属家庭ID', " +
|
|
|
+ "total_earned INT DEFAULT 0 COMMENT '累计获得', " +
|
|
|
+ "available INT DEFAULT 0 COMMENT '可用余额', " +
|
|
|
+ "frozen INT DEFAULT 0 COMMENT '冻结(提现审核中)', " +
|
|
|
+ "withdrawn INT DEFAULT 0 COMMENT '已提现', " +
|
|
|
+ "exchanged INT DEFAULT 0 COMMENT '已兑换', " +
|
|
|
+ "updated_at DATETIME, " +
|
|
|
+ "created_at DATETIME, " +
|
|
|
+ "UNIQUE KEY uk_user (user_id)" +
|
|
|
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户CF值余额'");
|
|
|
+ log.info("已创建user_platform_balance表");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("创建user_platform_balance表失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 迁移197: 创建 platform_balance_log 表(CF值流水)
|
|
|
+ try {
|
|
|
+ jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS platform_balance_log (" +
|
|
|
+ "id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
|
|
|
+ "user_id BIGINT NOT NULL COMMENT '用户ID', " +
|
|
|
+ "family_id BIGINT COMMENT '归属家庭ID', " +
|
|
|
+ "type VARCHAR(20) NOT NULL COMMENT 'earn/spend/freeze/unfreeze/withdraw', " +
|
|
|
+ "amount INT NOT NULL COMMENT '变动数量', " +
|
|
|
+ "balance_after INT NOT NULL COMMENT '变动后可用余额', " +
|
|
|
+ "ref_type VARCHAR(30) COMMENT 'product_order/activity/withdrawal/migration', " +
|
|
|
+ "ref_id BIGINT COMMENT '关联业务ID', " +
|
|
|
+ "remark VARCHAR(255) COMMENT '备注', " +
|
|
|
+ "created_at DATETIME, " +
|
|
|
+ "INDEX idx_user_time (user_id, created_at)" +
|
|
|
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='CF值流水'");
|
|
|
+ log.info("已创建platform_balance_log表");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("创建platform_balance_log表失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 迁移198: 存量佣金迁移为CF值(settled→available, pending→frozen)
|
|
|
+ try {
|
|
|
+ jdbcTemplate.execute("INSERT INTO user_platform_balance (user_id, total_earned, available, created_at, updated_at) " +
|
|
|
+ "SELECT referrer_id, SUM(commission_amount), SUM(commission_amount), NOW(), NOW() " +
|
|
|
+ "FROM commission_records WHERE status='settled' GROUP BY referrer_id " +
|
|
|
+ "ON DUPLICATE KEY UPDATE available=available+VALUES(available), " +
|
|
|
+ "total_earned=total_earned+VALUES(total_earned), updated_at=NOW()");
|
|
|
+ log.info("已迁移settled佣金为可用CF值");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("迁移settled佣金失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 迁移199: pending 佣金 → 冻结CF
|
|
|
+ try {
|
|
|
+ jdbcTemplate.execute("INSERT INTO user_platform_balance (user_id, total_earned, frozen, created_at, updated_at) " +
|
|
|
+ "SELECT referrer_id, SUM(commission_amount), SUM(commission_amount), NOW(), NOW() " +
|
|
|
+ "FROM commission_records WHERE status='pending' GROUP BY referrer_id " +
|
|
|
+ "ON DUPLICATE KEY UPDATE frozen=frozen+VALUES(frozen), " +
|
|
|
+ "total_earned=total_earned+VALUES(total_earned), updated_at=NOW()");
|
|
|
+ log.info("已迁移pending佣金为冻结CF值");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("迁移pending佣金失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 迁移200: activities表添加platform_points字段
|
|
|
+ ensureColumn("activities", "platform_points", "INT DEFAULT 0 COMMENT '活动奖励CF值(0=不发)'");
|
|
|
+
|
|
|
+ // 迁移201: 新增CF值配置项
|
|
|
+ insertSysConfigSeed("product_platform_points_share", "1000", "商品CF值利润分成比例(bps)");
|
|
|
+ insertSysConfigSeed("platform_withdraw_rate", "100", "CF值提现汇率(CF数/元)");
|
|
|
}
|
|
|
}
|