<?php
namespace app\plugins\vr_ticket;

class Event
{
    public function Install($params = [])
    {
        $db = \think\facade\Db::connect();
        $prefix = \think\facade\Config::get('database.connections.mysql.prefix');
        
        // 给 ShopXO 商品表追加 item_type 字段（MySQL 5.x 兼容写法）
        $query = $db->query("SHOW COLUMNS FROM `{$prefix}goods` LIKE 'item_type'");
        if (count($query) == 0) {
            $db->execute("ALTER TABLE `{$prefix}goods` ADD COLUMN `item_type` VARCHAR(20) NOT NULL DEFAULT 'normal' COMMENT '商品类型：normal=普通 goods ticket=票务 physical=周边' AFTER `is_shelves`");
        }

        $queryConfig = $db->query("SHOW COLUMNS FROM `{$prefix}goods` LIKE 'vr_goods_config'");
        if (count($queryConfig) == 0) {
            $db->execute("ALTER TABLE `{$prefix}goods` ADD COLUMN `vr_goods_config` LONGTEXT COMMENT '票务配置' AFTER `item_type`");
        }
    }

    public function Uninstall($params = [])
    {
        // 卸载操作通常由 uninstall.sql 完成
    }

    public function Upgrade($params = [])
    {
    }
}
?>