settingRepository = $settingRepository; } public function handle() { $this->info('Initializing reward points growth value settings...'); try { $this->initializeGrowthLevelsInCustomerGroups(); $this->initializeGrowthSettings(); $this->addMenuItems(); $this->info('✓ Growth value settings initialized successfully!'); $this->info('✓ Menu items added to admin panel!'); $this->info('You can now configure growth value in: Admin > Settings > Growth Value'); return 0; } catch (\Exception $e) { $this->error('Error initializing settings: ' . $e->getMessage()); $this->error($e->getTraceAsString()); return 1; } } /** * 在 ly_customer_groups 表中初始化成长值等级数据 */ protected function initializeGrowthLevelsInCustomerGroups() { $this->info('Initializing growth value levels in customer groups...'); $generalGroup = CustomerGroup::where('code', 'general')->first(); $wholesaleGroup = CustomerGroup::where('code', 'wholesale')->first(); if ($generalGroup) { $generalGroup->update([ 'min_growth_value' => 0, 'require_first_order' => false, 'growth_level_name' => 'General-V0', 'growth_discount_rate' => 0, 'growth_benefits' => ['基础会员服务'], 'growth_level_icon' => null, ]); $this->info('✓ General group updated with V0 level'); } if ($generalGroup) { CustomerGroup::updateOrCreate( ['code' => 'general_v1'], [ 'name' => '普通会员-V1', 'min_growth_value' => 0, 'require_first_order' => true, 'growth_level_name' => 'V1', 'growth_discount_rate' => 2, 'growth_benefits' => ['完成首单升级', '享受2%额外折扣', '优先客服支持'], 'growth_level_icon' => null, 'is_user_defined' => 1, ] ); $this->info('✓ Created V1 level (General V1)'); } if ($generalGroup) { CustomerGroup::updateOrCreate( ['code' => 'general_v2'], [ 'name' => '普通会员-V2', 'min_growth_value' => 1000, 'require_first_order' => false, 'growth_level_name' => 'V2', 'growth_discount_rate' => 5, 'growth_benefits' => ['享受5%额外折扣', '专属优惠券', '生日礼品', '优先发货'], 'growth_level_icon' => null, 'is_user_defined' => 1, ] ); $this->info('✓ Created V2 level (General V2)'); } if ($wholesaleGroup) { $wholesaleGroup->update([ 'min_growth_value' => 5000, 'require_first_order' => false, 'growth_level_name' => 'V3', 'growth_discount_rate' => 10, 'growth_benefits' => ['享受10%额外折扣', '专属客服经理', '新品优先体验', '免费配送', '专属活动邀请'], 'growth_level_icon' => null, ]); $this->info('✓ Wholesale group updated with V3 level'); } $this->info('✓ Growth value levels initialized in ly_customer_groups table'); } /** * 初始化成长值配置项 */ protected function initializeGrowthSettings() { $this->info('Initializing growth value settings...'); $settings = [ [ 'code' => 'growth_value_ratio', 'name' => '成长值计算比例', 'value' => '1', 'type' => 'number', 'group' => 'growth_value', 'description' => '每消费1元获得的成长值数量', 'is_enabled' => true, ], [ 'code' => 'growth_value_validity_days', 'name' => '成长值有效期(天)', 'value' => '365', 'type' => 'number', 'group' => 'growth_value', 'description' => '成长值的有效期,0表示永久有效', 'is_enabled' => true, ], ]; foreach ($settings as $settingData) { \Longyi\RewardPoints\Models\RewardPointSetting::updateOrCreate( ['code' => $settingData['code']], $settingData ); } $this->info('✓ Growth value settings initialized'); } /** * 添加成长值模块的菜单项到动态菜单 */ protected function addMenuItems() { $this->info('Adding growth value menu items to dynamic menu...'); // 检查是否已存在成长值模块的菜单项 $existingParent = MenuItem::where('key', 'settings.growth-value')->first(); if ($existingParent) { $this->warn('Growth value menu items already exist in dynamic menu.'); return; } // 创建子菜单项 $childItems = [ [ 'name' => '会员成长值', 'key' => 'customers.growth-value', 'route' => 'admin.growth-value.index', 'icon' => 'icon-users', 'sort_order' => 4, ], [ 'name' => '会员成长值记录', 'key' => 'customers.growth-history', 'route' => 'admin.growth-value.history', 'icon' => 'icon-list', 'sort_order' => 5, ], [ 'name' => '成长值设置', 'key' => 'customers.growth-settings', 'route' => 'admin.growth-value.settings', 'icon' => 'icon-setting', 'sort_order' => 6, ], ]; foreach ($childItems as $item) { MenuItem::create([ 'name' => $item['name'], 'key' => $item['key'], 'route' => $item['route'], 'icon' => $item['icon'], 'sort_order' => $item['sort_order'], 'parent_id' => 999, 'status' => 1, 'created_by' => 1, ]); } $this->info('✓ Growth value menu items added to dynamic menu successfully!'); } }