-- =====================================================================
-- FIGS 教育管理模块 - 测试数据
-- 覆盖完整业务链路: 员工 → 学生(家长/紧急联系人) → 课包 → 合同 → 排课消课 → 课时账本
-- 数据互相有关联(合同.sales_id 指向 staff.id, 消课扣的合同是真实存在的)
-- 租户: 000000
-- =====================================================================

SET NAMES utf8mb4;

-- 清空旧测试数据(按外键依赖反序), 仅清理测试ID段, 不动真实业务数据
DELETE FROM `edu_hours_log`        WHERE id BETWEEN 9000000001 AND 9000009999;
DELETE FROM `edu_lesson_student`   WHERE schedule_id BETWEEN 5001 AND 5099;
DELETE FROM `edu_lesson_schedule`  WHERE id BETWEEN 5001 AND 5099;
DELETE FROM `edu_contract_log`     WHERE contract_id BETWEEN 4001 AND 4099;
DELETE FROM `edu_contract_package` WHERE contract_id BETWEEN 4001 AND 4099;
DELETE FROM `edu_contract_gift`    WHERE contract_id BETWEEN 4001 AND 4099;
DELETE FROM `edu_contract`         WHERE id BETWEEN 4001 AND 4099;
DELETE FROM `edu_course_package_strategy` WHERE package_id BETWEEN 3001 AND 3099;
DELETE FROM `edu_course_package`   WHERE id BETWEEN 3001 AND 3099;
DELETE FROM `edu_student_parent`   WHERE student_id BETWEEN 2001 AND 2099;
DELETE FROM `edu_student_emergency` WHERE student_id BETWEEN 2001 AND 2099;
DELETE FROM `edu_student`          WHERE id BETWEEN 2001 AND 2099;
DELETE FROM `edu_staff_student`    WHERE staff_id BETWEEN 1001 AND 1099;
DELETE FROM `edu_staff`            WHERE id BETWEEN 1001 AND 1099;

-- =====================================================================
-- 一、员工 (4类角色各若干, ID 1001-1005)
-- =====================================================================
INSERT INTO `edu_staff`(`id`,`tenant_id`,`user_id`,`staff_no`,`name`,`role`,`phone`,`email`,`wechat`,`gender`,`entry_date`,`subject`,`title`,`max_students`,`commission_rate`,`dept_id`,`intro`,`status`,`remark`,`create_by`,`create_time`) VALUES
(1001,'000000',1,'SAL20260101001','张伟','SALES','13800001001','zhangwei@figs.com','zw001','0','2023-03-15',NULL,'高级顾问',0,0.1500,103,'5年教培行业销售经验，擅长留学规划','0','金牌顾问',1,NOW()),
(1002,'000000',3,'SAL20260101002','李娜','SALES','13800001002','lina@figs.com','ln002','1','2024-06-01',NULL,'顾问',0,0.1000,103,'2年教培销售，专注语培方向','0',NULL,1,NOW()),
(1003,'000000',NULL,'HKP20260101003','王芳','HOUSEKEEPER','13800001003','wangfang@figs.com','wf003','1','2022-09-01',NULL,'资深管家',30,0.0000,103,'8年学管经验，带生上限30人','0','明星管家',1,NOW()),
(1004,'000000',NULL,'TUT20260101004','陈晨','TUTOR','13800001004','chenchen@figs.com','cc004','0','2021-07-01','数学','高级教师',0,0.0000,103,'北师大数学硕士，10年高中数学教学','0','数学名师',1,NOW()),
(1005,'000000',NULL,'DOC20260101005','刘洋','DOC_WRITER','13800001005','liuyang@figs.com','ly005','0','2023-11-01',NULL,'文书主管',0,0.0000,103,'擅长美本/美研文书，年均300+篇','0',NULL,1,NOW());

