CREATE TABLE IF NOT EXISTS lucky_gift_draw_request (
  id BIGINT NOT NULL PRIMARY KEY,
  business_id VARCHAR(64) NOT NULL,
  consume_asset_record_id VARCHAR(64) DEFAULT NULL,
  sys_origin VARCHAR(32) NOT NULL,
  standard_id BIGINT NOT NULL,
  room_id BIGINT NOT NULL,
  send_user_id BIGINT NOT NULL,
  gift_id BIGINT NOT NULL,
  gift_price BIGINT NOT NULL DEFAULT 0,
  gift_num BIGINT NOT NULL DEFAULT 0,
  gift_is_free TINYINT(1) NOT NULL DEFAULT 0,
  provider_code INT NOT NULL DEFAULT 0,
  reward_total BIGINT NOT NULL DEFAULT 0,
  balance_after BIGINT NOT NULL DEFAULT 0,
  wallet_event_id VARCHAR(128) DEFAULT NULL,
  status VARCHAR(32) NOT NULL DEFAULT 'PENDING',
  error_message VARCHAR(1024) DEFAULT NULL,
  request_json LONGTEXT DEFAULT NULL,
  provider_response_json LONGTEXT DEFAULT NULL,
  response_json LONGTEXT DEFAULT NULL,
  create_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  update_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  UNIQUE KEY uk_lucky_gift_business (business_id),
  UNIQUE KEY uk_lucky_gift_wallet_event (wallet_event_id),
  KEY idx_lucky_gift_sender (sys_origin, send_user_id),
  KEY idx_lucky_gift_status (status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS lucky_gift_draw_order (
  id BIGINT NOT NULL PRIMARY KEY,
  business_id VARCHAR(64) NOT NULL,
  order_seed VARCHAR(64) NOT NULL,
  sort_no INT NOT NULL DEFAULT 0,
  accept_user_id BIGINT NOT NULL,
  provider_order_id VARCHAR(64) NOT NULL,
  is_win TINYINT(1) NOT NULL DEFAULT 0,
  reward_num BIGINT NOT NULL DEFAULT 0,
  create_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  update_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  UNIQUE KEY uk_lucky_gift_order (business_id, order_seed),
  KEY idx_lucky_gift_order_business (business_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
