@pisell/pisellos 0.0.229 → 0.0.231

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.
Files changed (65) hide show
  1. package/dist/modules/Order/index.d.ts +13 -2
  2. package/dist/modules/Order/index.js +84 -1
  3. package/dist/modules/Order/types.d.ts +43 -0
  4. package/dist/modules/Order/types.js +8 -0
  5. package/dist/modules/Payment/cash.d.ts +8 -0
  6. package/dist/modules/Payment/cash.js +20 -1
  7. package/dist/modules/Payment/cashRecommendationAlgorithm.d.ts +22 -0
  8. package/dist/modules/Payment/cashRecommendationAlgorithm.js +423 -0
  9. package/dist/modules/Payment/eftpos.js +1 -1
  10. package/dist/modules/Payment/index.d.ts +57 -94
  11. package/dist/modules/Payment/index.js +810 -1109
  12. package/dist/modules/Payment/mx51.d.ts +0 -0
  13. package/dist/modules/Payment/mx51.js +0 -0
  14. package/dist/modules/Payment/types.d.ts +358 -50
  15. package/dist/modules/Payment/types.js +103 -4
  16. package/dist/modules/Payment/utils.d.ts +17 -0
  17. package/dist/modules/Payment/utils.js +62 -0
  18. package/dist/modules/Payment/walletpass.d.ts +96 -0
  19. package/dist/modules/Payment/walletpass.js +492 -0
  20. package/dist/modules/Schedule/index.d.ts +9 -0
  21. package/dist/modules/Schedule/index.js +60 -0
  22. package/dist/solution/BookingTicket/index.d.ts +1 -1
  23. package/dist/solution/Checkout/appointmentDemo.json +1 -0
  24. package/dist/solution/Checkout/index.d.ts +415 -0
  25. package/dist/solution/Checkout/index.js +3622 -0
  26. package/dist/solution/Checkout/types.d.ts +737 -0
  27. package/dist/solution/Checkout/types.js +137 -0
  28. package/dist/solution/Checkout/utils/index.d.ts +73 -0
  29. package/dist/{modules/Payment/wallet.js → solution/Checkout/utils/index.js} +363 -70
  30. package/dist/solution/index.d.ts +1 -0
  31. package/dist/solution/index.js +2 -1
  32. package/lib/modules/Order/index.d.ts +13 -2
  33. package/lib/modules/Order/index.js +58 -1
  34. package/lib/modules/Order/types.d.ts +43 -0
  35. package/lib/modules/Payment/cash.d.ts +8 -0
  36. package/lib/modules/Payment/cash.js +14 -1
  37. package/lib/modules/Payment/cashRecommendationAlgorithm.d.ts +22 -0
  38. package/lib/modules/Payment/cashRecommendationAlgorithm.js +342 -0
  39. package/lib/modules/Payment/eftpos.js +1 -1
  40. package/lib/modules/Payment/index.d.ts +57 -94
  41. package/lib/modules/Payment/index.js +363 -525
  42. package/lib/modules/Payment/mx51.d.ts +0 -0
  43. package/lib/modules/Payment/mx51.js +0 -0
  44. package/lib/modules/Payment/types.d.ts +358 -50
  45. package/lib/modules/Payment/types.js +37 -2
  46. package/lib/modules/Payment/utils.d.ts +17 -0
  47. package/lib/modules/Payment/utils.js +67 -0
  48. package/lib/modules/Payment/walletpass.d.ts +96 -0
  49. package/lib/modules/Payment/walletpass.js +304 -0
  50. package/lib/modules/Schedule/index.d.ts +9 -0
  51. package/lib/modules/Schedule/index.js +36 -0
  52. package/lib/solution/BookingTicket/index.d.ts +1 -1
  53. package/lib/solution/Checkout/appointmentDemo.json +1 -0
  54. package/lib/solution/Checkout/index.d.ts +415 -0
  55. package/lib/solution/Checkout/index.js +2107 -0
  56. package/lib/solution/Checkout/types.d.ts +737 -0
  57. package/lib/solution/Checkout/types.js +80 -0
  58. package/lib/solution/Checkout/utils/index.d.ts +73 -0
  59. package/lib/solution/Checkout/utils/index.js +266 -0
  60. package/lib/solution/index.d.ts +1 -0
  61. package/lib/solution/index.js +3 -1
  62. package/package.json +1 -1
  63. package/dist/modules/Payment/wallet.d.ts +0 -11
  64. package/lib/modules/Payment/wallet.d.ts +0 -11
  65. package/lib/modules/Payment/wallet.js +0 -51
