@gt6/sdk 1.0.44 → 1.0.46
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 +165 -0
- package/dist/gt6-sdk.cjs.js.map +1 -1
- package/dist/gt6-sdk.esm.js +165 -0
- package/dist/gt6-sdk.esm.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/modules/products.d.ts +1 -0
- package/dist/modules/products.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
|
@@ -1877,6 +1877,64 @@ class ProductsAPI {
|
|
|
1877
1877
|
}
|
|
1878
1878
|
return product;
|
|
1879
1879
|
}
|
|
1880
|
+
/* 1.1 根据产品ID获取产品详情(平台用户都可以使用)
|
|
1881
|
+
*/
|
|
1882
|
+
async getProduct01_all(productId) {
|
|
1883
|
+
const product = await this.client.request(`/products_all/${productId}.json`);
|
|
1884
|
+
// 检查产品是否有销售区域和税费模板
|
|
1885
|
+
if (product.regions && product.regions.length > 0 &&
|
|
1886
|
+
product.taxTemplates && product.taxTemplates.length > 0) {
|
|
1887
|
+
try {
|
|
1888
|
+
// 获取税费信息
|
|
1889
|
+
const taxInfo = await this.getTaxInfo();
|
|
1890
|
+
// 为每个税费模板添加规则
|
|
1891
|
+
product.taxTemplates = product.taxTemplates.map(template => {
|
|
1892
|
+
const matchingTemplate = taxInfo.templates.find(t => t.templateId === template.templateId);
|
|
1893
|
+
if (matchingTemplate) {
|
|
1894
|
+
// 过滤出产品可销售区域的规则
|
|
1895
|
+
const productRegionIds = product.regions.map(r => r.regionId);
|
|
1896
|
+
const applicableRules = matchingTemplate.rules.filter(rule => productRegionIds.includes(rule.regionId));
|
|
1897
|
+
return {
|
|
1898
|
+
...template,
|
|
1899
|
+
rules: applicableRules
|
|
1900
|
+
};
|
|
1901
|
+
}
|
|
1902
|
+
return template;
|
|
1903
|
+
});
|
|
1904
|
+
}
|
|
1905
|
+
catch (error) {
|
|
1906
|
+
// 如果获取税费信息失败,不影响产品详情返回
|
|
1907
|
+
console.warn('Failed to fetch tax info:', error);
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
// 检查产品是否有销售区域和运费模板
|
|
1911
|
+
if (product.regions && product.regions.length > 0 &&
|
|
1912
|
+
product.shippingTemplates && product.shippingTemplates.length > 0) {
|
|
1913
|
+
try {
|
|
1914
|
+
// 获取运费信息
|
|
1915
|
+
const shippingInfo = await this.getShippingInfo();
|
|
1916
|
+
// 为每个运费模板添加规则
|
|
1917
|
+
product.shippingTemplates = product.shippingTemplates.map(template => {
|
|
1918
|
+
const matchingTemplate = shippingInfo.templates.find(t => t.templateId === template.templateId);
|
|
1919
|
+
if (matchingTemplate) {
|
|
1920
|
+
// 过滤出产品可销售区域的规则
|
|
1921
|
+
const productRegionIds = product.regions.map(r => r.regionId);
|
|
1922
|
+
const applicableRules = matchingTemplate.rules.filter(rule => productRegionIds.includes(rule.regionId));
|
|
1923
|
+
return {
|
|
1924
|
+
...template,
|
|
1925
|
+
rules: applicableRules
|
|
1926
|
+
};
|
|
1927
|
+
}
|
|
1928
|
+
return template;
|
|
1929
|
+
});
|
|
1930
|
+
}
|
|
1931
|
+
catch (error) {
|
|
1932
|
+
// 如果获取运费信息失败,不影响产品详情返回
|
|
1933
|
+
console.warn('Failed to fetch shipping info:', error);
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
return product;
|
|
1937
|
+
}
|
|
1880
1938
|
/**
|
|
1881
1939
|
* 1.2 获取平台产品分类列表
|
|
1882
1940
|
*/
|
|
@@ -3287,6 +3345,110 @@ class TransactionsAPI {
|
|
|
3287
3345
|
};
|
|
3288
3346
|
}
|
|
3289
3347
|
}
|
|
3348
|
+
/**
|
|
3349
|
+
* 获取用户平台信息
|
|
3350
|
+
* @param platformId 平台ID
|
|
3351
|
+
* @returns 用户平台信息响应
|
|
3352
|
+
*/
|
|
3353
|
+
async getUserInfo(platformId) {
|
|
3354
|
+
try {
|
|
3355
|
+
// 构建API URL
|
|
3356
|
+
const apiUrl = `/platforms/${platformId}.json`;
|
|
3357
|
+
const response = await this.client.request(apiUrl, {
|
|
3358
|
+
method: 'GET',
|
|
3359
|
+
headers: {
|
|
3360
|
+
'Content-Type': 'application/json'
|
|
3361
|
+
}
|
|
3362
|
+
});
|
|
3363
|
+
// 检查响应格式
|
|
3364
|
+
if (response && typeof response === 'object') {
|
|
3365
|
+
// 验证响应数据结构
|
|
3366
|
+
const userData = response;
|
|
3367
|
+
// 检查必要字段是否存在
|
|
3368
|
+
if (userData.id && userData.platformName) {
|
|
3369
|
+
return {
|
|
3370
|
+
success: true,
|
|
3371
|
+
message: '获取用户信息成功',
|
|
3372
|
+
data: userData
|
|
3373
|
+
};
|
|
3374
|
+
}
|
|
3375
|
+
else {
|
|
3376
|
+
return {
|
|
3377
|
+
success: false,
|
|
3378
|
+
message: '响应数据格式不正确'
|
|
3379
|
+
};
|
|
3380
|
+
}
|
|
3381
|
+
}
|
|
3382
|
+
return {
|
|
3383
|
+
success: false,
|
|
3384
|
+
message: '响应格式错误'
|
|
3385
|
+
};
|
|
3386
|
+
}
|
|
3387
|
+
catch (error) {
|
|
3388
|
+
// 如果是HTTP错误,尝试解析响应体
|
|
3389
|
+
if (error.statusCode && error.message) {
|
|
3390
|
+
// 对于401错误,返回认证失败信息
|
|
3391
|
+
if (error.statusCode === 401) {
|
|
3392
|
+
return {
|
|
3393
|
+
success: false,
|
|
3394
|
+
message: '认证失败,请重新登录'
|
|
3395
|
+
};
|
|
3396
|
+
}
|
|
3397
|
+
// 对于404错误,平台不存在
|
|
3398
|
+
if (error.statusCode === 404) {
|
|
3399
|
+
return {
|
|
3400
|
+
success: false,
|
|
3401
|
+
message: '平台不存在或已被删除'
|
|
3402
|
+
};
|
|
3403
|
+
}
|
|
3404
|
+
// 对于其他HTTP错误,返回状态码信息
|
|
3405
|
+
return {
|
|
3406
|
+
success: false,
|
|
3407
|
+
message: error.message || `HTTP ${error.statusCode} 错误`
|
|
3408
|
+
};
|
|
3409
|
+
}
|
|
3410
|
+
// 对于网络错误或其他错误
|
|
3411
|
+
return {
|
|
3412
|
+
success: false,
|
|
3413
|
+
message: error instanceof Error ? error.message : '获取用户信息失败'
|
|
3414
|
+
};
|
|
3415
|
+
}
|
|
3416
|
+
}
|
|
3417
|
+
/**
|
|
3418
|
+
* 1. 根据字段名查询字段值
|
|
3419
|
+
* @param platformInfo 平台信息数组
|
|
3420
|
+
* @param fieldName 字段名称
|
|
3421
|
+
* @returns 字段值或null
|
|
3422
|
+
*/
|
|
3423
|
+
getFieldByName(platformInfo, fieldName) {
|
|
3424
|
+
const field = platformInfo.find(info => info.fieldName === fieldName);
|
|
3425
|
+
return field ? field.fieldValue : null;
|
|
3426
|
+
}
|
|
3427
|
+
/**
|
|
3428
|
+
* 2. 根据别名查询字段值
|
|
3429
|
+
* @param platformInfo 平台信息数组
|
|
3430
|
+
* @param aliases 别名
|
|
3431
|
+
* @returns 字段值数组
|
|
3432
|
+
*/
|
|
3433
|
+
getFieldsByAliases(platformInfo, aliases) {
|
|
3434
|
+
return platformInfo.filter(info => info.aliases === aliases);
|
|
3435
|
+
}
|
|
3436
|
+
/**
|
|
3437
|
+
* 3. 获取管理员信息
|
|
3438
|
+
* @param userInfo 用户平台信息
|
|
3439
|
+
* @returns 管理员信息数组
|
|
3440
|
+
*/
|
|
3441
|
+
getAdminsInfo(userInfo) {
|
|
3442
|
+
return userInfo.admins || [];
|
|
3443
|
+
}
|
|
3444
|
+
/**
|
|
3445
|
+
* 4. 获取资金信息
|
|
3446
|
+
* @param userInfo 用户平台信息
|
|
3447
|
+
* @returns 资金信息对象
|
|
3448
|
+
*/
|
|
3449
|
+
getFundInfo(userInfo) {
|
|
3450
|
+
return userInfo.fund || null;
|
|
3451
|
+
}
|
|
3290
3452
|
}
|
|
3291
3453
|
|
|
3292
3454
|
/**
|
|
@@ -3486,6 +3648,9 @@ class GT6SDK {
|
|
|
3486
3648
|
async getProduct_all(productId) {
|
|
3487
3649
|
return this.products.getProduct_all(productId);
|
|
3488
3650
|
}
|
|
3651
|
+
async getProduct01_all(productId) {
|
|
3652
|
+
return this.products.getProduct01_all(productId);
|
|
3653
|
+
}
|
|
3489
3654
|
/**
|
|
3490
3655
|
* 8.2. 便捷方法:获取父平台产品分类列表
|
|
3491
3656
|
*/
|