@gt6/sdk 1.0.43 → 1.0.45
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/gt6-sdk.cjs.js +255 -0
- package/dist/gt6-sdk.cjs.js.map +1 -1
- package/dist/gt6-sdk.esm.js +255 -0
- package/dist/gt6-sdk.esm.js.map +1 -1
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/modules/articles.d.ts +37 -0
- package/dist/modules/articles.d.ts.map +1 -1
- package/dist/modules/transactions.d.ts +81 -0
- package/dist/modules/transactions.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/gt6-sdk.cjs.js
CHANGED
|
@@ -790,6 +790,151 @@ class ArticlesAPI {
|
|
|
790
790
|
filteredTotal // 过滤后的总数
|
|
791
791
|
};
|
|
792
792
|
}
|
|
793
|
+
/**
|
|
794
|
+
* 1.2.2 根据分类ID获取文章列表(支持搜索过滤)
|
|
795
|
+
*/
|
|
796
|
+
async getArticlesByCategory_all_search01(categoryId, searchOptions) {
|
|
797
|
+
// 将单个分类ID转换为数组
|
|
798
|
+
const categoryIds = Array.isArray(categoryId) ? categoryId : [categoryId];
|
|
799
|
+
// 收集所有指定分类下的文章数据
|
|
800
|
+
const allArticleData = [];
|
|
801
|
+
let totalArticles = 0;
|
|
802
|
+
// 遍历所有分类ID,获取每个分类的文章数据
|
|
803
|
+
for (const singleCategoryId of categoryIds) {
|
|
804
|
+
try {
|
|
805
|
+
const categoryData = await this.client.request(`/big-article-categories/${singleCategoryId}.json`);
|
|
806
|
+
if (categoryData && categoryData.articleIds && categoryData.articleIds.length > 0) {
|
|
807
|
+
allArticleData.push(...categoryData.articleIds);
|
|
808
|
+
totalArticles += categoryData.articleIds.length;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
catch (error) {
|
|
812
|
+
console.warn(`Failed to fetch data for category ${singleCategoryId}:`, error);
|
|
813
|
+
// 继续处理其他分类,不中断整个流程
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
if (allArticleData.length === 0) {
|
|
817
|
+
return {
|
|
818
|
+
articles: [],
|
|
819
|
+
total: 0,
|
|
820
|
+
page: searchOptions?.page || 1,
|
|
821
|
+
limit: searchOptions?.limit || 10,
|
|
822
|
+
filteredTotal: 0
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
// 应用搜索过滤
|
|
826
|
+
let filteredArticleIds = allArticleData.filter(articleObj => {
|
|
827
|
+
// 1. regionId 过滤
|
|
828
|
+
if (searchOptions?.regionIds && searchOptions.regionIds.length > 0) {
|
|
829
|
+
if (!articleObj.regionId || !searchOptions.regionIds.includes(articleObj.regionId)) {
|
|
830
|
+
return false;
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
// 2. price 范围过滤
|
|
834
|
+
if (searchOptions?.priceRange) {
|
|
835
|
+
const price = parseFloat(articleObj.price || '0');
|
|
836
|
+
if (searchOptions.priceRange.min !== undefined && price < searchOptions.priceRange.min) {
|
|
837
|
+
return false;
|
|
838
|
+
}
|
|
839
|
+
if (searchOptions.priceRange.max !== undefined && price > searchOptions.priceRange.max) {
|
|
840
|
+
return false;
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
// 3. Salary 范围过滤
|
|
844
|
+
if (searchOptions?.salaryRange) {
|
|
845
|
+
const salary = parseFloat(articleObj.Salary || '0');
|
|
846
|
+
if (searchOptions.salaryRange.min !== undefined && salary < searchOptions.salaryRange.min) {
|
|
847
|
+
return false;
|
|
848
|
+
}
|
|
849
|
+
if (searchOptions.salaryRange.max !== undefined && salary > searchOptions.salaryRange.max) {
|
|
850
|
+
return false;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
// 4. mileage 范围过滤
|
|
854
|
+
if (searchOptions?.mileageRange) {
|
|
855
|
+
// 处理里程数格式,如 "26000 km" -> 26000
|
|
856
|
+
const mileageStr = articleObj.Mileage || '0';
|
|
857
|
+
const mileageMatch = mileageStr.match(/(\d+(?:\.\d+)?)/);
|
|
858
|
+
const mileage = mileageMatch ? parseFloat(mileageMatch[1]) : 0;
|
|
859
|
+
if (searchOptions.mileageRange.min !== undefined && mileage < searchOptions.mileageRange.min) {
|
|
860
|
+
return false;
|
|
861
|
+
}
|
|
862
|
+
if (searchOptions.mileageRange.max !== undefined && mileage > searchOptions.mileageRange.max) {
|
|
863
|
+
return false;
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
// 5. propertyArea 范围过滤
|
|
867
|
+
if (searchOptions?.propertyAreaRange) {
|
|
868
|
+
const propertyArea = parseFloat(articleObj.propertyArea || '0');
|
|
869
|
+
if (searchOptions.propertyAreaRange.min !== undefined && propertyArea < searchOptions.propertyAreaRange.min) {
|
|
870
|
+
return false;
|
|
871
|
+
}
|
|
872
|
+
if (searchOptions.propertyAreaRange.max !== undefined && propertyArea > searchOptions.propertyAreaRange.max) {
|
|
873
|
+
return false;
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
// 6. plotArea 范围过滤
|
|
877
|
+
if (searchOptions?.plotAreaRange) {
|
|
878
|
+
const plotArea = parseFloat(articleObj.plotArea || '0');
|
|
879
|
+
if (searchOptions.plotAreaRange.min !== undefined && plotArea < searchOptions.plotAreaRange.min) {
|
|
880
|
+
return false;
|
|
881
|
+
}
|
|
882
|
+
if (searchOptions.plotAreaRange.max !== undefined && plotArea > searchOptions.plotAreaRange.max) {
|
|
883
|
+
return false;
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
// 7. tagIds 过滤
|
|
887
|
+
if (searchOptions?.tagIds && searchOptions.tagIds.length > 0) {
|
|
888
|
+
if (!articleObj.tagIds || articleObj.tagIds.length === 0) {
|
|
889
|
+
return false;
|
|
890
|
+
}
|
|
891
|
+
if (searchOptions.requireAllTags) {
|
|
892
|
+
// 要求包含所有指定的 tagIds
|
|
893
|
+
const hasAllTags = searchOptions.tagIds.every(tagId => articleObj.tagIds.includes(tagId));
|
|
894
|
+
if (!hasAllTags) {
|
|
895
|
+
return false;
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
else {
|
|
899
|
+
// 包含任意一个指定的 tagId 即可
|
|
900
|
+
const hasAnyTag = searchOptions.tagIds.some(tagId => articleObj.tagIds.includes(tagId));
|
|
901
|
+
if (!hasAnyTag) {
|
|
902
|
+
return false;
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
return true;
|
|
907
|
+
});
|
|
908
|
+
const filteredTotal = filteredArticleIds.length;
|
|
909
|
+
if (filteredTotal === 0) {
|
|
910
|
+
return {
|
|
911
|
+
articles: [],
|
|
912
|
+
total: totalArticles,
|
|
913
|
+
page: searchOptions?.page || 1,
|
|
914
|
+
limit: searchOptions?.limit || 10,
|
|
915
|
+
filteredTotal: 0
|
|
916
|
+
};
|
|
917
|
+
}
|
|
918
|
+
// 应用分页
|
|
919
|
+
const page = searchOptions?.page || 1;
|
|
920
|
+
const limit = searchOptions?.limit || 10;
|
|
921
|
+
const offset = (page - 1) * limit;
|
|
922
|
+
const paginatedArticleIds = filteredArticleIds.slice(offset, offset + limit);
|
|
923
|
+
// 获取文章详情
|
|
924
|
+
const articles = await Promise.all(paginatedArticleIds.map(articleObj => this.getArticle_all(articleObj.articleId)));
|
|
925
|
+
// 应用状态过滤
|
|
926
|
+
let finalArticles = articles;
|
|
927
|
+
if (searchOptions?.status) {
|
|
928
|
+
finalArticles = articles.filter(article => article.status === searchOptions.status);
|
|
929
|
+
}
|
|
930
|
+
return {
|
|
931
|
+
articles: finalArticles,
|
|
932
|
+
total: totalArticles, // 原始总数
|
|
933
|
+
page,
|
|
934
|
+
limit,
|
|
935
|
+
filteredTotal // 过滤后的总数
|
|
936
|
+
};
|
|
937
|
+
}
|
|
793
938
|
/**
|
|
794
939
|
* 1.2.1 根据平台ID获取文章列表(平台用户都可以使用)
|
|
795
940
|
*/
|
|
@@ -3142,6 +3287,110 @@ class TransactionsAPI {
|
|
|
3142
3287
|
};
|
|
3143
3288
|
}
|
|
3144
3289
|
}
|
|
3290
|
+
/**
|
|
3291
|
+
* 获取用户平台信息
|
|
3292
|
+
* @param platformId 平台ID
|
|
3293
|
+
* @returns 用户平台信息响应
|
|
3294
|
+
*/
|
|
3295
|
+
async getUserInfo(platformId) {
|
|
3296
|
+
try {
|
|
3297
|
+
// 构建API URL
|
|
3298
|
+
const apiUrl = `/platforms/${platformId}.json`;
|
|
3299
|
+
const response = await this.client.request(apiUrl, {
|
|
3300
|
+
method: 'GET',
|
|
3301
|
+
headers: {
|
|
3302
|
+
'Content-Type': 'application/json'
|
|
3303
|
+
}
|
|
3304
|
+
});
|
|
3305
|
+
// 检查响应格式
|
|
3306
|
+
if (response && typeof response === 'object') {
|
|
3307
|
+
// 验证响应数据结构
|
|
3308
|
+
const userData = response;
|
|
3309
|
+
// 检查必要字段是否存在
|
|
3310
|
+
if (userData.id && userData.platformName) {
|
|
3311
|
+
return {
|
|
3312
|
+
success: true,
|
|
3313
|
+
message: '获取用户信息成功',
|
|
3314
|
+
data: userData
|
|
3315
|
+
};
|
|
3316
|
+
}
|
|
3317
|
+
else {
|
|
3318
|
+
return {
|
|
3319
|
+
success: false,
|
|
3320
|
+
message: '响应数据格式不正确'
|
|
3321
|
+
};
|
|
3322
|
+
}
|
|
3323
|
+
}
|
|
3324
|
+
return {
|
|
3325
|
+
success: false,
|
|
3326
|
+
message: '响应格式错误'
|
|
3327
|
+
};
|
|
3328
|
+
}
|
|
3329
|
+
catch (error) {
|
|
3330
|
+
// 如果是HTTP错误,尝试解析响应体
|
|
3331
|
+
if (error.statusCode && error.message) {
|
|
3332
|
+
// 对于401错误,返回认证失败信息
|
|
3333
|
+
if (error.statusCode === 401) {
|
|
3334
|
+
return {
|
|
3335
|
+
success: false,
|
|
3336
|
+
message: '认证失败,请重新登录'
|
|
3337
|
+
};
|
|
3338
|
+
}
|
|
3339
|
+
// 对于404错误,平台不存在
|
|
3340
|
+
if (error.statusCode === 404) {
|
|
3341
|
+
return {
|
|
3342
|
+
success: false,
|
|
3343
|
+
message: '平台不存在或已被删除'
|
|
3344
|
+
};
|
|
3345
|
+
}
|
|
3346
|
+
// 对于其他HTTP错误,返回状态码信息
|
|
3347
|
+
return {
|
|
3348
|
+
success: false,
|
|
3349
|
+
message: error.message || `HTTP ${error.statusCode} 错误`
|
|
3350
|
+
};
|
|
3351
|
+
}
|
|
3352
|
+
// 对于网络错误或其他错误
|
|
3353
|
+
return {
|
|
3354
|
+
success: false,
|
|
3355
|
+
message: error instanceof Error ? error.message : '获取用户信息失败'
|
|
3356
|
+
};
|
|
3357
|
+
}
|
|
3358
|
+
}
|
|
3359
|
+
/**
|
|
3360
|
+
* 1. 根据字段名查询字段值
|
|
3361
|
+
* @param platformInfo 平台信息数组
|
|
3362
|
+
* @param fieldName 字段名称
|
|
3363
|
+
* @returns 字段值或null
|
|
3364
|
+
*/
|
|
3365
|
+
getFieldByName(platformInfo, fieldName) {
|
|
3366
|
+
const field = platformInfo.find(info => info.fieldName === fieldName);
|
|
3367
|
+
return field ? field.fieldValue : null;
|
|
3368
|
+
}
|
|
3369
|
+
/**
|
|
3370
|
+
* 2. 根据别名查询字段值
|
|
3371
|
+
* @param platformInfo 平台信息数组
|
|
3372
|
+
* @param aliases 别名
|
|
3373
|
+
* @returns 字段值数组
|
|
3374
|
+
*/
|
|
3375
|
+
getFieldsByAliases(platformInfo, aliases) {
|
|
3376
|
+
return platformInfo.filter(info => info.aliases === aliases);
|
|
3377
|
+
}
|
|
3378
|
+
/**
|
|
3379
|
+
* 3. 获取管理员信息
|
|
3380
|
+
* @param userInfo 用户平台信息
|
|
3381
|
+
* @returns 管理员信息数组
|
|
3382
|
+
*/
|
|
3383
|
+
getAdminsInfo(userInfo) {
|
|
3384
|
+
return userInfo.admins || [];
|
|
3385
|
+
}
|
|
3386
|
+
/**
|
|
3387
|
+
* 4. 获取资金信息
|
|
3388
|
+
* @param userInfo 用户平台信息
|
|
3389
|
+
* @returns 资金信息对象
|
|
3390
|
+
*/
|
|
3391
|
+
getFundInfo(userInfo) {
|
|
3392
|
+
return userInfo.fund || null;
|
|
3393
|
+
}
|
|
3145
3394
|
}
|
|
3146
3395
|
|
|
3147
3396
|
/**
|
|
@@ -3242,6 +3491,12 @@ class GT6SDK {
|
|
|
3242
3491
|
async getArticlesByCategory_all(categoryId, options) {
|
|
3243
3492
|
return this.articles.getArticlesByCategory_all(categoryId, options);
|
|
3244
3493
|
}
|
|
3494
|
+
async getArticlesByCategory_all_search(categoryId, options) {
|
|
3495
|
+
return this.articles.getArticlesByCategory_all_search(categoryId, options);
|
|
3496
|
+
}
|
|
3497
|
+
async getArticlesByCategory_all_search01(categoryId, options) {
|
|
3498
|
+
return this.articles.getArticlesByCategory_all_search01(categoryId, options);
|
|
3499
|
+
}
|
|
3245
3500
|
async getArticlesByplatform_all(platformId, options) {
|
|
3246
3501
|
return this.articles.getArticlesByplatform_all(platformId, options);
|
|
3247
3502
|
}
|