'代理域名池-新增', 'admin/agent/domain-pool/update' => '代理域名池-修改', 'admin/agent/domain-pool/delete' => '代理域名池-删除', ]; public function up(): void { if (!Schema::hasTable('agent_domain_pool')) { Schema::create('agent_domain_pool', function (Blueprint $t) { $t->id(); $t->string('domain', 255)->comment('域名或完整地址,原样保存'); $t->string('host', 255)->unique()->comment('主机名(小写),用于唯一和匹配绑定'); $t->string('type', 16)->default('')->comment('pc / h5 / 空=通用'); $t->unsignedTinyInteger('status')->default(1)->comment('1 启用 0 停用'); $t->string('remark', 255)->default(''); $t->unsignedBigInteger('created_by')->nullable(); $t->timestamps(); $t->index(['status', 'type']); }); } if (Schema::hasTable('agent_domains')) { $now = date('Y-m-d H:i:s'); foreach (DB::table('agent_domains')->orderBy('id')->get(['domain', 'host', 'type']) as $row) { if ($row->host === '' || DB::table('agent_domain_pool')->where('host', $row->host)->exists()) continue; DB::table('agent_domain_pool')->insert(['domain' => $row->domain, 'host' => $row->host, 'type' => (string) $row->type, 'status' => 1, 'remark' => '', 'created_at' => $now, 'updated_at' => $now]); } } $this->menus(); } private function menus(): void { if (!Schema::hasTable('menus')) return; $now = date('Y-m-d H:i:s'); $parentId = (int) DB::table('menus')->where('uri', 'agentRecharges')->where('type', 1)->value('parent_id'); $menuId = DB::table('menus')->where('uri', 'agentDomainPool')->where('type', 1)->value('id'); if (!$menuId) { $menuId = DB::table('menus')->insertGetId([ 'parent_id' => $parentId, 'title' => '代理域名管理', 'icon' => null, 'uri' => 'agentDomainPool', 'permission_name' => 'agent.agentDomainPool', 'sort' => 25, 'status' => 1, 'type' => 1, 'created_at' => $now, 'updated_at' => $now, ]); } $sort = 0; foreach (self::BUTTONS as $uri => $title) { if (!DB::table('menus')->where('uri', $uri)->exists()) { DB::table('menus')->insert(['parent_id' => $menuId, 'title' => $title, 'icon' => null, 'uri' => $uri, 'permission_name' => str_replace('/', '.', $uri), 'sort' => $sort, 'status' => 1, 'type' => 2, 'created_at' => $now, 'updated_at' => $now]); } $sort++; } } public function down(): void { if (Schema::hasTable('menus')) { $ids = DB::table('menus')->whereIn('uri', array_merge(['agentDomainPool'], array_keys(self::BUTTONS)))->pluck('id'); if (Schema::hasTable('role_menu')) DB::table('role_menu')->whereIn('menu_id', $ids)->delete(); DB::table('menus')->whereIn('id', $ids)->delete(); } Schema::dropIfExists('agent_domain_pool'); } };