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