setName('test_jst_spu') ->addArgument('spu', Argument::REQUIRED, 'SPU编码') ->setDescription('测试聚水潭按SPU拉取商品接口'); } protected function execute(Input $input, Output $output) { $spu = $input->getArgument('spu'); if (empty($spu)) { $output->error('请提供SPU编码'); $output->info('用法: php think test_jst_spu SPU编码'); $output->info('示例: php think test_jst_spu test123'); return; } $output->info('正在调用聚水潭API获取商品信息...'); $output->info('SPU: ' . $spu); $output->newLine(); try { $startTime = microtime(true); $haichaoJst = HaichaoJstServices::getServices(); $result = $haichaoJst->getProductListKuan($spu); $endTime = microtime(true); $costTime = round(($endTime - $startTime) * 1000, 2); $output->info('✅ API调用成功! 耗时: ' . $costTime . 'ms'); $output->newLine(); if (empty($result)) { $output->warning('⚠️ 未获取到任何数据'); return; } $output->info('📦 获取到的数据:'); $output->write(json_encode($result, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)); $output->newLine(); if (isset($result['code'])) { $output->info('响应码: ' . $result['code']); } if (isset($result['msg'])) { $output->info('响应消息: ' . $result['msg']); } if (isset($result['datas'])) { $output->info('商品数量: ' . count($result['datas'])); if (!empty($result['datas'])) { $output->newLine(); $output->info('📋 第一个商品信息:'); $firstProduct = $result['datas'][0]; $output->writeln(' - SPU ID: ' . ($firstProduct['i_id'] ?? 'N/A')); $output->writeln(' - 商品名称: ' . ($firstProduct['name'] ?? 'N/A')); $output->writeln(' - 售价: ' . ($firstProduct['s_price'] ?? 'N/A')); $output->writeln(' - 市场价: ' . ($firstProduct['market_price'] ?? 'N/A')); $output->writeln(' - 成本价: ' . ($firstProduct['c_price'] ?? 'N/A')); if (isset($firstProduct['skus']) && is_array($firstProduct['skus'])) { $output->writeln(' - SKU数量: ' . count($firstProduct['skus'])); } } } $output->newLine(); } catch (\Throwable $e) { $output->error('❌ API调用失败!'); $output->error('错误信息: ' . $e->getMessage()); $output->error('错误文件: ' . $e->getFile() . ':' . $e->getLine()); $output->newLine(); $output->info('堆栈跟踪:'); $output->write($e->getTraceAsString()); } } }