@gt6/sdk 1.0.12 → 1.0.14

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.
@@ -1081,6 +1081,331 @@ class UsersAPI {
1081
1081
  const result = await this.getUserFunds();
1082
1082
  return result.success ? result.fund : null;
1083
1083
  }
1084
+ /**
1085
+ * 获取用户支付记录列表
1086
+ * @param options 查询选项
1087
+ * @returns 支付记录列表响应
1088
+ */
1089
+ async getPaymentRecords(options) {
1090
+ try {
1091
+ // 获取用户token
1092
+ const token = this.getToken();
1093
+ if (!token) {
1094
+ return {
1095
+ success: false,
1096
+ records: [],
1097
+ total: 0,
1098
+ page: options?.page || 1,
1099
+ pageSize: options?.pageSize || 10,
1100
+ message: '用户未登录'
1101
+ };
1102
+ }
1103
+ // 构建查询参数
1104
+ const params = new URLSearchParams();
1105
+ if (options?.page)
1106
+ params.set('page', options.page.toString());
1107
+ if (options?.pageSize)
1108
+ params.set('pageSize', options.pageSize.toString());
1109
+ if (options?.status)
1110
+ params.set('status', options.status);
1111
+ if (options?.recordType)
1112
+ params.set('recordType', options.recordType.toString());
1113
+ if (options?.methodId)
1114
+ params.set('methodId', options.methodId.toString());
1115
+ const url = `/web/payment/records${params.toString() ? `?${params.toString()}` : ''}`;
1116
+ const response = await this.client.request(url, {
1117
+ method: 'GET',
1118
+ headers: {
1119
+ 'Authorization': `Bearer ${token}`,
1120
+ 'Content-Type': 'application/json'
1121
+ }
1122
+ });
1123
+ return response;
1124
+ }
1125
+ catch (error) {
1126
+ // 如果是HTTP错误,尝试解析响应体
1127
+ if (error.statusCode && error.message) {
1128
+ // 对于401错误,返回认证失败信息
1129
+ if (error.statusCode === 401) {
1130
+ return {
1131
+ success: false,
1132
+ records: [],
1133
+ total: 0,
1134
+ page: options?.page || 1,
1135
+ pageSize: options?.pageSize || 10,
1136
+ message: '认证失败,请重新登录'
1137
+ };
1138
+ }
1139
+ // 对于其他HTTP错误,返回状态码信息
1140
+ return {
1141
+ success: false,
1142
+ records: [],
1143
+ total: 0,
1144
+ page: options?.page || 1,
1145
+ pageSize: options?.pageSize || 10,
1146
+ message: error.message || `HTTP ${error.statusCode} 错误`
1147
+ };
1148
+ }
1149
+ // 对于网络错误或其他错误
1150
+ return {
1151
+ success: false,
1152
+ records: [],
1153
+ total: 0,
1154
+ page: options?.page || 1,
1155
+ pageSize: options?.pageSize || 10,
1156
+ message: error instanceof Error ? error.message : '获取支付记录失败'
1157
+ };
1158
+ }
1159
+ }
1160
+ /**
1161
+ * 获取用户支付记录列表(简化版本)
1162
+ * @param page 页码,默认为1
1163
+ * @param pageSize 每页数量,默认为10
1164
+ * @returns 支付记录列表或null
1165
+ */
1166
+ async getPaymentRecordsSimple(page = 1, pageSize = 10) {
1167
+ const result = await this.getPaymentRecords({ page, pageSize });
1168
+ return result.success ? {
1169
+ records: result.records,
1170
+ total: result.total,
1171
+ page: result.page,
1172
+ pageSize: result.pageSize
1173
+ } : null;
1174
+ }
1175
+ /**
1176
+ * 获取用户资金日志列表
1177
+ * @param options 查询选项
1178
+ * @returns 资金日志列表响应
1179
+ */
1180
+ async getFundLogs(options) {
1181
+ try {
1182
+ // 获取用户token
1183
+ const token = this.getToken();
1184
+ if (!token) {
1185
+ return {
1186
+ success: false,
1187
+ logs: [],
1188
+ total: 0,
1189
+ message: '用户未登录'
1190
+ };
1191
+ }
1192
+ // 构建查询参数
1193
+ const params = new URLSearchParams();
1194
+ if (options?.page)
1195
+ params.set('page', options.page.toString());
1196
+ if (options?.pageSize)
1197
+ params.set('pageSize', options.pageSize.toString());
1198
+ const url = `/web/user/fund/logs${params.toString() ? `?${params.toString()}` : ''}`;
1199
+ const response = await this.client.request(url, {
1200
+ method: 'GET',
1201
+ headers: {
1202
+ 'Authorization': `Bearer ${token}`,
1203
+ 'Content-Type': 'application/json'
1204
+ }
1205
+ });
1206
+ return response;
1207
+ }
1208
+ catch (error) {
1209
+ // 如果是HTTP错误,尝试解析响应体
1210
+ if (error.statusCode && error.message) {
1211
+ // 对于401错误,返回认证失败信息
1212
+ if (error.statusCode === 401) {
1213
+ return {
1214
+ success: false,
1215
+ logs: [],
1216
+ total: 0,
1217
+ message: '认证失败,请重新登录'
1218
+ };
1219
+ }
1220
+ // 对于其他HTTP错误,返回状态码信息
1221
+ return {
1222
+ success: false,
1223
+ logs: [],
1224
+ total: 0,
1225
+ message: error.message || `HTTP ${error.statusCode} 错误`
1226
+ };
1227
+ }
1228
+ // 对于网络错误或其他错误
1229
+ return {
1230
+ success: false,
1231
+ logs: [],
1232
+ total: 0,
1233
+ message: error instanceof Error ? error.message : '获取资金日志失败'
1234
+ };
1235
+ }
1236
+ }
1237
+ /**
1238
+ * 获取用户资金日志列表(简化版本)
1239
+ * @param page 页码,默认为1
1240
+ * @param pageSize 每页数量,默认为10
1241
+ * @returns 资金日志列表或null
1242
+ */
1243
+ async getFundLogsSimple(page = 1, pageSize = 10) {
1244
+ const result = await this.getFundLogs({ page, pageSize });
1245
+ return result.success ? {
1246
+ logs: result.logs,
1247
+ total: result.total
1248
+ } : null;
1249
+ }
1250
+ /**
1251
+ * 获取用户零售订单列表
1252
+ * @param options 查询选项
1253
+ * @returns 零售订单列表响应
1254
+ */
1255
+ async getRetailOrders(options) {
1256
+ try {
1257
+ // 获取用户token
1258
+ const token = this.getToken();
1259
+ if (!token) {
1260
+ return {
1261
+ success: false,
1262
+ data: {
1263
+ total: 0,
1264
+ page: options?.page || 1,
1265
+ pageSize: options?.pageSize || 10,
1266
+ orders: []
1267
+ },
1268
+ message: '用户未登录'
1269
+ };
1270
+ }
1271
+ // 构建查询参数
1272
+ const params = new URLSearchParams();
1273
+ if (options?.page)
1274
+ params.set('page', options.page.toString());
1275
+ if (options?.pageSize)
1276
+ params.set('page_size', options.pageSize.toString());
1277
+ const url = `/web/orders${params.toString() ? `?${params.toString()}` : ''}`;
1278
+ const response = await this.client.request(url, {
1279
+ method: 'GET',
1280
+ headers: {
1281
+ 'Authorization': `Bearer ${token}`,
1282
+ 'Content-Type': 'application/json'
1283
+ }
1284
+ });
1285
+ return response;
1286
+ }
1287
+ catch (error) {
1288
+ // 如果是HTTP错误,尝试解析响应体
1289
+ if (error.statusCode && error.message) {
1290
+ // 对于401错误,返回认证失败信息
1291
+ if (error.statusCode === 401) {
1292
+ return {
1293
+ success: false,
1294
+ data: {
1295
+ total: 0,
1296
+ page: options?.page || 1,
1297
+ pageSize: options?.pageSize || 10,
1298
+ orders: []
1299
+ },
1300
+ message: '认证失败,请重新登录'
1301
+ };
1302
+ }
1303
+ // 对于其他HTTP错误,返回状态码信息
1304
+ return {
1305
+ success: false,
1306
+ data: {
1307
+ total: 0,
1308
+ page: options?.page || 1,
1309
+ pageSize: options?.pageSize || 10,
1310
+ orders: []
1311
+ },
1312
+ message: error.message || `HTTP ${error.statusCode} 错误`
1313
+ };
1314
+ }
1315
+ // 对于网络错误或其他错误
1316
+ return {
1317
+ success: false,
1318
+ data: {
1319
+ total: 0,
1320
+ page: options?.page || 1,
1321
+ pageSize: options?.pageSize || 10,
1322
+ orders: []
1323
+ },
1324
+ message: error instanceof Error ? error.message : '获取零售订单失败'
1325
+ };
1326
+ }
1327
+ }
1328
+ /**
1329
+ * 获取用户零售订单列表(简化版本)
1330
+ * @param page 页码,默认为1
1331
+ * @param pageSize 每页数量,默认为10
1332
+ * @returns 零售订单列表或null
1333
+ */
1334
+ async getRetailOrdersSimple(page = 1, pageSize = 10) {
1335
+ const result = await this.getRetailOrders({ page, pageSize });
1336
+ return result.success ? {
1337
+ orders: result.data.orders,
1338
+ total: result.data.total,
1339
+ page: result.data.page,
1340
+ pageSize: result.data.pageSize
1341
+ } : null;
1342
+ }
1343
+ /**
1344
+ * 获取用户地址列表
1345
+ * @returns 地址列表响应
1346
+ */
1347
+ async getAddresses() {
1348
+ try {
1349
+ // 获取用户token
1350
+ const token = this.getToken();
1351
+ if (!token) {
1352
+ return {
1353
+ success: false,
1354
+ message: '用户未登录'
1355
+ };
1356
+ }
1357
+ const response = await this.client.request('/web/user/addresses', {
1358
+ method: 'GET',
1359
+ headers: {
1360
+ 'Authorization': `Bearer ${token}`,
1361
+ 'Content-Type': 'application/json'
1362
+ }
1363
+ });
1364
+ return response;
1365
+ }
1366
+ catch (error) {
1367
+ // 如果是HTTP错误,尝试解析响应体
1368
+ if (error.statusCode && error.message) {
1369
+ // 对于401错误,返回认证失败信息
1370
+ if (error.statusCode === 401) {
1371
+ return {
1372
+ success: false,
1373
+ message: '认证失败,请重新登录'
1374
+ };
1375
+ }
1376
+ // 对于其他HTTP错误,返回状态码信息
1377
+ return {
1378
+ success: false,
1379
+ message: error.message || `HTTP ${error.statusCode} 错误`
1380
+ };
1381
+ }
1382
+ // 对于网络错误或其他错误
1383
+ return {
1384
+ success: false,
1385
+ message: error instanceof Error ? error.message : '获取地址列表失败'
1386
+ };
1387
+ }
1388
+ }
1389
+ /**
1390
+ * 获取用户地址列表(简化版本)
1391
+ * @returns 地址列表或null
1392
+ */
1393
+ async getAddressesSimple() {
1394
+ const result = await this.getAddresses();
1395
+ return result.success && result.addresses ? result.addresses : null;
1396
+ }
1397
+ /**
1398
+ * 根据地址ID获取地址信息
1399
+ * @param addressId 地址ID
1400
+ * @returns 地址信息或null
1401
+ */
1402
+ async getAddressById(addressId) {
1403
+ const addresses = await this.getAddressesSimple();
1404
+ if (addresses) {
1405
+ return addresses.find(addr => addr.addressId === addressId) || null;
1406
+ }
1407
+ return null;
1408
+ }
1084
1409
  }