@@ -1,6 +1,6 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
- import { OrderModuleAPI, CommitOrderParams } from './types';
3
+ import { OrderModuleAPI, CommitOrderParams, CheckoutOrderParams } from './types';
4
4
  import { CartItem } from '../Cart/types';
5
5
  export declare class OrderModule extends BaseModule implements Module, OrderModuleAPI {
6
6
  protected defaultName: string;
@@ -11,7 +11,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
11
11
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
12
12
  createOrder(params: CommitOrderParams['query']): {
13
13
  type: "virtual" | "appointment_booking";
14
- platform: string;
14
+ platform: "pc" | "h5";
15
15
  sales_channel: string;
16
16
  order_sales_channel: string;
17
17
  bookings: any[];
@@ -26,4 +26,15 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
26
26
  type: 'holder' | 'account';
27
27
  }): boolean;
28
28
  submitOrder(order: CommitOrderParams): Promise<void>;
29
+ /**
30
+ * Checkout 专用:创建订单到后端
31
+ *
32
+ * 专门为 Checkout 模块设计的订单创建方法,
33
+ * 直接调用 /order/checkout 接口创建订单
34
+ * 接收已经处理好的订单数据,无需再处理购物车
35
+ *
36
+ * @param params Checkout 订单参数(已处理的订单数据)
37
+ * @returns 后端返回的订单数据(包含订单ID等)
38
+ */
39
+ createOrderByCheckout(params: CheckoutOrderParams): Promise<any>;
29
40
  }
