configPath}/task_config.json"; if (File::exists($configFile)) { return json_decode(File::get($configFile), true); } return [ 'tasks' => [], 'categories' => [] ]; } /** * 获取任务条件配置 * * @return array */ public function getTaskConditionConfig() { $configFile = "{$this->configPath}/task_condition_config.json"; if (File::exists($configFile)) { return json_decode(File::get($configFile), true); } return [ 'conditions' => [], 'condition_types' => [] ]; } /** * 获取任务奖励配置 * * @return array */ public function getTaskRewardConfig() { $configFile = "{$this->configPath}/task_reward_config.json"; if (File::exists($configFile)) { return json_decode(File::get($configFile), true); } return [ 'rewards' => [] ]; } /** * 获取任务消耗配置 * * @return array */ public function getTaskCostConfig() { $configFile = "{$this->configPath}/task_cost_config.json"; if (File::exists($configFile)) { return json_decode(File::get($configFile), true); } return [ 'costs' => [] ]; } /** * 导出任务基础配置表 * * @return string */ public function exportTaskConfig() { $taskConfig = [ 'tasks' => [], 'categories' => [] ]; try { // 尝试获取任务数据 if (Schema::hasTable('task_tasks')) { $tasks = Task::all(); foreach ($tasks as $task) { $taskConfig['tasks'][] = [ 'id' => $task->id, 'name' => $task->name, 'description' => $task->description, 'category_id' => $task->category_id, 'type' => $task->type, 'reset_type' => $task->reset_type, 'min_level' => $task->min_level ?? $task->level_required ?? 0, 'max_level' => $task->max_level ?? 0, 'time_limit' => $task->time_limit, 'start_time' => $task->start_time ? $task->start_time->toDateTimeString() : null, 'end_time' => $task->end_time ? $task->end_time->toDateTimeString() : null, 'sort_order' => $task->sort_order, 'is_active' => $task->is_active ]; } } // 尝试获取分类数据 if (Schema::hasTable('task_categories')) { $categories = TaskCategory::all(); foreach ($categories as $category) { $taskConfig['categories'][] = [ 'id' => $category->id, 'name' => $category->name, 'code' => $category->code, 'parent_id' => $category->parent_id ?? 0, 'sort_order' => $category->sort_order ]; } } } catch (\Exception $e) { Log::warning('Error exporting task config: ' . $e->getMessage()); } return json_encode($taskConfig, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); } /** * 导出任务条件配置表 * * @return string */ public function exportTaskConditionConfig() { $conditionConfig = [ 'conditions' => [], 'condition_types' => [] ]; try { // 尝试获取条件数据 if (Schema::hasTable('task_conditions')) { $conditions = TaskCondition::all(); foreach ($conditions as $condition) { $conditionConfig['conditions'][] = [ 'id' => $condition->id, 'task_id' => $condition->task_id, 'condition_type_id' => $condition->condition_type_id, 'param1' => $condition->param1, 'param2' => $condition->param2, 'target_value' => $condition->target_value, 'is_prerequisite' => $condition->is_prerequisite, 'extra_data' => $condition->extra_data, 'sort_order' => $condition->sort_order ]; } } // 尝试获取条件类型数据 if (Schema::hasTable('task_condition_types')) { $conditionTypes = TaskConditionType::all(); foreach ($conditionTypes as $type) { $conditionConfig['condition_types'][] = [ 'id' => $type->id, 'name' => $type->name, 'code' => $type->code, 'description' => $type->description ]; } } } catch (\Exception $e) { Log::warning('Error exporting task condition config: ' . $e->getMessage()); } return json_encode($conditionConfig, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); } /** * 导出任务奖励配置表 * * @return string */ public function exportTaskRewardConfig() { $rewardConfig = [ 'rewards' => [] ]; try { // 尝试获取奖励数据 if (Schema::hasTable('task_rewards')) { $rewards = TaskReward::all(); foreach ($rewards as $reward) { $rewardConfig['rewards'][] = [ 'id' => $reward->id, 'task_id' => $reward->task_id, 'reward_type' => $reward->reward_type, 'reward_param1' => $reward->reward_param1, 'reward_param2' => $reward->reward_param2, 'quantity' => $reward->quantity, 'extra_data' => $reward->extra_data, 'sort_order' => $reward->sort_order ]; } } } catch (\Exception $e) { Log::warning('Error exporting task reward config: ' . $e->getMessage()); } return json_encode($rewardConfig, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); } /** * 导出任务消耗配置表 * * @return string */ public function exportTaskCostConfig() { $costConfig = [ 'costs' => [] ]; try { // 尝试获取消耗数据 if (Schema::hasTable('task_costs')) { $costs = TaskCost::all(); foreach ($costs as $cost) { $costConfig['costs'][] = [ 'id' => $cost->id, 'task_id' => $cost->task_id, 'cost_type' => $cost->cost_type, 'cost_param1' => $cost->cost_param1, 'cost_param2' => $cost->cost_param2, 'quantity' => $cost->quantity, 'extra_data' => $cost->extra_data, 'sort_order' => $cost->sort_order ]; } } } catch (\Exception $e) { Log::warning('Error exporting task cost config: ' . $e->getMessage()); } return json_encode($costConfig, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); } }