@gt6/sdk 1.0.23 → 1.0.25
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.
- package/dist/core/types.d.ts +6 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/gt6-sdk.cjs.js +614 -0
- package/dist/gt6-sdk.cjs.js.map +1 -1
- package/dist/gt6-sdk.esm.js +614 -0
- package/dist/gt6-sdk.esm.js.map +1 -1
- package/dist/index.d.ts +104 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/modules/articles.d.ts +52 -0
- package/dist/modules/articles.d.ts.map +1 -1
- package/dist/modules/products.d.ts +48 -0
- package/dist/modules/products.d.ts.map +1 -1
- package/dist/modules/settings.d.ts +10 -0
- package/dist/modules/settings.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/gt6-sdk.cjs.js
CHANGED
@@ -107,6 +107,12 @@ class ArticlesAPI {
|
|
107
107
|
async getArticle(articleId) {
|
108
108
|
return this.client.request(`/articles/${articleId}.json`);
|
109
109
|
}
|
110
|
+
/**
|
111
|
+
* 1.1 根据文章ID获取文章详情(使用上级平台ID)
|
112
|
+
*/
|
113
|
+
async getArticle_p(articleId) {
|
114
|
+
return this.client.request(`/parentarticles/${articleId}.json`);
|
115
|
+
}
|
110
116
|
/**
|
111
117
|
* 2. 获取文章分类列表
|
112
118
|
*/
|
@@ -116,6 +122,15 @@ class ArticlesAPI {
|
|
116
122
|
const response = await this.client.request(`/article-categories/platform-${config.platformId}-root-${categoryId}.json`);
|
117
123
|
return response.categories;
|
118
124
|
}
|
125
|
+
/**
|
126
|
+
* 2.1 获取文章分类列表(使用下级平台ID)
|
127
|
+
*/
|
128
|
+
async getCategories_p(rootCategoryId_p) {
|
129
|
+
const config = this.client.getConfig();
|
130
|
+
const categoryId = rootCategoryId_p || config.rootCategoryId_p || '671920';
|
131
|
+
const response = await this.client.request(`/article-categories/platform-${config.platformId_p}-root-${categoryId}.json`);
|
132
|
+
return response.categories;
|
133
|
+
}
|
119
134
|
/**
|
120
135
|
* 3. 获取文章标签列表
|
121
136
|
*/
|
@@ -125,6 +140,15 @@ class ArticlesAPI {
|
|
125
140
|
const response = await this.client.request(`/article-tags/platform-${config.platformId}-${alias}.json`);
|
126
141
|
return response.tags;
|
127
142
|
}
|
143
|
+
/**
|
144
|
+
* 3.1 获取文章标签列表(使用下级平台ID)
|
145
|
+
*/
|
146
|
+
async getTags_p(tagAlias_p) {
|
147
|
+
const config = this.client.getConfig();
|
148
|
+
const alias = tagAlias_p || config.tagAlias_p || '001';
|
149
|
+
const response = await this.client.request(`/article-tags/platform-${config.platformId_p}-${alias}.json`);
|
150
|
+
return response.tags;
|
151
|
+
}
|
128
152
|
/**
|
129
153
|
* 4. 根据分类ID获取文章列表
|
130
154
|
* 支持单个分类ID或分类ID数组
|
@@ -171,6 +195,98 @@ class ArticlesAPI {
|
|
171
195
|
limit
|
172
196
|
};
|
173
197
|
}
|
198
|
+
/**
|
199
|
+
* 4.1 根据分类ID获取文章列表
|
200
|
+
* 支持单个分类ID或分类ID数组
|
201
|
+
*/
|
202
|
+
async getArticlesByCategory_p(categoryId, options) {
|
203
|
+
// 获取分类数据
|
204
|
+
const categories = await this.getCategories_p();
|
205
|
+
// 将单个分类ID转换为数组
|
206
|
+
const categoryIds = Array.isArray(categoryId) ? categoryId : [categoryId];
|
207
|
+
// 收集所有指定分类下的文章ID
|
208
|
+
const allArticleIds = [];
|
209
|
+
categoryIds.forEach(id => {
|
210
|
+
const targetCategory = categories.find(cat => cat.categoryId === id);
|
211
|
+
if (targetCategory) {
|
212
|
+
allArticleIds.push(...targetCategory.articleIds);
|
213
|
+
}
|
214
|
+
});
|
215
|
+
// 去重
|
216
|
+
const uniqueArticleIds = [...new Set(allArticleIds)];
|
217
|
+
if (uniqueArticleIds.length === 0) {
|
218
|
+
return {
|
219
|
+
articles: [],
|
220
|
+
total: 0,
|
221
|
+
page: options?.page || 1,
|
222
|
+
limit: options?.limit || 10
|
223
|
+
};
|
224
|
+
}
|
225
|
+
// 应用分页
|
226
|
+
const page = options?.page || 1;
|
227
|
+
const limit = options?.limit || 10;
|
228
|
+
const offset = (page - 1) * limit;
|
229
|
+
const paginatedArticleIds = uniqueArticleIds.slice(offset, offset + limit);
|
230
|
+
// 获取文章详情
|
231
|
+
const articles = await Promise.all(paginatedArticleIds.map(articleId => this.getArticle_p(articleId)));
|
232
|
+
// 应用状态过滤
|
233
|
+
let filteredArticles = articles;
|
234
|
+
if (options?.status) {
|
235
|
+
filteredArticles = articles.filter(article => article.status === options.status);
|
236
|
+
}
|
237
|
+
return {
|
238
|
+
articles: filteredArticles,
|
239
|
+
total: uniqueArticleIds.length,
|
240
|
+
page,
|
241
|
+
limit
|
242
|
+
};
|
243
|
+
}
|
244
|
+
/**
|
245
|
+
* 4.2 根据分类ID获取文章列表
|
246
|
+
* 支持单个分类ID或分类ID数组
|
247
|
+
*/
|
248
|
+
async getArticlesByCategory_t(categoryId, options) {
|
249
|
+
// 获取分类数据
|
250
|
+
const categories = await this.getCategories();
|
251
|
+
// 将单个分类ID转换为数组
|
252
|
+
const categoryIds = Array.isArray(categoryId) ? categoryId : [categoryId];
|
253
|
+
// 收集所有指定分类下的文章ID
|
254
|
+
const allArticleIds = [];
|
255
|
+
categoryIds.forEach(id => {
|
256
|
+
const targetCategory = categories.find(cat => cat.categoryId === id);
|
257
|
+
if (targetCategory) {
|
258
|
+
allArticleIds.push(...targetCategory.articleIds);
|
259
|
+
}
|
260
|
+
});
|
261
|
+
// 去重
|
262
|
+
const uniqueArticleIds = [...new Set(allArticleIds)];
|
263
|
+
if (uniqueArticleIds.length === 0) {
|
264
|
+
return {
|
265
|
+
articles: [],
|
266
|
+
total: 0,
|
267
|
+
page: options?.page || 1,
|
268
|
+
limit: options?.limit || 10
|
269
|
+
};
|
270
|
+
}
|
271
|
+
// 应用分页
|
272
|
+
const page = options?.page || 1;
|
273
|
+
const limit = options?.limit || 10;
|
274
|
+
const offset = (page - 1) * limit;
|
275
|
+
const paginatedArticleIds = uniqueArticleIds.slice(offset, offset + limit);
|
276
|
+
// 获取文章详情
|
277
|
+
const articles = await Promise.all(paginatedArticleIds.map(articleId => this.getArticle_p(articleId)));
|
278
|
+
// 应用状态过滤
|
279
|
+
let filteredArticles = articles;
|
280
|
+
if (options?.status) {
|
281
|
+
filteredArticles = articles.filter(article => article.status === options.status);
|
282
|
+
}
|
283
|
+
return {
|
284
|
+
articles: filteredArticles,
|
285
|
+
total: uniqueArticleIds.length,
|
286
|
+
page,
|
287
|
+
limit
|
288
|
+
};
|
289
|
+
}
|
174
290
|
/**
|
175
291
|
* 5. 根据标签ID获取文章列表
|
176
292
|
* 支持单个标签ID或标签ID数组
|
@@ -217,6 +333,98 @@ class ArticlesAPI {
|
|
217
333
|
limit
|
218
334
|
};
|
219
335
|
}
|
336
|
+
/**
|
337
|
+
* 5.1 根据标签ID获取文章列表
|
338
|
+
* 支持单个标签ID或标签ID数组
|
339
|
+
*/
|
340
|
+
async getArticlesByTag_p(tagId, options) {
|
341
|
+
// 获取标签数据,传递tagAlias参数
|
342
|
+
const tags = await this.getTags_p(options?.tagAlias);
|
343
|
+
// 将单个标签ID转换为数组
|
344
|
+
const tagIds = Array.isArray(tagId) ? tagId : [tagId];
|
345
|
+
// 收集所有指定标签下的文章ID
|
346
|
+
const allArticleIds = [];
|
347
|
+
tagIds.forEach(id => {
|
348
|
+
const targetTag = tags.find(tag => tag.tagId === id);
|
349
|
+
if (targetTag) {
|
350
|
+
allArticleIds.push(...targetTag.articleIds);
|
351
|
+
}
|
352
|
+
});
|
353
|
+
// 去重
|
354
|
+
const uniqueArticleIds = [...new Set(allArticleIds)];
|
355
|
+
if (uniqueArticleIds.length === 0) {
|
356
|
+
return {
|
357
|
+
articles: [],
|
358
|
+
total: 0,
|
359
|
+
page: options?.page || 1,
|
360
|
+
limit: options?.limit || 10
|
361
|
+
};
|
362
|
+
}
|
363
|
+
// 应用分页
|
364
|
+
const page = options?.page || 1;
|
365
|
+
const limit = options?.limit || 10;
|
366
|
+
const offset = (page - 1) * limit;
|
367
|
+
const paginatedArticleIds = uniqueArticleIds.slice(offset, offset + limit);
|
368
|
+
// 获取文章详情
|
369
|
+
const articles = await Promise.all(paginatedArticleIds.map(articleId => this.getArticle_p(articleId)));
|
370
|
+
// 应用状态过滤
|
371
|
+
let filteredArticles = articles;
|
372
|
+
if (options?.status) {
|
373
|
+
filteredArticles = articles.filter(article => article.status === options.status);
|
374
|
+
}
|
375
|
+
return {
|
376
|
+
articles: filteredArticles,
|
377
|
+
total: uniqueArticleIds.length,
|
378
|
+
page,
|
379
|
+
limit
|
380
|
+
};
|
381
|
+
}
|
382
|
+
/**
|
383
|
+
* 5.2 根据标签ID获取文章列表
|
384
|
+
* 支持单个标签ID或标签ID数组
|
385
|
+
*/
|
386
|
+
async getArticlesByTag_t(tagId, options) {
|
387
|
+
// 获取标签数据,传递tagAlias参数
|
388
|
+
const tags = await this.getTags(options?.tagAlias);
|
389
|
+
// 将单个标签ID转换为数组
|
390
|
+
const tagIds = Array.isArray(tagId) ? tagId : [tagId];
|
391
|
+
// 收集所有指定标签下的文章ID
|
392
|
+
const allArticleIds = [];
|
393
|
+
tagIds.forEach(id => {
|
394
|
+
const targetTag = tags.find(tag => tag.tagId === id);
|
395
|
+
if (targetTag) {
|
396
|
+
allArticleIds.push(...targetTag.articleIds);
|
397
|
+
}
|
398
|
+
});
|
399
|
+
// 去重
|
400
|
+
const uniqueArticleIds = [...new Set(allArticleIds)];
|
401
|
+
if (uniqueArticleIds.length === 0) {
|
402
|
+
return {
|
403
|
+
articles: [],
|
404
|
+
total: 0,
|
405
|
+
page: options?.page || 1,
|
406
|
+
limit: options?.limit || 10
|
407
|
+
};
|
408
|
+
}
|
409
|
+
// 应用分页
|
410
|
+
const page = options?.page || 1;
|
411
|
+
const limit = options?.limit || 10;
|
412
|
+
const offset = (page - 1) * limit;
|
413
|
+
const paginatedArticleIds = uniqueArticleIds.slice(offset, offset + limit);
|
414
|
+
// 获取文章详情
|
415
|
+
const articles = await Promise.all(paginatedArticleIds.map(articleId => this.getArticle_p(articleId)));
|
416
|
+
// 应用状态过滤
|
417
|
+
let filteredArticles = articles;
|
418
|
+
if (options?.status) {
|
419
|
+
filteredArticles = articles.filter(article => article.status === options.status);
|
420
|
+
}
|
421
|
+
return {
|
422
|
+
articles: filteredArticles,
|
423
|
+
total: uniqueArticleIds.length,
|
424
|
+
page,
|
425
|
+
limit
|
426
|
+
};
|
427
|
+
}
|
220
428
|
/**
|
221
429
|
* 6. 根据分类ID获取该分类的层级路径
|
222
430
|
* 用于前端面包屑导航
|
@@ -376,6 +584,65 @@ class ProductsAPI {
|
|
376
584
|
}
|
377
585
|
return product;
|
378
586
|
}
|
587
|
+
/**
|
588
|
+
* 1.1. 根据产品ID获取父平台产品详情
|
589
|
+
*/
|
590
|
+
async getProduct_p(productId) {
|
591
|
+
const product = await this.client.request(`/parentproducts/${productId}.json`);
|
592
|
+
// 检查产品是否有销售区域和税费模板
|
593
|
+
if (product.regions && product.regions.length > 0 &&
|
594
|
+
product.taxTemplates && product.taxTemplates.length > 0) {
|
595
|
+
try {
|
596
|
+
// 获取税费信息
|
597
|
+
const taxInfo = await this.getTaxInfo();
|
598
|
+
// 为每个税费模板添加规则
|
599
|
+
product.taxTemplates = product.taxTemplates.map(template => {
|
600
|
+
const matchingTemplate = taxInfo.templates.find(t => t.templateId === template.templateId);
|
601
|
+
if (matchingTemplate) {
|
602
|
+
// 过滤出产品可销售区域的规则
|
603
|
+
const productRegionIds = product.regions.map(r => r.regionId);
|
604
|
+
const applicableRules = matchingTemplate.rules.filter(rule => productRegionIds.includes(rule.regionId));
|
605
|
+
return {
|
606
|
+
...template,
|
607
|
+
rules: applicableRules
|
608
|
+
};
|
609
|
+
}
|
610
|
+
return template;
|
611
|
+
});
|
612
|
+
}
|
613
|
+
catch (error) {
|
614
|
+
// 如果获取税费信息失败,不影响产品详情返回
|
615
|
+
console.warn('Failed to fetch tax info:', error);
|
616
|
+
}
|
617
|
+
}
|
618
|
+
// 检查产品是否有销售区域和运费模板
|
619
|
+
if (product.regions && product.regions.length > 0 &&
|
620
|
+
product.shippingTemplates && product.shippingTemplates.length > 0) {
|
621
|
+
try {
|
622
|
+
// 获取运费信息
|
623
|
+
const shippingInfo = await this.getShippingInfo();
|
624
|
+
// 为每个运费模板添加规则
|
625
|
+
product.shippingTemplates = product.shippingTemplates.map(template => {
|
626
|
+
const matchingTemplate = shippingInfo.templates.find(t => t.templateId === template.templateId);
|
627
|
+
if (matchingTemplate) {
|
628
|
+
// 过滤出产品可销售区域的规则
|
629
|
+
const productRegionIds = product.regions.map(r => r.regionId);
|
630
|
+
const applicableRules = matchingTemplate.rules.filter(rule => productRegionIds.includes(rule.regionId));
|
631
|
+
return {
|
632
|
+
...template,
|
633
|
+
rules: applicableRules
|
634
|
+
};
|
635
|
+
}
|
636
|
+
return template;
|
637
|
+
});
|
638
|
+
}
|
639
|
+
catch (error) {
|
640
|
+
// 如果获取运费信息失败,不影响产品详情返回
|
641
|
+
console.warn('Failed to fetch shipping info:', error);
|
642
|
+
}
|
643
|
+
}
|
644
|
+
return product;
|
645
|
+
}
|
379
646
|
/**
|
380
647
|
* 2. 获取产品分类列表
|
381
648
|
*/
|
@@ -385,6 +652,15 @@ class ProductsAPI {
|
|
385
652
|
const response = await this.client.request(`/product-categories/platform-${config.platformId}-root-${categoryId}.json`);
|
386
653
|
return response.categories;
|
387
654
|
}
|
655
|
+
/**
|
656
|
+
* 2.1. 获取平台产品分类列表
|
657
|
+
*/
|
658
|
+
async getCategories_p(productRootCategoryId_p) {
|
659
|
+
const config = this.client.getConfig();
|
660
|
+
const categoryId = productRootCategoryId_p || config.productRootCategoryId_p;
|
661
|
+
const response = await this.client.request(`/product-categories/platform-${config.platformId_p}-root-${categoryId}.json`);
|
662
|
+
return response.categories;
|
663
|
+
}
|
388
664
|
/**
|
389
665
|
* 3. 获取产品标签列表
|
390
666
|
*/
|
@@ -394,6 +670,15 @@ class ProductsAPI {
|
|
394
670
|
const response = await this.client.request(`/product-tags/platform-${config.platformId}-${alias}.json`);
|
395
671
|
return response.tags;
|
396
672
|
}
|
673
|
+
/**
|
674
|
+
* 3.1. 获取平台产品标签列表
|
675
|
+
*/
|
676
|
+
async getTags_p(productTagAlias_p) {
|
677
|
+
const config = this.client.getConfig();
|
678
|
+
const alias = productTagAlias_p || config.productTagAlias_p;
|
679
|
+
const response = await this.client.request(`/product-tags/platform-${config.platformId_p}-${alias}.json`);
|
680
|
+
return response.tags;
|
681
|
+
}
|
397
682
|
/**
|
398
683
|
* 4. 根据分类ID获取产品列表
|
399
684
|
* 支持单个分类ID或分类ID数组
|
@@ -454,6 +739,124 @@ class ProductsAPI {
|
|
454
739
|
limit
|
455
740
|
};
|
456
741
|
}
|
742
|
+
/**
|
743
|
+
* 4.1. 根据分类ID获取平台产品列表
|
744
|
+
*/
|
745
|
+
async getProductsByCategory_p(categoryId, options) {
|
746
|
+
// 获取分类数据
|
747
|
+
const categories = await this.getCategories_p();
|
748
|
+
// 递归查找分类的函数
|
749
|
+
const findCategoryById = (cats, targetId) => {
|
750
|
+
for (const cat of cats) {
|
751
|
+
if (cat.categoryId === targetId) {
|
752
|
+
return cat;
|
753
|
+
}
|
754
|
+
if (cat.children && cat.children.length > 0) {
|
755
|
+
const found = findCategoryById(cat.children, targetId);
|
756
|
+
if (found)
|
757
|
+
return found;
|
758
|
+
}
|
759
|
+
}
|
760
|
+
return null;
|
761
|
+
};
|
762
|
+
// 将单个分类ID转换为数组
|
763
|
+
const categoryIds = Array.isArray(categoryId) ? categoryId : [categoryId];
|
764
|
+
// 收集所有指定分类下的产品ID
|
765
|
+
const allProductIds = [];
|
766
|
+
categoryIds.forEach(id => {
|
767
|
+
const targetCategory = findCategoryById(categories, id);
|
768
|
+
if (targetCategory) {
|
769
|
+
allProductIds.push(...targetCategory.productIds);
|
770
|
+
}
|
771
|
+
});
|
772
|
+
// 去重
|
773
|
+
const uniqueProductIds = [...new Set(allProductIds)];
|
774
|
+
if (uniqueProductIds.length === 0) {
|
775
|
+
return {
|
776
|
+
products: [],
|
777
|
+
total: 0,
|
778
|
+
page: options?.page || 1,
|
779
|
+
limit: options?.limit || 10
|
780
|
+
};
|
781
|
+
}
|
782
|
+
// 应用分页
|
783
|
+
const page = options?.page || 1;
|
784
|
+
const limit = options?.limit || 10;
|
785
|
+
const offset = (page - 1) * limit;
|
786
|
+
const paginatedProductIds = uniqueProductIds.slice(offset, offset + limit);
|
787
|
+
// 获取产品详情
|
788
|
+
const products = await Promise.all(paginatedProductIds.map(productId => this.getProduct_p(productId)));
|
789
|
+
// 应用状态过滤
|
790
|
+
let filteredProducts = products;
|
791
|
+
if (options?.status !== undefined) {
|
792
|
+
filteredProducts = products.filter(product => product.status === options.status);
|
793
|
+
}
|
794
|
+
return {
|
795
|
+
products: filteredProducts,
|
796
|
+
total: uniqueProductIds.length,
|
797
|
+
page,
|
798
|
+
limit
|
799
|
+
};
|
800
|
+
}
|
801
|
+
/**
|
802
|
+
* 4.2. 根据分类ID获取平台产品列表
|
803
|
+
*/
|
804
|
+
async getProductsByCategory_t(categoryId, options) {
|
805
|
+
// 获取分类数据
|
806
|
+
const categories = await this.getCategories();
|
807
|
+
// 递归查找分类的函数
|
808
|
+
const findCategoryById = (cats, targetId) => {
|
809
|
+
for (const cat of cats) {
|
810
|
+
if (cat.categoryId === targetId) {
|
811
|
+
return cat;
|
812
|
+
}
|
813
|
+
if (cat.children && cat.children.length > 0) {
|
814
|
+
const found = findCategoryById(cat.children, targetId);
|
815
|
+
if (found)
|
816
|
+
return found;
|
817
|
+
}
|
818
|
+
}
|
819
|
+
return null;
|
820
|
+
};
|
821
|
+
// 将单个分类ID转换为数组
|
822
|
+
const categoryIds = Array.isArray(categoryId) ? categoryId : [categoryId];
|
823
|
+
// 收集所有指定分类下的产品ID
|
824
|
+
const allProductIds = [];
|
825
|
+
categoryIds.forEach(id => {
|
826
|
+
const targetCategory = findCategoryById(categories, id);
|
827
|
+
if (targetCategory) {
|
828
|
+
allProductIds.push(...targetCategory.productIds);
|
829
|
+
}
|
830
|
+
});
|
831
|
+
// 去重
|
832
|
+
const uniqueProductIds = [...new Set(allProductIds)];
|
833
|
+
if (uniqueProductIds.length === 0) {
|
834
|
+
return {
|
835
|
+
products: [],
|
836
|
+
total: 0,
|
837
|
+
page: options?.page || 1,
|
838
|
+
limit: options?.limit || 10
|
839
|
+
};
|
840
|
+
}
|
841
|
+
// 应用分页
|
842
|
+
const page = options?.page || 1;
|
843
|
+
const limit = options?.limit || 10;
|
844
|
+
const offset = (page - 1) * limit;
|
845
|
+
const paginatedProductIds = uniqueProductIds.slice(offset, offset + limit);
|
846
|
+
// 获取产品详情
|
847
|
+
const products = await Promise.all(paginatedProductIds.map(productId => this.getProduct_p(productId)));
|
848
|
+
// 应用状态过滤
|
849
|
+
let filteredProducts = products;
|
850
|
+
if (options?.status !== undefined) {
|
851
|
+
filteredProducts = products.filter(product => product.status === options.status);
|
852
|
+
}
|
853
|
+
return {
|
854
|
+
products: filteredProducts,
|
855
|
+
total: uniqueProductIds.length,
|
856
|
+
page,
|
857
|
+
limit
|
858
|
+
};
|
859
|
+
}
|
457
860
|
/**
|
458
861
|
* 5. 根据标签ID获取产品列表
|
459
862
|
* 支持单个标签ID或标签ID数组
|
@@ -500,6 +903,96 @@ class ProductsAPI {
|
|
500
903
|
limit
|
501
904
|
};
|
502
905
|
}
|
906
|
+
/**
|
907
|
+
* 5.1. 根据标签ID获取平台产品列表
|
908
|
+
*/
|
909
|
+
async getProductsByTag_p(tagId, options) {
|
910
|
+
// 获取标签数据,传递productTagAlias参数
|
911
|
+
const tags = await this.getTags_p(options?.productTagAlias);
|
912
|
+
// 将单个标签ID转换为数组
|
913
|
+
const tagIds = Array.isArray(tagId) ? tagId : [tagId];
|
914
|
+
// 收集所有指定标签下的产品ID
|
915
|
+
const allProductIds = [];
|
916
|
+
tagIds.forEach(id => {
|
917
|
+
const targetTag = tags.find(tag => tag.tagId === id);
|
918
|
+
if (targetTag) {
|
919
|
+
allProductIds.push(...targetTag.productIds);
|
920
|
+
}
|
921
|
+
});
|
922
|
+
// 去重
|
923
|
+
const uniqueProductIds = [...new Set(allProductIds)];
|
924
|
+
if (uniqueProductIds.length === 0) {
|
925
|
+
return {
|
926
|
+
products: [],
|
927
|
+
total: 0,
|
928
|
+
page: options?.page || 1,
|
929
|
+
limit: options?.limit || 10
|
930
|
+
};
|
931
|
+
}
|
932
|
+
// 应用分页
|
933
|
+
const page = options?.page || 1;
|
934
|
+
const limit = options?.limit || 10;
|
935
|
+
const offset = (page - 1) * limit;
|
936
|
+
const paginatedProductIds = uniqueProductIds.slice(offset, offset + limit);
|
937
|
+
// 获取产品详情
|
938
|
+
const products = await Promise.all(paginatedProductIds.map(productId => this.getProduct_p(productId)));
|
939
|
+
// 应用状态过滤
|
940
|
+
let filteredProducts = products;
|
941
|
+
if (options?.status !== undefined) {
|
942
|
+
filteredProducts = products.filter(product => product.status === options.status);
|
943
|
+
}
|
944
|
+
return {
|
945
|
+
products: filteredProducts,
|
946
|
+
total: uniqueProductIds.length,
|
947
|
+
page,
|
948
|
+
limit
|
949
|
+
};
|
950
|
+
}
|
951
|
+
/**
|
952
|
+
* 5.2. 根据标签ID获取平台产品列表
|
953
|
+
*/
|
954
|
+
async getProductsByTag_t(tagId, options) {
|
955
|
+
// 获取标签数据,传递productTagAlias参数
|
956
|
+
const tags = await this.getTags(options?.productTagAlias);
|
957
|
+
// 将单个标签ID转换为数组
|
958
|
+
const tagIds = Array.isArray(tagId) ? tagId : [tagId];
|
959
|
+
// 收集所有指定标签下的产品ID
|
960
|
+
const allProductIds = [];
|
961
|
+
tagIds.forEach(id => {
|
962
|
+
const targetTag = tags.find(tag => tag.tagId === id);
|
963
|
+
if (targetTag) {
|
964
|
+
allProductIds.push(...targetTag.productIds);
|
965
|
+
}
|
966
|
+
});
|
967
|
+
// 去重
|
968
|
+
const uniqueProductIds = [...new Set(allProductIds)];
|
969
|
+
if (uniqueProductIds.length === 0) {
|
970
|
+
return {
|
971
|
+
products: [],
|
972
|
+
total: 0,
|
973
|
+
page: options?.page || 1,
|
974
|
+
limit: options?.limit || 10
|
975
|
+
};
|
976
|
+
}
|
977
|
+
// 应用分页
|
978
|
+
const page = options?.page || 1;
|
979
|
+
const limit = options?.limit || 10;
|
980
|
+
const offset = (page - 1) * limit;
|
981
|
+
const paginatedProductIds = uniqueProductIds.slice(offset, offset + limit);
|
982
|
+
// 获取产品详情
|
983
|
+
const products = await Promise.all(paginatedProductIds.map(productId => this.getProduct_p(productId)));
|
984
|
+
// 应用状态过滤
|
985
|
+
let filteredProducts = products;
|
986
|
+
if (options?.status !== undefined) {
|
987
|
+
filteredProducts = products.filter(product => product.status === options.status);
|
988
|
+
}
|
989
|
+
return {
|
990
|
+
products: filteredProducts,
|
991
|
+
total: uniqueProductIds.length,
|
992
|
+
page,
|
993
|
+
limit
|
994
|
+
};
|
995
|
+
}
|
503
996
|
/**
|
504
997
|
* 6. 根据分类ID获取该分类的层级路径
|
505
998
|
* 用于前端面包屑导航
|
@@ -715,6 +1208,16 @@ class SettingsAPI {
|
|
715
1208
|
const response = await this.client.request(`/settings/platform-${config.platformId}-${alias}.json`);
|
716
1209
|
return response.settings;
|
717
1210
|
}
|
1211
|
+
/**
|
1212
|
+
* 获取平台全局设置列表
|
1213
|
+
* 根据平台ID和别名获取所有全局设置
|
1214
|
+
*/
|
1215
|
+
async getSettings_p(settingAlias_p) {
|
1216
|
+
const config = this.client.getConfig();
|
1217
|
+
const alias = settingAlias_p || config.settingAlias_p || '01';
|
1218
|
+
const response = await this.client.request(`/settings/platform-${config.platformId_p}-${alias}.json`);
|
1219
|
+
return response.settings;
|
1220
|
+
}
|
718
1221
|
/**
|
719
1222
|
* 获取指定设置
|
720
1223
|
* 根据设置key直接获取单个设置
|
@@ -730,6 +1233,21 @@ class SettingsAPI {
|
|
730
1233
|
return null;
|
731
1234
|
}
|
732
1235
|
}
|
1236
|
+
/**
|
1237
|
+
* 获取平台用户指定设置
|
1238
|
+
* 根据设置key直接获取单个设置
|
1239
|
+
*/
|
1240
|
+
async getSetting_p(key) {
|
1241
|
+
const config = this.client.getConfig();
|
1242
|
+
try {
|
1243
|
+
const response = await this.client.request(`/settings/platform-${config.platformId_p}-${key}.json`);
|
1244
|
+
return response.setting;
|
1245
|
+
}
|
1246
|
+
catch (error) {
|
1247
|
+
console.warn(`Failed to fetch setting ${key}:`, error);
|
1248
|
+
return null;
|
1249
|
+
}
|
1250
|
+
}
|
733
1251
|
}
|
734
1252
|
|
735
1253
|
class FormsAPI {
|
@@ -2023,30 +2541,72 @@ class GT6SDK {
|
|
2023
2541
|
async getArticle(articleId) {
|
2024
2542
|
return this.articles.getArticle(articleId);
|
2025
2543
|
}
|
2544
|
+
/**
|
2545
|
+
* 1.1. 便捷方法:根据文章ID获取文章详情(使用上级平台ID)
|
2546
|
+
*/
|
2547
|
+
async getArticle_p(articleId) {
|
2548
|
+
return this.articles.getArticle_p(articleId);
|
2549
|
+
}
|
2026
2550
|
/**
|
2027
2551
|
* 2. 便捷方法:获取文章分类列表
|
2028
2552
|
*/
|
2029
2553
|
async getCategories(rootCategoryId) {
|
2030
2554
|
return this.articles.getCategories(rootCategoryId);
|
2031
2555
|
}
|
2556
|
+
/**
|
2557
|
+
* 2.1. 便捷方法:获取文章分类列表(使用下级平台ID)
|
2558
|
+
*/
|
2559
|
+
async getCategories_p(rootCategoryId_p) {
|
2560
|
+
return this.articles.getCategories_p(rootCategoryId_p);
|
2561
|
+
}
|
2032
2562
|
/**
|
2033
2563
|
* 3. 便捷方法:获取文章标签列表
|
2034
2564
|
*/
|
2035
2565
|
async getTags(tagAlias) {
|
2036
2566
|
return this.articles.getTags(tagAlias);
|
2037
2567
|
}
|
2568
|
+
/**
|
2569
|
+
* 3.1. 便捷方法:获取文章标签列表(使用下级平台ID)
|
2570
|
+
*/
|
2571
|
+
async getTags_p(tagAlias_p) {
|
2572
|
+
return this.articles.getTags_p(tagAlias_p);
|
2573
|
+
}
|
2038
2574
|
/**
|
2039
2575
|
* 4. 便捷方法:根据分类ID获取文章列表
|
2040
2576
|
*/
|
2041
2577
|
async getArticlesByCategory(categoryId, options) {
|
2042
2578
|
return this.articles.getArticlesByCategory(categoryId, options);
|
2043
2579
|
}
|
2580
|
+
/**
|
2581
|
+
* 4.1. 便捷方法:根据分类ID获取文章列表(使用下级平台ID)
|
2582
|
+
*/
|
2583
|
+
async getArticlesByCategory_p(categoryId, options) {
|
2584
|
+
return this.articles.getArticlesByCategory_p(categoryId, options);
|
2585
|
+
}
|
2586
|
+
/**
|
2587
|
+
* 4.2. 便捷方法:根据分类ID获取文章列表(使用当前分类数据)
|
2588
|
+
*/
|
2589
|
+
async getArticlesByCategory_t(categoryId, options) {
|
2590
|
+
return this.articles.getArticlesByCategory_t(categoryId, options);
|
2591
|
+
}
|
2044
2592
|
/**
|
2045
2593
|
* 5. 便捷方法:根据标签ID获取文章列表
|
2046
2594
|
*/
|
2047
2595
|
async getArticlesByTag(tagId, options) {
|
2048
2596
|
return this.articles.getArticlesByTag(tagId, options);
|
2049
2597
|
}
|
2598
|
+
/**
|
2599
|
+
* 5.1. 便捷方法:根据标签ID获取文章列表(使用下级平台ID)
|
2600
|
+
*/
|
2601
|
+
async getArticlesByTag_p(tagId, options) {
|
2602
|
+
return this.articles.getArticlesByTag_p(tagId, options);
|
2603
|
+
}
|
2604
|
+
/**
|
2605
|
+
* 5.2. 便捷方法:根据标签ID获取文章列表(使用当前标签数据)
|
2606
|
+
*/
|
2607
|
+
async getArticlesByTag_t(tagId, options) {
|
2608
|
+
return this.articles.getArticlesByTag_t(tagId, options);
|
2609
|
+
}
|
2050
2610
|
/**
|
2051
2611
|
* 6. 便捷方法:根据分类ID获取该分类的层级路径
|
2052
2612
|
*/
|
@@ -2065,30 +2625,72 @@ class GT6SDK {
|
|
2065
2625
|
async getProduct(productId) {
|
2066
2626
|
return this.products.getProduct(productId);
|
2067
2627
|
}
|
2628
|
+
/**
|
2629
|
+
* 8.1. 便捷方法:根据产品ID获取父平台产品详情
|
2630
|
+
*/
|
2631
|
+
async getProduct_p(productId) {
|
2632
|
+
return this.products.getProduct_p(productId);
|
2633
|
+
}
|
2068
2634
|
/**
|
2069
2635
|
* 9. 便捷方法:获取产品分类列表
|
2070
2636
|
*/
|
2071
2637
|
async getProductCategories(productRootCategoryId) {
|
2072
2638
|
return this.products.getCategories(productRootCategoryId);
|
2073
2639
|
}
|
2640
|
+
/**
|
2641
|
+
* 9.1. 便捷方法:获取父平台产品分类列表
|
2642
|
+
*/
|
2643
|
+
async getProductCategories_p(productRootCategoryId_p) {
|
2644
|
+
return this.products.getCategories_p(productRootCategoryId_p);
|
2645
|
+
}
|
2074
2646
|
/**
|
2075
2647
|
* 10. 便捷方法:获取产品标签列表
|
2076
2648
|
*/
|
2077
2649
|
async getProductTags(productTagAlias) {
|
2078
2650
|
return this.products.getTags(productTagAlias);
|
2079
2651
|
}
|
2652
|
+
/**
|
2653
|
+
* 10.1. 便捷方法:获取父平台产品标签列表
|
2654
|
+
*/
|
2655
|
+
async getProductTags_p(productTagAlias_p) {
|
2656
|
+
return this.products.getTags_p(productTagAlias_p);
|
2657
|
+
}
|
2080
2658
|
/**
|
2081
2659
|
* 11. 便捷方法:根据分类ID获取产品列表
|
2082
2660
|
*/
|
2083
2661
|
async getProductsByCategory(categoryId, options) {
|
2084
2662
|
return this.products.getProductsByCategory(categoryId, options);
|
2085
2663
|
}
|
2664
|
+
/**
|
2665
|
+
* 11.1. 便捷方法:根据分类ID获取父平台产品列表
|
2666
|
+
*/
|
2667
|
+
async getProductsByCategory_p(categoryId, options) {
|
2668
|
+
return this.products.getProductsByCategory_p(categoryId, options);
|
2669
|
+
}
|
2670
|
+
/**
|
2671
|
+
* 11.2. 便捷方法:根据分类ID获取父平台产品列表(使用当前分类数据)
|
2672
|
+
*/
|
2673
|
+
async getProductsByCategory_t(categoryId, options) {
|
2674
|
+
return this.products.getProductsByCategory_t(categoryId, options);
|
2675
|
+
}
|
2086
2676
|
/**
|
2087
2677
|
* 12. 便捷方法:根据标签ID获取产品列表
|
2088
2678
|
*/
|
2089
2679
|
async getProductsByTag(tagId, options) {
|
2090
2680
|
return this.products.getProductsByTag(tagId, options);
|
2091
2681
|
}
|
2682
|
+
/**
|
2683
|
+
* 12.1. 便捷方法:根据标签ID获取父平台产品列表
|
2684
|
+
*/
|
2685
|
+
async getProductsByTag_p(tagId, options) {
|
2686
|
+
return this.products.getProductsByTag_p(tagId, options);
|
2687
|
+
}
|
2688
|
+
/**
|
2689
|
+
* 12.2. 便捷方法:根据标签ID获取父平台产品列表(使用当前标签数据)
|
2690
|
+
*/
|
2691
|
+
async getProductsByTag_t(tagId, options) {
|
2692
|
+
return this.products.getProductsByTag_t(tagId, options);
|
2693
|
+
}
|
2092
2694
|
/**
|
2093
2695
|
* 13. 便捷方法:根据分类ID获取该分类的层级路径
|
2094
2696
|
*/
|
@@ -2125,12 +2727,24 @@ class GT6SDK {
|
|
2125
2727
|
async getSettings(settingAlias) {
|
2126
2728
|
return this.settings.getSettings(settingAlias);
|
2127
2729
|
}
|
2730
|
+
/**
|
2731
|
+
* 18.1. 便捷方法:获取父平台全局设置列表
|
2732
|
+
*/
|
2733
|
+
async getSettings_p(settingAlias_p) {
|
2734
|
+
return this.settings.getSettings_p(settingAlias_p);
|
2735
|
+
}
|
2128
2736
|
/**
|
2129
2737
|
* 19. 便捷方法:获取指定设置
|
2130
2738
|
*/
|
2131
2739
|
async getSetting(key) {
|
2132
2740
|
return this.settings.getSetting(key);
|
2133
2741
|
}
|
2742
|
+
/**
|
2743
|
+
* 19.1. 便捷方法:获取父平台指定设置
|
2744
|
+
*/
|
2745
|
+
async getSetting_p(key) {
|
2746
|
+
return this.settings.getSetting_p(key);
|
2747
|
+
}
|
2134
2748
|
/**
|
2135
2749
|
* 20. 便捷方法:获取支付方式列表
|
2136
2750
|
*/
|