@pisell/pisellos 0.10.8 → 0.10.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.
Files changed (98) hide show
  1. package/dist/core/index.js +0 -1
  2. package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +18 -2
  3. package/dist/model/strategy/adapter/dataVariant/evaluator.js +287 -101
  4. package/dist/model/strategy/adapter/dataVariant/type.d.ts +25 -0
  5. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  6. package/dist/model/strategy/adapter/walletPass/evaluator.js +0 -2
  7. package/dist/model/strategy/adapter/walletPass/type.d.ts +5 -0
  8. package/dist/model/strategy/adapter/walletPass/utils.js +57 -26
  9. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +7 -3
  10. package/dist/modules/BookingContext/utils/productExtend.js +5 -9
  11. package/dist/modules/BookingContext/utils/timeSlices.js +24 -3
  12. package/dist/modules/Customer/index.d.ts +4 -0
  13. package/dist/modules/Customer/index.js +91 -59
  14. package/dist/modules/Customer/types.d.ts +2 -0
  15. package/dist/modules/Discount/index.d.ts +2 -0
  16. package/dist/modules/Discount/index.js +38 -5
  17. package/dist/modules/Discount/types.d.ts +11 -0
  18. package/dist/modules/Order/index.d.ts +20 -1
  19. package/dist/modules/Order/index.js +976 -730
  20. package/dist/modules/Order/types.d.ts +6 -1
  21. package/dist/modules/Order/utils/virtualSettlement.d.ts +56 -0
  22. package/dist/modules/Order/utils/virtualSettlement.js +271 -0
  23. package/dist/modules/Order/utils.js +89 -48
  24. package/dist/modules/Payment/types.d.ts +2 -0
  25. package/dist/modules/Payment/utils.js +4 -1
  26. package/dist/modules/Payment/walletpass.d.ts +11 -0
  27. package/dist/modules/Payment/walletpass.js +235 -60
  28. package/dist/modules/Product/types.d.ts +23 -0
  29. package/dist/modules/ProductList/index.d.ts +15 -2
  30. package/dist/modules/ProductList/index.js +92 -13
  31. package/dist/modules/SalesSummary/index.d.ts +1 -0
  32. package/dist/modules/SalesSummary/index.js +4 -3
  33. package/dist/modules/SalesSummary/types.d.ts +1 -0
  34. package/dist/modules/SalesSummary/utils.d.ts +1 -0
  35. package/dist/modules/SalesSummary/utils.js +21 -1
  36. package/dist/server/index.d.ts +9 -0
  37. package/dist/server/index.js +90 -58
  38. package/dist/server/modules/order/index.d.ts +1 -0
  39. package/dist/server/modules/order/index.js +252 -94
  40. package/dist/server/utils/small-ticket.js +2 -1
  41. package/dist/solution/BaseSales/index.d.ts +26 -2
  42. package/dist/solution/BaseSales/index.js +1310 -931
  43. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
  44. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +78 -12
  45. package/dist/solution/BookingByStep/index.d.ts +3 -3
  46. package/dist/solution/BookingTicket/index.d.ts +5 -1
  47. package/dist/solution/BookingTicket/index.js +221 -159
  48. package/dist/solution/BookingTicket/utils/addProductDecision.js +2 -1
  49. package/dist/solution/ScanOrder/index.js +25 -64
  50. package/lib/core/index.js +0 -1
  51. package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +18 -2
  52. package/lib/model/strategy/adapter/dataVariant/evaluator.js +170 -7
  53. package/lib/model/strategy/adapter/dataVariant/type.d.ts +25 -0
  54. package/lib/model/strategy/adapter/walletPass/evaluator.js +0 -2
  55. package/lib/model/strategy/adapter/walletPass/type.d.ts +5 -0
  56. package/lib/model/strategy/adapter/walletPass/utils.js +62 -11
  57. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +3 -0
  58. package/lib/modules/BookingContext/utils/productExtend.js +4 -3
  59. package/lib/modules/BookingContext/utils/timeSlices.js +18 -3
  60. package/lib/modules/Customer/index.d.ts +4 -0
  61. package/lib/modules/Customer/index.js +11 -0
  62. package/lib/modules/Customer/types.d.ts +2 -0
  63. package/lib/modules/Discount/index.d.ts +2 -0
  64. package/lib/modules/Discount/index.js +37 -3
  65. package/lib/modules/Discount/types.d.ts +11 -0
  66. package/lib/modules/Order/index.d.ts +20 -1
  67. package/lib/modules/Order/index.js +393 -128
  68. package/lib/modules/Order/types.d.ts +6 -1
  69. package/lib/modules/Order/utils/virtualSettlement.d.ts +56 -0
  70. package/lib/modules/Order/utils/virtualSettlement.js +300 -0
  71. package/lib/modules/Order/utils.js +65 -21
  72. package/lib/modules/Payment/types.d.ts +2 -0
  73. package/lib/modules/Payment/utils.js +5 -1
  74. package/lib/modules/Payment/walletpass.d.ts +11 -0
  75. package/lib/modules/Payment/walletpass.js +198 -17
  76. package/lib/modules/Product/types.d.ts +23 -0
  77. package/lib/modules/ProductList/index.d.ts +15 -2
  78. package/lib/modules/ProductList/index.js +85 -3
  79. package/lib/modules/SalesSummary/index.d.ts +1 -0
  80. package/lib/modules/SalesSummary/index.js +10 -2
  81. package/lib/modules/SalesSummary/types.d.ts +1 -0
  82. package/lib/modules/SalesSummary/utils.d.ts +1 -0
  83. package/lib/modules/SalesSummary/utils.js +25 -1
  84. package/lib/server/index.d.ts +9 -0
  85. package/lib/server/index.js +54 -14
  86. package/lib/server/modules/order/index.d.ts +1 -0
  87. package/lib/server/modules/order/index.js +66 -2
  88. package/lib/server/utils/small-ticket.js +1 -1
  89. package/lib/solution/BaseSales/index.d.ts +26 -2
  90. package/lib/solution/BaseSales/index.js +261 -23
  91. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
  92. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +61 -11
  93. package/lib/solution/BookingByStep/index.d.ts +3 -3
  94. package/lib/solution/BookingTicket/index.d.ts +5 -1
  95. package/lib/solution/BookingTicket/index.js +30 -2
  96. package/lib/solution/BookingTicket/utils/addProductDecision.js +2 -1
  97. package/lib/solution/ScanOrder/index.js +17 -54
  98. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  import { CartItem } from '../Cart/types';
