-- 同步退卡业绩表的退卡时间到明细表和业绩表
-- 数据来源：lq_hytk_hytk.tksj（退卡时间）

-- ============================================
-- 1. 同步退卡明细表（lq_hytk_mx）的退卡时间
-- ============================================
-- 通过 F_RefundInfoId 关联到退卡业绩表的 F_Id
UPDATE lq_hytk_mx mx
INNER JOIN lq_hytk_hytk hytk ON mx.F_RefundInfoId = hytk.F_Id
SET mx.tksj = hytk.tksj
WHERE hytk.tksj IS NOT NULL
    AND (mx.tksj IS NULL OR mx.tksj != hytk.tksj);

-- ============================================
-- 2. 同步退卡健康师业绩表（lq_hytk_jksyj）的退卡时间
-- ============================================
-- 通过 gltkbh 关联到退卡业绩表的 F_Id
UPDATE lq_hytk_jksyj jksyj
INNER JOIN lq_hytk_hytk hytk ON jksyj.gltkbh = hytk.F_Id
SET jksyj.tksj = hytk.tksj
WHERE hytk.tksj IS NOT NULL
    AND (jksyj.tksj IS NULL OR jksyj.tksj != hytk.tksj);

-- ============================================
-- 3. 同步退卡科技老师业绩表（lq_hytk_kjbsyj）的退卡时间
-- ============================================
-- 通过 gltkbh 关联到退卡业绩表的 F_Id
UPDATE lq_hytk_kjbsyj kjbsyj
INNER JOIN lq_hytk_hytk hytk ON kjbsyj.gltkbh = hytk.F_Id
SET kjbsyj.tksj = hytk.tksj
WHERE hytk.tksj IS NOT NULL
    AND (kjbsyj.tksj IS NULL OR kjbsyj.tksj != hytk.tksj);

