@pisell/pisellos 2.3.109 → 2.3.111
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/modules/OpenData/index.d.ts +1 -1
- package/dist/modules/OpenData/index.js +19 -11
- package/dist/modules/Order/index.d.ts +1 -0
- package/dist/modules/Order/index.js +22 -21
- package/dist/modules/Payment/cashRecommendationAlgorithm.d.ts +4 -5
- package/dist/modules/Payment/cashRecommendationAlgorithm.js +17 -367
- package/dist/server/index.js +4 -5
- package/dist/server/utils/small-ticket.d.ts +8 -5
- package/dist/server/utils/small-ticket.js +678 -140
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +6 -0
- package/dist/solution/BookingTicket/index.js +548 -485
- package/dist/utils/os-private-payload.d.ts +5 -0
- package/dist/utils/os-private-payload.js +17 -0
- package/lib/model/strategy/adapter/promotion/index.js +1 -46
- package/lib/modules/OpenData/index.d.ts +1 -1
- package/lib/modules/OpenData/index.js +9 -1
- package/lib/modules/Order/index.d.ts +1 -0
- package/lib/modules/Order/index.js +15 -18
- package/lib/modules/Payment/cashRecommendationAlgorithm.d.ts +4 -5
- package/lib/modules/Payment/cashRecommendationAlgorithm.js +9 -354
- package/lib/server/index.js +4 -5
- package/lib/server/utils/small-ticket.d.ts +8 -5
- package/lib/server/utils/small-ticket.js +524 -65
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +6 -0
- package/lib/solution/BookingTicket/index.js +32 -3
- package/lib/utils/os-private-payload.d.ts +5 -0
- package/lib/utils/os-private-payload.js +22 -0
- package/package.json +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
import { cloneDeep } from 'lodash-es';
|
|
3
|
+
var OS_PRIVATE_FIELD_PREFIX = '_os_';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Remove top-level fields reserved for communication with the PisellOS proxy.
|
|
7
|
+
* Nested business payloads are intentionally left untouched.
|
|
8
|
+
*/
|
|
9
|
+
export function stripOsPrivatePayloadFields(data) {
|
|
10
|
+
var next = cloneDeep(data);
|
|
11
|
+
if (!next || _typeof(next) !== 'object' || Array.isArray(next)) return next;
|
|
12
|
+
var record = next;
|
|
13
|
+
Object.keys(record).forEach(function (key) {
|
|
14
|
+
if (key.startsWith(OS_PRIVATE_FIELD_PREFIX)) delete record[key];
|
|
15
|
+
});
|
|
16
|
+
return next;
|
|
17
|
+
}
|
|
@@ -1,46 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "BUY_X_GET_Y_FREE_STRATEGY", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _examples.BUY_X_GET_Y_FREE_STRATEGY;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "ITEM_REWARD_STRATEGY", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _examples.ITEM_REWARD_STRATEGY;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
Object.defineProperty(exports, "PromotionAdapter", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function () {
|
|
21
|
-
return _adapter.PromotionAdapter;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperty(exports, "PromotionEvaluator", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
get: function () {
|
|
27
|
-
return _evaluator.PromotionEvaluator;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
Object.defineProperty(exports, "X_ITEMS_FOR_Y_PRICE_STRATEGY", {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
get: function () {
|
|
33
|
-
return _examples.X_ITEMS_FOR_Y_PRICE_STRATEGY;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
Object.defineProperty(exports, "default", {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
get: function () {
|
|
39
|
-
return _adapter.default;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
var _evaluator = require("./evaluator");
|
|
43
|
-
var _adapter = _interopRequireWildcard(require("./adapter"));
|
|
44
|
-
var _examples = require("./examples");
|
|
45
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
46
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
1
|
+
"use strict";
|
|
@@ -33,7 +33,7 @@ export declare class OpenDataModule extends BaseModule implements Module {
|
|
|
33
33
|
getOpenData(): OpenDataConfig | null;
|
|
34
34
|
getInvoiceLayoutConfig(): InvoiceLayoutConfig;
|
|
35
35
|
getInvoiceTemplateSettings(): InvoiceTemplateSettings;
|
|
36
|
-
ensureInvoiceTemplateSettings(target: string): Promise<InvoiceTemplateSettings>;
|
|
36
|
+
ensureInvoiceTemplateSettings(target: string, openDataConfig?: OpenDataConfig): Promise<InvoiceTemplateSettings>;
|
|
37
37
|
private commitInvoiceTemplateSettings;
|
|
38
38
|
private resolveInvoiceTemplateSettings;
|
|
39
39
|
private buildInvoiceTemplateCacheKey;
|
|
@@ -211,8 +211,16 @@ class OpenDataModule extends _BaseModule.BaseModule {
|
|
|
211
211
|
}
|
|
212
212
|
return (0, _utils.getDefaultInvoiceTemplateSettings)();
|
|
213
213
|
}
|
|
214
|
-
async ensureInvoiceTemplateSettings(target) {
|
|
214
|
+
async ensureInvoiceTemplateSettings(target, openDataConfig) {
|
|
215
215
|
const normalizedTarget = String(target || '').trim();
|
|
216
|
+
if (openDataConfig && openDataConfig !== this.store.data) {
|
|
217
|
+
// 部分解决方案会在初始化参数中直接收到已经拉取完成的 OpenData。
|
|
218
|
+
// 将它纳入模块状态后再解析 Document,避免为了 Invoice 重复请求 setting,
|
|
219
|
+
// 同时让后续同步 getter 能校验同一份 document id 与 target。
|
|
220
|
+
this.fetchRevision += 1;
|
|
221
|
+
this.store.data = openDataConfig;
|
|
222
|
+
this.store.lastFetchedAt = Date.now();
|
|
223
|
+
}
|
|
216
224
|
const config = this.store.data;
|
|
217
225
|
if (!normalizedTarget || !config) {
|
|
218
226
|
return (0, _utils.getDefaultInvoiceTemplateSettings)();
|
|
@@ -588,6 +588,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
588
588
|
*/
|
|
589
589
|
createOrderByCheckout(params: CheckoutOrderParams): Promise<any>;
|
|
590
590
|
submitSalesOrder<T = any>(params: SubmitSalesOrderParams): Promise<T>;
|
|
591
|
+
private isSalesCheckoutHandledByOsServer;
|
|
591
592
|
/**
|
|
592
593
|
* 发送支付链接邮件。
|
|
593
594
|
*
|
|
@@ -9,6 +9,7 @@ var _types = require("./types");
|
|
|
9
9
|
var _utils = require("./utils");
|
|
10
10
|
var _utils2 = require("../Product/utils");
|
|
11
11
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
12
|
+
var _osPrivatePayload = require("../../utils/os-private-payload");
|
|
12
13
|
var _salesNotes = require("./salesNotes");
|
|
13
14
|
var _paymentUtils = require("./payment-utils");
|
|
14
15
|
var _paymentNumber = require("../../utils/payment-number");
|
|
@@ -72,13 +73,6 @@ function getVoucherPaymentLifecycleKey(payment) {
|
|
|
72
73
|
if (!isVoucherPaymentRecord(payment)) return null;
|
|
73
74
|
return `${String(payment.voucher_id)}::${String(payment.status || '')}`;
|
|
74
75
|
}
|
|
75
|
-
function hasPersistedOrderId(orderId) {
|
|
76
|
-
if (orderId === undefined || orderId === null || orderId === '') return false;
|
|
77
|
-
if (typeof orderId === 'string' && orderId.startsWith('LOCAL_')) return false;
|
|
78
|
-
const normalizedOrderId = Number(orderId);
|
|
79
|
-
if (Number.isFinite(normalizedOrderId)) return normalizedOrderId > 0;
|
|
80
|
-
return String(orderId).trim() !== '';
|
|
81
|
-
}
|
|
82
76
|
class OrderModule extends _BaseModule.BaseModule {
|
|
83
77
|
defaultName = 'order';
|
|
84
78
|
defaultVersion = '1.0.0';
|
|
@@ -482,7 +476,6 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
482
476
|
this.store.virtualCurrencyList = prepareConfigResult?.virtualCurrencyList || [];
|
|
483
477
|
if (prepareConfigResult) {
|
|
484
478
|
this.writePointCardSnapshotFromPrepareConfig({
|
|
485
|
-
orderId,
|
|
486
479
|
customerId: params.customerId,
|
|
487
480
|
availableWalletPassList: prepareConfigResult.availableWalletPassList || []
|
|
488
481
|
});
|
|
@@ -1022,8 +1015,6 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1022
1015
|
const tempOrder = this.store.tempOrder;
|
|
1023
1016
|
if (!tempOrder) return;
|
|
1024
1017
|
if (String(tempOrder.customer_id ?? '') !== String(params.customerId)) return;
|
|
1025
|
-
const effectiveOrderId = params.orderId ?? tempOrder.order_id;
|
|
1026
|
-
if (hasPersistedOrderId(effectiveOrderId)) return;
|
|
1027
1018
|
tempOrder.order_meta_list = {
|
|
1028
1019
|
...((0, _utils.normalizeOrderMetaList)(tempOrder.order_meta_list) || {}),
|
|
1029
1020
|
point_cards_snapshot: (0, _utils.buildPointCardSnapshotFromWalletPassList)(params.availableWalletPassList)
|
|
@@ -2699,7 +2690,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2699
2690
|
email: tempOrder.email
|
|
2700
2691
|
});
|
|
2701
2692
|
const nextCustomerId = tempOrder.customer_id ?? null;
|
|
2702
|
-
if (String(previousCustomerId ?? '') !== String(nextCustomerId ?? '')
|
|
2693
|
+
if (String(previousCustomerId ?? '') !== String(nextCustomerId ?? '')) {
|
|
2703
2694
|
this.store.availableWalletIds = [];
|
|
2704
2695
|
this.clearTempOrderPointCardSnapshot(tempOrder);
|
|
2705
2696
|
}
|
|
@@ -2739,9 +2730,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2739
2730
|
if (String(previousCustomerId ?? '') !== String(nextCustomerId ?? '')) {
|
|
2740
2731
|
this.store.availableWalletIds = [];
|
|
2741
2732
|
this.store.virtualCurrencyList = [];
|
|
2742
|
-
|
|
2743
|
-
this.clearTempOrderPointCardSnapshot(tempOrder);
|
|
2744
|
-
}
|
|
2733
|
+
this.clearTempOrderPointCardSnapshot(tempOrder);
|
|
2745
2734
|
(0, _utils.clearTempOrderHolderAssignments)(tempOrder);
|
|
2746
2735
|
this.clearCustomerBoundDiscounts(tempOrder);
|
|
2747
2736
|
this.applyDiscount();
|
|
@@ -2781,9 +2770,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2781
2770
|
if (tempOrder._extend) delete tempOrder._extend.customerSnapshot;
|
|
2782
2771
|
this.store.availableWalletIds = [];
|
|
2783
2772
|
this.store.virtualCurrencyList = [];
|
|
2784
|
-
|
|
2785
|
-
this.clearTempOrderPointCardSnapshot(tempOrder);
|
|
2786
|
-
}
|
|
2773
|
+
this.clearTempOrderPointCardSnapshot(tempOrder);
|
|
2787
2774
|
this.clearCustomerBoundDiscounts(tempOrder);
|
|
2788
2775
|
this.applyDiscount();
|
|
2789
2776
|
this.persistTempOrder();
|
|
@@ -4680,11 +4667,21 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4680
4667
|
query
|
|
4681
4668
|
} = params;
|
|
4682
4669
|
const fetchUrl = url || '/order/sales/checkout';
|
|
4683
|
-
|
|
4670
|
+
const requestQuery = this.isSalesCheckoutHandledByOsServer(fetchUrl) ? query : (0, _osPrivatePayload.stripOsPrivatePayloadFields)(query);
|
|
4671
|
+
return this.request.post(fetchUrl, requestQuery, {
|
|
4684
4672
|
osServer: true,
|
|
4685
4673
|
customToast: () => {}
|
|
4686
4674
|
});
|
|
4687
4675
|
}
|
|
4676
|
+
isSalesCheckoutHandledByOsServer(fetchUrl) {
|
|
4677
|
+
const server = this.core?.server;
|
|
4678
|
+
if (!server || typeof server.hasRoute !== 'function') return false;
|
|
4679
|
+
const requestBaseUrl = String(this.request?.baseUrl || '/shop').replace(/\/+$/, '');
|
|
4680
|
+
if (!requestBaseUrl.startsWith('/')) return false;
|
|
4681
|
+
const normalizedFetchUrl = fetchUrl.startsWith('/') ? fetchUrl : `/${fetchUrl}`;
|
|
4682
|
+
const routePath = normalizedFetchUrl === requestBaseUrl || normalizedFetchUrl.startsWith(`${requestBaseUrl}/`) ? normalizedFetchUrl : `${requestBaseUrl}${normalizedFetchUrl}`;
|
|
4683
|
+
return server.hasRoute('post', routePath) === true;
|
|
4684
|
+
}
|
|
4688
4685
|
|
|
4689
4686
|
/**
|
|
4690
4687
|
* 发送支付链接邮件。
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
* 现金支付推荐算法
|
|
3
3
|
*
|
|
4
4
|
* 核心原理:
|
|
5
|
-
* 1.
|
|
6
|
-
* 2.
|
|
7
|
-
* 3.
|
|
8
|
-
* 4. 根据组合判断去重,避免扩展组合
|
|
5
|
+
* 1. 第一项始终是精确应付金额
|
|
6
|
+
* 2. 其余推荐只能是严格大于应付金额的真实币种面额
|
|
7
|
+
* 3. 最多推荐三个更高面额
|
|
9
8
|
*/
|
|
10
9
|
/**
|
|
11
10
|
* 常见国家货币面额配置
|
|
@@ -13,7 +12,7 @@
|
|
|
13
12
|
export declare const CURRENCY_DENOMINATIONS: Record<string, number[]>;
|
|
14
13
|
/**
|
|
15
14
|
* 最优支付金额推荐算法
|
|
16
|
-
*
|
|
15
|
+
* 返回精确应付金额,以及最多三个更高的真实币种面额
|
|
17
16
|
*
|
|
18
17
|
* @param targetAmount 目标金额
|
|
19
18
|
* @param denominations 币种面值数组
|
|
@@ -9,10 +9,9 @@ exports.recommendOptimalPayments = recommendOptimalPayments;
|
|
|
9
9
|
* 现金支付推荐算法
|
|
10
10
|
*
|
|
11
11
|
* 核心原理:
|
|
12
|
-
* 1.
|
|
13
|
-
* 2.
|
|
14
|
-
* 3.
|
|
15
|
-
* 4. 根据组合判断去重,避免扩展组合
|
|
12
|
+
* 1. 第一项始终是精确应付金额
|
|
13
|
+
* 2. 其余推荐只能是严格大于应付金额的真实币种面额
|
|
14
|
+
* 3. 最多推荐三个更高面额
|
|
16
15
|
*/
|
|
17
16
|
|
|
18
17
|
/**
|
|
@@ -48,364 +47,20 @@ const CURRENCY_DENOMINATIONS = exports.CURRENCY_DENOMINATIONS = {
|
|
|
48
47
|
'DEFAULT': [100, 50, 20, 10, 5, 1, 0.5, 0.25, 0.1, 0.05, 0.01]
|
|
49
48
|
};
|
|
50
49
|
|
|
51
|
-
/**
|
|
52
|
-
* 支付组合类型定义
|
|
53
|
-
*/
|
|
54
|
-
|
|
55
50
|
/**
|
|
56
51
|
* 最优支付金额推荐算法
|
|
57
|
-
*
|
|
52
|
+
* 返回精确应付金额,以及最多三个更高的真实币种面额
|
|
58
53
|
*
|
|
59
54
|
* @param targetAmount 目标金额
|
|
60
55
|
* @param denominations 币种面值数组
|
|
61
56
|
* @returns 推荐支付金额数组
|
|
62
57
|
*/
|
|
63
58
|
function recommendOptimalPayments(targetAmount, denominations) {
|
|
64
|
-
|
|
65
|
-
if (targetAmount <= 0 || !isFinite(targetAmount) || isNaN(targetAmount)) {
|
|
59
|
+
if (targetAmount <= 0 || !Number.isFinite(targetAmount)) {
|
|
66
60
|
return [];
|
|
67
61
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
// 过滤有效面额并限制搜索空间以提高性能
|
|
73
|
-
const maxReasonableDenom = targetAmount * 5; // 适度限制搜索空间
|
|
74
|
-
const validDenoms = denominations.filter(denom => denom > 0 && isFinite(denom) && !isNaN(denom) && denom <= maxReasonableDenom).slice(0, 8); // 限制面额数量以提高性能
|
|
75
|
-
|
|
76
|
-
if (validDenoms.length === 0) {
|
|
77
|
-
// 如果没有合适的面额,返回最接近的整数金额
|
|
78
|
-
return [Math.ceil(targetAmount)];
|
|
79
|
-
}
|
|
80
|
-
try {
|
|
81
|
-
// 处理精度问题,将金额转换为整数计算
|
|
82
|
-
const precision = 100; // 假设最小单位是0.01
|
|
83
|
-
const target = Math.round(targetAmount * precision);
|
|
84
|
-
const denoms = validDenoms.map(d => Math.round(d * precision)).sort((a, b) => b - a);
|
|
85
|
-
|
|
86
|
-
// 存储不同的支付组合方案
|
|
87
|
-
const paymentOptions = [];
|
|
88
|
-
|
|
89
|
-
// 首先尝试找到精确匹配的组合
|
|
90
|
-
const exactCombination = findExactCombination(target, denoms, precision);
|
|
91
|
-
if (exactCombination) {
|
|
92
|
-
paymentOptions.push(exactCombination);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// 为了提高效率,我们将按币种数量来生成组合
|
|
96
|
-
// 1币种组合:只用一种面额
|
|
97
|
-
for (let i = 0; i < Math.min(denoms.length, 6); i++) {
|
|
98
|
-
const denom = denoms[i];
|
|
99
|
-
const count = Math.ceil(target / denom);
|
|
100
|
-
const sum = count * denom;
|
|
101
|
-
if (sum >= target && count <= 12) {
|
|
102
|
-
// 限制硬币数量以提高性能
|
|
103
|
-
paymentOptions.push({
|
|
104
|
-
combination: Array(count).fill(denom / precision),
|
|
105
|
-
sum: sum / precision,
|
|
106
|
-
coinCount: count,
|
|
107
|
-
denomTypes: 1
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// 2币种组合:使用两种面额(大幅限制搜索范围以提高性能)
|
|
113
|
-
for (let i = 0; i < Math.min(denoms.length - 1, 5); i++) {
|
|
114
|
-
for (let j = i + 1; j < Math.min(denoms.length, 6); j++) {
|
|
115
|
-
const denom1 = denoms[i];
|
|
116
|
-
const denom2 = denoms[j];
|
|
117
|
-
|
|
118
|
-
// 大幅限制搜索范围,基于目标金额动态调整
|
|
119
|
-
const maxCount1 = Math.min(Math.ceil(target / denom1) + 1, 8);
|
|
120
|
-
const maxCount2 = Math.min(Math.ceil(target / denom2) + 1, 10);
|
|
121
|
-
for (let count1 = 1; count1 <= maxCount1; count1++) {
|
|
122
|
-
for (let count2 = 1; count2 <= maxCount2; count2++) {
|
|
123
|
-
const sum = count1 * denom1 + count2 * denom2;
|
|
124
|
-
if (sum >= target) {
|
|
125
|
-
const combination = [...Array(count1).fill(denom1 / precision), ...Array(count2).fill(denom2 / precision)];
|
|
126
|
-
paymentOptions.push({
|
|
127
|
-
combination: combination,
|
|
128
|
-
sum: sum / precision,
|
|
129
|
-
coinCount: count1 + count2,
|
|
130
|
-
denomTypes: 2
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// 3币种组合:使用三种面额(大幅限制搜索以提高效率)
|
|
139
|
-
for (let i = 0; i < Math.min(denoms.length - 2, 3); i++) {
|
|
140
|
-
for (let j = i + 1; j < Math.min(denoms.length - 1, 4); j++) {
|
|
141
|
-
for (let k = j + 1; k < Math.min(denoms.length, 5); k++) {
|
|
142
|
-
const denom1 = denoms[i];
|
|
143
|
-
const denom2 = denoms[j];
|
|
144
|
-
const denom3 = denoms[k];
|
|
145
|
-
|
|
146
|
-
// 大幅限制搜索范围
|
|
147
|
-
const maxCount1 = Math.min(Math.ceil(target / denom1) + 1, 5);
|
|
148
|
-
const maxCount2 = Math.min(Math.ceil(target / denom2) + 1, 6);
|
|
149
|
-
const maxCount3 = Math.min(Math.ceil(target / denom3) + 1, 8);
|
|
150
|
-
for (let count1 = 1; count1 <= maxCount1; count1++) {
|
|
151
|
-
for (let count2 = 1; count2 <= maxCount2; count2++) {
|
|
152
|
-
for (let count3 = 1; count3 <= maxCount3; count3++) {
|
|
153
|
-
const sum = count1 * denom1 + count2 * denom2 + count3 * denom3;
|
|
154
|
-
if (sum >= target) {
|
|
155
|
-
const combination = [...Array(count1).fill(denom1 / precision), ...Array(count2).fill(denom2 / precision), ...Array(count3).fill(denom3 / precision)];
|
|
156
|
-
paymentOptions.push({
|
|
157
|
-
combination: combination,
|
|
158
|
-
sum: sum / precision,
|
|
159
|
-
coinCount: count1 + count2 + count3,
|
|
160
|
-
denomTypes: 3
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// 4币种组合:使用四种面额(极度限制搜索以提高性能)
|
|
171
|
-
for (let i = 0; i < Math.min(denoms.length - 3, 2); i++) {
|
|
172
|
-
for (let j = i + 1; j < Math.min(denoms.length - 2, 3); j++) {
|
|
173
|
-
for (let k = j + 1; k < Math.min(denoms.length - 1, 4); k++) {
|
|
174
|
-
for (let l = k + 1; l < Math.min(denoms.length, 5); l++) {
|
|
175
|
-
const denom1 = denoms[i];
|
|
176
|
-
const denom2 = denoms[j];
|
|
177
|
-
const denom3 = denoms[k];
|
|
178
|
-
const denom4 = denoms[l];
|
|
179
|
-
|
|
180
|
-
// 极度限制搜索范围
|
|
181
|
-
const maxCount1 = Math.min(Math.ceil(target / denom1) + 1, 3);
|
|
182
|
-
const maxCount2 = Math.min(Math.ceil(target / denom2) + 1, 4);
|
|
183
|
-
const maxCount3 = Math.min(Math.ceil(target / denom3) + 1, 5);
|
|
184
|
-
const maxCount4 = Math.min(Math.ceil(target / denom4) + 1, 6);
|
|
185
|
-
for (let count1 = 1; count1 <= maxCount1; count1++) {
|
|
186
|
-
for (let count2 = 1; count2 <= maxCount2; count2++) {
|
|
187
|
-
for (let count3 = 1; count3 <= maxCount3; count3++) {
|
|
188
|
-
for (let count4 = 1; count4 <= maxCount4; count4++) {
|
|
189
|
-
const sum = count1 * denom1 + count2 * denom2 + count3 * denom3 + count4 * denom4;
|
|
190
|
-
if (sum >= target) {
|
|
191
|
-
const combination = [...Array(count1).fill(denom1 / precision), ...Array(count2).fill(denom2 / precision), ...Array(count3).fill(denom3 / precision), ...Array(count4).fill(denom4 / precision)];
|
|
192
|
-
paymentOptions.push({
|
|
193
|
-
combination: combination,
|
|
194
|
-
sum: sum / precision,
|
|
195
|
-
coinCount: count1 + count2 + count3 + count4,
|
|
196
|
-
denomTypes: 4
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// 如果没有找到任何组合,提供默认建议
|
|
209
|
-
if (paymentOptions.length === 0) {
|
|
210
|
-
// 找到大于等于目标金额的最小面额
|
|
211
|
-
const minValidDenom = validDenoms.find(denom => denom >= targetAmount);
|
|
212
|
-
if (minValidDenom) {
|
|
213
|
-
return [minValidDenom];
|
|
214
|
-
} else {
|
|
215
|
-
// 使用最大面额的组合
|
|
216
|
-
const maxDenom = Math.max(...validDenoms);
|
|
217
|
-
const count = Math.ceil(targetAmount / maxDenom);
|
|
218
|
-
return [count * maxDenom];
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
// 移除重复和扩展组合
|
|
223
|
-
const uniqueCombinations = removeDuplicateAndExtendedCombinations(paymentOptions, targetAmount);
|
|
224
|
-
|
|
225
|
-
// 按币种类型数量排序,然后按总硬币数量排序,最后按金额排序
|
|
226
|
-
uniqueCombinations.sort((a, b) => {
|
|
227
|
-
if (a.denomTypes !== b.denomTypes) {
|
|
228
|
-
return a.denomTypes - b.denomTypes;
|
|
229
|
-
}
|
|
230
|
-
if (a.coinCount !== b.coinCount) {
|
|
231
|
-
return a.coinCount - b.coinCount;
|
|
232
|
-
}
|
|
233
|
-
return a.sum - b.sum;
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
// 按金额去重并返回推荐的支付金额
|
|
237
|
-
const uniqueAmounts = new Set();
|
|
238
|
-
const finalResults = [];
|
|
239
|
-
for (const item of uniqueCombinations) {
|
|
240
|
-
const roundedAmount = Math.round(item.sum * 100) / 100; // 处理浮点数精度
|
|
241
|
-
if (!uniqueAmounts.has(roundedAmount) && finalResults.length < 10) {
|
|
242
|
-
uniqueAmounts.add(roundedAmount);
|
|
243
|
-
finalResults.push(roundedAmount);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
return finalResults.sort((a, b) => a - b);
|
|
247
|
-
} catch (error) {
|
|
248
|
-
// 发生错误时返回安全的默认值
|
|
249
|
-
console.warn('推荐支付金额计算出错:', error);
|
|
250
|
-
// 返回最接近的整数金额作为兜底
|
|
251
|
-
const safeAmount = Math.ceil(targetAmount);
|
|
252
|
-
return [targetAmount, safeAmount];
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* 尝试找到精确匹配目标金额的组合
|
|
258
|
-
*/
|
|
259
|
-
function findExactCombination(target, denoms, precision) {
|
|
260
|
-
// 简单的深度优先搜索,限制搜索深度
|
|
261
|
-
function dfs(remaining, denomIndex, currentCombination) {
|
|
262
|
-
if (remaining === 0) {
|
|
263
|
-
return currentCombination;
|
|
264
|
-
}
|
|
265
|
-
if (remaining < 0 || denomIndex >= denoms.length || currentCombination.length > 10) {
|
|
266
|
-
return null;
|
|
267
|
-
}
|
|
268
|
-
const denom = denoms[denomIndex];
|
|
269
|
-
|
|
270
|
-
// 尝试使用当前面额 0 到 maxCount 次
|
|
271
|
-
const maxCount = Math.min(Math.floor(remaining / denom), 8);
|
|
272
|
-
for (let count = maxCount; count >= 0; count--) {
|
|
273
|
-
const newCombination = [...currentCombination, ...Array(count).fill(denom)];
|
|
274
|
-
const result = dfs(remaining - count * denom, denomIndex + 1, newCombination);
|
|
275
|
-
if (result) {
|
|
276
|
-
return result;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
return null;
|
|
280
|
-
}
|
|
281
|
-
const exactMatch = dfs(target, 0, []);
|
|
282
|
-
if (exactMatch && exactMatch.length > 0) {
|
|
283
|
-
const denomTypes = new Set(exactMatch).size;
|
|
284
|
-
return {
|
|
285
|
-
combination: exactMatch.map(d => d / precision),
|
|
286
|
-
sum: target / precision,
|
|
287
|
-
coinCount: exactMatch.length,
|
|
288
|
-
denomTypes: denomTypes
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
return null;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* 移除重复和扩展组合
|
|
296
|
-
* 核心原理:如果组合A包含组合B的所有硬币,并且还有额外硬币,则A是B的扩展,应该被移除
|
|
297
|
-
*/
|
|
298
|
-
function removeDuplicateAndExtendedCombinations(combinations, targetAmount) {
|
|
299
|
-
const result = [];
|
|
300
|
-
|
|
301
|
-
// 按币种类型数量、硬币数量、金额排序,确保较简单的组合在前面
|
|
302
|
-
combinations.sort((a, b) => {
|
|
303
|
-
if (a.denomTypes !== b.denomTypes) {
|
|
304
|
-
return a.denomTypes - b.denomTypes;
|
|
305
|
-
}
|
|
306
|
-
if (a.coinCount !== b.coinCount) {
|
|
307
|
-
return a.coinCount - b.coinCount;
|
|
308
|
-
}
|
|
309
|
-
return a.sum - b.sum;
|
|
310
|
-
});
|
|
311
|
-
for (let i = 0; i < combinations.length; i++) {
|
|
312
|
-
const current = combinations[i];
|
|
313
|
-
let shouldSkip = false;
|
|
314
|
-
|
|
315
|
-
// 检查当前组合是否与已添加的组合重复或者是扩展
|
|
316
|
-
for (let j = 0; j < result.length; j++) {
|
|
317
|
-
const existing = result[j];
|
|
318
|
-
|
|
319
|
-
// 如果完全相同,跳过
|
|
320
|
-
if (isSameCombination(current.combination, existing.combination)) {
|
|
321
|
-
shouldSkip = true;
|
|
322
|
-
break;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
// 如果当前组合是已存在组合的扩展,跳过
|
|
326
|
-
if (isExtensionOf(current.combination, existing.combination)) {
|
|
327
|
-
shouldSkip = true;
|
|
328
|
-
break;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// 检查是否有其他组合是当前组合的扩展,如果有,移除那些扩展
|
|
333
|
-
if (!shouldSkip) {
|
|
334
|
-
// 移除所有当前组合的扩展
|
|
335
|
-
for (let j = result.length - 1; j >= 0; j--) {
|
|
336
|
-
if (isExtensionOf(result[j].combination, current.combination)) {
|
|
337
|
-
result.splice(j, 1);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
result.push(current);
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
return result;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* 检查组合A是否是组合B的扩展(即A包含B的所有硬币,并且还有额外的硬币)
|
|
348
|
-
*/
|
|
349
|
-
function isExtensionOf(combinationA, combinationB) {
|
|
350
|
-
// 如果A的硬币数量少于等于B,A不可能是B的扩展
|
|
351
|
-
if (combinationA.length <= combinationB.length) {
|
|
352
|
-
return false;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
// 统计每个面额的数量
|
|
356
|
-
const countA = {};
|
|
357
|
-
const countB = {};
|
|
358
|
-
combinationA.forEach(coin => {
|
|
359
|
-
countA[coin] = (countA[coin] || 0) + 1;
|
|
360
|
-
});
|
|
361
|
-
combinationB.forEach(coin => {
|
|
362
|
-
countB[coin] = (countB[coin] || 0) + 1;
|
|
363
|
-
});
|
|
364
|
-
|
|
365
|
-
// 检查B的所有面额在A中是否都有足够的数量
|
|
366
|
-
for (const coin in countB) {
|
|
367
|
-
if (!countA[coin] || countA[coin] < countB[coin]) {
|
|
368
|
-
return false;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
// 检查A是否有B没有的额外硬币
|
|
373
|
-
let hasExtra = false;
|
|
374
|
-
for (const coin in countA) {
|
|
375
|
-
if (countA[coin] > (countB[coin] || 0)) {
|
|
376
|
-
hasExtra = true;
|
|
377
|
-
break;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
return hasExtra;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* 检查两个组合是否本质相同(相同的面额组合)
|
|
385
|
-
*/
|
|
386
|
-
function isSameCombination(combinationA, combinationB) {
|
|
387
|
-
if (combinationA.length !== combinationB.length) {
|
|
388
|
-
return false;
|
|
389
|
-
}
|
|
390
|
-
const countA = {};
|
|
391
|
-
const countB = {};
|
|
392
|
-
combinationA.forEach(coin => {
|
|
393
|
-
countA[coin] = (countA[coin] || 0) + 1;
|
|
394
|
-
});
|
|
395
|
-
combinationB.forEach(coin => {
|
|
396
|
-
countB[coin] = (countB[coin] || 0) + 1;
|
|
397
|
-
});
|
|
398
|
-
|
|
399
|
-
// 检查两个组合是否有相同的面额和数量
|
|
400
|
-
for (const coin in countA) {
|
|
401
|
-
if (countA[coin] !== (countB[coin] || 0)) {
|
|
402
|
-
return false;
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
for (const coin in countB) {
|
|
406
|
-
if (countB[coin] !== (countA[coin] || 0)) {
|
|
407
|
-
return false;
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
return true;
|
|
62
|
+
const precision = 100;
|
|
63
|
+
const normalizedTarget = Math.round(targetAmount * precision) / precision;
|
|
64
|
+
const higherDenominations = [...new Set((Array.isArray(denominations) ? denominations : []).filter(denomination => denomination > 0 && Number.isFinite(denomination)).map(denomination => Math.round(denomination * precision) / precision))].filter(denomination => denomination > normalizedTarget).sort((a, b) => a - b).slice(0, 3);
|
|
65
|
+
return [normalizedTarget, ...higherDenominations];
|
|
411
66
|
}
|
package/lib/server/index.js
CHANGED
|
@@ -29,6 +29,7 @@ var _BaseSales = require("../solution/BaseSales");
|
|
|
29
29
|
var _paymentUtils = require("../modules/Order/payment-utils");
|
|
30
30
|
var _salesNotes = require("../modules/Order/salesNotes");
|
|
31
31
|
var _orderCollectionIdentity = require("../modules/Order/utils/orderCollectionIdentity");
|
|
32
|
+
var _osPrivatePayload = require("../utils/os-private-payload");
|
|
32
33
|
var _OpenData = require("../modules/OpenData");
|
|
33
34
|
var _modules = require("./modules");
|
|
34
35
|
Object.keys(_modules).forEach(function (key) {
|
|
@@ -643,7 +644,7 @@ class Server {
|
|
|
643
644
|
} = params;
|
|
644
645
|
const normalizedData = await this.normalizeCheckoutSubmitData(params.data, title);
|
|
645
646
|
const numberedData = await this.ensureCheckoutOrderNumbers(normalizedData, title);
|
|
646
|
-
const checkoutData = this.normalizeCheckoutCollections(this.applyCheckoutFulfillmentBuzzer(numberedData, title));
|
|
647
|
+
const checkoutData = this.normalizeCheckoutCollections((0, _osPrivatePayload.stripOsPrivatePayloadFields)(this.applyCheckoutFulfillmentBuzzer(numberedData, title)));
|
|
647
648
|
const remoteCheckoutData = this.buildRemoteCheckoutData(checkoutData, title);
|
|
648
649
|
const deviceHeaders = await this.buildCheckoutDeviceHeaders(title);
|
|
649
650
|
if (!this.app?.request?.post) {
|
|
@@ -715,11 +716,9 @@ class Server {
|
|
|
715
716
|
return next;
|
|
716
717
|
}
|
|
717
718
|
buildRemoteCheckoutData(data, title) {
|
|
718
|
-
const next = (0,
|
|
719
|
+
const next = (0, _osPrivatePayload.stripOsPrivatePayloadFields)(this.omitCheckoutSyncMode(data));
|
|
719
720
|
if (!next || typeof next !== 'object') return next;
|
|
720
721
|
const record = next;
|
|
721
|
-
delete record[OS_FULFILLMENT_REF_MODE_FIELD];
|
|
722
|
-
delete record[OS_INVOICE_LAYOUT_CONFIG_FIELD];
|
|
723
722
|
this.applyKioskCheckoutOperator(record);
|
|
724
723
|
if (!Array.isArray(record.payments)) return next;
|
|
725
724
|
const originalPayments = record.payments;
|
|
@@ -4330,7 +4329,7 @@ class Server {
|
|
|
4330
4329
|
}
|
|
4331
4330
|
const normalizedData = await this.normalizeCheckoutSubmitData(data, title);
|
|
4332
4331
|
const numberedData = await this.ensureCheckoutOrderNumbers(normalizedData, title);
|
|
4333
|
-
const checkoutData = this.normalizeCheckoutCollections(this.applyCheckoutFulfillmentBuzzer(numberedData, title));
|
|
4332
|
+
const checkoutData = this.normalizeCheckoutCollections((0, _osPrivatePayload.stripOsPrivatePayloadFields)(this.applyCheckoutFulfillmentBuzzer(numberedData, title)));
|
|
4334
4333
|
const pendingResult = await this.handlePendingSyncCheckoutOrder({
|
|
4335
4334
|
backendPath,
|
|
4336
4335
|
data: checkoutData,
|