@gt6/sdk 1.0.36 → 1.0.38

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.
@@ -619,6 +619,96 @@ class ArticlesAPI {
619
619
  depth: actualDepth
620
620
  };
621
621
  }
622
+ /******************************************************************************************
623
+ * 1.1 根据文章ID获取文章详情(平台用户都可以使用)
624
+ */
625
+ async getArticle_all(articleId) {
626
+ return this.client.request(`/articles_all/${articleId}.json`);
627
+ }
628
+ /**
629
+ * 1.2 根据分类ID获取文章列表(平台用户都可以使用)
630
+ */
631
+ async getArticlesByCategory_all(categoryId, options) {
632
+ // 从大型分类静态文件获取该分类的文章ID列表
633
+ const categoryData = await this.client.request(`/big-article-categories/${categoryId}.json`);
634
+ if (!categoryData || !categoryData.articleIds || categoryData.articleIds.length === 0) {
635
+ return {
636
+ articles: [],
637
+ total: 0,
638
+ page: options?.page || 1,
639
+ limit: options?.limit || 10
640
+ };
641
+ }
642
+ // 应用分页
643
+ const page = options?.page || 1;
644
+ const limit = options?.limit || 10;
645
+ const offset = (page - 1) * limit;
646
+ const paginatedArticleIds = categoryData.articleIds.slice(offset, offset + limit);
647
+ // 获取文章详情
648
+ const articles = await Promise.all(paginatedArticleIds.map(articleId => this.getArticle_all(articleId)));
649
+ // 应用状态过滤
650
+ let filteredArticles = articles;
651
+ if (options?.status) {
652
+ filteredArticles = articles.filter(article => article.status === options.status);
653
+ }
654
+ return {
655
+ articles: filteredArticles,
656
+ total: categoryData.articleIds.length,
657
+ page,
658
+ limit
659
+ };
660
+ }
661
+ /**
662
+ * 1.3 获取文章分类列表(平台用户都可以使用)
663
+ */
664
+ async getArticlesCategories_all(rootCategoryId) {
665
+ const config = this.client.getConfig();
666
+ const categoryId = rootCategoryId || config.rootCategoryId;
667
+ const response = await this.client.request(`/big-article-categories/platform-${config.platformId}-root-${categoryId}.json`);
668
+ return response.categories;
669
+ }
670
+ /**
671
+ * 1.4 根据单个标签ID获取平台文章列表
672
+ * 使用getTags_p_single获取指定标签数据,然后获取文章详情
673
+ * @param tagId 单个标签ID
674
+ * @param options 查询选项
675
+ */
676
+ async getArticlesByTag_single_all(tagId, options) {
677
+ // 获取指定标签的数据
678
+ const tagData = await this.getTags_p_single(tagId);
679
+ if (!tagData || !tagData.articleIds || tagData.articleIds.length === 0) {
680
+ // 剔除articleIds字段
681
+ const { articleIds, ...tagInfo } = tagData;
682
+ return {
683
+ articles: [],
684
+ total: 0,
685
+ page: options?.page || 1,
686
+ limit: options?.limit || 10,
687
+ tag: tagInfo
688
+ };
689
+ }
690
+ // 应用分页
691
+ const page = options?.page || 1;
692
+ const limit = options?.limit || 10;
693
+ const offset = (page - 1) * limit;
694
+ const paginatedArticleIds = tagData.articleIds.slice(offset, offset + limit);
695
+ // 获取文章详情
696
+ const articles = await Promise.all(paginatedArticleIds.map(articleId => this.getArticle_all(articleId)));
697
+ // 应用状态过滤
698
+ let filteredArticles = articles;
699
+ if (options?.status) {
700
+ filteredArticles = articles.filter(article => article.status === options.status);
701
+ }
702
+ // 剔除articleIds字段
703
+ const { articleIds, ...tagInfo } = tagData;
704
+ return {
705
+ articles: filteredArticles,
706
+ total: tagData.articleIds.length,
707
+ page,
708
+ limit,
709
+ tag: tagInfo
710
+ };
711
+ }
622
712
  }
623
713
 
624
714
  class ProductsAPI {
@@ -743,65 +833,6 @@ class ProductsAPI {
743
833
  }
744
834
  return product;
745
835
  }
