BEGIN;

-- 本地财务页面演示数据，所有记录都带同一 seed 标记，便于完整回滚。
DO $$
BEGIN
  IF NOT EXISTS (SELECT 1 FROM worker_users WHERE id IN (1, 3)) THEN
    RAISE EXCEPTION 'worker_users id=1 and id=3 are required for finance demo seed';
  END IF;
END $$;

INSERT INTO orders (
  provider, platform, shop_id, shop_name, platform_order_id,
  order_status, pay_status, buyer_id, buyer_name, receiver_contact,
  total_amount, currency, raw_payload_json, paid_at, created_at, updated_at
) VALUES
  ('demo', 'channel_a', 'demo-shop-a', '财务演示渠道A', 'DEMO-FIN-A-001', 'paid', 'paid', 'demo-buyer-1', '演示买家1', '13800000001', 13000, 'CNY', '{"seed":"finance-demo-20260902"}', '2026-09-01 09:15:00+08', '2026-09-01 08:50:00+08', '2026-09-01 09:15:00+08'),
  ('demo', 'channel_a', 'demo-shop-a', '财务演示渠道A', 'DEMO-FIN-A-002', 'paid', 'paid', 'demo-buyer-2', '演示买家2', '13800000002', 27500, 'CNY', '{"seed":"finance-demo-20260902"}', '2026-09-02 10:20:00+08', '2026-09-02 10:00:00+08', '2026-09-02 10:20:00+08'),
  ('demo', 'channel_b', 'demo-shop-b', '财务演示渠道B', 'DEMO-FIN-B-001', 'refunded', 'refunded', 'demo-buyer-3', '演示买家3', '13800000003', 8600, 'CNY', '{"seed":"finance-demo-20260902"}', '2026-09-02 11:10:00+08', '2026-09-02 11:00:00+08', '2026-09-02 11:40:00+08'),
  ('demo', 'channel_b', 'demo-shop-b', '财务演示渠道B', 'DEMO-FIN-B-002', 'paid', 'paid', 'demo-buyer-4', '演示买家4', '13800000004', 19900, 'CNY', '{"seed":"finance-demo-20260902"}', '2026-09-02 18:30:00+08', '2026-09-02 18:00:00+08', '2026-09-02 18:30:00+08'),
  ('demo', 'channel_c', 'demo-shop-c', '财务演示渠道C', 'DEMO-FIN-C-001', 'paid', 'paid', 'demo-buyer-5', '演示买家5', '13800000005', 4200, 'CNY', '{"seed":"finance-demo-20260902"}', '2026-09-03 14:05:00+08', '2026-09-03 13:45:00+08', '2026-09-03 14:05:00+08')
ON CONFLICT (provider, platform, shop_id, platform_order_id) DO NOTHING;

INSERT INTO worker_finance_requests (
  worker_id, request_type, status, amount, account_channel, account_name, account_no,
  note, reviewed_note, payload_json, created_at, updated_at, reviewed_at, frozen_amount
) VALUES
  (1, 'recharge', 'approved', 5000, 'manual', '测试修改昵称鸭', 'demo-recharge-a', '演示充值 A', '演示数据已通过', '{"seed":"finance-demo-20260902"}', '2026-09-01 11:30:00+08', '2026-09-01 12:00:00+08', '2026-09-01 12:00:00+08', 0),
  (1, 'withdraw', 'approved', 1800, 'alipay', '测试修改昵称鸭', 'demo-alipay-a', '演示提现 A', '演示数据已打款', '{"seed":"finance-demo-20260902"}', '2026-09-01 15:40:00+08', '2026-09-01 16:20:00+08', '2026-09-01 16:20:00+08', 0),
  (3, 'withdraw', 'approved', 3200, 'wechat', '01邀请的', 'demo-wechat-b', '演示提现 B', '演示数据已打款', '{"seed":"finance-demo-20260902"}', '2026-09-02 10:05:00+08', '2026-09-02 10:45:00+08', '2026-09-02 10:45:00+08', 0),
  (3, 'withdraw', 'pending', 4500, 'alipay', '01邀请的', 'demo-alipay-pending', '演示待处理提现', '', '{"seed":"finance-demo-20260902"}', '2026-09-02 13:30:00+08', '2026-09-02 13:30:00+08', NULL, 0),
  (3, 'recharge', 'approved', 7600, 'wechat', '01邀请的', 'demo-wechat-recharge', '演示充值 B', '演示数据已通过', '{"seed":"finance-demo-20260902"}', '2026-09-02 18:40:00+08', '2026-09-02 19:05:00+08', '2026-09-02 19:05:00+08', 0),
  (1, 'withdraw', 'rejected', 1100, 'alipay', '测试修改昵称鸭', 'demo-alipay-rejected', '演示已拒绝提现', '演示数据已拒绝', '{"seed":"finance-demo-20260902"}', '2026-09-02 20:00:00+08', '2026-09-02 20:10:00+08', '2026-09-02 20:10:00+08', 0);

INSERT INTO worker_wallet_ledgers (
  worker_id, ledger_type, amount, balance_after, frozen_after,
  related_work_order_id, audit_status, note, payload_json, created_at
) VALUES
  (1, 'reward_settlement', 3000, 3000, 0, NULL, 'approved', '演示打手报酬 A', '{"seed":"finance-demo-20260902"}', '2026-09-01 10:00:00+08'),
  (3, 'reward_settlement', 4500, 4500, 0, NULL, 'approved', '演示打手报酬 B', '{"seed":"finance-demo-20260902"}', '2026-09-02 12:10:00+08'),
  (3, 'sharing_reward', 2200, 6700, 0, NULL, 'approved', '演示拼单报酬 B', '{"seed":"finance-demo-20260902"}', '2026-09-02 19:20:00+08'),
  (1, 'after_sales_balance_deduction', -800, 2200, 0, NULL, 'approved', '演示资金回收 A', '{"seed":"finance-demo-20260902"}', '2026-09-02 14:00:00+08');

COMMIT;