-- =====================================================================
-- 二、学生 + 家长 + 紧急联系人 (3个学生, ID 2001-2003)
-- =====================================================================
INSERT INTO `edu_student`(`id`,`tenant_id`,`student_no`,`name`,`gender`,`birthday`,`phone`,`wechat`,`school`,`grade`,`target_school`,`subjects`,`address`,`source`,`level`,`intent_level`,`first_visit_at`,`enroll_at`,`tags`,`status`,`remark`,`create_by`,`create_time`) VALUES
(2001,'000000','STU0002001','赵小明','0','2008-05-12','13900002001','xm_zhao','市第三中学','高三','清华大学','数学,物理','海淀区中关村大街1号','老带新','VIP','A','2026-01-10 10:00:00','2026-01-15 14:30:00','理科,目标985','2','重点跟进学员',1,NOW()),
(2002,'000000','STU0002002','钱小红','1','2009-08-20','13900002002','xh_qian','人大附中','高二','北京大学','英语,语文','海淀区海淀路5号','地推','VIP','B','2026-02-01 09:00:00','2026-02-10 11:00:00','文科,英语薄弱','2',NULL,1,NOW()),
(2003,'000000','STU0002003','孙小刚','0','2010-11-03','13900002003','xg_sun','清华附中','高一','复旦大学','数学','朝阳区望京路8号','线上','普通','C','2026-03-05 15:00:00',NULL,'理科,补差','1','潜在转试听',1,NOW());

-- 家长 (每个学生1-2个)
INSERT INTO `edu_student_parent`(`id`,`tenant_id`,`student_id`,`relation`,`name`,`phone`,`wechat`,`occupation`,`is_primary`,`receive_notice`,`remark`,`create_by`,`create_time`) VALUES
(2101,'000000',2001,'FATHER','赵建国','13700002101','zj_parent','工程师','Y','Y','付款决策人',1,NOW()),
(2102,'000000',2001,'MOTHER','周丽','13700002102','zl_parent','教师','N','Y','日常对接',1,NOW()),
(2103,'000000',2002,'MOTHER','孙梅','13700002103','sm_parent','医生','Y','Y','高知家庭',1,NOW()),
(2104,'000000',2003,'FATHER','孙强','13700002104','sq_parent','公务员','Y','Y',NULL,1,NOW());

-- 紧急联系人
INSERT INTO `edu_student_emergency`(`id`,`tenant_id`,`student_id`,`name`,`relation`,`phone`,`remark`,`create_by`,`create_time`) VALUES
(2201,'000000',2001,'赵建国','父亲','13700002101','同主联系人',1,NOW()),
(2202,'000000',2002,'钱爸爸','父亲','13700002202',NULL,1,NOW()),
(2203,'000000',2003,'李阿姨','阿姨','13700002203','临时托管联系人',1,NOW());

-- =====================================================================
-- 三、课包 + 价格策略 (4个课包, ID 3001-3004)
-- =====================================================================
INSERT INTO `edu_course_package`(`id`,`tenant_id`,`package_code`,`package_name`,`package_type`,`subject`,`grade`,`total_hours`,`lesson_count`,`valid_days`,`max_students`,`list_price`,`sale_price`,`cost_price`,`gift_hours`,`hours_per_lesson`,`description`,`is_hot`,`is_gift`,`status`,`remark`,`create_by`,`create_time`) VALUES
(3001,'000000','PKG-EXP-MATH','高一数学体验课','EXPERIENCE','数学','高一',2.00,1,30,1,400.00,99.00,50.00,0.00,2.00,'2小时一对一数学体验课，名师诊断薄弱点','Y','N','0','暑期引流款',1,NOW()),
(3002,'000000','PKG-MATH-G3','高三数学冲刺课包','PACKAGE','数学','高三',40.00,20,180,1,12000.00,9600.00,6000.00,4.00,2.00,'40课时高考数学冲刺，含4课时赠送，每周2次','Y','N','0','爆款冲刺课包',1,NOW()),
(3003,'000000','PKG-ENG-1V1','英语一对一精讲','SINGLE','英语','高二',20.00,10,365,1,8000.00,7200.00,5000.00,0.00,2.00,'20课时英语1v1精讲，外教+中教双师','N','N','0',NULL,1,NOW()),
(3004,'000000','PKG-ALL-SCIENCE','理科全期课程','COURSE','物理','高三',60.00,30,365,4,15000.00,13500.00,9000.00,6.00,2.00,'60课时高三物理全期，小班制(4人)','N','N','0','全期系统课',1,NOW());

