best-unit 2.1.5 → 2.1.9
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/dist/best-unit.cjs +8 -8
- package/dist/best-unit.js +454 -466
- package/dist/types/global.d.ts +5 -0
- package/package.json +1 -1
- package/src/api/index.ts +11 -38
- package/src/components/business/payment-sdk/offline-payment/fund-allocation.tsx +17 -8
- package/src/demo/App.tsx +2 -2
- package/src/types/global.d.ts +5 -0
- package/src/utils/business/index.ts +2 -0
package/dist/types/global.d.ts
CHANGED
package/package.json
CHANGED
package/src/api/index.ts
CHANGED
|
@@ -7,51 +7,19 @@ export interface MerchantBalanceItem {
|
|
|
7
7
|
bizType: string;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export const getAllBalances = async () => {
|
|
11
|
-
const fundUnitParams = JSON.parse(
|
|
12
|
-
sessionStorage.getItem("fund_unit_params") || "{}",
|
|
13
|
-
);
|
|
14
|
-
return http()
|
|
15
|
-
.post("/merchant/all-balances", {
|
|
16
|
-
merchant_id: Number(fundUnitParams.merchantId),
|
|
17
|
-
})
|
|
18
|
-
.then((res) => {
|
|
19
|
-
const allBalances: MerchantBalanceItem[] = (
|
|
20
|
-
Array.isArray(res?.data) ? res.data : []
|
|
21
|
-
).map((item: any) => ({
|
|
22
|
-
fundBalanceId: String(item.fund_balance_id || ""),
|
|
23
|
-
merchantId: Number(item.merchant_id || 0),
|
|
24
|
-
bizType: String(item.biz_type || ""),
|
|
25
|
-
}));
|
|
26
|
-
|
|
27
|
-
sessionStorage.setItem("allBalances", JSON.stringify(allBalances));
|
|
28
|
-
return allBalances;
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
|
|
32
10
|
// 获取余额
|
|
33
11
|
export async function getBalance() {
|
|
34
12
|
const fundUnitParams = JSON.parse(
|
|
35
13
|
sessionStorage.getItem("fund_unit_params") || "{}",
|
|
36
14
|
);
|
|
37
|
-
|
|
38
|
-
const balanceRequest = http().get("/balance", {
|
|
15
|
+
const res = await http().get("/balance", {
|
|
39
16
|
params: {
|
|
40
17
|
merchant_id: fundUnitParams.merchantId,
|
|
41
18
|
biz_type: fundUnitParams.bizType,
|
|
42
19
|
fund_balance_id: fundUnitParams.fundBalanceId,
|
|
43
20
|
},
|
|
44
21
|
});
|
|
45
|
-
const
|
|
46
|
-
balanceRequest,
|
|
47
|
-
getAllBalances(),
|
|
48
|
-
]);
|
|
49
|
-
|
|
50
|
-
if (balanceRes.status !== "fulfilled") {
|
|
51
|
-
throw balanceRes.reason;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const data = balanceRes.value.data;
|
|
22
|
+
const data = res.data;
|
|
55
23
|
const balanceData = {
|
|
56
24
|
fundBalanceId: data.fund_balance_id,
|
|
57
25
|
merchantId: data.merchant_id,
|
|
@@ -67,12 +35,16 @@ export async function getBalance() {
|
|
|
67
35
|
pendingAmount: data.pending_amount,
|
|
68
36
|
status: data.status,
|
|
69
37
|
createdAt: data.created_at,
|
|
38
|
+
merchantBalances: (Array.isArray(data.merchant_balances)
|
|
39
|
+
? data.merchant_balances
|
|
40
|
+
: []
|
|
41
|
+
).map((item: any) => ({
|
|
42
|
+
fundBalanceId: item.fund_balance_id,
|
|
43
|
+
merchantId: item.merchant_id,
|
|
44
|
+
bizType: item.biz_type,
|
|
45
|
+
})),
|
|
70
46
|
};
|
|
71
47
|
|
|
72
|
-
if (allBalancesRes.status !== "fulfilled") {
|
|
73
|
-
console.error("获取子业务账户列表失败:", allBalancesRes.reason);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
48
|
sessionStorage.setItem("balanceData", JSON.stringify(balanceData));
|
|
77
49
|
return balanceData;
|
|
78
50
|
}
|
|
@@ -156,6 +128,7 @@ export const createOfflineRecharge = async (data: any) => {
|
|
|
156
128
|
allocation_ratios: Boolean(data.useFundAllocation)
|
|
157
129
|
? (data.allocationRatios || []).map((item: any) => ({
|
|
158
130
|
fund_balance_id: item.fundBalanceId,
|
|
131
|
+
biz_type: item.bizType,
|
|
159
132
|
ratio: String(item.ratio),
|
|
160
133
|
}))
|
|
161
134
|
: [],
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useEffect, useState } from "preact/hooks";
|
|
2
2
|
import { t } from "@/local";
|
|
3
|
-
import {
|
|
3
|
+
import { type MerchantBalanceItem } from "@/api";
|
|
4
|
+
import { getBalanceData } from "@/utils/business";
|
|
4
5
|
|
|
5
6
|
interface FundAllocationSectionProps {
|
|
6
7
|
theme: any;
|
|
@@ -45,17 +46,24 @@ export function useFundAllocation() {
|
|
|
45
46
|
);
|
|
46
47
|
};
|
|
47
48
|
|
|
48
|
-
const cached = JSON.parse(sessionStorage.getItem("
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
const cached = JSON.parse(sessionStorage.getItem("balanceData") || "{}");
|
|
50
|
+
const cachedMerchantBalances = Array.isArray(cached?.merchantBalances)
|
|
51
|
+
? cached.merchantBalances
|
|
52
|
+
: [];
|
|
53
|
+
if (cachedMerchantBalances.length > 0) {
|
|
54
|
+
applySubBusinesses(cachedMerchantBalances);
|
|
51
55
|
}
|
|
52
56
|
|
|
53
|
-
|
|
54
|
-
.then((
|
|
55
|
-
applySubBusinesses(
|
|
57
|
+
getBalanceData()
|
|
58
|
+
.then((balanceData: any) => {
|
|
59
|
+
applySubBusinesses(
|
|
60
|
+
Array.isArray(balanceData?.merchantBalances)
|
|
61
|
+
? balanceData.merchantBalances
|
|
62
|
+
: [],
|
|
63
|
+
);
|
|
56
64
|
})
|
|
57
65
|
.catch(() => {
|
|
58
|
-
if (
|
|
66
|
+
if (cachedMerchantBalances.length === 0) {
|
|
59
67
|
applySubBusinesses([]);
|
|
60
68
|
}
|
|
61
69
|
});
|
|
@@ -123,6 +131,7 @@ export function useFundAllocation() {
|
|
|
123
131
|
|
|
124
132
|
return subBusinesses.map((item) => ({
|
|
125
133
|
fundBalanceId: item.fundBalanceId,
|
|
134
|
+
bizType: item.bizType,
|
|
126
135
|
ratio: String(subBizPercentages[item.bizType] || ""),
|
|
127
136
|
}));
|
|
128
137
|
};
|
package/src/demo/App.tsx
CHANGED
|
@@ -39,13 +39,13 @@ export default function DemoApp() {
|
|
|
39
39
|
initFundUnit({
|
|
40
40
|
token:
|
|
41
41
|
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZXJjaGFudF9pZCI6MTAwMiwidGltZXN0YW1wIjoxNzUzNDMwNjkyLCJleHAiOjE3NTM0MzQyOTJ9.OPYKUxLQ3C36rKiAmCnUwxTkvM9eKgtsnoxrB9Ntrag",
|
|
42
|
-
fund_balance_id: "FB1FNZ5Q55M7QP2C",
|
|
42
|
+
// fund_balance_id: "FB1FNZ5Q55M7QP2C",
|
|
43
43
|
user_id: "19b8a77c-d3fc-45da-9520-4a07463123df",
|
|
44
44
|
locale: locale as Locale,
|
|
45
45
|
theme: theme ?? Theme.WHITE,
|
|
46
46
|
env: env ?? currentEnv,
|
|
47
47
|
size: Size.SMALL,
|
|
48
|
-
biz_type: "
|
|
48
|
+
biz_type: "ad",
|
|
49
49
|
merchant_id: "1128",
|
|
50
50
|
// theme_config: {
|
|
51
51
|
// white: {
|
package/src/types/global.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getAllDicts, getBalance } from "@/api";
|
|
2
2
|
import { resetHttpInstance } from "@/api/axiosInstance";
|
|
3
3
|
import { Locale, Size, Theme, type Env } from "@/types";
|
|
4
|
+
import type { MerchantBalanceItem } from "@/api";
|
|
4
5
|
|
|
5
6
|
// 余额数据结构接口
|
|
6
7
|
export interface BalanceData {
|
|
@@ -17,6 +18,7 @@ export interface BalanceData {
|
|
|
17
18
|
pendingAmount: string;
|
|
18
19
|
status: string;
|
|
19
20
|
createdAt: string;
|
|
21
|
+
merchantBalances: MerchantBalanceItem[];
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
interface ThemeConfig {
|