|
@@ -5261,6 +5261,7 @@ try {
|
|
|
runMigration81();
|
|
runMigration81();
|
|
|
runMigration82();
|
|
runMigration82();
|
|
|
runMigration86();
|
|
runMigration86();
|
|
|
|
|
+ runMigration88();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void runMigration81() {
|
|
private void runMigration81() {
|
|
@@ -5582,4 +5583,66 @@ try {
|
|
|
log.warn("创建 butler_assignments 表失败:{}", e.getMessage());
|
|
log.warn("创建 butler_assignments 表失败:{}", e.getMessage());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private void runMigration88() {
|
|
|
|
|
+ // 迁移 88: 创建家庭公共账户体系(family_earnings / family_earnings_member / family_earnings_record)
|
|
|
|
|
+ // 表 1: family_earnings(家庭总账)
|
|
|
|
|
+ try {
|
|
|
|
|
+ jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS family_earnings (" +
|
|
|
|
|
+ "id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
|
|
|
|
|
+ "family_id BIGINT NOT NULL UNIQUE COMMENT '家庭 ID', " +
|
|
|
|
|
+ "total_earned BIGINT NOT NULL DEFAULT 0 COMMENT '累计推荐收入(分)', " +
|
|
|
|
|
+ "available_amount BIGINT NOT NULL DEFAULT 0 COMMENT '当前可支配余额(分)', " +
|
|
|
|
|
+ "withdrawn_amount BIGINT NOT NULL DEFAULT 0 COMMENT '已提现金额(分)', " +
|
|
|
|
|
+ "distributed_amount BIGINT NOT NULL DEFAULT 0 COMMENT '已颁发给成员的金额(分)', " +
|
|
|
|
|
+ "updated_at DATETIME, " +
|
|
|
|
|
+ "created_at DATETIME DEFAULT CURRENT_TIMESTAMP, " +
|
|
|
|
|
+ "INDEX idx_family_id (family_id)" +
|
|
|
|
|
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='家庭公共账户'");
|
|
|
|
|
+ log.info("已创建 family_earnings 表");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.warn("创建 family_earnings 表失败:{}", e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 表 2: family_earnings_member(成员已分配余额)
|
|
|
|
|
+ try {
|
|
|
|
|
+ jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS family_earnings_member (" +
|
|
|
|
|
+ "id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
|
|
|
|
|
+ "family_id BIGINT NOT NULL, " +
|
|
|
|
|
+ "user_id BIGINT NOT NULL, " +
|
|
|
|
|
+ "allocated_amount BIGINT NOT NULL DEFAULT 0 COMMENT '管理员累计分配(分)', " +
|
|
|
|
|
+ "consumed_amount BIGINT NOT NULL DEFAULT 0 COMMENT '已消费金额(分)', " +
|
|
|
|
|
+ "available_amount BIGINT NOT NULL DEFAULT 0 COMMENT '可消费余额=allocated-consumed(分)', " +
|
|
|
|
|
+ "can_use_family_balance TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否允许使用家庭公共池', " +
|
|
|
|
|
+ "updated_at DATETIME, " +
|
|
|
|
|
+ "created_at DATETIME DEFAULT CURRENT_TIMESTAMP, " +
|
|
|
|
|
+ "UNIQUE KEY idx_family_user (family_id, user_id)" +
|
|
|
|
|
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='家庭成员已分配余额'");
|
|
|
|
|
+ log.info("已创建 family_earnings_member 表");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.warn("创建 family_earnings_member 表失败:{}", e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 表 3: family_earnings_record(收支流水)
|
|
|
|
|
+ try {
|
|
|
|
|
+ jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS family_earnings_record (" +
|
|
|
|
|
+ "id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
|
|
|
|
|
+ "family_id BIGINT NOT NULL, " +
|
|
|
|
|
+ "type VARCHAR(20) NOT NULL COMMENT 'earn 收入/withdraw 提现/distribute 颁发/consume 消费', " +
|
|
|
|
|
+ "amount BIGINT NOT NULL COMMENT '金额(分)', " +
|
|
|
|
|
+ "from_user_id BIGINT COMMENT '操作人', " +
|
|
|
|
|
+ "to_user_id BIGINT COMMENT '受益人(颁发/消费时填写)', " +
|
|
|
|
|
+ "note VARCHAR(255) COMMENT '备注', " +
|
|
|
|
|
+ "created_at DATETIME DEFAULT CURRENT_TIMESTAMP, " +
|
|
|
|
|
+ "INDEX idx_family_id (family_id), " +
|
|
|
|
|
+ "INDEX idx_type (type)" +
|
|
|
|
|
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='家庭收益收支流水'");
|
|
|
|
|
+ log.info("已创建 family_earnings_record 表");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.warn("创建 family_earnings_record 表失败:{}", e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // commission_records 加 family_id 列
|
|
|
|
|
+ ensureColumn("commission_records", "family_id", "BIGINT COMMENT '归属家庭 ID'");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|