InsertUrsTransferFeeAdminMenuCommand.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Module\UrsPromotion\Commands;
  3. use Illuminate\Console\Command;
  4. use Dcat\Admin\Models\Menu;
  5. /**
  6. * 插入URS转出手续费配置后台菜单命令
  7. */
  8. class InsertUrsTransferFeeAdminMenuCommand extends Command
  9. {
  10. /**
  11. * 命令签名
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'urs:insert-transfer-fee-admin-menu';
  16. /**
  17. * 命令描述
  18. *
  19. * @var string
  20. */
  21. protected $description = '插入URS转出手续费配置后台管理菜单';
  22. /**
  23. * 执行命令
  24. */
  25. public function handle()
  26. {
  27. $this->info('开始插入URS转出手续费配置后台管理菜单...');
  28. try {
  29. // 查找URS推广管理的父菜单
  30. $parentMenu = Menu::where('title', 'URS推广管理')->first();
  31. if (!$parentMenu) {
  32. $this->error('未找到URS推广管理父菜单,请先运行 php artisan urs:insert-admin-menu');
  33. return 1;
  34. }
  35. // 检查菜单是否已存在
  36. $existingMenu = Menu::where('title', 'URS转出手续费配置')
  37. ->where('parent_id', $parentMenu->id)
  38. ->first();
  39. if ($existingMenu) {
  40. $this->warn('URS转出手续费配置菜单已存在,跳过创建');
  41. return 0;
  42. }
  43. // 获取当前最大排序值
  44. $maxOrder = Menu::where('parent_id', $parentMenu->id)->max('order') ?? 0;
  45. // 创建菜单
  46. $menu = new Menu();
  47. $menu->parent_id = $parentMenu->id;
  48. $menu->order = $maxOrder + 1;
  49. $menu->title = 'URS转出手续费配置';
  50. $menu->icon = 'feather icon-percent';
  51. $menu->uri = 'urs-promotion/transfer-fee-config';
  52. $menu->created_at = now();
  53. $menu->updated_at = now();
  54. $menu->save();
  55. $this->info('URS转出手续费配置菜单创建成功!');
  56. $this->info("菜单ID: {$menu->id}");
  57. $this->info("菜单标题: {$menu->title}");
  58. $this->info("菜单URI: {$menu->uri}");
  59. $this->info("父菜单: {$parentMenu->title}");
  60. $this->info("排序: {$menu->order}");
  61. return 0;
  62. } catch (\Exception $e) {
  63. $this->error('插入菜单失败: ' . $e->getMessage());
  64. return 1;
  65. }
  66. }
  67. }