param('page', 1); $limit = (int)$request->param('limit', 20); $keyword = $request->param('keyword', ''); $categoryId = $request->param('categoryId', ''); $minPrice = $request->param('minPrice', ''); $maxPrice = $request->param('maxPrice', ''); $sort = $request->param('sort', ''); // 构建搜索参数 $params = [ 'page' => max(1, $page), 'limit' => min(max(1, $limit), 50), ]; if (!empty($keyword)) { $params['keyword'] = $keyword; } if (!empty($categoryId)) { $params['categoryId'] = (int)$categoryId; } if ($minPrice !== '' && $minPrice > 0) { $params['minPrice'] = (float)$minPrice; } if ($maxPrice !== '' && $maxPrice > 0) { $params['maxPrice'] = (float)$maxPrice; } if (!empty($sort)) { $params['sort'] = $sort; } // 调用1688 API获取商品列表 $result = $productService->searchProducts($params); if ($result === false) { return app('json')->fail('获取1688商品列表失败,请查看日志'); } return app('json')->success($result); } /** * 获取1688分销商品详情 * * @param ProductService $productService * @return \think\response\Json * * @api {GET} /admin/alibaba/goods/detail 获取商品详情 * @apiParam {string} [access_token] 1688 access_token(不传则使用配置中的默认token) * @apiParam {int} productId 1688商品ID(必填) */ public function detail(ProductService $productService) { $request = app('request'); $productId = $request->param('productId', ''); if (empty($productId)) { return app('json')->fail('参数错误:productId不能为空'); } // 调用1688 API获取商品详情 $result = $productService->getProductDetail($productId); if ($result === false) { return app('json')->fail('获取1688商品详情失败,请查看日志'); } return app('json')->success($result); } }