Procházet zdrojové kódy

feat(admin): 添加1688商品类目获取功能

- 在路由中新增 category 接口
- 实现 Goods 控制器中的 category 方法
- 添加 ProductService 的 getCategories 服务方法
- 集成 alibaba.category.get-1 API 接口
- 支持通过 categoryId 参数获取指定类目信息
- 提供完整的 API 文档注释
shichen před 2 měsíci
rodič
revize
0a105ca16d

+ 28 - 0
app/controller/admin/alibaba/Goods.php

@@ -151,4 +151,32 @@ class Goods
151 151
 
152 152
         return app('json')->fail('入库失败:' . implode('; ', array_values($result['fail'])));
153 153
     }
154
+
155
+    /**
156
+     * 获取1688商品类目列表
157
+     *
158
+     * API: com.alibaba.product:alibaba.category.get-1
159
+     * 文档: https://open.1688.com/api/apidocdetail.htm?id=com.alibaba.product%3Aalibaba.category.get-1
160
+     *
161
+     * @param ProductService $productService
162
+     * @return mixed
163
+     *
164
+     * @api {GET} /admin/alibaba/goods/category 获取商品类目
165
+     * @apiParam {string}  [access_token]  1688 access_token(不传则使用配置中的默认token)
166
+     * @apiParam {int}     [categoryId=0]  类目ID,顶级类目传0
167
+     */
168
+    public function category(ProductService $productService)
169
+    {
170
+        $request = app('request');
171
+
172
+        $categoryId = (int)$request->param('categoryId', 0);
173
+
174
+        $result = $productService->getCategories($categoryId);
175
+
176
+        if ($result === false) {
177
+            return app('json')->fail('获取1688商品类目失败,请查看日志!');
178
+        }
179
+
180
+        return app('json')->success($result);
181
+    }
154 182
 }

+ 29 - 0
app/services/ThirdParty/AlibabaAgent/ProductService.php

@@ -741,4 +741,33 @@ class ProductService extends AlibabaAgentBaseService
741 741
             'fail'    => $fail,
742 742
         ];
743 743
     }
744
+
745
+    /**
746
+     * 获取1688商品类目列表
747
+     *
748
+     * API: com.alibaba.product:alibaba.category.get-1
749
+     *
750
+     * @param string $categoryId 类目ID,顶级类目传0
751
+     * @return array|false
752
+     */
753
+    public function getCategories(string $categoryId = '0')
754
+    {
755
+        $businessParams = [
756
+            'categoryID' => $categoryId,
757
+        ];
758
+
759
+        $result = $this->executeParam2(
760
+            'com.alibaba.product',
761
+            'alibaba.category.get',
762
+            1,
763
+            $businessParams
764
+        );
765
+
766
+        if ($result === false) {
767
+            return false;
768
+        }
769
+
770
+        // 返回结果中的 categoryInfo 字段包含类目列表
771
+        return $result['result']['categoryInfo'] ?? $result['categoryInfo'] ?? [];
772
+    }
744 773
 }

+ 1 - 0
route/admin.php

@@ -718,6 +718,7 @@ Route::group(config('admin.api_admin_prefix') . '/', function () {
718 718
             Route::get('lst', '/lst')->name('alibabaGoodsLst');
719 719
             Route::get('detail', '/detail')->name('alibabaGoodsDetail');
720 720
             Route::post('import', '/import')->name('alibabaGoodsImport');
721
+            Route::get('category', '/category')->name('alibabaGoodsCategory');
721 722
         })->prefix('admin.alibaba.Goods');
722 723
 
723 724