-- =====================================================
-- 美食团购预订单支付字段
-- 表：app_food_booking_order
-- 说明：支持微信小程序 JSAPI 真实支付
-- =====================================================

ALTER TABLE `app_food_booking_order`
    ADD COLUMN `pay_order_id` VARCHAR(64) DEFAULT NULL COMMENT '支付订单ID' AFTER `guest_phone`,
    ADD COLUMN `pay_channel` VARCHAR(32) DEFAULT NULL COMMENT '支付渠道' AFTER `pay_order_id`,
    ADD COLUMN `pay_status` VARCHAR(32) DEFAULT 'unpaid' COMMENT '支付状态：unpaid-待支付 preparing-参数已生成 paid-已支付 closed-已关闭' AFTER `pay_channel`,
    ADD COLUMN `pay_time` DATETIME DEFAULT NULL COMMENT '支付时间' AFTER `pay_status`,
    ADD COLUMN `expire_time` DATETIME DEFAULT NULL COMMENT '支付过期时间' AFTER `pay_time`;

UPDATE `app_food_booking_order`
SET `pay_status` = 'paid'
WHERE `book_status` IN ('pending_use', 'used')
  AND (`pay_status` IS NULL OR `pay_status` = 'unpaid');
