value: return self::resolveTaskSource($sourceId, $typeInfo); case REWARD_SOURCE_TYPE::ACTIVITY->value: return self::resolveActivitySource($sourceId, $typeInfo); case REWARD_SOURCE_TYPE::FARM_INIT->value: case REWARD_SOURCE_TYPE::FARM_HARVEST->value: case REWARD_SOURCE_TYPE::FARM_PLANT->value: return self::resolveFarmSource($sourceType, $sourceId, $typeInfo); case REWARD_SOURCE_TYPE::URSPROMOTION_REGISTER->value: case REWARD_SOURCE_TYPE::URSPROMOTION_REWARD->value: case REWARD_SOURCE_TYPE::URSPROMOTION_BACKFILL->value: return self::resolvePromotionSource($sourceType, $sourceId, $typeInfo); case REWARD_SOURCE_TYPE::SIGN_IN->value: return self::resolveSignInSource($sourceId, $typeInfo); case REWARD_SOURCE_TYPE::ACHIEVEMENT->value: return self::resolveAchievementSource($sourceId, $typeInfo); case REWARD_SOURCE_TYPE::LEVEL->value: return self::resolveLevelSource($sourceId, $typeInfo); case REWARD_SOURCE_TYPE::CHEST->value: return self::resolveChestSource($sourceId, $typeInfo); case REWARD_SOURCE_TYPE::CRAFT->value: return self::resolveCraftSource($sourceId, $typeInfo); case REWARD_SOURCE_TYPE::SHOP_PURCHASE->value: return self::resolveShopSource($sourceId, $typeInfo); case REWARD_SOURCE_TYPE::DAILY_LOGIN->value: return self::resolveDailyLoginSource($sourceId, $typeInfo); case REWARD_SOURCE_TYPE::INVITE_FRIEND->value: return self::resolveInviteSource($sourceId, $typeInfo); case REWARD_SOURCE_TYPE::SYSTEM->value: case REWARD_SOURCE_TYPE::TEST->value: return self::resolveSystemSource($sourceType, $sourceId, $typeInfo); default: return self::getUnknownSource($sourceType, $sourceId); } } catch (\Exception $e) { Log::warning('解析奖励来源失败', [ 'source_type' => $sourceType, 'source_id' => $sourceId, 'error' => $e->getMessage() ]); return self::getErrorSource($sourceType, $sourceId, $e->getMessage()); } } /** * 解析任务来源 */ private static function resolveTaskSource(int $taskId, array $typeInfo): array { // 由于Task模型可能不存在,先返回基础信息 return [ 'type' => $typeInfo['name'], 'name' => "任务奖励 (ID: {$taskId})", 'description' => $typeInfo['description'], 'link' => $typeInfo['admin_link'] ? "{$typeInfo['admin_link']}/{$taskId}" : null, 'status' => 'found', 'category' => $typeInfo['category'], 'extra' => [ 'task_id' => $taskId, 'source_type' => REWARD_SOURCE_TYPE::TASK->value ] ]; } /** * 解析活动来源 */ private static function resolveActivitySource(int $activityId, array $typeInfo): array { return [ 'type' => $typeInfo['name'], 'name' => "活动奖励 (ID: {$activityId})", 'description' => $typeInfo['description'], 'link' => $typeInfo['admin_link'] ? "{$typeInfo['admin_link']}/{$activityId}" : null, 'status' => 'found', 'category' => $typeInfo['category'], 'extra' => [ 'activity_id' => $activityId, 'source_type' => REWARD_SOURCE_TYPE::ACTIVITY->value ] ]; } /** * 解析农场来源 */ private static function resolveFarmSource(string $sourceType, int $sourceId, array $typeInfo): array { // 根据不同的农场操作类型,sourceId可能指向不同的表 if ($sourceType === REWARD_SOURCE_TYPE::FARM_INIT->value) { // 农场初始化,sourceId通常是用户ID return [ 'type' => $typeInfo['name'], 'name' => "用户农场初始化 (用户ID: {$sourceId})", 'description' => $typeInfo['description'], 'link' => $typeInfo['admin_link'] ? "{$typeInfo['admin_link']}/users/{$sourceId}" : null, 'status' => 'found', 'category' => $typeInfo['category'], 'extra' => [ 'operation_type' => $sourceType, 'target_user_id' => $sourceId, 'source_type' => $sourceType ] ]; } // 其他农场操作 return [ 'type' => $typeInfo['name'], 'name' => "农场操作奖励 (ID: {$sourceId})", 'description' => $typeInfo['description'], 'link' => $typeInfo['admin_link'], 'status' => 'found', 'category' => $typeInfo['category'], 'extra' => [ 'operation_type' => $sourceType, 'operation_id' => $sourceId, 'source_type' => $sourceType ] ]; } /** * 解析推广来源 */ private static function resolvePromotionSource(string $sourceType, int $sourceId, array $typeInfo): array { return [ 'type' => $typeInfo['name'], 'name' => "URS推广奖励 (ID: {$sourceId})", 'description' => $typeInfo['description'], 'link' => $typeInfo['admin_link'] ? "{$typeInfo['admin_link']}/user-mappings/{$sourceId}" : null, 'status' => 'found', 'category' => $typeInfo['category'], 'extra' => [ 'mapping_id' => $sourceId, 'source_type' => $sourceType ] ]; } /** * 解析签到来源 */ private static function resolveSignInSource(int $sourceId, array $typeInfo): array { return [ 'type' => $typeInfo['name'], 'name' => "每日签到奖励 (ID: {$sourceId})", 'description' => $typeInfo['description'], 'link' => $typeInfo['admin_link'] ? "{$typeInfo['admin_link']}/logs/{$sourceId}" : null, 'status' => 'found', 'category' => $typeInfo['category'], 'extra' => [ 'sign_in_id' => $sourceId, 'source_type' => REWARD_SOURCE_TYPE::SIGN_IN->value ] ]; } /** * 解析成就来源 */ private static function resolveAchievementSource(int $sourceId, array $typeInfo): array { return [ 'type' => $typeInfo['name'], 'name' => "成就奖励 (ID: {$sourceId})", 'description' => $typeInfo['description'], 'link' => $typeInfo['admin_link'] ? "{$typeInfo['admin_link']}/{$sourceId}" : null, 'status' => 'found', 'category' => $typeInfo['category'], 'extra' => [ 'achievement_id' => $sourceId, 'source_type' => REWARD_SOURCE_TYPE::ACHIEVEMENT->value ] ]; } /** * 解析等级来源 */ private static function resolveLevelSource(int $sourceId, array $typeInfo): array { return [ 'type' => $typeInfo['name'], 'name' => "等级奖励 (等级: {$sourceId})", 'description' => $typeInfo['description'], 'link' => $typeInfo['admin_link'], 'status' => 'found', 'category' => $typeInfo['category'], 'extra' => [ 'level' => $sourceId, 'source_type' => REWARD_SOURCE_TYPE::LEVEL->value ] ]; } /** * 解析宝箱来源 */ private static function resolveChestSource(int $sourceId, array $typeInfo): array { return [ 'type' => $typeInfo['name'], 'name' => "宝箱奖励 (ID: {$sourceId})", 'description' => $typeInfo['description'], 'link' => $typeInfo['admin_link'] ? "{$typeInfo['admin_link']}/{$sourceId}" : null, 'status' => 'found', 'category' => $typeInfo['category'], 'extra' => [ 'chest_id' => $sourceId, 'source_type' => REWARD_SOURCE_TYPE::CHEST->value ] ]; } /** * 解析合成来源 */ private static function resolveCraftSource(int $sourceId, array $typeInfo): array { return [ 'type' => $typeInfo['name'], 'name' => "合成奖励 (ID: {$sourceId})", 'description' => $typeInfo['description'], 'link' => $typeInfo['admin_link'] ? "{$typeInfo['admin_link']}/{$sourceId}" : null, 'status' => 'found', 'category' => $typeInfo['category'], 'extra' => [ 'craft_id' => $sourceId, 'source_type' => REWARD_SOURCE_TYPE::CRAFT->value ] ]; } /** * 解析商店来源 */ private static function resolveShopSource(int $sourceId, array $typeInfo): array { return [ 'type' => $typeInfo['name'], 'name' => "商店购买奖励 (订单ID: {$sourceId})", 'description' => $typeInfo['description'], 'link' => $typeInfo['admin_link'] ? "{$typeInfo['admin_link']}/orders/{$sourceId}" : null, 'status' => 'found', 'category' => $typeInfo['category'], 'extra' => [ 'order_id' => $sourceId, 'source_type' => REWARD_SOURCE_TYPE::SHOP_PURCHASE->value ] ]; } /** * 解析每日登录来源 */ private static function resolveDailyLoginSource(int $sourceId, array $typeInfo): array { return [ 'type' => $typeInfo['name'], 'name' => "每日登录奖励 (ID: {$sourceId})", 'description' => $typeInfo['description'], 'link' => $typeInfo['admin_link'] ? "{$typeInfo['admin_link']}/logs/{$sourceId}" : null, 'status' => 'found', 'category' => $typeInfo['category'], 'extra' => [ 'login_id' => $sourceId, 'source_type' => REWARD_SOURCE_TYPE::DAILY_LOGIN->value ] ]; } /** * 解析邀请好友来源 */ private static function resolveInviteSource(int $sourceId, array $typeInfo): array { return [ 'type' => $typeInfo['name'], 'name' => "邀请好友奖励 (邀请ID: {$sourceId})", 'description' => $typeInfo['description'], 'link' => $typeInfo['admin_link'] ? "{$typeInfo['admin_link']}/invites/{$sourceId}" : null, 'status' => 'found', 'category' => $typeInfo['category'], 'extra' => [ 'invite_id' => $sourceId, 'source_type' => REWARD_SOURCE_TYPE::INVITE_FRIEND->value ] ]; } /** * 解析系统来源 */ private static function resolveSystemSource(string $sourceType, int $sourceId, array $typeInfo): array { return [ 'type' => $typeInfo['name'], 'name' => "{$typeInfo['name']} (ID: {$sourceId})", 'description' => $typeInfo['description'], 'link' => $typeInfo['admin_link'], 'status' => 'found', 'category' => $typeInfo['category'], 'extra' => [ 'operation_id' => $sourceId, 'source_type' => $sourceType ] ]; } /** * 获取未知来源信息 */ private static function getUnknownSource(string $sourceType, int $sourceId): array { return [ 'type' => '未知来源', 'name' => "未知来源类型: {$sourceType}", 'description' => "来源ID: {$sourceId}", 'link' => null, 'status' => 'unknown', 'extra' => [ 'raw_source_type' => $sourceType, 'raw_source_id' => $sourceId ] ]; } /** * 获取错误来源信息 */ private static function getErrorSource(string $sourceType, int $sourceId, string $error): array { return [ 'type' => '解析错误', 'name' => "解析失败: {$sourceType}", 'description' => "来源ID: {$sourceId}, 错误: {$error}", 'link' => null, 'status' => 'error', 'extra' => [ 'error_message' => $error, 'raw_source_type' => $sourceType, 'raw_source_id' => $sourceId ] ]; } /** * 获取格式化的显示文本 * * @param string $sourceType 来源类型 * @param int $sourceId 来源ID * @param bool $includeLink 是否包含链接 * @return string 格式化的显示文本 */ public static function getDisplayText(string $sourceType, int $sourceId, bool $includeLink = false): string { $info = self::resolve($sourceType, $sourceId); $text = "{$info['type']}: {$info['name']}"; if ($includeLink && $info['link']) { return "{$text}"; } return $text; } /** * 获取简短的显示文本 * * @param string $sourceType 来源类型 * @param int $sourceId 来源ID * @return string 简短的显示文本 */ public static function getShortDisplayText(string $sourceType, int $sourceId): string { $info = self::resolve($sourceType, $sourceId); return $info['name']; } }