| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- namespace Longyi\RewardPoints\Console\Commands;
- use Illuminate\Console\Command;
- use Longyi\RewardPoints\Repositories\RewardPointSettingRepository;
- use Longyi\DynamicMenu\Models\MenuItem;
- class InitializeGrowthSettings extends Command
- {
- protected $signature = 'reward-points:init-growth-settings';
- protected $description = 'Initialize reward points settings in database';
- protected $settingRepository;
- public function __construct(RewardPointSettingRepository $settingRepository)
- {
- parent::__construct();
- $this->settingRepository = $settingRepository;
- }
- public function handle()
- {
- $this->info('Initializing reward points settings...');
- try {
- $this->settingRepository->initializeDefaultSettings();
- $this->info('✓ Default settings initialized successfully!');
- $this->info('You can now configure reward points in admin panel.');
- // 添加数据
- $this->addItems();
- return 0;
- } catch (\Exception $e) {
- $this->error('Error initializing settings: ' . $e->getMessage());
- return 1;
- }
- }
- /**
- * 添加积分模块的菜单项到动态菜单
- */
- protected function addItems()
- {
- $this->info('Adding reward points menu items to dynamic menu...');
- // 检查是否已存在积分模块的菜单项
- $existingParent = MenuItem::where('key', 'settings.reward-points')->first();
- if ($existingParent) {
- $this->warn('Reward points menu items already exist in dynamic menu.');
- return;
- }
- $this->info('✓ Reward points menu items added to dynamic menu successfully!');
- }
- }
|