1085
1410
 
1086
1411
  /**
@@ -1354,6 +1679,60 @@ class GT6SDK {
1354
1679
  async getFunds() {
1355
1680
  return this.users.getFunds();
1356
1681
  }
1682
+ /**
1683
+ * 41. 便捷方法:获取用户支付记录列表
1684
+ */
1685
+ async getPaymentRecords(options) {
1686
+ return this.users.getPaymentRecords(options);
1687
+ }
1688
+ /**
1689
+ * 42. 便捷方法:获取用户支付记录列表(简化版本)
1690
+ */
1691
+ async getPaymentRecordsSimple(page = 1, pageSize = 10) {
1692
+ return this.users.getPaymentRecordsSimple(page, pageSize);
1693
+ }
1694
+ /**
1695
+ * 便捷方法:获取用户资金日志列表
1696
+ */
1697
+ async getFundLogs(options) {
1698
+ return this.users.getFundLogs(options);
1699
+ }
1700
+ /**
1701
+ * 便捷方法:获取用户资金日志列表(简化版本)
1702
+ */
1703
+ async getFundLogsSimple(page = 1, pageSize = 10) {
1704
+ return this.users.getFundLogsSimple(page, pageSize);
1705
+ }
1706
+ /**
1707
+ * 便捷方法:获取用户零售订单列表
1708
+ */
1709
+ async getRetailOrders(options) {
1710
+ return this.users.getRetailOrders(options);
1711
+ }
1712
+ /**
1713
+ * 便捷方法:获取用户零售订单列表(简化版本)
1714
+ */
1715
+ async getRetailOrdersSimple(page = 1, pageSize = 10) {
1716
+ return this.users.getRetailOrdersSimple(page, pageSize);
1717
+ }
1718
+ /**
1719
+ * 便捷方法:获取用户地址列表
1720
+ */
1721
+ async getAddresses() {
1722
+ return this.users.getAddresses();
1723
+ }
1724
+ /**
1725
+ * 便捷方法:获取用户地址列表(简化版本)
1726
+ */
1727
+ async getAddressesSimple() {
1728
+ return this.users.getAddressesSimple();
1729
+ }
1730
+ /**
1731
+ * 便捷方法:根据地址ID获取地址信息
1732
+ */
1733
+ async getAddressById(addressId) {
1734
+ return this.users.getAddressById(addressId);
1735
+ }
1357
1736
  }
1358
1737
 
1359
1738
  exports.ArticlesAPI = ArticlesAPI;