@@ -41,7 +41,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
41
41
  const order = {
42
42
  type: (params == null ? void 0 : params.type) || "appointment_booking",
43
43
  // 要从外面拿,virtual
44
- platform: (params == null ? void 0 : params.platform) === "pc" ? "PC" : "H5",
44
+ platform: (params == null ? void 0 : params.platform) || "pc",
45
45
  sales_channel: "my_pisel",
46
46
  order_sales_channel: "online_store",
47
47
  bookings: [],
@@ -101,6 +101,63 @@ var OrderModule = class extends import_BaseModule.BaseModule {
101
101
  const params = this.createOrder(query);
102
102
  return this.request.post(fetchUrl, params);
103
103
  }
104
+ /**
105
+ * Checkout 专用:创建订单到后端
106
+ *
107
+ * 专门为 Checkout 模块设计的订单创建方法,
108
+ * 直接调用 /order/checkout 接口创建订单
109
+ * 接收已经处理好的订单数据,无需再处理购物车
110
+ *
111
+ * @param params Checkout 订单参数(已处理的订单数据)
112
+ * @returns 后端返回的订单数据(包含订单ID等)
113
+ */
114
+ async createOrderByCheckout(params) {
115
+ var _a, _b, _c, _d, _e, _f, _g, _h;
116
+ console.log("[Order] createOrderByCheckout 开始创建订单:", {
117
+ type: params.type,
118
+ platform: params.platform,
119
+ is_deposit: params.is_deposit,
120
+ customer_id: params.customer_id,
121
+ bookingsCount: ((_a = params.bookings) == null ? void 0 : _a.length) || 0,
122
+ relationProductsCount: ((_b = params.relation_products) == null ? void 0 : _b.length) || 0,
123
+ paymentsCount: ((_c = params.payments) == null ? void 0 : _c.length) || 0
124
+ });
125
+ try {
126
+ const orderData = {
127
+ sales_channel: "my_pisel",
128
+ order_sales_channel: "online_store",
129
+ shop_note: "",
130
+ schedule_date: "",
131
+ is_deposit: 0,
132
+ bookings: [],
133
+ relation_products: [],
134
+ relation_forms: [],
135
+ payments: [],
136
+ ...params
137
+ // 使用传入的参数覆盖默认值
138
+ };
139
+ console.log("[Order] 调用后端接口创建订单:", {
140
+ url: "/order/checkout",
141
+ orderType: orderData.type,
142
+ platform: orderData.platform,
143
+ isDeposit: orderData.is_deposit,
144
+ customerId: orderData.customer_id,
145
+ bookingsCount: ((_d = orderData.bookings) == null ? void 0 : _d.length) || 0,
146
+ relationProductsCount: ((_e = orderData.relation_products) == null ? void 0 : _e.length) || 0,
147
+ paymentsCount: ((_f = orderData.payments) == null ? void 0 : _f.length) || 0,
148
+ paymentsMethods: ((_g = orderData.payments) == null ? void 0 : _g.map((p) => p.code)) || []
149
+ });
150
+ const response = await this.request.post("/order/checkout", orderData);
151
+ console.log("[Order] 订单创建成功,后端响应:", {
152
+ success: !!response,
153
+ hasOrderId: !!(((_h = response == null ? void 0 : response.data) == null ? void 0 : _h.order_id) || (response == null ? void 0 : response.order_id))
154
+ });
155
+ return response;
156
+ } catch (error) {
157
+ console.error("[Order] createOrderByCheckout 创建订单失败:", error);
158
+ throw error;
159
+ }
160
+ }
104
161
  };
105
162
  // Annotate the CommonJS export names for ESM import in node:
