argument('user_id'); $this->info("开始测试推广Handler功能"); $this->info("农场用户ID: {$userId}"); $this->line(''); // 检查用户映射关系 $this->info("=== 检查用户映射关系 ==="); $ursUserId = UrsUserMappingService::getUrsUserId($userId); if (!$ursUserId) { $this->error("用户未进入URS推广系统,无法测试"); return; } $this->info("URS用户ID: {$ursUserId}"); $this->line(''); // 测试InfoHandler $this->info("=== 测试推广信息Handler ==="); $this->testInfoHandler($userId); $this->line(''); // 测试ListHandler $this->info("=== 测试推广列表Handler ==="); $this->testListHandler($userId); $this->line(''); $this->info("✅ 推广Handler测试完成!"); } /** * 测试InfoHandler * * @param int $userId */ private function testInfoHandler(int $userId): void { try { // 创建模拟响应对象 $response = new Response(); // 创建Handler $handler = new InfoHandler($response); $handler->user_id = $userId; // 创建请求数据 $request = new RequestPromotionInfo(); $request->setTimes(time()); // 执行Handler $result = $handler->handle($request); // 输出结果 $this->info("推广信息获取成功:"); $this->info("- 总人数: " . $result->getTotalCount()); $this->info("- 直推人数: " . $result->getDirectCount()); $this->info("- 间推人数: " . $result->getIndirectCount()); $this->info("- 今日团队新增: " . $result->getDayRecentCount()); $this->info("- 今日直推新增: " . $result->getDayDirectCount()); $this->info("- 团队活跃人数: " . $result->getActiveCount()); $this->info("- 直推活跃人数: " . $result->getDirectActiveCount()); // 显示收益信息 $todayReward = $result->getTodayReward(); if ($todayReward) { $this->info("- 今日收益:"); $this->displayRewardInfo($todayReward, " "); } else { $this->info("- 今日收益: 无"); } $totalReward = $result->getTotalReward(); if ($totalReward) { $this->info("- 总收益:"); $this->displayRewardInfo($totalReward, " "); } else { $this->info("- 总收益: 无"); } } catch (\Exception $e) { $this->error("InfoHandler测试失败: " . $e->getMessage()); $this->error("错误详情: " . $e->getTraceAsString()); } } /** * 测试ListHandler * * @param int $userId */ private function testListHandler(int $userId): void { try { // 创建模拟响应对象 $response = new Response(); // 创建Handler $handler = new ListHandler($response); $handler->user_id = $userId; // 创建请求数据 $request = new RequestPromotionList(); // 设置分页参数 $page = new RequestPage(); $page->setPage(1); $page->setPerPage(10); $request->setPage($page); $request->setLevel(0); // 全部等级 // 执行Handler $result = $handler->handle($request); // 输出结果 $this->info("推广列表获取成功:"); $responsePage = $result->getPage(); if ($responsePage) { $this->info("- 当前页: " . $responsePage->getCurrentPage()); $this->info("- 每页大小: " . $responsePage->getPerPage()); $this->info("- 总记录数: " . $responsePage->getTotal()); $this->info("- 总页数: " . $responsePage->getLastPage()); $this->info("- 是否有下一页: " . ($responsePage->getHasMore() ? '是' : '否')); } $list = $result->getList(); $this->info("- 当前页记录数: " . count($list)); // 显示前3条记录详情 $displayCount = min(3, count($list)); for ($i = 0; $i < $displayCount; $i++) { $item = $list[$i]; $this->info(" 第" . ($i + 1) . "条:"); $this->info(" 用户ID: " . $item->getUserId()); $this->info(" 昵称: " . $item->getNickname()); $this->info(" 头像: " . $item->getAvatar()); $this->info(" 财富: " . $item->getFund2()); $this->info(" 贡献: " . $item->getContribution()); $this->info(" 房屋等级: " . $item->getHouseLevel()); } if (count($list) > 3) { $this->info(" ... 还有 " . (count($list) - 3) . " 条记录"); } } catch (\Exception $e) { $this->error("ListHandler测试失败: " . $e->getMessage()); $this->error("错误详情: " . $e->getTraceAsString()); } } /** * 显示奖励信息 * * @param \Uraus\Kku\Common\Reward $reward * @param string $prefix */ private function displayRewardInfo($reward, string $prefix = ""): void { // 显示代币奖励 $coins = $reward->getCoins(); if ($coins && count($coins) > 0) { $this->info($prefix . "代币奖励:"); foreach ($coins as $coin) { $typeName = $this->getCoinTypeName($coin->getType()); $this->info($prefix . " - {$typeName}: " . $coin->getQuantity()); } } // 显示物品奖励 $items = $reward->getItems(); if ($items && count($items) > 0) { $this->info($prefix . "物品奖励: " . count($items) . "种"); } // 显示其他奖励类型 $gods = $reward->getGods(); if ($gods && count($gods) > 0) { $this->info($prefix . "图腾奖励: " . count($gods) . "个"); } $lands = $reward->getLands(); if ($lands && count($lands) > 0) { $this->info($prefix . "土地奖励: " . count($lands) . "块"); } $pets = $reward->getPets(); if ($pets && count($pets) > 0) { $this->info($prefix . "宠物奖励: " . count($pets) . "只"); } } /** * 获取代币类型名称 * * @param int $type * @return string */ private function getCoinTypeName(int $type): string { $typeNames = [ 1 => '金币', 2 => '钻石', 3 => '钻石(冻结)' ]; return $typeNames[$type] ?? "未知类型({$type})"; } }