@gt6/sdk 1.0.22 → 1.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,11 +25,6 @@ class GT6Client {
25
25
  async request(endpoint, options = {}) {
26
26
  const url = `${this.config.baseUrl}${endpoint}`;
27
27
  const cacheKey = `${options.method || 'GET'}:${url}`;
28
- // 添加调试信息
29
- console.log('🔍 SDK client.request - endpoint:', endpoint);
30
- console.log('🔍 SDK client.request - baseUrl:', this.config.baseUrl);
31
- console.log('🔍 SDK client.request - 完整URL:', url);
32
- console.log('🔍 SDK client.request - method:', options.method || 'GET');
33
28
  // 检查缓存(只对GET请求缓存)
34
29
  if (this.config.cache?.enabled && options.method !== 'POST' && options.method !== 'PUT' && options.method !== 'DELETE') {
35
30
  const cached = this.cache.get(cacheKey);
@@ -377,6 +372,65 @@ class ProductsAPI {
377
372
  }
378
373
  return product;
379
374
  }
375
+ /**
376
+ * 1.1. 根据产品ID获取父平台产品详情
377
+ */
378
+ async getProduct_p(productId) {
379
+ const product = await this.client.request(`/parentproducts/${productId}.json`);
380
+ // 检查产品是否有销售区域和税费模板
381
+ if (product.regions && product.regions.length > 0 &&
382
+ product.taxTemplates && product.taxTemplates.length > 0) {
383
+ try {
384
+ // 获取税费信息
385
+ const taxInfo = await this.getTaxInfo();
386
+ // 为每个税费模板添加规则
387
+ product.taxTemplates = product.taxTemplates.map(template => {
388
+ const matchingTemplate = taxInfo.templates.find(t => t.templateId === template.templateId);
389
+ if (matchingTemplate) {
390
+ // 过滤出产品可销售区域的规则
391
+ const productRegionIds = product.regions.map(r => r.regionId);
392
+ const applicableRules = matchingTemplate.rules.filter(rule => productRegionIds.includes(rule.regionId));
393
+ return {
394
+ ...template,
395
+ rules: applicableRules
396
+ };
397
+ }
398
+ return template;
399
+ });
400
+ }
401
+ catch (error) {
402
+ // 如果获取税费信息失败,不影响产品详情返回
403
+ console.warn('Failed to fetch tax info:', error);
404
+ }
405
+ }
406
+ // 检查产品是否有销售区域和运费模板
407
+ if (product.regions && product.regions.length > 0 &&
408
+ product.shippingTemplates && product.shippingTemplates.length > 0) {
409
+ try {
410
+ // 获取运费信息
411
+ const shippingInfo = await this.getShippingInfo();
412
+ // 为每个运费模板添加规则
413
+ product.shippingTemplates = product.shippingTemplates.map(template => {
414
+ const matchingTemplate = shippingInfo.templates.find(t => t.templateId === template.templateId);
415
+ if (matchingTemplate) {
416
+ // 过滤出产品可销售区域的规则
417
+ const productRegionIds = product.regions.map(r => r.regionId);
418
+ const applicableRules = matchingTemplate.rules.filter(rule => productRegionIds.includes(rule.regionId));
419
+ return {
420
+ ...template,
421
+ rules: applicableRules
422
+ };
423
+ }
424
+ return template;
425
+ });
426
+ }
427
+ catch (error) {
428
+ // 如果获取运费信息失败,不影响产品详情返回
429
+ console.warn('Failed to fetch shipping info:', error);
430
+ }
431
+ }
432
+ return product;
433
+ }
380
434
  /**
381
435
  * 2. 获取产品分类列表
382
436
  */
@@ -386,6 +440,15 @@ class ProductsAPI {
386
440
  const response = await this.client.request(`/product-categories/platform-${config.platformId}-root-${categoryId}.json`);
387
441
  return response.categories;
388
442
  }
443
+ /**
444
+ * 2.1. 获取平台产品分类列表
445
+ */
446
+ async getCategories_p(productRootCategoryId_p) {
447
+ const config = this.client.getConfig();
448
+ const categoryId = productRootCategoryId_p || config.productRootCategoryId_p;
449
+ const response = await this.client.request(`/product-categories/platform-${config.platformId_p}-root-${categoryId}.json`);
450
+ return response.categories;
451
+ }
389
452
  /**
390
453
  * 3. 获取产品标签列表
391
454
  */
@@ -395,6 +458,15 @@ class ProductsAPI {
395
458
  const response = await this.client.request(`/product-tags/platform-${config.platformId}-${alias}.json`);
396
459
  return response.tags;
397
460
  }
461
+ /**
462
+ * 3.1. 获取平台产品标签列表
463
+ */
464
+ async getTags_p(productTagAlias_p) {
465
+ const config = this.client.getConfig();
466
+ const alias = productTagAlias_p || config.productTagAlias_p;
467
+ const response = await this.client.request(`/product-tags/platform-${config.platformId_p}-${alias}.json`);
468
+ return response.tags;
469
+ }
398
470
  /**
399
471
  * 4. 根据分类ID获取产品列表
400
472
  * 支持单个分类ID或分类ID数组
@@ -455,6 +527,124 @@ class ProductsAPI {
455
527
  limit
456
528
  };
457
529
  }
530
+ /**
531
+ * 4.1. 根据分类ID获取平台产品列表
532
+ */
533
+ async getProductsByCategory_p(categoryId, options) {
534
+ // 获取分类数据
535
+ const categories = await this.getCategories_p();
536
+ // 递归查找分类的函数
537
+ const findCategoryById = (cats, targetId) => {
538
+ for (const cat of cats) {
539
+ if (cat.categoryId === targetId) {
540
+ return cat;
541
+ }
542
+ if (cat.children && cat.children.length > 0) {
543
+ const found = findCategoryById(cat.children, targetId);
544
+ if (found)
545
+ return found;
546
+ }
547
+ }
548
+ return null;
549
+ };
550
+ // 将单个分类ID转换为数组
551
+ const categoryIds = Array.isArray(categoryId) ? categoryId : [categoryId];
552
+ // 收集所有指定分类下的产品ID
553
+ const allProductIds = [];
554
+ categoryIds.forEach(id => {
555
+ const targetCategory = findCategoryById(categories, id);
556
+ if (targetCategory) {
557
+ allProductIds.push(...targetCategory.productIds);
558
+ }
559
+ });
560
+ // 去重
561
+ const uniqueProductIds = [...new Set(allProductIds)];
562
+ if (uniqueProductIds.length === 0) {
563
+ return {
564
+ products: [],
565
+ total: 0,
566
+ page: options?.page || 1,
567
+ limit: options?.limit || 10
568
+ };
569
+ }
570
+ // 应用分页
571
+ const page = options?.page || 1;
572
+ const limit = options?.limit || 10;
573
+ const offset = (page - 1) * limit;
574
+ const paginatedProductIds = uniqueProductIds.slice(offset, offset + limit);
575
+ // 获取产品详情
576
+ const products = await Promise.all(paginatedProductIds.map(productId => this.getProduct_p(productId)));
577
+ // 应用状态过滤
578
+ let filteredProducts = products;
579
+ if (options?.status !== undefined) {
580
+ filteredProducts = products.filter(product => product.status === options.status);
581
+ }
582
+ return {
583
+ products: filteredProducts,
584
+ total: uniqueProductIds.length,
585
+ page,
586
+ limit
587
+ };
588
+ }
589
+ /**
590
+ * 4.2. 根据分类ID获取平台产品列表
591
+ */
592
+ async getProductsByCategory_t(categoryId, options) {
593
+ // 获取分类数据
594
+ const categories = await this.getCategories();
595
+ // 递归查找分类的函数
596
+ const findCategoryById = (cats, targetId) => {
597
+ for (const cat of cats) {
598
+ if (cat.categoryId === targetId) {
599
+ return cat;
600
+ }
601
+ if (cat.children && cat.children.length > 0) {
602
+ const found = findCategoryById(cat.children, targetId);
603
+ if (found)
604
+ return found;
605
+ }
606
+ }
607
+ return null;
608
+ };
609
+ // 将单个分类ID转换为数组
610
+ const categoryIds = Array.isArray(categoryId) ? categoryId : [categoryId];
611
+ // 收集所有指定分类下的产品ID
612
+ const allProductIds = [];
613
+ categoryIds.forEach(id => {
614
+ const targetCategory = findCategoryById(categories, id);
615
+ if (targetCategory) {
616
+ allProductIds.push(...targetCategory.productIds);
617
+ }
618
+ });
619
+ // 去重
620
+ const uniqueProductIds = [...new Set(allProductIds)];
621
+ if (uniqueProductIds.length === 0) {
622
+ return {
623
+ products: [],
624
+ total: 0,
625
+ page: options?.page || 1,
626
+ limit: options?.limit || 10
627
+ };
628
+ }
629
+ // 应用分页
630
+ const page = options?.page || 1;
631
+ const limit = options?.limit || 10;
632
+ const offset = (page - 1) * limit;
633
+ const paginatedProductIds = uniqueProductIds.slice(offset, offset + limit);
634
+ // 获取产品详情
635
+ const products = await Promise.all(paginatedProductIds.map(productId => this.getProduct_p(productId)));
636
+ // 应用状态过滤
637
+ let filteredProducts = products;
638
+ if (options?.status !== undefined) {
639
+ filteredProducts = products.filter(product => product.status === options.status);
640
+ }
641
+ return {
642
+ products: filteredProducts,
643
+ total: uniqueProductIds.length,
644
+ page,
645
+ limit
646
+ };
647
+ }
458
648
  /**
459
649
  * 5. 根据标签ID获取产品列表
460
650
  * 支持单个标签ID或标签ID数组
@@ -501,6 +691,96 @@ class ProductsAPI {
501
691
  limit
502
692
  };
503
693
  }
694
+ /**
695
+ * 5.1. 根据标签ID获取平台产品列表
696
+ */
697
+ async getProductsByTag_p(tagId, options) {
698
+ // 获取标签数据,传递productTagAlias参数
699
+ const tags = await this.getTags_p(options?.productTagAlias);
700
+ // 将单个标签ID转换为数组
701
+ const tagIds = Array.isArray(tagId) ? tagId : [tagId];
702
+ // 收集所有指定标签下的产品ID
703
+ const allProductIds = [];
704
+ tagIds.forEach(id => {
705
+ const targetTag = tags.find(tag => tag.tagId === id);
706
+ if (targetTag) {
707
+ allProductIds.push(...targetTag.productIds);
708
+ }
709
+ });
710
+ // 去重
711
+ const uniqueProductIds = [...new Set(allProductIds)];
712
+ if (uniqueProductIds.length === 0) {
713
+ return {
714
+ products: [],
715
+ total: 0,
716
+ page: options?.page || 1,
717
+ limit: options?.limit || 10
718
+ };
719
+ }
720
+ // 应用分页
721
+ const page = options?.page || 1;
722
+ const limit = options?.limit || 10;
723
+ const offset = (page - 1) * limit;
724
+ const paginatedProductIds = uniqueProductIds.slice(offset, offset + limit);
725
+ // 获取产品详情
726
+ const products = await Promise.all(paginatedProductIds.map(productId => this.getProduct_p(productId)));
727
+ // 应用状态过滤
728
+ let filteredProducts = products;
729
+ if (options?.status !== undefined) {
730
+ filteredProducts = products.filter(product => product.status === options.status);
731
+ }
732
+ return {
733
+ products: filteredProducts,
734
+ total: uniqueProductIds.length,
735
+ page,
736
+ limit
737
+ };
738
+ }
739
+ /**
740
+ * 5.2. 根据标签ID获取平台产品列表
741
+ */
742
+ async getProductsByTag_t(tagId, options) {
743
+ // 获取标签数据,传递productTagAlias参数
744
+ const tags = await this.getTags(options?.productTagAlias);
745
+ // 将单个标签ID转换为数组
746
+ const tagIds = Array.isArray(tagId) ? tagId : [tagId];
747
+ // 收集所有指定标签下的产品ID
748
+ const allProductIds = [];
749
+ tagIds.forEach(id => {
750
+ const targetTag = tags.find(tag => tag.tagId === id);
751
+ if (targetTag) {
752
+ allProductIds.push(...targetTag.productIds);
753
+ }
754
+ });
755
+ // 去重
756
+ const uniqueProductIds = [...new Set(allProductIds)];
757
+ if (uniqueProductIds.length === 0) {
758
+ return {
759
+ products: [],
760
+ total: 0,
761
+ page: options?.page || 1,
762
+ limit: options?.limit || 10
763
+ };
764
+ }
765
+ // 应用分页
766
+ const page = options?.page || 1;
767
+ const limit = options?.limit || 10;
768
+ const offset = (page - 1) * limit;
769
+ const paginatedProductIds = uniqueProductIds.slice(offset, offset + limit);
770
+ // 获取产品详情
771
+ const products = await Promise.all(paginatedProductIds.map(productId => this.getProduct_p(productId)));
772
+ // 应用状态过滤
773
+ let filteredProducts = products;
774
+ if (options?.status !== undefined) {
775
+ filteredProducts = products.filter(product => product.status === options.status);
776
+ }
777
+ return {
778
+ products: filteredProducts,
779
+ total: uniqueProductIds.length,
780
+ page,
781
+ limit
782
+ };
783
+ }
504
784
  /**
505
785
  * 6. 根据分类ID获取该分类的层级路径
506
786
  * 用于前端面包屑导航
@@ -716,6 +996,16 @@ class SettingsAPI {
716
996
  const response = await this.client.request(`/settings/platform-${config.platformId}-${alias}.json`);
717
997
  return response.settings;
718
998
  }
999
+ /**
1000
+ * 获取平台全局设置列表
1001
+ * 根据平台ID和别名获取所有全局设置
1002
+ */
1003
+ async getSettings_p(settingAlias_p) {
1004
+ const config = this.client.getConfig();
1005
+ const alias = settingAlias_p || config.settingAlias_p || '01';
1006
+ const response = await this.client.request(`/settings/platform-${config.platformId_p}-${alias}.json`);
1007
+ return response.settings;
1008
+ }
719
1009
  /**
720
1010
  * 获取指定设置
721
1011
  * 根据设置key直接获取单个设置
@@ -731,6 +1021,21 @@ class SettingsAPI {
731
1021
  return null;
732
1022
  }
733
1023
  }
1024
+ /**
1025
+ * 获取平台用户指定设置
1026
+ * 根据设置key直接获取单个设置
1027
+ */
1028
+ async getSetting_p(key) {
1029
+ const config = this.client.getConfig();
1030
+ try {
1031
+ const response = await this.client.request(`/settings/platform-${config.platformId_p}-${key}.json`);
1032
+ return response.setting;
1033
+ }
1034
+ catch (error) {
1035
+ console.warn(`Failed to fetch setting ${key}:`, error);
1036
+ return null;
1037
+ }
1038
+ }
734
1039
  }
735
1040
 
736
1041
  class FormsAPI {
@@ -1358,10 +1663,7 @@ class UsersAPI {
1358
1663
  message: '用户未登录'
1359
1664
  };
1360
1665
  }
1361
- // 构建URL,确保查询参数正确编码
1362
- const url = `/web/user/addresses?userType=${encodeURIComponent(userType.toString())}`;
1363
- console.log('🔍 SDK getAddresses - 构建的URL:', url);
1364
- const response = await this.client.request(url, {
1666
+ const response = await this.client.request(`/web/user/addresses?userType=${userType}`, {
1365
1667
  method: 'GET',
1366
1668
  headers: {
1367
1669
  'Authorization': `Bearer ${token}`,
@@ -2069,30 +2371,72 @@ class GT6SDK {
2069
2371
  async getProduct(productId) {
2070
2372
  return this.products.getProduct(productId);
2071
2373
  }
2374
+ /**
2375
+ * 8.1. 便捷方法:根据产品ID获取父平台产品详情
2376
+ */
2377
+ async getProduct_p(productId) {
2378
+ return this.products.getProduct_p(productId);
2379
+ }
2072
2380
  /**
2073
2381
  * 9. 便捷方法:获取产品分类列表
2074
2382
  */
2075
2383
  async getProductCategories(productRootCategoryId) {
2076
2384
  return this.products.getCategories(productRootCategoryId);
2077
2385
  }
2386
+ /**
2387
+ * 9.1. 便捷方法:获取父平台产品分类列表
2388
+ */
2389
+ async getProductCategories_p(productRootCategoryId_p) {
2390
+ return this.products.getCategories_p(productRootCategoryId_p);
2391
+ }
2078
2392
  /**
2079
2393
  * 10. 便捷方法:获取产品标签列表
2080
2394
  */
2081
2395
  async getProductTags(productTagAlias) {
2082
2396
  return this.products.getTags(productTagAlias);
2083
2397
  }
2398
+ /**
2399
+ * 10.1. 便捷方法:获取父平台产品标签列表
2400
+ */
2401
+ async getProductTags_p(productTagAlias_p) {
2402
+ return this.products.getTags_p(productTagAlias_p);
2403
+ }
2084
2404
  /**
2085
2405
  * 11. 便捷方法:根据分类ID获取产品列表
2086
2406
  */
2087
2407
  async getProductsByCategory(categoryId, options) {
2088
2408
  return this.products.getProductsByCategory(categoryId, options);
2089
2409
  }
2410
+ /**
2411
+ * 11.1. 便捷方法:根据分类ID获取父平台产品列表
2412
+ */
2413
+ async getProductsByCategory_p(categoryId, options) {
2414
+ return this.products.getProductsByCategory_p(categoryId, options);
2415
+ }
2416
+ /**
2417
+ * 11.2. 便捷方法:根据分类ID获取父平台产品列表(使用当前分类数据)
2418
+ */
2419
+ async getProductsByCategory_t(categoryId, options) {
2420
+ return this.products.getProductsByCategory_t(categoryId, options);
2421
+ }
2090
2422
  /**
2091
2423
  * 12. 便捷方法:根据标签ID获取产品列表
2092
2424
  */
2093
2425
  async getProductsByTag(tagId, options) {
2094
2426
  return this.products.getProductsByTag(tagId, options);
2095
2427
  }
2428
+ /**
2429
+ * 12.1. 便捷方法:根据标签ID获取父平台产品列表
2430
+ */
2431
+ async getProductsByTag_p(tagId, options) {
2432
+ return this.products.getProductsByTag_p(tagId, options);
2433
+ }
2434
+ /**
2435
+ * 12.2. 便捷方法:根据标签ID获取父平台产品列表(使用当前标签数据)
2436
+ */
2437
+ async getProductsByTag_t(tagId, options) {
2438
+ return this.products.getProductsByTag_t(tagId, options);
2439
+ }
2096
2440
  /**
2097
2441
  * 13. 便捷方法:根据分类ID获取该分类的层级路径
2098
2442
  */
@@ -2129,12 +2473,24 @@ class GT6SDK {
2129
2473
  async getSettings(settingAlias) {
2130
2474
  return this.settings.getSettings(settingAlias);
2131
2475
  }
2476
+ /**
2477
+ * 18.1. 便捷方法:获取父平台全局设置列表
2478
+ */
2479
+ async getSettings_p(settingAlias_p) {
2480
+ return this.settings.getSettings_p(settingAlias_p);
2481
+ }
2132
2482
  /**
2133
2483
  * 19. 便捷方法:获取指定设置
2134
2484
  */
2135
2485
  async getSetting(key) {
2136
2486
  return this.settings.getSetting(key);
2137
2487
  }
2488
+ /**
2489
+ * 19.1. 便捷方法:获取父平台指定设置
2490
+ */
2491
+ async getSetting_p(key) {
2492
+ return this.settings.getSetting_p(key);
2493
+ }
2138
2494
  /**
2139
2495
  * 20. 便捷方法:获取支付方式列表
2140
2496
  */