@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.
- package/README.md +415 -0
- package/dist/gt6-sdk.cjs.js +379 -0
- package/dist/gt6-sdk.cjs.js.map +1 -1
- package/dist/gt6-sdk.esm.js +379 -0
- package/dist/gt6-sdk.esm.js.map +1 -1
- package/dist/index.d.ts +49 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/modules/users.d.ts +181 -0
- package/dist/modules/users.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
@@ -1818,6 +1818,421 @@ const currentUser = sdk.getCurrentUser();
|
|
1818
1818
|
}
|
1819
1819
|
```
|
1820
1820
|
|
1821
|
+
### 用户资金和订单管理
|
1822
|
+
|
1823
|
+
用户模块还提供了资金信息、资金日志、零售订单和地址管理功能。
|
1824
|
+
|
1825
|
+
#### 获取用户资金信息
|
1826
|
+
|
1827
|
+
```javascript
|
1828
|
+
// 获取用户资金信息(完整响应)
|
1829
|
+
const fundsResponse = await sdk.getUserFunds();
|
1830
|
+
if (fundsResponse.success) {
|
1831
|
+
console.log('可用余额:', fundsResponse.fund.fund);
|
1832
|
+
console.log('冻结金额:', fundsResponse.fund.noFund);
|
1833
|
+
console.log('租金:', fundsResponse.fund.rentFund);
|
1834
|
+
console.log('保证金:', fundsResponse.fund.marginFund);
|
1835
|
+
console.log('冻结保证金:', fundsResponse.fund.marginNoFund);
|
1836
|
+
console.log('积分:', fundsResponse.fund.userIntegral);
|
1837
|
+
console.log('信用等级:', fundsResponse.fund.creditLevel);
|
1838
|
+
} else {
|
1839
|
+
console.error('获取资金信息失败:', fundsResponse.message);
|
1840
|
+
}
|
1841
|
+
|
1842
|
+
// 获取用户资金信息(简化版本)
|
1843
|
+
const funds = await sdk.getFunds();
|
1844
|
+
if (funds) {
|
1845
|
+
console.log('可用余额:', funds.fund);
|
1846
|
+
console.log('冻结金额:', funds.noFund);
|
1847
|
+
} else {
|
1848
|
+
console.log('获取资金信息失败');
|
1849
|
+
}
|
1850
|
+
```
|
1851
|
+
|
1852
|
+
#### 获取资金日志列表
|
1853
|
+
|
1854
|
+
```javascript
|
1855
|
+
// 获取资金日志列表(完整响应)
|
1856
|
+
const fundLogsResponse = await sdk.getFundLogs({
|
1857
|
+
page: 1,
|
1858
|
+
pageSize: 10
|
1859
|
+
});
|
1860
|
+
|
1861
|
+
if (fundLogsResponse.success) {
|
1862
|
+
console.log('资金日志总数:', fundLogsResponse.total);
|
1863
|
+
fundLogsResponse.logs.forEach(log => {
|
1864
|
+
console.log(`日志ID: ${log.logId}`);
|
1865
|
+
console.log(`操作类型: ${log.fieldName}`);
|
1866
|
+
console.log(`变动金额: ${log.changeAmount}`);
|
1867
|
+
console.log(`新余额: ${log.newBalance}`);
|
1868
|
+
console.log(`操作时间: ${log.operationTime}`);
|
1869
|
+
console.log(`备注: ${log.remark || '-'}`);
|
1870
|
+
});
|
1871
|
+
} else {
|
1872
|
+
console.error('获取资金日志失败:', fundLogsResponse.message);
|
1873
|
+
}
|
1874
|
+
|
1875
|
+
// 获取资金日志列表(简化版本)
|
1876
|
+
const fundLogs = await sdk.getFundLogsSimple(1, 10);
|
1877
|
+
if (fundLogs) {
|
1878
|
+
console.log('资金日志总数:', fundLogs.total);
|
1879
|
+
fundLogs.logs.forEach(log => {
|
1880
|
+
console.log(`操作类型: ${log.fieldName}, 变动金额: ${log.changeAmount}`);
|
1881
|
+
});
|
1882
|
+
} else {
|
1883
|
+
console.log('获取资金日志失败');
|
1884
|
+
}
|
1885
|
+
```
|
1886
|
+
|
1887
|
+
#### 获取零售订单列表
|
1888
|
+
|
1889
|
+
```javascript
|
1890
|
+
// 获取零售订单列表(完整响应)
|
1891
|
+
const retailOrdersResponse = await sdk.getRetailOrders({
|
1892
|
+
page: 1,
|
1893
|
+
pageSize: 10
|
1894
|
+
});
|
1895
|
+
|
1896
|
+
if (retailOrdersResponse.success) {
|
1897
|
+
console.log('订单总数:', retailOrdersResponse.data.total);
|
1898
|
+
retailOrdersResponse.data.orders.forEach(order => {
|
1899
|
+
console.log(`订单ID: ${order.order_id}`);
|
1900
|
+
console.log(`订单金额: $${order.total_amount}`);
|
1901
|
+
console.log(`支付方式: ${order.pay_way}`);
|
1902
|
+
console.log(`订单状态: ${order.status}`);
|
1903
|
+
console.log(`创建时间: ${order.created_at}`);
|
1904
|
+
|
1905
|
+
// 订单详情
|
1906
|
+
if (order.details && order.details.length > 0) {
|
1907
|
+
order.details.forEach(detail => {
|
1908
|
+
console.log(` 商品ID: ${detail.product_id}`);
|
1909
|
+
console.log(` SKU: ${detail.sku}`);
|
1910
|
+
console.log(` 数量: ${detail.quantity}`);
|
1911
|
+
console.log(` 单价: $${detail.single_price}`);
|
1912
|
+
console.log(` 总价: $${detail.total_price}`);
|
1913
|
+
});
|
1914
|
+
}
|
1915
|
+
});
|
1916
|
+
} else {
|
1917
|
+
console.error('获取零售订单失败:', retailOrdersResponse.message);
|
1918
|
+
}
|
1919
|
+
|
1920
|
+
// 获取零售订单列表(简化版本)
|
1921
|
+
const retailOrders = await sdk.getRetailOrdersSimple(1, 10);
|
1922
|
+
if (retailOrders) {
|
1923
|
+
console.log('订单总数:', retailOrders.total);
|
1924
|
+
retailOrders.orders.forEach(order => {
|
1925
|
+
console.log(`订单ID: ${order.order_id}, 金额: $${order.total_amount}, 状态: ${order.status}`);
|
1926
|
+
});
|
1927
|
+
} else {
|
1928
|
+
console.log('获取零售订单失败');
|
1929
|
+
}
|
1930
|
+
```
|
1931
|
+
|
1932
|
+
#### 获取用户地址列表
|
1933
|
+
|
1934
|
+
```javascript
|
1935
|
+
// 获取用户地址列表(完整响应)
|
1936
|
+
const addressesResponse = await sdk.getAddresses();
|
1937
|
+
if (addressesResponse.success && addressesResponse.addresses) {
|
1938
|
+
addressesResponse.addresses.forEach(address => {
|
1939
|
+
console.log(`地址ID: ${address.addressId}`);
|
1940
|
+
console.log(`收货人: ${address.consignee}`);
|
1941
|
+
console.log(`电话: ${address.phone}`);
|
1942
|
+
console.log(`地址: ${address.address}`);
|
1943
|
+
console.log(`区域ID: ${address.regionId}`);
|
1944
|
+
console.log(`是否默认: ${address.isDefault}`);
|
1945
|
+
});
|
1946
|
+
} else {
|
1947
|
+
console.error('获取地址列表失败:', addressesResponse.message);
|
1948
|
+
}
|
1949
|
+
|
1950
|
+
// 获取用户地址列表(简化版本)
|
1951
|
+
const addresses = await sdk.getAddressesSimple();
|
1952
|
+
if (addresses) {
|
1953
|
+
addresses.forEach(address => {
|
1954
|
+
console.log(`收货人: ${address.consignee}, 地址: ${address.address}`);
|
1955
|
+
});
|
1956
|
+
} else {
|
1957
|
+
console.log('获取地址列表失败');
|
1958
|
+
}
|
1959
|
+
|
1960
|
+
// 根据地址ID获取地址信息
|
1961
|
+
const address = await sdk.getAddressById(123);
|
1962
|
+
if (address) {
|
1963
|
+
console.log('地址信息:', address);
|
1964
|
+
} else {
|
1965
|
+
console.log('地址不存在');
|
1966
|
+
}
|
1967
|
+
```
|
1968
|
+
|
1969
|
+
#### 获取支付记录列表
|
1970
|
+
|
1971
|
+
```javascript
|
1972
|
+
// 获取支付记录列表(完整响应)
|
1973
|
+
const paymentRecordsResponse = await sdk.getPaymentRecords({
|
1974
|
+
page: 1,
|
1975
|
+
pageSize: 10,
|
1976
|
+
status: 'completed', // 可选:筛选状态
|
1977
|
+
recordType: 1, // 可选:筛选记录类型
|
1978
|
+
methodId: 1 // 可选:筛选支付方式
|
1979
|
+
});
|
1980
|
+
|
1981
|
+
if (paymentRecordsResponse.success) {
|
1982
|
+
console.log('支付记录总数:', paymentRecordsResponse.total);
|
1983
|
+
paymentRecordsResponse.records.forEach(record => {
|
1984
|
+
console.log(`记录ID: ${record.id}`);
|
1985
|
+
console.log(`订单ID: ${record.orderId}`);
|
1986
|
+
console.log(`金额: $${record.amount}`);
|
1987
|
+
console.log(`状态: ${record.status}`);
|
1988
|
+
console.log(`创建时间: ${record.createTime}`);
|
1989
|
+
console.log(`描述: ${record.description || '-'}`);
|
1990
|
+
});
|
1991
|
+
} else {
|
1992
|
+
console.error('获取支付记录失败:', paymentRecordsResponse.message);
|
1993
|
+
}
|
1994
|
+
|
1995
|
+
// 获取支付记录列表(简化版本)
|
1996
|
+
const paymentRecords = await sdk.getPaymentRecordsSimple(1, 10);
|
1997
|
+
if (paymentRecords) {
|
1998
|
+
console.log('支付记录总数:', paymentRecords.total);
|
1999
|
+
paymentRecords.records.forEach(record => {
|
2000
|
+
console.log(`订单ID: ${record.orderId}, 金额: $${record.amount}, 状态: ${record.status}`);
|
2001
|
+
});
|
2002
|
+
} else {
|
2003
|
+
console.log('获取支付记录失败');
|
2004
|
+
}
|
2005
|
+
```
|
2006
|
+
|
2007
|
+
#### 在Astro组件中使用
|
2008
|
+
|
2009
|
+
```astro
|
2010
|
+
---
|
2011
|
+
// dashboard.astro
|
2012
|
+
import { GT6SDK } from '@gt6/sdk';
|
2013
|
+
|
2014
|
+
const sdk = new GT6SDK({
|
2015
|
+
baseUrl: 'https://data.shopasb.io',
|
2016
|
+
platformId: '1747558688'
|
2017
|
+
});
|
2018
|
+
|
2019
|
+
// 检查用户登录状态
|
2020
|
+
const isLoggedIn = sdk.isLoggedIn();
|
2021
|
+
let userFunds = null;
|
2022
|
+
let fundLogs = null;
|
2023
|
+
let retailOrders = null;
|
2024
|
+
|
2025
|
+
if (isLoggedIn) {
|
2026
|
+
// 获取用户资金信息
|
2027
|
+
userFunds = await sdk.getFunds();
|
2028
|
+
|
2029
|
+
// 获取资金日志
|
2030
|
+
fundLogs = await sdk.getFundLogsSimple(1, 5);
|
2031
|
+
|
2032
|
+
// 获取零售订单
|
2033
|
+
retailOrders = await sdk.getRetailOrdersSimple(1, 5);
|
2034
|
+
}
|
2035
|
+
---
|
2036
|
+
|
2037
|
+
<html>
|
2038
|
+
<head>
|
2039
|
+
<title>用户仪表板</title>
|
2040
|
+
</head>
|
2041
|
+
<body>
|
2042
|
+
{isLoggedIn ? (
|
2043
|
+
<div>
|
2044
|
+
<h1>用户仪表板</h1>
|
2045
|
+
|
2046
|
+
<!-- 资金信息 -->
|
2047
|
+
{userFunds && (
|
2048
|
+
<div>
|
2049
|
+
<h2>资金信息</h2>
|
2050
|
+
<p>可用余额: ${userFunds.fund}</p>
|
2051
|
+
<p>冻结金额: ${userFunds.noFund}</p>
|
2052
|
+
<p>积分: {userFunds.userIntegral}</p>
|
2053
|
+
</div>
|
2054
|
+
)}
|
2055
|
+
|
2056
|
+
<!-- 资金日志 -->
|
2057
|
+
{fundLogs && (
|
2058
|
+
<div>
|
2059
|
+
<h2>最近资金日志</h2>
|
2060
|
+
<ul>
|
2061
|
+
{fundLogs.logs.map(log => (
|
2062
|
+
<li>
|
2063
|
+
{log.fieldName}: {log.changeAmount} (余额: {log.newBalance})
|
2064
|
+
<br>
|
2065
|
+
<small>{new Date(log.operationTime).toLocaleString()}</small>
|
2066
|
+
</li>
|
2067
|
+
))}
|
2068
|
+
</ul>
|
2069
|
+
</div>
|
2070
|
+
)}
|
2071
|
+
|
2072
|
+
<!-- 零售订单 -->
|
2073
|
+
{retailOrders && (
|
2074
|
+
<div>
|
2075
|
+
<h2>最近订单</h2>
|
2076
|
+
<ul>
|
2077
|
+
{retailOrders.orders.map(order => (
|
2078
|
+
<li>
|
2079
|
+
订单 #{order.order_id}: ${order.total_amount}
|
2080
|
+
<br>
|
2081
|
+
<small>状态: {order.status}</small>
|
2082
|
+
</li>
|
2083
|
+
))}
|
2084
|
+
</ul>
|
2085
|
+
</div>
|
2086
|
+
)}
|
2087
|
+
</div>
|
2088
|
+
) : (
|
2089
|
+
<div>
|
2090
|
+
<h1>请先登录</h1>
|
2091
|
+
<a href="/login">去登录</a>
|
2092
|
+
</div>
|
2093
|
+
)}
|
2094
|
+
</body>
|
2095
|
+
</html>
|
2096
|
+
```
|
2097
|
+
|
2098
|
+
#### 类型定义
|
2099
|
+
|
2100
|
+
```typescript
|
2101
|
+
// 资金信息类型
|
2102
|
+
interface UserFunds {
|
2103
|
+
id: number;
|
2104
|
+
userId: number;
|
2105
|
+
userType: number;
|
2106
|
+
fund: string; // 可用余额
|
2107
|
+
noFund: string; // 冻结金额
|
2108
|
+
rentFund: string; // 租金
|
2109
|
+
marginFund: string; // 保证金
|
2110
|
+
marginNoFund: string; // 冻结保证金
|
2111
|
+
userIntegral: number; // 积分
|
2112
|
+
creditLevel: number; // 信用等级
|
2113
|
+
}
|
2114
|
+
|
2115
|
+
// 资金日志类型
|
2116
|
+
interface FundLog {
|
2117
|
+
logId: number;
|
2118
|
+
fundId: number | null;
|
2119
|
+
userId: number;
|
2120
|
+
fieldName: string; // 操作类型
|
2121
|
+
oldBalance: string; // 旧余额
|
2122
|
+
newBalance: string; // 新余额
|
2123
|
+
changeAmount: string; // 变动金额
|
2124
|
+
operatorId: number; // 操作者ID
|
2125
|
+
operationTime: string; // 操作时间
|
2126
|
+
remark: string | null; // 备注
|
2127
|
+
}
|
2128
|
+
|
2129
|
+
// 零售订单类型
|
2130
|
+
interface RetailOrder {
|
2131
|
+
order_id: number;
|
2132
|
+
user_id: number;
|
2133
|
+
user_type: number;
|
2134
|
+
total_amount: number; // 订单总金额
|
2135
|
+
pay_way: number; // 支付方式
|
2136
|
+
payment_record_id: number | null;
|
2137
|
+
fund_log_id: number | null;
|
2138
|
+
status: number; // 订单状态
|
2139
|
+
product_type: number;
|
2140
|
+
created_at: string; // 创建时间
|
2141
|
+
updated_at: string; // 更新时间
|
2142
|
+
platform_id: number;
|
2143
|
+
d1: number;
|
2144
|
+
d2: number;
|
2145
|
+
d3: number;
|
2146
|
+
details: RetailOrderDetail[]; // 订单详情
|
2147
|
+
}
|
2148
|
+
|
2149
|
+
// 零售订单详情类型
|
2150
|
+
interface RetailOrderDetail {
|
2151
|
+
detail_id: number;
|
2152
|
+
product_id: number;
|
2153
|
+
product_name: string;
|
2154
|
+
address_id: number;
|
2155
|
+
sku: string;
|
2156
|
+
shipping_fee: number; // 运费
|
2157
|
+
tax_fee: number; // 税费
|
2158
|
+
quantity: number; // 数量
|
2159
|
+
single_price: number; // 单价
|
2160
|
+
total_price: number; // 总价
|
2161
|
+
region_id: number;
|
2162
|
+
remark: string;
|
2163
|
+
created_at: string;
|
2164
|
+
updated_at: string;
|
2165
|
+
}
|
2166
|
+
|
2167
|
+
// 地址信息类型
|
2168
|
+
interface AddressInfo {
|
2169
|
+
addressId: number;
|
2170
|
+
consignee: string; // 收货人
|
2171
|
+
phone: string; // 电话
|
2172
|
+
address: string; // 地址
|
2173
|
+
regionId: number; // 区域ID
|
2174
|
+
isDefault: boolean; // 是否默认地址
|
2175
|
+
}
|
2176
|
+
|
2177
|
+
// 支付记录类型
|
2178
|
+
interface PaymentRecord {
|
2179
|
+
id: number;
|
2180
|
+
orderId: string;
|
2181
|
+
userId: number;
|
2182
|
+
userType: number;
|
2183
|
+
methodId: number; // 支付方式ID
|
2184
|
+
recordType: number; // 记录类型
|
2185
|
+
amount: string; // 金额
|
2186
|
+
status: string; // 状态
|
2187
|
+
description?: string; // 描述
|
2188
|
+
adminDescription?: string;
|
2189
|
+
img?: string; // 图片
|
2190
|
+
createTime: string; // 创建时间
|
2191
|
+
updateTime?: string; // 更新时间
|
2192
|
+
}
|
2193
|
+
```
|
2194
|
+
|
2195
|
+
### 错误处理
|
2196
|
+
|
2197
|
+
用户认证方法返回统一的响应格式:
|
2198
|
+
|
2199
|
+
```typescript
|
2200
|
+
// 登录成功响应
|
2201
|
+
{
|
2202
|
+
success: true,
|
2203
|
+
token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
|
2204
|
+
user: {
|
2205
|
+
userId: 123,
|
2206
|
+
username: "testuser",
|
2207
|
+
userLevel: 1,
|
2208
|
+
status: true,
|
2209
|
+
platformId: 1,
|
2210
|
+
d1: 0,
|
2211
|
+
d2: 0,
|
2212
|
+
d3: 0
|
2213
|
+
}
|
2214
|
+
}
|
2215
|
+
|
2216
|
+
// 登录失败响应
|
2217
|
+
{
|
2218
|
+
success: false,
|
2219
|
+
message: "用户名或密码错误"
|
2220
|
+
}
|
2221
|
+
|
2222
|
+
// 注册成功响应
|
2223
|
+
{
|
2224
|
+
success: true,
|
2225
|
+
userId: 123,
|
2226
|
+
message: "注册成功"
|
2227
|
+
}
|
2228
|
+
|
2229
|
+
// 注册失败响应
|
2230
|
+
{
|
2231
|
+
success: false,
|
2232
|
+
message: "用户名已存在"
|
2233
|
+
}
|
2234
|
+
```
|
2235
|
+
|
1821
2236
|
### 安全注意事项
|
1822
2237
|
|
1823
2238
|
1. **密码安全**: 确保密码在传输前进行适当的加密
|