746
- /**
747
- * 1.2. 根据产品ID全部产品详情(包括自定义和平台)
748
- */
749
- async getProduct_all(productId) {
750
- const product = await this.client.request(`/products_all/${productId}.json`);
751
- // 检查产品是否有销售区域和税费模板
752
- if (product.regions_Parent && product.regions_Parent.length > 0 &&
753
- product.taxTemplates && product.taxTemplates.length > 0) {
754
- try {
755
- // 获取税费信息
756
- const taxInfo = await this.getTaxInfo01(product.platformId);
757
- // 为每个税费模板添加规则
758
- product.taxTemplates = product.taxTemplates.map(template => {
759
- const matchingTemplate = taxInfo.templates.find(t => t.templateId === template.templateId);
760
- if (matchingTemplate) {
761
- // 过滤出产品可销售区域的规则
762
- const productRegionIds = product.regions_Parent.map(r => r.regionId);
763
- const applicableRules = matchingTemplate.rules.filter(rule => productRegionIds.includes(rule.regionId));
764
- return {
765
- ...template,
766
- rules: applicableRules
767
- };
768
- }
769
- return template;
770
- });
771
- }
772
- catch (error) {
773
- // 如果获取税费信息失败,不影响产品详情返回
774
- console.warn('Failed to fetch tax info:', error);
775
- }
776
- }
777
- // 检查产品是否有销售区域和运费模板
778
- if (product.regions_Parent && product.regions_Parent.length > 0 &&
779
- product.shippingTemplates && product.shippingTemplates.length > 0) {
780
- try {
781
- // 获取运费信息
782
- const shippingInfo = await this.getShippingInfo01(product.platformId);
783
- // 为每个运费模板添加规则
784
- product.shippingTemplates = product.shippingTemplates.map(template => {
785
- const matchingTemplate = shippingInfo.templates.find(t => t.templateId === template.templateId);
786
- if (matchingTemplate) {
787
- // 过滤出产品可销售区域的规则
788
- const productRegionIds = product.regions_Parent.map(r => r.regionId);
789
- const applicableRules = matchingTemplate.rules.filter(rule => productRegionIds.includes(rule.regionId));
790
- return {
791
- ...template,
792
- rules: applicableRules
793
- };
794
- }
795
- return template;
796
- });
797
- }
798
- catch (error) {
799
- // 如果获取运费信息失败,不影响产品详情返回
800
- console.warn('Failed to fetch shipping info:', error);
801
- }
802
- }
803
- return product;
804
- }
805
836
  /**
806
837
  * 2. 获取产品分类列表
807
838
  */
@@ -1477,6 +1508,166 @@ class ProductsAPI {
1477
1508
  const attribute = method.attrs.find(attr => attr.attrName === attrName);
1478
1509
  return attribute ? attribute.attrValue : null;
1479
1510
  }