-- 价格策略 (给冲刺课包配置: 打折 + 加赠)
INSERT INTO `edu_course_package_strategy`(`id`,`tenant_id`,`package_id`,`strategy_name`,`strategy_type`,`condition_type`,`condition_value`,`discount_rate`,`reduce_amount`,`gift_hours`,`cashback_amount`,`priority`,`status`,`remark`,`create_by`,`create_time`) VALUES
(3101,'000000',3002,'早鸟9折','DISCOUNT','NONE',0,0.90,0.00,0.00,0.00,10,'0','开学季限时',1,NOW()),
(3102,'000000',3002,'满1万减500','REDUCE','AMOUNT',10000,1.00,500.00,0.00,0.00,8,'0','阶梯优惠',1,NOW()),
(3103,'000000',3002,'老带新加赠2课时','GIFT','NONE',0,1.00,0.00,2.00,0.00,5,'0','转介绍福利',1,NOW());

-- =====================================================================
-- 四、合同 (3份不同状态, ID 4001-4003)
--   4001 执行中(主力, 关联排课消课)
--   4002 草稿
--   4003 已退费
-- =====================================================================

-- 4001: 赵小明报名数学冲刺课包, 执行中, 已消耗8课时, 剩余36
INSERT INTO `edu_contract`(`id`,`tenant_id`,`contract_no`,`student_id`,`contract_type`,`parent_contract_id`,`sign_date`,`effective_date`,`expire_date`,`total_amount`,`discount_amount`,`paid_amount`,`refund_amount`,`total_hours`,`used_hours`,`remain_hours`,`gift_hours`,`payment_method`,`payment_status`,`status`,`sales_id`,`housekeeper_id`,`sign_location`,`description`,`signed_at`,`activated_at`,`remark`,`create_by`,`create_time`) VALUES
(4001,'000000','EDUCT20260115001',2001,'ENROLL',NULL,'2026-01-15','2026-01-15','2026-07-15',9600.00,2400.00,9600.00,0.00,40.00,8.00,32.00,4.00,'WECHAT','2','2',1001,1003,'北京海淀校区','高三数学冲刺课包报名','2026-01-15 14:30:00','2026-01-15 15:00:00','主力合同',1,'2026-01-15 14:00:00'),
(4002,'000000','EDUCT20260320002',2002,'ENROLL',NULL,'2026-03-20',NULL,NULL,7200.00,800.00,0.00,0.00,20.00,0.00,20.00,0.00,NULL,'0','0',1002,1003,'北京海淀校区','英语1v1精讲草稿, 待客户确认',NULL,NULL,'草稿待激活',1,NOW()),
(4003,'000000','EDUCT20260210003',2003,'REFUND',NULL,'2026-02-10','2026-02-10','2026-08-10',9600.00,2400.00,9600.00,3600.00,40.00,16.00,0.00,4.00,'ALIPAY','3','4',1001,1003,'线上签约','已退费合同(消了16课时后退剩余)',NULL,'2026-02-10 10:00:00','退费结案',1,'2026-02-10 09:00:00');

