<?php

use think\migration\Migrator;
use think\facade\Db;

class AddVersionMenu extends Migrator
{
    public function change()
    {
        // 检查是否已存在版本管理菜单
        $exists = Db::name('system_menu')->where(['node' => 'version_manage'])->find();
        if (!$exists) {
            // 添加版本管理主菜单
            $pid = Db::name('system_menu')->insertGetId([
                'pid' => 0,
                'title' => '版本管理',
                'icon' => 'layui-icon layui-icon-template-1',
                'node' => 'version_manage',
                'url' => '#',
                'sort' => 100,
                'status' => 1,
                'create_at' => date('Y-m-d H:i:s'),
            ]);

            // 添加版本列表菜单
            $menu_id = Db::name('system_menu')->insertGetId([
                'pid' => $pid,
                'title' => '版本列表',
                'icon' => 'layui-icon layui-icon-list',
                'node' => 'version_manage/version/index',
                'url' => 'manager/version/index',
                'sort' => 100,
                'status' => 1,
                'create_at' => date('Y-m-d H:i:s'),
            ]);

            // 添加操作权限节点(不显示在菜单中)
            Db::name('system_menu')->insertAll([
                [
                    'pid' => $menu_id,
                    'title' => '添加版本',
                    'icon' => 'layui-icon layui-icon-add-1',
                    'node' => 'version_manage/version/add',
                    'url' => 'manager/version/add',
                    'sort' => 100,
                    'status' => 0, // 不显示在菜单中
                    'create_at' => date('Y-m-d H:i:s'),
                ],
                [
                    'pid' => $menu_id,
                    'title' => '编辑版本',
                    'icon' => 'layui-icon layui-icon-edit',
                    'node' => 'version_manage/version/edit',
                    'url' => 'manager/version/edit',
                    'sort' => 100,
                    'status' => 0, // 不显示在菜单中
                    'create_at' => date('Y-m-d H:i:s'),
                ],
                [
                    'pid' => $menu_id,
                    'title' => '删除版本',
                    'icon' => 'layui-icon layui-icon-delete',
                    'node' => 'version_manage/version/remove',
                    'url' => 'manager/version/remove',
                    'sort' => 100,
                    'status' => 0, // 不显示在菜单中
                    'create_at' => date('Y-m-d H:i:s'),
                ],
                [
                    'pid' => $menu_id,
                    'title' => '版本状态',
                    'icon' => 'layui-icon layui-icon-circle',
                    'node' => 'version_manage/version/state',
                    'url' => 'manager/version/state',
                    'sort' => 100,
                    'status' => 0, // 不显示在菜单中
                    'create_at' => date('Y-m-d H:i:s'),
                ]
            ]);
        }
    }
} 