1511
+ /******************************************************************************************
1512
+ * 1.1 根据产品ID获取产品详情(平台用户都可以使用)
1513
+ */
1514
+ async getProduct_all(productId) {
1515
+ const product = await this.client.request(`/products_all/${productId}.json`);
1516
+ // 检查产品是否有销售区域和税费模板
1517
+ if (product.regions_Parent && product.regions_Parent.length > 0 &&
1518
+ product.taxTemplates && product.taxTemplates.length > 0) {
1519
+ try {
1520
+ // 获取税费信息
1521
+ const taxInfo = await this.getTaxInfo01(product.platformId);
1522
+ // 为每个税费模板添加规则
1523
+ product.taxTemplates = product.taxTemplates.map(template => {
1524
+ const matchingTemplate = taxInfo.templates.find(t => t.templateId === template.templateId);
1525
+ if (matchingTemplate) {
1526
+ // 过滤出产品可销售区域的规则
1527
+ const productRegionIds = product.regions_Parent.map(r => r.regionId);
1528
+ const applicableRules = matchingTemplate.rules.filter(rule => productRegionIds.includes(rule.regionId));
1529
+ return {
1530
+ ...template,
1531
+ rules: applicableRules
1532
+ };
1533
+ }
1534
+ return template;
1535
+ });
1536
+ }
1537
+ catch (error) {
1538
+ // 如果获取税费信息失败,不影响产品详情返回
1539
+ console.warn('Failed to fetch tax info:', error);
1540
+ }
1541
+ }
1542
+ // 检查产品是否有销售区域和运费模板
1543
+ if (product.regions_Parent && product.regions_Parent.length > 0 &&
1544
+ product.shippingTemplates && product.shippingTemplates.length > 0) {
1545
+ try {
1546
+ // 获取运费信息
1547
+ const shippingInfo = await this.getShippingInfo01(product.platformId);
1548
+ // 为每个运费模板添加规则
1549
+ product.shippingTemplates = product.shippingTemplates.map(template => {
1550
+ const matchingTemplate = shippingInfo.templates.find(t => t.templateId === template.templateId);
1551
+ if (matchingTemplate) {
1552
+ // 过滤出产品可销售区域的规则
1553
+ const productRegionIds = product.regions_Parent.map(r => r.regionId);
1554
+ const applicableRules = matchingTemplate.rules.filter(rule => productRegionIds.includes(rule.regionId));
1555
+ return {
1556
+ ...template,
1557
+ rules: applicableRules
1558
+ };
1559
+ }
1560
+ return template;
1561
+ });
1562
+ }
1563
+ catch (error) {
1564
+ // 如果获取运费信息失败,不影响产品详情返回
1565
+ console.warn('Failed to fetch shipping info:', error);
1566
+ }
1567
+ }
1568
+ return product;
1569
+ }
1570
+ /**
1571
+ * 1.2 获取平台产品分类列表
1572
+ */
1573
+ async getProductsCategories_all(productRootCategoryId) {
1574
+ const config = this.client.getConfig();
1575
+ const categoryId = productRootCategoryId || config.productRootCategoryId;
1576
+ const response = await this.client.request(`/big-product-categories/platform-${config.platformId}-root-${categoryId}.json`);
1577
+ return response.categories;
1578
+ }
1579
+ /**
1580
+ * 1.3 根据大分类ID获取平台产品列表
1581
+ * 适配big-product-categories/${categoryId}.json新结构,支持排序和分页,直接返回数据
1582
+ * @param categoryId 分类ID
1583
+ * @param options { page, limit, sortBy }
1584
+ * sortBy: 'createdAt-desc' | 'createdAt-asc' | 'price-desc' | 'price-asc'
1585
+ */
1586
+ async getProductsByCategory_all(categoryId, options) {
1587
+ // 从大型分类静态文件获取该分类的产品信息列表
1588
+ const categoryData = await this.client.request(`/big-product-categories/${categoryId}.json`);
1589
+ if (!categoryData || !categoryData.productInfos || categoryData.productInfos.length === 0) {
1590
+ return {
1591
+ products: [],
1592
+ total: 0,
1593
+ page: options?.page || 1,
1594
+ limit: options?.limit || 10
1595
+ };
1596
+ }
1597
+ // 排序
1598
+ let sortedProducts = [...categoryData.productInfos];
1599
+ const sortBy = options?.sortBy || 'createdAt-desc';
1600
+ if (sortBy === 'createdAt-desc') {
1601
+ sortedProducts.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
1602
+ }
1603
+ else if (sortBy === 'createdAt-asc') {
1604
+ sortedProducts.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
1605
+ }
1606
+ else if (sortBy === 'price-desc') {
1607
+ sortedProducts.sort((a, b) => parseFloat(b.price) - parseFloat(a.price));
1608
+ }
1609
+ else if (sortBy === 'price-asc') {
1610
+ sortedProducts.sort((a, b) => parseFloat(a.price) - parseFloat(b.price));
1611
+ }
1612
+ // 应用分页
1613
+ const page = options?.page || 1;
1614
+ const limit = options?.limit || 10;
1615
+ const offset = (page - 1) * limit;
1616
+ const paginatedProducts = sortedProducts.slice(offset, offset + limit);
1617
+ // 应用状态过滤(如果有status字段)
1618
+ let filteredProducts = paginatedProducts;
1619
+ if (options?.status !== undefined) {
1620
+ filteredProducts = paginatedProducts.filter(product => product.status === options.status);
1621
+ }
1622
+ return {
1623
+ products: filteredProducts,
1624
+ total: categoryData.productInfos.length,
1625
+ page,
1626
+ limit
1627
+ };
1628
+ }
1629
+ /**
1630
+ * 1.4 根据单个标签ID获取平台产品列表
1631
+ * 使用getTags_p_single获取指定标签数据,然后获取产品详情
1632
+ * @param tagId 单个标签ID
1633
+ * @param options 查询选项
1634
+ */
1635
+ async getProductsByTag_single_all(tagId, options) {
1636
+ // 获取指定标签的数据
1637
+ const tagData = await this.getTags_p_single(tagId);
1638
+ if (!tagData || !tagData.productIds || tagData.productIds.length === 0) {
1639
+ // 剔除productIds字段
1640
+ const { productIds, ...tagInfo } = tagData;
1641
+ return {
1642
+ products: [],
1643
+ total: 0,
1644
+ page: options?.page || 1,
1645
+ limit: options?.limit || 10,
1646
+ tag: tagInfo
1647
+ };
1648
+ }
1649
+ // 应用分页
1650
+ const page = options?.page || 1;
1651
+ const limit = options?.limit || 10;
1652
+ const offset = (page - 1) * limit;
1653
+ const paginatedProductIds = tagData.productIds.slice(offset, offset + limit);
1654
+ // 获取产品详情
1655
+ const products = await Promise.all(paginatedProductIds.map(productId => this.getProduct_all(productId)));
1656
+ // 应用状态过滤
1657
+ let filteredProducts = products;
1658
+ if (options?.status !== undefined) {
1659
+ filteredProducts = products.filter(product => product.status === options.status);
1660
+ }
1661
+ // 剔除productIds字段
1662
+ const { productIds, ...tagInfo } = tagData;
1663
+ return {
1664
+ products: filteredProducts,
1665
+ total: tagData.productIds.length,
1666
+ page,
1667
+ limit,
1668
+ tag: tagInfo
1669
+ };
1670
+ }
1480
1671
  }