-- 合同课包明细 (4001/4002/4003 各对应一个课包)
INSERT INTO `edu_contract_package`(`id`,`tenant_id`,`contract_id`,`package_id`,`package_name`,`package_type`,`total_hours`,`used_hours`,`remain_hours`,`gift_hours`,`list_price`,`sale_price`,`discount_amount`,`final_amount`,`strategy_id`,`expire_date`,`status`,`create_by`,`create_time`) VALUES
(4101,'000000',4001,3002,'高三数学冲刺课包','PACKAGE',40.00,8.00,32.00,4.00,12000.00,9600.00,2400.00,9600.00,3101,'2026-07-15','0',1,'2026-01-15 14:00:00'),
(4102,'000000',4002,3003,'英语一对一精讲','SINGLE',20.00,0.00,20.00,0.00,8000.00,7200.00,800.00,7200.00,NULL,'2027-03-20','0',1,NOW()),
(4103,'000000',4003,3002,'高三数学冲刺课包','PACKAGE',40.00,16.00,0.00,4.00,12000.00,9600.00,2400.00,9600.00,3101,'2026-02-10','2',1,'2026-02-10 09:00:00');

-- 合同赠送明细 (4001 有赠送)
INSERT INTO `edu_contract_gift`(`id`,`tenant_id`,`contract_id`,`gift_type`,`gift_hours`,`gift_count`,`used_hours`,`remain_hours`,`reason`,`expire_date`,`status`,`create_by`,`create_time`) VALUES
(4201,'000000',4001,'HOURS',4.00,2,1.00,3.00,'老带新加赠','2026-07-15','0',1,'2026-01-15 14:00:00');

-- 合同操作流水 (4001: 创建+激活; 4003: 退费)
INSERT INTO `edu_contract_log`(`id`,`tenant_id`,`contract_id`,`action`,`amount`,`hours_delta`,`ref_contract_id`,`operator_id`,`operator_name`,`reason`,`log_time`,`create_by`,`create_time`) VALUES
(4301,'000000',4001,'CREATE',9600.00,40.00,NULL,1001,'张伟','创建合同','2026-01-15 14:00:00',1,'2026-01-15 14:00:00'),
(4302,'000000',4001,'PAY',9600.00,0.00,NULL,1,'admin','微信收款9600','2026-01-15 15:00:00',1,'2026-01-15 15:00:00'),
(4303,'000000',4001,'ACTIVATE',9600.00,40.00,NULL,1,'admin','合同激活','2026-01-15 15:00:00',1,'2026-01-15 15:00:00'),
(4304,'000000',4003,'CREATE',9600.00,40.00,NULL,1001,'张伟','创建合同','2026-02-10 09:00:00',1,'2026-02-10 09:00:00'),
(4305,'000000',4003,'REFUND',-3600.00,-24.00,NULL,1,'admin','按已消课比例退费','2026-03-01 10:00:00',1,'2026-03-01 10:00:00');

-- =====================================================================
-- 五、排课消课 (赵小明的数学课, 多种状态, ID 5001-5004)
-- =====================================================================
INSERT INTO `edu_lesson_schedule`(`id`,`tenant_id`,`schedule_no`,`student_id`,`contract_id`,`tutor_id`,`subject`,`lesson_type`,`class_name`,`lesson_date`,`start_time`,`end_time`,`duration_hours`,`classroom`,`lesson_content`,`homework`,`max_students`,`enrolled_count`,`status`,`check_in_at`,`check_out_at`,`consume_hours`,`consume_rate`,`comment`,`remark`,`create_by`,`create_time`) VALUES
-- 5001: 已消课(消耗4课时, 1v1比例2)
(5001,'000000','EDUSC20260201001',2001,4001,1004,'数学','ONE_ON_ONE',NULL,'2026-02-01','2026-02-01 09:00:00','2026-02-01 11:00:00',2.00,'海淀校区-A教室','函数与导数: 单调性判定','完成课后习题1-10',1,1,'2','2026-02-01 08:55:00','2026-02-01 11:05:00',4.00,2.00,'掌握良好, 导数应用需加强',NULL,1,NOW()),
-- 5002: 已消课(消耗4课时)
(5002,'000000','EDUSC20260208001',2001,4001,1004,'数学','ONE_ON_ONE',NULL,'2026-02-08','2026-02-08 14:00:00','2026-02-08 16:00:00',2.00,'海淀校区-A教室','三角函数: 图像与性质','复习公式, 完成习题册P30',1,1,'2','2026-02-08 13:58:00','2026-02-08 16:02:00',4.00,2.00,'三角变换熟练度提升',NULL,1,NOW()),
-- 5003: 已签到, 今天上午的课, 待消课
(5003,'000000','EDUSC-TODAY-001',2001,4001,1004,'数学','ONE_ON_ONE',NULL,CURDATE(),
  CONCAT(CURDATE(),' 09:00:00'),CONCAT(CURDATE(),' 11:00:00'),2.00,'海淀校区-B教室','数列: 等差等比综合','整理数列求和方法',1,1,'1',
  CONCAT(CURDATE(),' 08:58:00'),NULL,0.00,2.00,NULL,NULL,1,NOW()),
