@gt6/sdk 1.0.11 → 1.0.13

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.
@@ -1023,6 +1023,155 @@ class UsersAPI {
1023
1023
  localStorage.removeItem('rememberedPassword');
1024
1024
  }
1025
1025
  }
1026
+ /**
1027
+ * 获取用户资金信息
1028
+ * @returns 用户资金信息
1029
+ */
1030
+ async getUserFunds() {
1031
+ try {
1032
+ // 获取用户token
1033
+ const token = this.getToken();
1034
+ if (!token) {
1035
+ return {
1036
+ success: false,
1037
+ fund: {},
1038
+ message: '用户未登录'
1039
+ };
1040
+ }
1041
+ const response = await this.client.request('/web/user/fund', {
1042
+ method: 'GET',
1043
+ headers: {
1044
+ 'Authorization': `Bearer ${token}`,
1045
+ 'Content-Type': 'application/json'
1046
+ }
1047
+ });
1048
+ return response;
1049
+ }
1050
+ catch (error) {
1051
+ // 如果是HTTP错误,尝试解析响应体
1052
+ if (error.statusCode && error.message) {
1053
+ // 对于401错误,返回认证失败信息
1054
+ if (error.statusCode === 401) {
1055
+ return {
1056
+ success: false,
1057
+ fund: {},
1058
+ message: '认证失败,请重新登录'
1059
+ };
1060
+ }
1061
+ // 对于其他HTTP错误,返回状态码信息
1062
+ return {
1063
+ success: false,
1064
+ fund: {},
1065
+ message: error.message || `HTTP ${error.statusCode} 错误`
1066
+ };
1067
+ }
1068
+ // 对于网络错误或其他错误
1069
+ return {
1070
+ success: false,
1071
+ fund: {},
1072
+ message: error instanceof Error ? error.message : '获取资金信息失败'
1073
+ };
1074
+ }
1075
+ }
1076
+ /**
1077
+ * 获取用户资金信息(简化版本,返回资金对象或null)
1078
+ * @returns 用户资金信息或null
1079
+ */
1080
+ async getFunds() {
1081
+ const result = await this.getUserFunds();
1082
+ return result.success ? result.fund : null;
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
+ }
1026
1175
  }
1027
1176
 
1028
1177
  /**
@@ -1284,6 +1433,30 @@ class GT6SDK {
1284
1433
  clearRememberedLogin() {
1285
1434
  return this.users.clearRememberedLogin();
1286
1435
  }
1436
+ /**
1437
+ * 39. 便捷方法:获取用户资金信息
1438
+ */
1439
+ async getUserFunds() {
1440
+ return this.users.getUserFunds();
1441
+ }
1442
+ /**
1443
+ * 40. 便捷方法:获取用户资金信息(简化版本)
1444
+ */
1445
+ async getFunds() {
1446
+ return this.users.getFunds();
1447
+ }
1448
+ /**
1449
+ * 41. 便捷方法:获取用户支付记录列表
1450
+ */
1451
+ async getPaymentRecords(options) {
1452
+ return this.users.getPaymentRecords(options);
1453
+ }
1454
+ /**
1455
+ * 42. 便捷方法:获取用户支付记录列表(简化版本)
1456
+ */
1457
+ async getPaymentRecordsSimple(page = 1, pageSize = 10) {
1458
+ return this.users.getPaymentRecordsSimple(page, pageSize);
1459
+ }
1287
1460
  }
1288
1461
 
1289
1462
  exports.ArticlesAPI = ArticlesAPI;