| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace App\Module\UrsPromotion\Commands;
- use Illuminate\Console\Command;
- use Dcat\Admin\Models\Menu;
- /**
- * 插入URS转出手续费配置后台菜单命令
- */
- class InsertUrsTransferFeeAdminMenuCommand extends Command
- {
- /**
- * 命令签名
- *
- * @var string
- */
- protected $signature = 'urs:insert-transfer-fee-admin-menu';
- /**
- * 命令描述
- *
- * @var string
- */
- protected $description = '插入URS转出手续费配置后台管理菜单';
- /**
- * 执行命令
- */
- public function handle()
- {
- $this->info('开始插入URS转出手续费配置后台管理菜单...');
- try {
- // 查找URS推广管理的父菜单
- $parentMenu = Menu::where('title', 'URS推广管理')->first();
-
- if (!$parentMenu) {
- $this->error('未找到URS推广管理父菜单,请先运行 php artisan urs:insert-admin-menu');
- return 1;
- }
- // 检查菜单是否已存在
- $existingMenu = Menu::where('title', 'URS转出手续费配置')
- ->where('parent_id', $parentMenu->id)
- ->first();
- if ($existingMenu) {
- $this->warn('URS转出手续费配置菜单已存在,跳过创建');
- return 0;
- }
- // 获取当前最大排序值
- $maxOrder = Menu::where('parent_id', $parentMenu->id)->max('order') ?? 0;
- // 创建菜单
- $menu = new Menu();
- $menu->parent_id = $parentMenu->id;
- $menu->order = $maxOrder + 1;
- $menu->title = 'URS转出手续费配置';
- $menu->icon = 'feather icon-percent';
- $menu->uri = 'urs-promotion/transfer-fee-config';
- $menu->created_at = now();
- $menu->updated_at = now();
- $menu->save();
- $this->info('URS转出手续费配置菜单创建成功!');
- $this->info("菜单ID: {$menu->id}");
- $this->info("菜单标题: {$menu->title}");
- $this->info("菜单URI: {$menu->uri}");
- $this->info("父菜单: {$parentMenu->title}");
- $this->info("排序: {$menu->order}");
- return 0;
- } catch (\Exception $e) {
- $this->error('插入菜单失败: ' . $e->getMessage());
- return 1;
- }
- }
- }
|