-- 5004: 待上课, 明天的课
(5004,'000000','EDUSC-TOMORROW-001',2001,4001,1004,'数学','ONE_ON_ONE',NULL,DATE_ADD(CURDATE(),INTERVAL 1 DAY),
  CONCAT(DATE_ADD(CURDATE(),INTERVAL 1 DAY),' 14:00:00'),CONCAT(DATE_ADD(CURDATE(),INTERVAL 1 DAY),' 16:00:00'),2.00,'线上-Zoom','立体几何: 空间向量','预习课本内容',1,1,'0',
  NULL,NULL,0.00,2.00,NULL,NULL,1,NOW());

-- 排课-学生关联 (每条排课对应一个学生)
INSERT INTO `edu_lesson_student`(`id`,`tenant_id`,`schedule_id`,`student_id`,`contract_id`,`package_id`,`hours_should`,`hours_actual`,`consume_rate`,`status`,`check_in_at`,`check_out_at`,`remark`,`create_by`,`create_time`) VALUES
(5101,'000000',5001,2001,4001,3002,2.00,4.00,2.00,'2','2026-02-01 08:55:00','2026-02-01 11:05:00',NULL,1,NOW()),
(5102,'000000',5002,2001,4001,3002,2.00,4.00,2.00,'2','2026-02-08 13:58:00','2026-02-08 16:02:00',NULL,1,NOW()),
(5103,'000000',5003,2001,4001,3002,2.00,0.00,2.00,'1',CONCAT(CURDATE(),' 08:58:00'),NULL,'已签到待消课',1,NOW()),
(5104,'000000',5004,2001,4001,3002,2.00,0.00,2.00,'0',NULL,NULL,NULL,1,NOW());

-- =====================================================================
-- 六、课时账本 (合同4001激活的购买流水 + 两次消课流水)
-- =====================================================================
INSERT INTO `edu_hours_log`(`id`,`tenant_id`,`log_no`,`student_id`,`contract_id`,`package_id`,`schedule_id`,`business_type`,`direction`,`hours`,`before_hours`,`after_hours`,`rate`,`reason`,`operator_id`,`operator_name`,`log_time`,`create_by`,`create_time`) VALUES
(9000000001,'000000','EDUHL20260115001',2001,4001,3002,NULL,'PURCHASE','+',40.00,0.00,40.00,1.00,'合同激活, 购买40课时',1,'admin','2026-01-15 15:00:00',1,'2026-01-15 15:00:00'),
(9000000002,'000000','EDUHL20260201001',2001,4001,3002,5001,'CONSUME','-',4.00,40.00,36.00,2.00,'消课: EDUSC20260201001',1,'admin','2026-02-01 11:05:00',1,'2026-02-01 11:05:00'),
(9000000003,'000000','EDUHL20260208001',2001,4001,3002,5002,'CONSUME','-',4.00,36.00,32.00,2.00,'消课: EDUSC20260208001',1,'admin','2026-02-08 16:02:00',1,'2026-02-08 16:02:00');
