@gt6/sdk 1.0.12 → 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.
@@ -1077,6 +1077,97 @@ 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
+ }
1080
1171
  }
1081
1172
 
1082
1173
  /**
@@ -1350,6 +1441,18 @@ class GT6SDK {
1350
1441
  async getFunds() {
1351
1442
  return this.users.getFunds();
1352
1443
  }
1444
+ /**
1445
+ * 41. 便捷方法:获取用户支付记录列表
1446
+ */
1447
+ async getPaymentRecords(options) {
1448
+ return this.users.getPaymentRecords(options);
1449
+ }
1450
+ /**
1451
+ * 42. 便捷方法:获取用户支付记录列表(简化版本)
1452
+ */
1453
+ async getPaymentRecordsSimple(page = 1, pageSize = 10) {
1454
+ return this.users.getPaymentRecordsSimple(page, pageSize);
1455
+ }
1353
1456
  }
1354
1457
 
1355
1458
  export { ArticlesAPI, FormsAPI, GT6Client, GT6Error, GT6SDK, ProductsAPI, SettingsAPI, UsersAPI, GT6SDK as default };