2
2
  import type { DiscountModule } from '../Discount';
3
3
  import type { RulesModule } from '../Rules';
4
- import type { Discount } from '../Discount/types';
4
+ import type { Discount, VirtualCurrencyAsset } from '../Discount/types';
5
5
  import type { UnavailableReason } from '../Rules/types';
6
6
  import type { SubmitPayloadEnhancer } from './utils';
7
7
  import type { PaymentItem } from '../Payment/types';
@@ -194,6 +194,7 @@ export interface OrderProduct extends OrderProductIdentity {
194
194
  gift_card?: number;
195
195
  selling_price: string;
196
196
  original_price: string;
197
+ payment_price?: string;
197
198
  tax_fee: string;
198
199
  is_charge_tax: number;
199
200
  discount_list: OrderProductDiscountItem[];
@@ -275,6 +276,7 @@ export interface OrderTempOrder {
275
276
  products: OrderProduct[];
276
277
  bookings: any[];
277
278
  payments: any[];
279
+ refunds?: any[];
278
280
  surcharges: any[];
279
281
  discount_list?: any[];
280
282
  relation_forms: any[];
@@ -312,6 +314,7 @@ export interface OrderState {
312
314
  syncState?: OrderSyncState;
313
315
  discountList: any[];
314
316
  availableWalletIds?: number[];
317
+ virtualCurrencyList?: VirtualCurrencyAsset[];
315
318
  discount: DiscountModule | null;
316
319
  rules: RulesModule | null;
317
320
  }
@@ -709,6 +712,8 @@ export interface OrderModuleAPI {
709
712
  addNewOrder: () => Promise<OrderTempOrder>;
710
713
  restoreOrder: () => OrderTempOrder;
711
714
  getOrderProducts: () => OrderProduct[];
715
+ getVirtualCurrencyList: () => VirtualCurrencyAsset[];
716
+ clearOrderForSettlementSwitch: () => Promise<OrderTempOrder>;
712
717
  getOrderSummary: () => Promise<OrderSummary>;
713
718
  recalculateSummary: (options?: {
714
719
  createIfMissing?: boolean;
@@ -0,0 +1,56 @@
1
+ import type { OrderProduct, OrderTempOrder } from '../types';
2
+ export interface SelectedSettlementSnapshot extends Record<string, any> {
3
+ settlement_type: 'legal_currency' | 'virtual_currency';
4
+ currency_product_id?: number;
5
+ price: string | number;
6
+ unit_label?: any;
7
+ symbol?: any;
8
+ amount_format?: string;
9
+ }
10
+ export interface LegalCurrencySnapshot {
11
+ currency_code: string;
12
+ currency_symbol: string;
13
+ currency_format: string;
14
+ }
15
+ export declare function resolveSettlementDisplayValue(value: unknown): string;
16
+ export declare class OrderSettlementConflictError extends Error {
17
+ readonly currentSettlementKey: string;
18
+ readonly incomingSettlementKey: string;
19
+ readonly code = "ORDER_SETTLEMENT_CONFLICT";
20
+ constructor(currentSettlementKey: string, incomingSettlementKey: string);
21
+ }
22
+ export declare class VirtualCurrencyAssetNotFoundError extends Error {
23
+ readonly currencyProductId: number;
24
+ readonly code = "VIRTUAL_CURRENCY_ASSET_NOT_FOUND";
25
+ constructor(currencyProductId: number);
26
+ }
27
+ export declare class VirtualCurrencyBalanceError extends Error {
28
+ readonly balance: string;
29
+ readonly requiredAmount: string;
30
+ readonly code = "VIRTUAL_CURRENCY_BALANCE_INSUFFICIENT";
31
+ constructor(balance: string, requiredAmount: string);
32
+ }
33
+ export declare function getSelectedSettlementSnapshot(product: Partial<OrderProduct> | null | undefined): SelectedSettlementSnapshot | null;
34
+ export declare function getTempOrderSettlementSnapshot(tempOrder: OrderTempOrder | null | undefined): SelectedSettlementSnapshot | null;
35
+ export declare function isVirtualSettlementProduct(product: Partial<OrderProduct> | null | undefined): boolean;
36
+ export declare function getSettlementKey(snapshot: SelectedSettlementSnapshot | null | undefined): string | null;
37
+ export declare function getTempOrderSettlementKey(tempOrder: OrderTempOrder | null | undefined): string | null;
38
+ export declare function isVirtualSettlementOrder(tempOrder: OrderTempOrder | null | undefined): boolean;
39
+ /**
40
+ * 详情展示识别同时支持已提交订单的 currency_settlement_config。
41
+ * cart_settlement_* 是交易过程内部状态,服务端详情不保证返回。
42
+ */
43
+ export declare function isVirtualSettlementDisplayOrder(tempOrder: OrderTempOrder | null | undefined): boolean;
44
+ /**
45
+ * 将购物车锁定的结算单位提升为订单级状态。
46
+ * 商品行快照只负责价格归一化;展示与提交统一读取 tempOrder.currency_*。
47
+ */
48
+ export declare function applyTempOrderSettlementState(tempOrder: OrderTempOrder, snapshot: SelectedSettlementSnapshot): void;
49
+ /** 清空购物车结算锁,并恢复进入虚拟币结算前的店铺法币。 */
50
+ export declare function releaseTempOrderSettlementState(tempOrder: OrderTempOrder): void;
51
+ /**
52
+ * 将已选择虚拟币的订单商品行固化为最终价语义。
53
+ * 函数幂等,可安全用于加车、合并、hydrate 和提交前兜底。
54
+ */
55
+ export declare function normalizeVirtualSettlementOrderProduct<T extends Partial<OrderProduct>>(product: T): T;
56
+ export declare function normalizeVirtualSettlementProducts<T extends Partial<OrderProduct>>(products: T[]): T[];
@@ -0,0 +1,300 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/modules/Order/utils/virtualSettlement.ts
30
+ var virtualSettlement_exports = {};
31
+ __export(virtualSettlement_exports, {
32
+ OrderSettlementConflictError: () => OrderSettlementConflictError,
33
+ VirtualCurrencyAssetNotFoundError: () => VirtualCurrencyAssetNotFoundError,
34
+ VirtualCurrencyBalanceError: () => VirtualCurrencyBalanceError,
35
+ applyTempOrderSettlementState: () => applyTempOrderSettlementState,
36
+ getSelectedSettlementSnapshot: () => getSelectedSettlementSnapshot,
37
+ getSettlementKey: () => getSettlementKey,
38
+ getTempOrderSettlementKey: () => getTempOrderSettlementKey,
39
+ getTempOrderSettlementSnapshot: () => getTempOrderSettlementSnapshot,
40
+ isVirtualSettlementDisplayOrder: () => isVirtualSettlementDisplayOrder,
41
+ isVirtualSettlementOrder: () => isVirtualSettlementOrder,
42
+ isVirtualSettlementProduct: () => isVirtualSettlementProduct,
43
+ normalizeVirtualSettlementOrderProduct: () => normalizeVirtualSettlementOrderProduct,
44
+ normalizeVirtualSettlementProducts: () => normalizeVirtualSettlementProducts,
45
+ releaseTempOrderSettlementState: () => releaseTempOrderSettlementState,
46
+ resolveSettlementDisplayValue: () => resolveSettlementDisplayValue
47
+ });
48
+ module.exports = __toCommonJS(virtualSettlement_exports);
49
+ var import_decimal = __toESM(require("decimal.js"));
50
+ function resolveSettlementDisplayValue(value) {
51
+ if (value === void 0 || value === null)
52
+ return "";
53
+ if (typeof value === "string" || typeof value === "number") {
54
+ return String(value);
55
+ }
56
+ const localized = value;
57
+ return String(
58
+ localized.auto ?? localized.default ?? localized.original ?? localized.en ?? localized["zh-CN"] ?? localized["zh-HK"] ?? ""
59
+ );
60
+ }
61
+ var OrderSettlementConflictError = class extends Error {
62
+ constructor(currentSettlementKey, incomingSettlementKey) {
63
+ super("Different currencies and WalletPass units cannot be mixed in one cart.");
64
+ this.currentSettlementKey = currentSettlementKey;
65
+ this.incomingSettlementKey = incomingSettlementKey;
66
+ this.code = "ORDER_SETTLEMENT_CONFLICT";
67
+ this.name = "OrderSettlementConflictError";
68
+ }
69
+ };
70
+ var VirtualCurrencyAssetNotFoundError = class extends Error {
71
+ constructor(currencyProductId) {
72
+ super("No matching virtual currency card is available.");
73
+ this.currencyProductId = currencyProductId;
74
+ this.code = "VIRTUAL_CURRENCY_ASSET_NOT_FOUND";
75
+ this.name = "VirtualCurrencyAssetNotFoundError";
76
+ }
77
+ };
78
+ var VirtualCurrencyBalanceError = class extends Error {
79
+ constructor(balance, requiredAmount) {
80
+ super("Insufficient virtual currency balance.");
81
+ this.balance = balance;
82
+ this.requiredAmount = requiredAmount;
83
+ this.code = "VIRTUAL_CURRENCY_BALANCE_INSUFFICIENT";
84
+ this.name = "VirtualCurrencyBalanceError";
85
+ }
86
+ };
87
+ function getSelectedSettlementSnapshot(product) {
88
+ var _a;
89
+ const snapshot = (_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.selected_settlement_snapshot;
90
+ if (!snapshot || typeof snapshot !== "object")
91
+ return null;
92
+ if (snapshot.settlement_type !== "legal_currency" && snapshot.settlement_type !== "virtual_currency") {
93
+ return null;
94
+ }
95
+ return snapshot;
96
+ }
97
+ function getTempOrderSettlementSnapshot(tempOrder) {
98
+ var _a, _b;
99
+ const snapshot = (_a = tempOrder == null ? void 0 : tempOrder.metadata) == null ? void 0 : _a.cart_settlement_snapshot;
100
+ if (snapshot && typeof snapshot === "object" && (snapshot.settlement_type === "legal_currency" || snapshot.settlement_type === "virtual_currency")) {
101
+ return snapshot;
102
+ }
103
+ return getSelectedSettlementSnapshot((_b = tempOrder == null ? void 0 : tempOrder.products) == null ? void 0 : _b[0]);
104
+ }
105
+ function isVirtualSettlementProduct(product) {
106
+ var _a;
107
+ return ((_a = getSelectedSettlementSnapshot(product)) == null ? void 0 : _a.settlement_type) === "virtual_currency";
108
+ }
109
+ function getSettlementKey(snapshot) {
110
+ if (!snapshot)
111
+ return null;
112
+ if (snapshot.settlement_type === "legal_currency")
113
+ return "legal_currency";
114
+ const currencyProductId = Number(snapshot.currency_product_id);
115
+ return Number.isFinite(currencyProductId) && currencyProductId > 0 ? `virtual_currency:${currencyProductId}` : null;
116
+ }
117
+ function getTempOrderSettlementKey(tempOrder) {
118
+ var _a, _b;
119
+ if (!((_a = tempOrder == null ? void 0 : tempOrder.products) == null ? void 0 : _a.length))
120
+ return null;
121
+ const storedKey = (_b = tempOrder.metadata) == null ? void 0 : _b.cart_settlement_key;
122
+ if (typeof storedKey === "string" && storedKey)
123
+ return storedKey;
124
+ return getSettlementKey(getTempOrderSettlementSnapshot(tempOrder)) || "legal_currency";
125
+ }
126
+ function isVirtualSettlementOrder(tempOrder) {
127
+ var _a;
128
+ return ((_a = getTempOrderSettlementKey(tempOrder)) == null ? void 0 : _a.startsWith("virtual_currency:")) === true;
129
+ }
130
+ function isVirtualSettlementDisplayOrder(tempOrder) {
131
+ var _a, _b;
132
+ return ((_b = (_a = tempOrder == null ? void 0 : tempOrder.metadata) == null ? void 0 : _a.currency_settlement_config) == null ? void 0 : _b.settlement_type) === "virtual_currency" || isVirtualSettlementOrder(tempOrder);
133
+ }
134
+ function getLegalCurrencySnapshot(tempOrder) {
135
+ var _a;
136
+ const snapshot = (_a = tempOrder.metadata) == null ? void 0 : _a.legal_currency_snapshot;
137
+ if (!snapshot || typeof snapshot !== "object")
138
+ return null;
139
+ return {
140
+ currency_code: String(snapshot.currency_code || ""),
141
+ currency_symbol: String(snapshot.currency_symbol || ""),
142
+ currency_format: String(snapshot.currency_format || "symbol_first")
143
+ };
144
+ }
145
+ function captureLegalCurrencySnapshot(tempOrder) {
146
+ tempOrder.metadata = tempOrder.metadata || {};
147
+ if (getLegalCurrencySnapshot(tempOrder))
148
+ return;
149
+ tempOrder.metadata.legal_currency_snapshot = {
150
+ currency_code: String(tempOrder.currency_code || ""),
151
+ currency_symbol: String(tempOrder.currency_symbol || ""),
152
+ currency_format: String(tempOrder.currency_format || "symbol_first")
153
+ };
154
+ }
155
+ function applyTempOrderSettlementState(tempOrder, snapshot) {
156
+ tempOrder.metadata = tempOrder.metadata || {};
157
+ const settlementKey = getSettlementKey(snapshot) || "legal_currency";
158
+ if (snapshot.settlement_type === "virtual_currency") {
159
+ captureLegalCurrencySnapshot(tempOrder);
160
+ const currencyProductId = Number(snapshot.currency_product_id);
161
+ tempOrder.metadata.currency_settlement_config = {
162
+ settlement_type: "virtual_currency",
163
+ settlement_ids: Number.isFinite(currencyProductId) && currencyProductId > 0 ? [currencyProductId] : []
164
+ };
165
+ } else {
166
+ delete tempOrder.metadata.currency_settlement_config;
167
+ }
168
+ tempOrder.metadata.cart_settlement_key = settlementKey;
169
+ tempOrder.metadata.cart_settlement_snapshot = { ...snapshot };
170
+ tempOrder.currency_code = resolveSettlementDisplayValue(snapshot.unit_label) || tempOrder.currency_code;
171
+ tempOrder.currency_symbol = resolveSettlementDisplayValue(snapshot.symbol) || tempOrder.currency_symbol;
172
+ tempOrder.currency_format = String(
173
+ snapshot.amount_format || tempOrder.currency_format || "symbol_first"
174
+ );
175
+ }
176
+ function releaseTempOrderSettlementState(tempOrder) {
177
+ tempOrder.metadata = tempOrder.metadata || {};
178
+ const legalCurrency = getLegalCurrencySnapshot(tempOrder);
179
+ if (legalCurrency) {
180
+ tempOrder.currency_code = legalCurrency.currency_code;
181
+ tempOrder.currency_symbol = legalCurrency.currency_symbol;
182
+ tempOrder.currency_format = legalCurrency.currency_format;
183
+ }
184
+ delete tempOrder.metadata.cart_settlement_key;
185
+ delete tempOrder.metadata.cart_settlement_snapshot;
186
+ delete tempOrder.metadata.currency_settlement_config;
187
+ }
188
+ function toMoney(value) {
189
+ try {
190
+ return new import_decimal.default(String(value ?? 0)).toDecimalPlaces(2).toFixed(2);
191
+ } catch {
192
+ return "0.00";
193
+ }
194
+ }
195
+ function zeroOptions(options) {
196
+ if (!Array.isArray(options))
197
+ return [];
198
+ return options.map((option) => ({
199
+ ...option,
200
+ add_price: 0
201
+ }));
202
+ }
203
+ function zeroBundles(bundles) {
204
+ if (!Array.isArray(bundles))
205
+ return [];
206
+ return bundles.map((bundle) => ({
207
+ ...bundle,
208
+ price: 0,
209
+ custom_price: 0,
210
+ bundle_selling_price: 0,
211
+ bundle_payment_price: 0,
212
+ surcharge_fee: 0,
213
+ tax_fee: 0,
214
+ original_tax_fee: 0,
215
+ is_charge_tax: 0,
216
+ discount_list: [],
217
+ relation_surcharge_ids: [],
218
+ option: zeroOptions(bundle == null ? void 0 : bundle.option),
219
+ metadata: {
220
+ ...(bundle == null ? void 0 : bundle.metadata) || {},
221
+ surcharge_fee: "0.00",
222
+ relation_surcharge_ids: [],
223
+ product_discount_difference: "",
224
+ tax_fee_rounding_remainder: "0.00",
225
+ surcharge_rounding_remainder: "0.00"
226
+ }
227
+ }));
228
+ }
229
+ function normalizeVirtualSettlementOrderProduct(product) {
230
+ var _a;
231
+ const snapshot = getSelectedSettlementSnapshot(product);
232
+ if ((snapshot == null ? void 0 : snapshot.settlement_type) !== "virtual_currency")
233
+ return product;
234
+ const virtualPrice = toMoney(snapshot.price);
235
+ const metadata = {
236
+ ...product.metadata || {},
237
+ source_product_price: virtualPrice,
238
+ main_product_original_price: virtualPrice,
239
+ main_product_selling_price: virtualPrice,
240
+ main_product_attached_bundle_selling_price: virtualPrice,
241
+ main_product_attached_bundle_payment_price: virtualPrice,
242
+ main_product_attached_bundle_surcharge_fee: "0.00",
243
+ main_product_attached_bundle_tax_fee: "0.00",
244
+ surcharge_rounding_remainder: "0.00",
245
+ tax_fee_rounding_remainder: "0.00",
246
+ relation_surcharge_ids: [],
247
+ average_discount_amount_rate: "1",
248
+ product_discount_difference: "",
249
+ discountable_flag: 0,
250
+ price_schema_version: 2,
251
+ selected_settlement_snapshot: {
252
+ ...snapshot,
253
+ price: virtualPrice
254
+ }
255
+ };
256
+ return {
257
+ ...product,
258
+ selling_price: virtualPrice,
259
+ original_price: virtualPrice,
260
+ payment_price: virtualPrice,
261
+ discount_list: [],
262
+ is_charge_tax: 0,
263
+ tax_fee: "0.00",
264
+ original_tax_fee: 0,
265
+ tax_fee_rounding_remainder: 0,
266
+ original_tax_fee_rounding_remainder: 0,
267
+ surcharge_fee: "0.00",
268
+ surcharge_rounding_remainder: 0,
269
+ relation_surcharge_ids: [],
270
+ product_sku: {
271
+ ...product.product_sku || {},
272
+ option: zeroOptions((_a = product.product_sku) == null ? void 0 : _a.option)
273
+ },
274
+ product_bundle: zeroBundles(product.product_bundle),
275
+ metadata
276
+ };
277
+ }
278
+ function normalizeVirtualSettlementProducts(products) {
279
+ return (products || []).map(
280
+ (product) => normalizeVirtualSettlementOrderProduct(product)
281
+ );
282
+ }
283
+ // Annotate the CommonJS export names for ESM import in node:
284
+ 0 && (module.exports = {
285
+ OrderSettlementConflictError,
286
+ VirtualCurrencyAssetNotFoundError,
287
+ VirtualCurrencyBalanceError,
288
+ applyTempOrderSettlementState,
289
+ getSelectedSettlementSnapshot,
290
+ getSettlementKey,
291
+ getTempOrderSettlementKey,
292
+ getTempOrderSettlementSnapshot,
293
+ isVirtualSettlementDisplayOrder,
294
+ isVirtualSettlementOrder,
295
+ isVirtualSettlementProduct,
296
+ normalizeVirtualSettlementOrderProduct,
297
+ normalizeVirtualSettlementProducts,
298
+ releaseTempOrderSettlementState,
299
+ resolveSettlementDisplayValue
300
+ });
@@ -705,7 +705,7 @@ function normalizeSubmitPlatform(platform) {
705
705
  return "H5";
706
706
  return value;
707
707
  }
708
- function formatSubmitOptionItems(options) {
708
+ function formatSubmitOptionItems(options, formatOptions = {}) {
709
709
  if (!Array.isArray(options))
710
710
  return [];
711
711
  return options.map((d) => {
@@ -716,8 +716,11 @@ function formatSubmitOptionItems(options) {
716
716
  option_group_id: d == null ? void 0 : d.option_group_id
717
717
  };
718
718
  const addPrice = (d == null ? void 0 : d.add_price) ?? (d == null ? void 0 : d.price);
719
- if (addPrice !== void 0)
719
+ if (formatOptions.virtualSettlementMode) {
720
+ option.add_price = 0;
721
+ } else if (addPrice !== void 0) {
720
722
  option.add_price = String(addPrice);
723
+ }
721
724
  delete option.price;
722
725
  return option;
723
726
  });
@@ -734,7 +737,7 @@ function toMoneyString(value) {
734
737
  return "0.00";
735
738
  return String(value);
736
739
  }
737
- function formatSubmitBundleItems(bundle) {
740
+ function formatSubmitBundleItems(bundle, formatOptions = {}) {
738
741
  if (!Array.isArray(bundle))
739
742
  return [];
740
743
  return bundle.map((b) => {
@@ -744,9 +747,9 @@ function formatSubmitBundleItems(bundle) {
744
747
  custom_product_bundle_map_id: _customProductBundleMapId,
745
748
  ...submitMetadata
746
749
  } = existedMetadata;
747
- const sellingPrice = getBundleSellingMagnitude(rawBundle).toFixed(2);
748
- const paymentPrice = rawBundle.bundle_payment_price !== void 0 && rawBundle.bundle_payment_price !== null && rawBundle.bundle_payment_price !== "" ? toMoneyString(rawBundle.bundle_payment_price) : sellingPrice;
749
- const priceValue = rawBundle.price ?? rawBundle.custom_price ?? rawBundle.bundle_selling_price;
750
+ const sellingPrice = formatOptions.virtualSettlementMode ? "0.00" : getBundleSellingMagnitude(rawBundle).toFixed(2);
751
+ const paymentPrice = formatOptions.virtualSettlementMode ? "0.00" : rawBundle.bundle_payment_price !== void 0 && rawBundle.bundle_payment_price !== null && rawBundle.bundle_payment_price !== "" ? toMoneyString(rawBundle.bundle_payment_price) : sellingPrice;
752
+ const priceValue = formatOptions.virtualSettlementMode ? 0 : rawBundle.price ?? rawBundle.custom_price ?? rawBundle.bundle_selling_price;
750
753
  const relationSurchargeIds = Array.isArray(rawBundle.relation_surcharge_ids) ? rawBundle.relation_surcharge_ids : Array.isArray(existedMetadata.relation_surcharge_ids) ? existedMetadata.relation_surcharge_ids : [];
751
754
  const surchargeFee = toMoneyString(
752
755
  rawBundle.surcharge_fee ?? existedMetadata.surcharge_fee
@@ -759,7 +762,7 @@ function formatSubmitBundleItems(bundle) {
759
762
  const bundleMapId = resolveSubmitBundleMapId(rawBundle);
760
763
  const hasSubmitBundleDiscounts = Array.isArray(rawBundle.discount_list) && rawBundle.discount_list.length > 0;
761
764
  return {
762
- is_charge_tax: rawBundle.is_charge_tax ?? 0,
765
+ is_charge_tax: formatOptions.virtualSettlementMode ? 0 : rawBundle.is_charge_tax ?? 0,
763
766
  bundle_variant_id: rawBundle.bundle_variant_id ?? 0,
764
767
  num,
765
768
  quantity: toBundleNumber(rawBundle.quantity ?? rawBundle.num, num),
@@ -770,7 +773,7 @@ function formatSubmitBundleItems(bundle) {
770
773
  price_type_ext: rawBundle.price_type_ext ?? rawBundle.custom_price_type_ext ?? "",
771
774
  bundle_selling_price: sellingPrice,
772
775
  bundle_payment_price: paymentPrice,
773
- option: formatSubmitOptionItems(rawBundle.option),
776
+ option: formatSubmitOptionItems(rawBundle.option, formatOptions),
774
777
  bundle_group_id: (rawBundle == null ? void 0 : rawBundle.bundle_group_id) ?? (rawBundle == null ? void 0 : rawBundle.group_id),
775
778
  bundle_id: (rawBundle == null ? void 0 : rawBundle.bundle_id) ?? (rawBundle == null ? void 0 : rawBundle.id),
776
779
  bundle_product_id: (rawBundle == null ? void 0 : rawBundle.bundle_product_id) ?? (rawBundle == null ? void 0 : rawBundle._bundle_product_id),
@@ -778,15 +781,15 @@ function formatSubmitBundleItems(bundle) {
778
781
  metadata: {
779
782
  ...submitMetadata,
780
783
  ...hasSubmitBundleDiscounts && bundleMapId !== void 0 ? { custom_product_bundle_map_id: bundleMapId } : {},
781
- surcharge_fee: surchargeFee,
782
- relation_surcharge_ids: relationSurchargeIds,
783
- product_discount_difference: productDiscountDifference
784
+ surcharge_fee: formatOptions.virtualSettlementMode ? "0.00" : surchargeFee,
785
+ relation_surcharge_ids: formatOptions.virtualSettlementMode ? [] : relationSurchargeIds,
786
+ product_discount_difference: formatOptions.virtualSettlementMode ? "" : productDiscountDifference
784
787
  }
785
788
  };
786
789
  });
787
790
  }
788
- function normalizeSubmitProduct(product) {
789
- var _a;
791
+ function normalizeSubmitProduct(product, formatOptions = {}) {
792
+ var _a, _b;
790
793
  const { unique_identification_number: _runtimeUid, ...submitProduct } = product;
791
794
  const {
792
795
  num,
@@ -801,6 +804,8 @@ function normalizeSubmitProduct(product) {
801
804
  delete productRest[`product_${"option"}_item`];
802
805
  const rawMetadata = submitProduct.metadata || {};
803
806
  const bookingUid = rawMetadata.booking_uid;
807
+ const hasProductBundle = Array.isArray(submitProduct.product_bundle) && submitProduct.product_bundle.length > 0;
808
+ const bundleEdit = submitProduct.bundle_edit ?? rawMetadata.bundle_edit ?? (hasProductBundle ? 0 : void 0);
804
809
  const cleanMetadata = {};
805
810
  if (rawMetadata.unique_identification_number) {
806
811
  cleanMetadata.unique_identification_number = rawMetadata.unique_identification_number;
@@ -818,8 +823,10 @@ function normalizeSubmitProduct(product) {
818
823
  "tax_fee_rounding_remainder",
819
824
  "relation_surcharge_ids",
820
825
  "discountable_flag",
826
+ "price_schema_version",
821
827
  "parent_unique_identification_number",
822
- "product_add_schedule_time"
828
+ "product_add_schedule_time",
829
+ "data_variant_ids"
823
830
  ];
824
831
  for (const key of priceMetaKeys) {
825
832
  if (rawMetadata[key] !== void 0) {
@@ -836,21 +843,54 @@ function normalizeSubmitProduct(product) {
836
843
  if (rawMetadata.holder_config !== void 0) {
837
844
  cleanMetadata.holder_config = rawMetadata.holder_config;
838
845
  }
846
+ const virtualPrice = toMoneyString(
847
+ ((_a = rawMetadata.selected_settlement_snapshot) == null ? void 0 : _a.price) ?? submitProduct.selling_price
848
+ );
849
+ if (formatOptions.virtualSettlementMode) {
850
+ Object.assign(cleanMetadata, {
851
+ source_product_price: virtualPrice,
852
+ main_product_original_price: virtualPrice,
853
+ main_product_selling_price: virtualPrice,
854
+ main_product_attached_bundle_selling_price: virtualPrice,
855
+ main_product_attached_bundle_payment_price: virtualPrice,
856
+ main_product_attached_bundle_surcharge_fee: "0.00",
857
+ main_product_attached_bundle_tax_fee: "0.00",
858
+ surcharge_rounding_remainder: "0.00",
859
+ tax_fee_rounding_remainder: "0.00",
860
+ relation_surcharge_ids: [],
861
+ average_discount_amount_rate: "1",
862
+ product_discount_difference: "",
863
+ discountable_flag: 0,
864
+ price_schema_version: 2
865
+ });
866
+ }
839
867
  const productSku = {
840
868
  ...submitProduct.product_sku && typeof submitProduct.product_sku === "object" ? submitProduct.product_sku : {},
841
- option: formatSubmitOptionItems((_a = submitProduct.product_sku) == null ? void 0 : _a.option)
869
+ option: formatSubmitOptionItems(
870
+ (_b = submitProduct.product_sku) == null ? void 0 : _b.option,
871
+ formatOptions
872
+ )
842
873
  };
843
874
  return {
844
875
  ...productRest,
876
+ ...formatOptions.virtualSettlementMode ? {
877
+ selling_price: virtualPrice,
878
+ original_price: virtualPrice,
879
+ is_charge_tax: 0
880
+ } : {},
845
881
  ...bookingUid ? { booking_uid: bookingUid } : {},
882
+ ...bundleEdit !== void 0 ? { bundle_edit: bundleEdit } : {},
846
883
  product_quantity: toBundleNumber(num ?? submitProduct.product_quantity, 1),
847
884
  product_sku: productSku,
848
- discount_list: collectSubmitProductDiscountList(submitProduct),
849
- product_bundle: formatSubmitBundleItems(submitProduct.product_bundle),
885
+ discount_list: formatOptions.virtualSettlementMode ? [] : collectSubmitProductDiscountList(submitProduct),
886
+ product_bundle: formatSubmitBundleItems(
887
+ submitProduct.product_bundle,
888
+ formatOptions
889
+ ),
850
890
  metadata: cleanMetadata,
851
891
  // 出站兼容:后端消费 payment_price 字段(行 composite 已减整单折扣均摊)。
852
892
  // 由整单折扣均摊层产出;缺省(无折扣)时与 selling_price 同义。
853
- payment_price: submitProduct.payment_price ?? submitProduct.selling_price
893
+ payment_price: formatOptions.virtualSettlementMode ? virtualPrice : submitProduct.payment_price ?? submitProduct.selling_price
854
894
  };
855
895
  }
856
896
  var SUBMIT_BOOKING_METADATA_WHITELIST = [
@@ -953,7 +993,7 @@ function createDefaultTempOrder(params) {
953
993
  };
954
994
  }
955
995
  function buildSubmitPayload(params) {
956
- var _a;
996
+ var _a, _b, _c;
957
997
  const {
958
998
  tempOrder,
959
999
  cacheId,
@@ -967,6 +1007,7 @@ function buildSubmitPayload(params) {
967
1007
  } = params;
968
1008
  const scheduleDate = tempOrder.schedule_date || tempOrder.created_at || formatDateTime(now);
969
1009
  const bookingUuid = (0, import_orderCollectionIdentity.createUuidV4)();
1010
+ const virtualSettlementMode = ((_b = (_a = tempOrder.metadata) == null ? void 0 : _a.currency_settlement_config) == null ? void 0 : _b.settlement_type) === "virtual_currency";
970
1011
  const {
971
1012
  _extend,
972
1013
  relation_id: _relationId,
@@ -990,7 +1031,7 @@ function buildSubmitPayload(params) {
990
1031
  } = tempOrder;
991
1032
  let submitType = type ?? tempOrder.type;
992
1033
  if (!submitType) {
993
- if ((_a = tempOrder == null ? void 0 : tempOrder.bookings) == null ? void 0 : _a.length) {
1034
+ if ((_c = tempOrder == null ? void 0 : tempOrder.bookings) == null ? void 0 : _c.length) {
994
1035
  submitType = "appointment_booking";
995
1036
  } else {
996
1037
  submitType = "virtual";
@@ -1038,12 +1079,15 @@ function buildSubmitPayload(params) {
1038
1079
  const {
1039
1080
  collect_pax: _collectPax,
1040
1081
  table_occupancy_duration: _tableOccupancyDuration,
1082
+ cart_settlement_key: _cartSettlementKey,
1083
+ cart_settlement_snapshot: _cartSettlementSnapshot,
1084
+ legal_currency_snapshot: _legalCurrencySnapshot,
1041
1085
  ...rest
1042
1086
  } = tempOrder.metadata || {};
1043
1087
  return { ...rest };
1044
1088
  })(),
1045
1089
  products: (tempOrder.products || []).map(
1046
- (product) => normalizeSubmitProduct(product)
1090
+ (product) => normalizeSubmitProduct(product, { virtualSettlementMode })
1047
1091
  )
1048
1092
  };
1049
1093
  if (!enhance)
@@ -486,6 +486,8 @@ export interface WalletPassPayment {
486
486
  importWalletAssetsSnapshot: (snapshot: WalletAssetsSnapshot) => WalletAssetsState;
487
487
  /** 设置单张钱包资产的选择状态并重新计算其实际抵扣额。 */
488
488
  selectWalletAsset: (assetId: WalletAssetId, options: SelectWalletAssetOptions) => WalletAssetsState;
489
+ /** 更新已选钱包资产的手动使用金额,并保持原有选择顺序重新计算。 */
490
+ updateWalletAssetAmount: (assetId: WalletAssetId, amount: number) => WalletAssetsState;
489
491
  /** 精确搜索钱包资产;仅当前券可用时自动选择。 */
490
492
  scanWalletAssetAsync: (code: string) => Promise<ScanWalletAssetResult>;
491
493
  /** 清空未确认的钱包资产选择。 */
@@ -34,7 +34,11 @@ var formatWalletPassList2PreparePayments = (list) => {
34
34
  const formatted = (list || []).map((item) => {
35
35
  return {
36
36
  voucher_id: item.id || 0,
37
- amount: Number(item.edit_current_amount || getAvailableMaxAmount(item)) || 0,
37
+ // 前端策略重算后的 actualDeduction 才是最终可同步金额;
38
+ // edit_current_amount 只是用户请求值,仍可能被策略和订单剩余金额裁剪。
39
+ amount: Number(
40
+ item.actualDeduction ?? item.edit_current_amount ?? getAvailableMaxAmount(item)
41
+ ) || 0,
38
42
  tag: item.tag || "",
39
43
  wallet_pass_usage_unit: item.wallet_pass_usage_unit || {},
40
44
  wallet_pass_use_value: item.wallet_pass_use_value || void 0
@@ -24,6 +24,11 @@ export declare class WalletPassPaymentImpl implements WalletPassPayment {
24
24
  private emitEvent;
25
25
  private publishWalletAssetsState;
26
26
  private recalculateWalletAssets;
27
+ /**
28
+ * 搜索接口只返回后端 Wallet Pass 数据,不包含前端策略 config。
29
+ * 在资产进入共享选择状态前补齐策略结果,避免增量重算回退到接口状态。
30
+ */
31
+ private formatSearchedWalletPaymentAssets;
27
32
  /** 获取当前缓存中所有支付类 Wallet 资产的扫码 code。 */
28
33
  private getSearchedWalletAssetCodes;
29
34
  /**
@@ -106,7 +111,13 @@ export declare class WalletPassPaymentImpl implements WalletPassPayment {
106
111
  getWalletAssetsState(): WalletAssetsState;
107
112
  exportWalletAssetsSnapshot(): WalletAssetsSnapshot;
108
113
  importWalletAssetsSnapshot(snapshot: WalletAssetsSnapshot): WalletAssetsState;
114
+ private updateWalletAssetEditAmountInCaches;
109
115
  selectWalletAsset(assetId: WalletAssetId, options: SelectWalletAssetOptions): WalletAssetsState;
116
+ /**
117
+ * 更新已选资产的手动金额。只允许在当前实际抵扣额内向下调整,
118
+ * 金额为 0 时沿用 legacy 行为取消选择。
119
+ */
120
+ updateWalletAssetAmount(assetId: WalletAssetId, amount: number): WalletAssetsState;
110
121
  scanWalletAssetAsync(code: string): Promise<ScanWalletAssetResult>;
111
122
  clearWalletAssetSelection(): WalletAssetsState;
112
123
  setCommittedWalletAssets(committedIds: WalletAssetId[], committedAssets?: any[]): WalletAssetsState;