1481
1672
 
1482
1673
  class SettingsAPI {
@@ -2880,8 +3071,32 @@ class GT6SDK {
2880
3071
  async getArticlesByCategory(categoryId, options) {
2881
3072
  return this.articles.getArticlesByCategory(categoryId, options);
2882
3073
  }
3074
+ /*********************************************************************************************
3075
+ * 4.1. 便捷方法:根据分类ID获取文章列表(使用上级平台ID)
3076
+ */
3077
+ async getArticlesByCategory_all(categoryId, options) {
3078
+ return this.articles.getArticlesByCategory_all(categoryId, options);
3079
+ }
2883
3080
  /**
2884
- * 4.1. 便捷方法:根据分类ID获取文章列表(使用下级平台ID)
3081
+ * 4.2. 便捷方法:获取文章分类列表
3082
+ */
3083
+ async getArticlesCategories_all(rootCategoryId) {
3084
+ return this.articles.getArticlesCategories_all(rootCategoryId);
3085
+ }
3086
+ /**
3087
+ * 4.3. 便捷方法:根据单个标签ID获取平台文章列表
3088
+ */
3089
+ async getArticlesByTag_single_all(tagId, options) {
3090
+ return this.articles.getArticlesByTag_single_all(tagId, options);
3091
+ }
3092
+ /**
3093
+ * 4.4. 便捷方法:根据文章ID获取文章详情(使用上级平台ID)
3094
+ */
3095
+ async getArticle_all(articleId) {
3096
+ return this.articles.getArticle_all(articleId);
3097
+ }
3098
+ /*********************************************************************************************
3099
+ * 4.5. 便捷方法:根据分类ID获取文章列表(使用下级平台ID)
2885
3100
  */
2886
3101
  async getArticlesByCategory_p(categoryId, options) {
2887
3102
  return this.articles.getArticlesByCategory_p(categoryId, options);
@@ -2958,6 +3173,24 @@ class GT6SDK {
2958
3173
  async getCategories_b(rootCategoryId) {
2959
3174
  return this.products.getCategories_b(rootCategoryId);
2960
3175
  }
3176
+ /**
3177
+ * 8.1.2. 便捷方法:获取父平台产品分类列表
3178
+ */
3179
+ async getProductsCategories_all(productRootCategoryId) {
3180
+ return this.products.getProductsCategories_all(productRootCategoryId);
3181
+ }
3182
+ /**
3183
+ * 8.1.3. 便捷方法:根据大分类ID获取平台产品列表
3184
+ */
3185
+ async getProductsByCategory_all(categoryId, options) {
3186
+ return this.products.getProductsByCategory_all(categoryId, options);
3187
+ }
3188
+ /**
3189
+ * 8.1.4. 便捷方法:根据单个标签ID获取平台产品列表
3190
+ */
3191
+ async getProductsByTag_single_all(tagId, options) {
3192
+ return this.products.getProductsByTag_single_all(tagId, options);
3193
+ }
2961
3194
  /**
2962
3195
  * 9. 便捷方法:获取产品分类列表
2963
3196
  */