InitializeGrowthSettings.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace Longyi\RewardPoints\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Longyi\RewardPoints\Repositories\RewardPointSettingRepository;
  5. use Longyi\DynamicMenu\Models\MenuItem;
  6. class InitializeGrowthSettings extends Command
  7. {
  8. protected $signature = 'reward-points:init-growth-settings';
  9. protected $description = 'Initialize reward points settings in database';
  10. protected $settingRepository;
  11. public function __construct(RewardPointSettingRepository $settingRepository)
  12. {
  13. parent::__construct();
  14. $this->settingRepository = $settingRepository;
  15. }
  16. public function handle()
  17. {
  18. $this->info('Initializing reward points settings...');
  19. try {
  20. $this->settingRepository->initializeDefaultSettings();
  21. $this->info('✓ Default settings initialized successfully!');
  22. $this->info('You can now configure reward points in admin panel.');
  23. // 添加数据
  24. $this->addItems();
  25. return 0;
  26. } catch (\Exception $e) {
  27. $this->error('Error initializing settings: ' . $e->getMessage());
  28. return 1;
  29. }
  30. }
  31. /**
  32. * 添加积分模块的菜单项到动态菜单
  33. */
  34. protected function addItems()
  35. {
  36. $this->info('Adding reward points menu items to dynamic menu...');
  37. // 检查是否已存在积分模块的菜单项
  38. $existingParent = MenuItem::where('key', 'settings.reward-points')->first();
  39. if ($existingParent) {
  40. $this->warn('Reward points menu items already exist in dynamic menu.');
  41. return;
  42. }
  43. $this->info('✓ Reward points menu items added to dynamic menu successfully!');
  44. }
  45. }