106
163
  0 && (module.exports = {
@@ -18,6 +18,43 @@ export interface CommitOrderParams {
18
18
  platform?: 'pc' | 'h5';
19
19
  };
20
20
  }
21
+ /**
22
+ * 支付项数据
23
+ */
24
+ export interface PaymentItemData {
25
+ /** 当前支付项的唯一 ID */
26
+ uuid: string;
27
+ /** 当前支付方式付出去多少钱 */
28
+ amount: string;
29
+ /** 支付类型代码 */
30
+ code: string;
31
+ /** 支付类型id */
32
+ id: number;
33
+ /** 支付类型名称 */
34
+ name: string;
35
+ /** 支付类型 */
36
+ type: string;
37
+ /** 是否已同步到后端 */
38
+ isSynced?: boolean;
39
+ }
40
+ /**
41
+ * Checkout 专用订单创建参数
42
+ */
43
+ export interface CheckoutOrderParams {
44
+ type: 'virtual' | 'appointment_booking';
45
+ platform: 'PC' | 'H5';
46
+ sales_channel?: string;
47
+ order_sales_channel?: string;
48
+ bookings?: any[];
49
+ shop_note?: string;
50
+ schedule_date?: string;
51
+ is_deposit?: number;
52
+ relation_products?: any[];
53
+ relation_forms?: any[];
54
+ payments?: PaymentItemData[];
55
+ customer_id?: string;
56
+ [key: string]: any;
57
+ }
21
58
  /**
22
59
  * 订单模块 API
23
60
  */
@@ -40,4 +77,10 @@ export interface OrderModuleAPI {
40
77
  * @param params 订单信息
41
78
  */
42
79
  submitOrder: (params: CommitOrderParams) => Promise<void>;
80
+ /**
81
+ * Checkout 专用:创建订单到后端
82
+ * @param params 订单参数
83
+ * @returns 后端返回的订单数据
84
+ */
85
+ createOrderByCheckout: (params: CheckoutOrderParams) => Promise<any>;
43
86
  }
@@ -8,4 +8,12 @@ export declare class CashPaymentImpl implements CashPayment {
8
8
  constructor(paymentModule: PaymentModule);
9
9
  processCashPayment(amount: number, orderUuid: string): Promise<void>;
10
10
  getCashBalance(): Promise<number>;
11
+ /**
12
+ * 获取推荐支付金额
13
+ * 基于目标金额和货币类型,返回最优支付金额建议
14
+ * @param money 目标支付金额
15
+ * @param currency 货币代码 (如: 'CNY', 'USD', 'EUR' 等)
16
+ * @returns 推荐支付金额数组
17
+ */
18
+ getRecommendedAmount(money: number, currency: string): number[];
11
19
  }
@@ -22,6 +22,7 @@ __export(cash_exports, {
22
22
  CashPaymentImpl: () => CashPaymentImpl
23
23
  });
24
24
  module.exports = __toCommonJS(cash_exports);
25
+ var import_cashRecommendationAlgorithm = require("./cashRecommendationAlgorithm");
25
26
  var CashPaymentImpl = class {
26
27
  constructor(paymentModule) {
27
28
  this.paymentModule = paymentModule;
@@ -39,11 +40,23 @@ var CashPaymentImpl = class {
39
40
  type: cashMethod.type,
40
41
  voucher_id: ""
41
42
  };
42
- await this.paymentModule.pushPaymentAsync(orderUuid, paymentItem);
43
+ await this.paymentModule.addPaymentItemAsync(orderUuid, paymentItem);
43
44
  }
44
45
  async getCashBalance() {
45
46
  return 0;
46
47
  }
48
+ /**
49
+ * 获取推荐支付金额
50
+ * 基于目标金额和货币类型,返回最优支付金额建议
51
+ * @param money 目标支付金额
52
+ * @param currency 货币代码 (如: 'CNY', 'USD', 'EUR' 等)
53
+ * @returns 推荐支付金额数组
54
+ */
55
+ getRecommendedAmount(money, currency) {
56
+ const upperCurrency = currency.toUpperCase();
57
+ const denominations = import_cashRecommendationAlgorithm.CURRENCY_DENOMINATIONS[upperCurrency] || import_cashRecommendationAlgorithm.CURRENCY_DENOMINATIONS["DEFAULT"];
58
+ return (0, import_cashRecommendationAlgorithm.recommendOptimalPayments)(money, denominations);
59
+ }
47
60
  };
48
61
  // Annotate the CommonJS export names for ESM import in node:
49
62
  0 && (module.exports = {
@@ -0,0 +1,22 @@
1
+ /**
2
+ * 现金支付推荐算法
3
+ *
4
+ * 核心原理:
5
+ * 1. 每个推荐金额都应该是独立的最优组合
6
+ * 2. 不推荐在已有最优解基础上添加额外面额的组合
7
+ * 3. 优先推荐使用不同数量币种的组合
8
+ * 4. 根据组合判断去重,避免扩展组合
9
+ */
10
+ /**
11
+ * 常见国家货币面额配置
12
+ */
13
+ export declare const CURRENCY_DENOMINATIONS: Record<string, number[]>;
14
+ /**
15
+ * 最优支付金额推荐算法
16
+ * 推荐通过不同数量面额组合刚好足够支付的最小金额
17
+ *
18
+ * @param targetAmount 目标金额
19
+ * @param denominations 币种面值数组
20
+ * @returns 推荐支付金额数组
21
+ */
22
+ export declare function recommendOptimalPayments(targetAmount: number, denominations: number[]): number[];
@@ -0,0 +1,342 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/modules/Payment/cashRecommendationAlgorithm.ts
20
+ var cashRecommendationAlgorithm_exports = {};
21
+ __export(cashRecommendationAlgorithm_exports, {
22
+ CURRENCY_DENOMINATIONS: () => CURRENCY_DENOMINATIONS,
23
+ recommendOptimalPayments: () => recommendOptimalPayments
24
+ });
25
+ module.exports = __toCommonJS(cashRecommendationAlgorithm_exports);
26
+ var CURRENCY_DENOMINATIONS = {
27
+ // 美元
28
+ "USD": [100, 50, 20, 10, 5, 2, 1, 0.5, 0.25, 0.1, 0.05, 0.01],
29
+ // 人民币
30
+ "CNY": [100, 50, 20, 10, 5, 1, 0.5, 0.1, 0.05, 0.01],
31
+ "RMB": [100, 50, 20, 10, 5, 1, 0.5, 0.1, 0.05, 0.01],
32
+ // 欧元
33
+ "EUR": [500, 200, 100, 50, 20, 10, 5, 2, 1, 0.5, 0.2, 0.1, 0.05, 0.02, 0.01],
34
+ // 日元
35
+ "JPY": [1e4, 5e3, 2e3, 1e3, 500, 100, 50, 10, 5, 1],
36
+ // 英镑
37
+ "GBP": [50, 20, 10, 5, 2, 1, 0.5, 0.2, 0.1, 0.05, 0.02, 0.01],
38
+ // 澳元
39
+ "AUD": [100, 50, 20, 10, 5, 2, 1, 0.5, 0.2, 0.1],
40
+ // 加元
41
+ "CAD": [100, 50, 20, 10, 5, 2, 1, 0.25, 0.1, 0.05],
42
+ // 港元
43
+ "HKD": [1e3, 500, 100, 50, 20, 10, 5, 2, 1, 0.5, 0.2, 0.1],
44
+ // 新台币
45
+ "TWD": [2e3, 1e3, 500, 200, 100, 50, 10, 5, 1],
46
+ // 韩元
47
+ "KRW": [5e4, 1e4, 5e3, 1e3, 500, 100, 50, 10, 5, 1],
48
+ // 新加坡元
49
+ "SGD": [1e4, 1e3, 100, 50, 10, 5, 2, 1, 0.5, 0.2, 0.1, 0.05, 0.01],
50
+ // 瑞士法郎
51
+ "CHF": [1e3, 200, 100, 50, 20, 10, 5, 2, 1, 0.5, 0.2, 0.1, 0.05],
52
+ // 默认通用面额(如果币种不在列表中)
53
+ "DEFAULT": [100, 50, 20, 10, 5, 1, 0.5, 0.25, 0.1, 0.05, 0.01]
54
+ };
55
+ function recommendOptimalPayments(targetAmount, denominations) {
56
+ if (targetAmount <= 0 || !isFinite(targetAmount) || isNaN(targetAmount)) {
57
+ return [];
58
+ }
59
+ if (!denominations || !Array.isArray(denominations) || denominations.length === 0) {
60
+ return [Math.ceil(targetAmount)];
61
+ }
62
+ const maxReasonableDenom = targetAmount * 5;
63
+ const validDenoms = denominations.filter((denom) => denom > 0 && isFinite(denom) && !isNaN(denom) && denom <= maxReasonableDenom).slice(0, 8);
64
+ if (validDenoms.length === 0) {
65
+ return [Math.ceil(targetAmount)];
66
+ }
67
+ try {
68
+ const precision = 100;
69
+ const target = Math.round(targetAmount * precision);
70
+ const denoms = validDenoms.map((d) => Math.round(d * precision)).sort((a, b) => b - a);
71
+ const paymentOptions = [];
72
+ const exactCombination = findExactCombination(target, denoms, precision);
73
+ if (exactCombination) {
74
+ paymentOptions.push(exactCombination);
75
+ }
76
+ for (let i = 0; i < Math.min(denoms.length, 6); i++) {
77
+ const denom = denoms[i];
78
+ const count = Math.ceil(target / denom);
79
+ const sum = count * denom;
80
+ if (sum >= target && count <= 12) {
81
+ paymentOptions.push({
82
+ combination: Array(count).fill(denom / precision),
83
+ sum: sum / precision,
84
+ coinCount: count,
85
+ denomTypes: 1
86
+ });
87
+ }
88
+ }
89
+ for (let i = 0; i < Math.min(denoms.length - 1, 5); i++) {
90
+ for (let j = i + 1; j < Math.min(denoms.length, 6); j++) {
91
+ const denom1 = denoms[i];
92
+ const denom2 = denoms[j];
93
+ const maxCount1 = Math.min(Math.ceil(target / denom1) + 1, 8);
94
+ const maxCount2 = Math.min(Math.ceil(target / denom2) + 1, 10);
95
+ for (let count1 = 1; count1 <= maxCount1; count1++) {
96
+ for (let count2 = 1; count2 <= maxCount2; count2++) {
97
+ const sum = count1 * denom1 + count2 * denom2;
98
+ if (sum >= target) {
99
+ const combination = [
100
+ ...Array(count1).fill(denom1 / precision),
101
+ ...Array(count2).fill(denom2 / precision)
102
+ ];
103
+ paymentOptions.push({
104
+ combination,
105
+ sum: sum / precision,
106
+ coinCount: count1 + count2,
107
+ denomTypes: 2
108
+ });
109
+ }
110
+ }
111
+ }
112
+ }
113
+ }
114
+ for (let i = 0; i < Math.min(denoms.length - 2, 3); i++) {
115
+ for (let j = i + 1; j < Math.min(denoms.length - 1, 4); j++) {
116
+ for (let k = j + 1; k < Math.min(denoms.length, 5); k++) {
117
+ const denom1 = denoms[i];
118
+ const denom2 = denoms[j];
119
+ const denom3 = denoms[k];
120
+ const maxCount1 = Math.min(Math.ceil(target / denom1) + 1, 5);
121
+ const maxCount2 = Math.min(Math.ceil(target / denom2) + 1, 6);
122
+ const maxCount3 = Math.min(Math.ceil(target / denom3) + 1, 8);
123
+ for (let count1 = 1; count1 <= maxCount1; count1++) {
124
+ for (let count2 = 1; count2 <= maxCount2; count2++) {
125
+ for (let count3 = 1; count3 <= maxCount3; count3++) {
126
+ const sum = count1 * denom1 + count2 * denom2 + count3 * denom3;
127
+ if (sum >= target) {
128
+ const combination = [
129
+ ...Array(count1).fill(denom1 / precision),
130
+ ...Array(count2).fill(denom2 / precision),
131
+ ...Array(count3).fill(denom3 / precision)
132
+ ];
133
+ paymentOptions.push({
134
+ combination,
135
+ sum: sum / precision,
136
+ coinCount: count1 + count2 + count3,
137
+ denomTypes: 3
138
+ });
139
+ }
140
+ }
141
+ }
142
+ }
143
+ }
144
+ }
145
+ }
146
+ for (let i = 0; i < Math.min(denoms.length - 3, 2); i++) {
147
+ for (let j = i + 1; j < Math.min(denoms.length - 2, 3); j++) {
148
+ for (let k = j + 1; k < Math.min(denoms.length - 1, 4); k++) {
149
+ for (let l = k + 1; l < Math.min(denoms.length, 5); l++) {
150
+ const denom1 = denoms[i];
151
+ const denom2 = denoms[j];
152
+ const denom3 = denoms[k];
153
+ const denom4 = denoms[l];
154
+ const maxCount1 = Math.min(Math.ceil(target / denom1) + 1, 3);
155
+ const maxCount2 = Math.min(Math.ceil(target / denom2) + 1, 4);
156
+ const maxCount3 = Math.min(Math.ceil(target / denom3) + 1, 5);
157
+ const maxCount4 = Math.min(Math.ceil(target / denom4) + 1, 6);
158
+ for (let count1 = 1; count1 <= maxCount1; count1++) {
159
+ for (let count2 = 1; count2 <= maxCount2; count2++) {
160
+ for (let count3 = 1; count3 <= maxCount3; count3++) {
161
+ for (let count4 = 1; count4 <= maxCount4; count4++) {
162
+ const sum = count1 * denom1 + count2 * denom2 + count3 * denom3 + count4 * denom4;
163
+ if (sum >= target) {
164
+ const combination = [
165
+ ...Array(count1).fill(denom1 / precision),
166
+ ...Array(count2).fill(denom2 / precision),
167
+ ...Array(count3).fill(denom3 / precision),
168
+ ...Array(count4).fill(denom4 / precision)
169
+ ];
170
+ paymentOptions.push({
171
+ combination,
172
+ sum: sum / precision,
173
+ coinCount: count1 + count2 + count3 + count4,
174
+ denomTypes: 4
175
+ });
176
+ }
177
+ }
178
+ }
179
+ }
180
+ }
181
+ }
182
+ }
183
+ }
184
+ }
185
+ if (paymentOptions.length === 0) {
186
+ const minValidDenom = validDenoms.find((denom) => denom >= targetAmount);
187
+ if (minValidDenom) {
188
+ return [minValidDenom];
189
+ } else {
190
+ const maxDenom = Math.max(...validDenoms);
191
+ const count = Math.ceil(targetAmount / maxDenom);
192
+ return [count * maxDenom];
193
+ }
194
+ }
195
+ const uniqueCombinations = removeDuplicateAndExtendedCombinations(paymentOptions, targetAmount);
196
+ uniqueCombinations.sort((a, b) => {
197
+ if (a.denomTypes !== b.denomTypes) {
198
+ return a.denomTypes - b.denomTypes;
199
+ }
200
+ if (a.coinCount !== b.coinCount) {
201
+ return a.coinCount - b.coinCount;
202
+ }
203
+ return a.sum - b.sum;
204
+ });
205
+ const uniqueAmounts = /* @__PURE__ */ new Set();
206
+ const finalResults = [];
207
+ for (const item of uniqueCombinations) {
208
+ const roundedAmount = Math.round(item.sum * 100) / 100;
209
+ if (!uniqueAmounts.has(roundedAmount) && finalResults.length < 10) {
210
+ uniqueAmounts.add(roundedAmount);
211
+ finalResults.push(roundedAmount);
212
+ }
213
+ }
214
+ return finalResults.sort((a, b) => a - b);
215
+ } catch (error) {
216
+ console.warn("推荐支付金额计算出错:", error);
217
+ const safeAmount = Math.ceil(targetAmount);
218
+ return [targetAmount, safeAmount];
219
+ }
220
+ }
221
+ function findExactCombination(target, denoms, precision) {
222
+ function dfs(remaining, denomIndex, currentCombination) {
223
+ if (remaining === 0) {
224
+ return currentCombination;
225
+ }
226
+ if (remaining < 0 || denomIndex >= denoms.length || currentCombination.length > 10) {
227
+ return null;
228
+ }
229
+ const denom = denoms[denomIndex];
230
+ const maxCount = Math.min(Math.floor(remaining / denom), 8);
231
+ for (let count = maxCount; count >= 0; count--) {
232
+ const newCombination = [...currentCombination, ...Array(count).fill(denom)];
233
+ const result = dfs(remaining - count * denom, denomIndex + 1, newCombination);
234
+ if (result) {
235
+ return result;
236
+ }
237
+ }
238
+ return null;
239
+ }
240
+ const exactMatch = dfs(target, 0, []);
241
+ if (exactMatch && exactMatch.length > 0) {
242
+ const denomTypes = new Set(exactMatch).size;
243
+ return {
244
+ combination: exactMatch.map((d) => d / precision),
245
+ sum: target / precision,
246
+ coinCount: exactMatch.length,
247
+ denomTypes
248
+ };
249
+ }
250
+ return null;
251
+ }
252
+ function removeDuplicateAndExtendedCombinations(combinations, targetAmount) {
253
+ const result = [];
254
+ combinations.sort((a, b) => {
255
+ if (a.denomTypes !== b.denomTypes) {
256
+ return a.denomTypes - b.denomTypes;
257
+ }
258
+ if (a.coinCount !== b.coinCount) {
259
+ return a.coinCount - b.coinCount;
260
+ }
261
+ return a.sum - b.sum;
262
+ });
263
+ for (let i = 0; i < combinations.length; i++) {
264
+ const current = combinations[i];
265
+ let shouldSkip = false;
266
+ for (let j = 0; j < result.length; j++) {
267
+ const existing = result[j];
268
+ if (isSameCombination(current.combination, existing.combination)) {
269
+ shouldSkip = true;
270
+ break;
271
+ }
272
+ if (isExtensionOf(current.combination, existing.combination)) {
273
+ shouldSkip = true;
274
+ break;
275
+ }
276
+ }
277
+ if (!shouldSkip) {
278
+ for (let j = result.length - 1; j >= 0; j--) {
279
+ if (isExtensionOf(result[j].combination, current.combination)) {
280
+ result.splice(j, 1);
281
+ }
282
+ }
283
+ result.push(current);
284
+ }
285
+ }
286
+ return result;
287
+ }
288
+ function isExtensionOf(combinationA, combinationB) {
289
+ if (combinationA.length <= combinationB.length) {
290
+ return false;
291
+ }
292
+ const countA = {};
293
+ const countB = {};
294
+ combinationA.forEach((coin) => {
295
+ countA[coin] = (countA[coin] || 0) + 1;
296
+ });
297
+ combinationB.forEach((coin) => {
298
+ countB[coin] = (countB[coin] || 0) + 1;
299
+ });
300
+ for (const coin in countB) {
301
+ if (!countA[coin] || countA[coin] < countB[coin]) {
302
+ return false;
303
+ }
304
+ }
305
+ let hasExtra = false;
306
+ for (const coin in countA) {
307
+ if (countA[coin] > (countB[coin] || 0)) {
308
+ hasExtra = true;
309
+ break;
310
+ }
311
+ }
312
+ return hasExtra;
313
+ }
314
+ function isSameCombination(combinationA, combinationB) {
315
+ if (combinationA.length !== combinationB.length) {
316
+ return false;
317
+ }
318
+ const countA = {};
319
+ const countB = {};
320
+ combinationA.forEach((coin) => {
321
+ countA[coin] = (countA[coin] || 0) + 1;
322
+ });
323
+ combinationB.forEach((coin) => {
324
+ countB[coin] = (countB[coin] || 0) + 1;
325
+ });
326
+ for (const coin in countA) {
327
+ if (countA[coin] !== (countB[coin] || 0)) {
328
+ return false;
329
+ }
330
+ }
331
+ for (const coin in countB) {
332
+ if (countB[coin] !== (countA[coin] || 0)) {
333
+ return false;
334
+ }
335
+ }
336
+ return true;
337
+ }
338
+ // Annotate the CommonJS export names for ESM import in node:
339
+ 0 && (module.exports = {
340
+ CURRENCY_DENOMINATIONS,
341
+ recommendOptimalPayments
342
+ });
@@ -39,7 +39,7 @@ var EftposPaymentImpl = class {
39
39
  type: eftposMethod.type,
40
40
  voucher_id: ""
41
41
  };
42
- await this.paymentModule.pushPaymentAsync(orderUuid, paymentItem);
42
+ await this.paymentModule.addPaymentItemAsync(orderUuid, paymentItem);
43
43
  }
44
44
  async checkDeviceStatus() {
45
45
  return true;