| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- <?php
- namespace App\Module\AppGame\Commands;
- use App\Module\AppGame\Handler\Promotion\InfoHandler;
- use App\Module\AppGame\Handler\Promotion\ListHandler;
- use App\Module\UrsPromotion\Services\UrsUserMappingService;
- use Illuminate\Console\Command;
- use Uraus\Kku\Request\RequestPromotionInfo;
- use Uraus\Kku\Request\RequestPromotionList;
- use Uraus\Kku\Common\RequestPage;
- use Uraus\Kku\Response;
- /**
- * 测试推广Handler功能
- */
- class TestPromotionHandlerCommand extends Command
- {
- /**
- * 命令签名
- *
- * @var string
- */
- protected $signature = 'test:promotion-handler {user_id : 农场用户ID}';
- /**
- * 命令描述
- *
- * @var string
- */
- protected $description = '测试推广数据获取Handler功能';
- /**
- * 执行命令
- */
- public function handle()
- {
- $userId = (int)$this->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})";
- }
- }
|