Explorar el Código

feat(butler): add butler entities + migration + schema

Xiaogang Liao hace 3 meses
padre
commit
c79f5f20b2

+ 84 - 0
cfc-backend/src/main/java/com/etotem/cfc/config/DatabaseInitializer.java

@@ -5454,5 +5454,89 @@ try {
         } catch (Exception e) {
             log.warn("创建supply_hierarchy_change_request表失败: {}", e.getMessage());
         }
+
+        try {
+            jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS butler_profiles (" +
+                    "id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
+                    "user_id BIGINT NOT NULL, " +
+                    "tier VARCHAR(10), " +
+                    "status VARCHAR(20) DEFAULT 'pending', " +
+                    "member_count INT DEFAULT 0, " +
+                    "max_members INT DEFAULT 50, " +
+                    "annual_fee_l1 BIGINT, " +
+                    "annual_fee_l2 BIGINT, " +
+                    "description TEXT, " +
+                    "certificates TEXT, " +
+                    "reject_reason VARCHAR(500), " +
+                    "commission_rate_l1 INT DEFAULT 1000, " +
+                    "commission_rate_l2 INT DEFAULT 5000, " +
+                    "created_at DATETIME DEFAULT CURRENT_TIMESTAMP, " +
+                    "updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, " +
+                    "approved_at DATETIME, " +
+                    "UNIQUE KEY uk_user_id (user_id), " +
+                    "INDEX idx_status (status), " +
+                    "INDEX idx_tier (tier)" +
+                    ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='管家服务提供商档案'");
+            log.info("已创建butler_profiles表");
+        } catch (Exception e) {
+            log.warn("创建butler_profiles表失败: {}", e.getMessage());
+        }
+
+        try {
+            jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS butler_service_records (" +
+                    "id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
+                    "butler_id BIGINT NOT NULL, " +
+                    "member_user_id BIGINT NOT NULL, " +
+                    "subscription_id BIGINT, " +
+                    "service_type VARCHAR(20) NOT NULL, " +
+                    "amount_p BIGINT NOT NULL, " +
+                    "platform_fee_p BIGINT DEFAULT 0, " +
+                    "butler_amount_p BIGINT DEFAULT 0, " +
+                    "member_tier VARCHAR(10), " +
+                    "year_month VARCHAR(7), " +
+                    "remark VARCHAR(500), " +
+                    "created_at DATETIME DEFAULT CURRENT_TIMESTAMP, " +
+                    "INDEX idx_butler_id (butler_id), " +
+                    "INDEX idx_member_user_id (member_user_id), " +
+                    "INDEX idx_year_month (year_month)" +
+                    ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='管家服务记录'");
+            log.info("已创建butler_service_records表");
+        } catch (Exception e) {
+            log.warn("创建butler_service_records表失败: {}", e.getMessage());
+        }
+
+        try {
+            jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS butler_commission_settlements (" +
+                    "id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
+                    "butler_id BIGINT NOT NULL, " +
+                    "year_month VARCHAR(7) NOT NULL, " +
+                    "member_count INT DEFAULT 0, " +
+                    "annual_base_amount_p BIGINT DEFAULT 0, " +
+                    "annual_butler_amount_p BIGINT DEFAULT 0, " +
+                    "annual_platform_amount_p BIGINT DEFAULT 0, " +
+                    "per_session_total_p BIGINT DEFAULT 0, " +
+                    "per_session_platform_total_p BIGINT DEFAULT 0, " +
+                    "per_session_butler_total_p BIGINT DEFAULT 0, " +
+                    "total_butler_amount_p BIGINT DEFAULT 0, " +
+                    "status VARCHAR(20) DEFAULT 'pending', " +
+                    "settled_at DATETIME, " +
+                    "settled_by BIGINT, " +
+                    "created_at DATETIME DEFAULT CURRENT_TIMESTAMP, " +
+                    "UNIQUE KEY uk_butler_month (butler_id, year_month), " +
+                    "INDEX idx_status (status), " +
+                    "INDEX idx_year_month (year_month)" +
+                    ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='管家月度佣金结算单'");
+            log.info("已创建butler_commission_settlements表");
+        } catch (Exception e) {
+            log.warn("创建butler_commission_settlements表失败: {}", e.getMessage());
+        }
+
+        try {
+            jdbcTemplate.execute("ALTER TABLE users ADD COLUMN butler_status VARCHAR(20)");
+            jdbcTemplate.execute("ALTER TABLE users ADD COLUMN butler_info TEXT");
+            jdbcTemplate.execute("ALTER TABLE users ADD COLUMN butler_approved_at DATETIME");
+            log.info("已添加butler相关列到users表");
+        } catch (Exception e) {
+        }
     }
 }

+ 9 - 0
cfc-backend/src/main/java/com/etotem/cfc/entity/User.java

@@ -129,6 +129,15 @@ public class User implements Serializable {
     // 累计获得佣金(分)
     private Long totalCommissionEarned;
 
+    // 管家状态
+    private String butlerStatus;
+
+    // 管家资质信息 (JSON)
+    private String butlerInfo;
+
+    // 管家认证通过时间
+    private Date butlerApprovedAt;
+
     private Date createdAt;
 
     private Date updatedAt;

+ 65 - 0
cfc-backend/src/main/resources/schema.sql

@@ -30,6 +30,9 @@ CREATE TABLE IF NOT EXISTS users (
     mascot VARCHAR(20) DEFAULT NULL COMMENT 'AI助手形象: xibao(浠宝)/fubao(福宝)',
     created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
     updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+    butler_status VARCHAR(20) COMMENT '管家状态: null/pending/approved/rejected',
+    butler_info TEXT COMMENT '管家资质信息(JSON)',
+    butler_approved_at DATETIME COMMENT '管家认证通过时间',
     INDEX idx_openid (openid),
     INDEX idx_family_id (family_id),
     INDEX idx_phone (phone)
@@ -2821,3 +2824,65 @@ CREATE TABLE IF NOT EXISTS supply_hierarchy_change_request (
     KEY idx_system_applicant (system_id, applicant_id),
     KEY idx_status (status)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='供应商更换上级申请表';
+
+CREATE TABLE IF NOT EXISTS butler_profiles (
+    id BIGINT AUTO_INCREMENT PRIMARY KEY,
+    user_id BIGINT NOT NULL COMMENT '用户ID',
+    tier VARCHAR(10) COMMENT '服务等级: L1/L2',
+    status VARCHAR(20) DEFAULT 'pending' COMMENT '状态: pending/approved/rejected',
+    member_count INT DEFAULT 0 COMMENT '当前服务家庭数',
+    max_members INT DEFAULT 50 COMMENT '最大服务家庭上限',
+    annual_fee_l1 BIGINT COMMENT '年费L1档(P点)',
+    annual_fee_l2 BIGINT COMMENT '年费L2档(P点)',
+    description TEXT COMMENT '个人简介',
+    certificates TEXT COMMENT '资质证书URL(JSON数组)',
+    reject_reason VARCHAR(500) COMMENT '审核拒绝原因',
+    commission_rate_l1 INT DEFAULT 1000 COMMENT '年度分佣比例L1(basis points,10000=100%)',
+    commission_rate_l2 INT DEFAULT 5000 COMMENT '年度分佣比例L2(basis points,10000=100%)',
+    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
+    updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+    approved_at DATETIME COMMENT '审核通过时间',
+    UNIQUE KEY uk_user_id (user_id),
+    INDEX idx_status (status),
+    INDEX idx_tier (tier)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='管家服务提供商档案';
+
+CREATE TABLE IF NOT EXISTS butler_service_records (
+    id BIGINT AUTO_INCREMENT PRIMARY KEY,
+    butler_id BIGINT NOT NULL COMMENT '管家用户ID',
+    member_user_id BIGINT NOT NULL COMMENT '会员用户ID',
+    subscription_id BIGINT COMMENT '关联订阅记录ID(年费服务时)',
+    service_type VARCHAR(20) NOT NULL COMMENT '服务类型: annual/per_session',
+    amount_p BIGINT NOT NULL COMMENT '服务金额(P点)',
+    platform_fee_p BIGINT DEFAULT 0 COMMENT '平台留成(P点)',
+    butler_amount_p BIGINT DEFAULT 0 COMMENT '管家所得(P点)',
+    member_tier VARCHAR(10) COMMENT '会员订阅级别: L1/L2',
+    year_month VARCHAR(7) COMMENT '结算年月 YYYY-MM',
+    remark VARCHAR(500) COMMENT '备注',
+    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
+    INDEX idx_butler_id (butler_id),
+    INDEX idx_member_user_id (member_user_id),
+    INDEX idx_year_month (year_month),
+    INDEX idx_service_type (service_type)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='管家服务记录';
+
+CREATE TABLE IF NOT EXISTS butler_commission_settlements (
+    id BIGINT AUTO_INCREMENT PRIMARY KEY,
+    butler_id BIGINT NOT NULL COMMENT '管家用户ID',
+    year_month VARCHAR(7) NOT NULL COMMENT '结算年月 YYYY-MM',
+    member_count INT DEFAULT 0 COMMENT '本月服务家庭数',
+    annual_base_amount_p BIGINT DEFAULT 0 COMMENT '年费基准总额(P点)',
+    annual_butler_amount_p BIGINT DEFAULT 0 COMMENT '年费-管家所得(P点)',
+    annual_platform_amount_p BIGINT DEFAULT 0 COMMENT '年费-平台留成(P点)',
+    per_session_total_p BIGINT DEFAULT 0 COMMENT '按次服务总金额(P点)',
+    per_session_platform_total_p BIGINT DEFAULT 0 COMMENT '按次-平台留成(P点)',
+    per_session_butler_total_p BIGINT DEFAULT 0 COMMENT '按次-管家所得(P点)',
+    total_butler_amount_p BIGINT DEFAULT 0 COMMENT '本月管家总所得(P点)',
+    status VARCHAR(20) DEFAULT 'pending' COMMENT '结算状态: pending/paid',
+    settled_at DATETIME COMMENT '确认发放时间',
+    settled_by BIGINT COMMENT '结算确认人',
+    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
+    UNIQUE KEY uk_butler_month (butler_id, year_month),
+    INDEX idx_status (status),
+    INDEX idx_year_month (year_month)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='管家月度佣金结算单';