@pisell/pisellos 2.3.114 → 2.3.116
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/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/modules/Order/index.d.ts +13 -3
- package/dist/modules/Order/index.js +316 -248
- package/dist/modules/Order/types.d.ts +11 -0
- package/dist/modules/Order/utils.d.ts +3 -1
- package/dist/modules/Order/utils.js +171 -63
- package/dist/server/modules/order/index.js +6 -0
- package/dist/server/modules/order/types.d.ts +9 -0
- package/dist/server/utils/small-ticket.js +108 -4
- package/dist/solution/BaseSales/index.d.ts +6 -0
- package/dist/solution/BaseSales/index.js +364 -163
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +4 -0
- package/dist/solution/BookingTicket/index.js +155 -94
- package/lib/modules/Order/index.d.ts +13 -3
- package/lib/modules/Order/index.js +50 -15
- package/lib/modules/Order/types.d.ts +11 -0
- package/lib/modules/Order/utils.d.ts +3 -1
- package/lib/modules/Order/utils.js +101 -0
- package/lib/server/modules/order/index.js +6 -0
- package/lib/server/modules/order/types.d.ts +9 -0
- package/lib/server/utils/small-ticket.js +114 -11
- package/lib/solution/BaseSales/index.d.ts +6 -0
- package/lib/solution/BaseSales/index.js +120 -22
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +4 -0
- package/lib/solution/BookingTicket/index.js +35 -5
- package/package.json +1 -1
|
@@ -86,6 +86,8 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
86
86
|
openCache = false;
|
|
87
87
|
sessionStoragePersistEnabled = false;
|
|
88
88
|
sessionStorageRestoreRecord = null;
|
|
89
|
+
/** 只允许当前订单最新的 prepare/config 请求回写客户资产态。 */
|
|
90
|
+
customerWalletPrepareConfigEpoch = 0;
|
|
89
91
|
salesSummaryModuleName;
|
|
90
92
|
rulesHooksOverride;
|
|
91
93
|
moduleHooksOverride;
|
|
@@ -453,10 +455,21 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
453
455
|
return (0, _utils.createDefaultOrderRulesHooks)();
|
|
454
456
|
}
|
|
455
457
|
|
|
458
|
+
/**
|
|
459
|
+
* Stable across notifyTempOrderChanged's immutable copy, but changes when a
|
|
460
|
+
* different local/server order becomes current.
|
|
461
|
+
*/
|
|
462
|
+
getDiscountConfigOrderIdentityKey(tempOrder) {
|
|
463
|
+
const identity = this.getOrderIdentity();
|
|
464
|
+
return JSON.stringify([identity?.orderId ?? tempOrder?.order_id ?? '', tempOrder?.request_unique_idempotency_token ?? '', identity?.externalSaleNumber ?? tempOrder?.external_sale_number ?? '', identity?.localId ?? tempOrder?._extend?.localId ?? this.cacheId ?? '']);
|
|
465
|
+
}
|
|
466
|
+
|
|
456
467
|
// ─── Discount: 公共 API ───
|
|
457
468
|
|
|
458
469
|
async loadDiscountConfig(params) {
|
|
459
470
|
const orderId = params.orderId || this.store.tempOrder?.order_id || undefined;
|
|
471
|
+
const requestEpoch = ++this.customerWalletPrepareConfigEpoch;
|
|
472
|
+
const requestOrderIdentityKey = this.getDiscountConfigOrderIdentityKey(this.store.tempOrder);
|
|
460
473
|
const prepareConfigResult = await this.store.discount?.loadPrepareConfig({
|
|
461
474
|
customer_id: params.customerId,
|
|
462
475
|
action: params.action || (orderId ? 'edit' : 'create'),
|
|
@@ -471,13 +484,17 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
471
484
|
order_id: orderId
|
|
472
485
|
} : {})
|
|
473
486
|
});
|
|
487
|
+
const isCurrentRequest = () => requestEpoch === this.customerWalletPrepareConfigEpoch && this.getDiscountConfigOrderIdentityKey(this.store.tempOrder) === requestOrderIdentityKey && String(this.store.tempOrder?.customer_id ?? '') === String(params.customerId);
|
|
488
|
+
if (!isCurrentRequest()) {
|
|
489
|
+
return this.getDiscountList();
|
|
490
|
+
}
|
|
474
491
|
const discountList = prepareConfigResult?.discountList;
|
|
475
|
-
this.store.availableWalletIds = prepareConfigResult?.availableWalletIds || [];
|
|
476
|
-
this.store.virtualCurrencyList = prepareConfigResult?.virtualCurrencyList || [];
|
|
477
492
|
if (prepareConfigResult) {
|
|
478
|
-
this.
|
|
493
|
+
this.writeCustomerWalletSnapshotsFromPrepareConfig({
|
|
479
494
|
customerId: params.customerId,
|
|
480
|
-
|
|
495
|
+
availableWalletIds: prepareConfigResult.availableWalletIds || [],
|
|
496
|
+
availableWalletPassList: prepareConfigResult.availableWalletPassList || [],
|
|
497
|
+
virtualCurrencyList: prepareConfigResult.virtualCurrencyList || []
|
|
481
498
|
});
|
|
482
499
|
}
|
|
483
500
|
if (discountList) {
|
|
@@ -493,9 +510,12 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
493
510
|
return true;
|
|
494
511
|
});
|
|
495
512
|
const mergedDiscountList = [...currentEditDiscounts, ...currentScanDiscounts, ...runtimeDiscounts];
|
|
513
|
+
if (!isCurrentRequest()) return this.getDiscountList();
|
|
496
514
|
await this.store.discount?.setOriginalDiscountList(mergedDiscountList);
|
|
515
|
+
if (!isCurrentRequest()) return this.getDiscountList();
|
|
497
516
|
await this.store.discount?.setDiscountList(mergedDiscountList);
|
|
498
517
|
}
|
|
518
|
+
if (!isCurrentRequest()) return this.getDiscountList();
|
|
499
519
|
if (params.apply !== false && this.store.tempOrder?.products?.length) {
|
|
500
520
|
this.applyDiscount();
|
|
501
521
|
}
|
|
@@ -510,6 +530,9 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
510
530
|
getVirtualCurrencyList() {
|
|
511
531
|
return (0, _lodashEs.cloneDeep)(this.store.virtualCurrencyList || []);
|
|
512
532
|
}
|
|
533
|
+
getCustomerWalletPrepareConfigEpoch() {
|
|
534
|
+
return this.customerWalletPrepareConfigEpoch;
|
|
535
|
+
}
|
|
513
536
|
async syncScannedDiscountsToOriginalDiscountList(discountList) {
|
|
514
537
|
const scanDiscounts = (discountList || []).filter(discount => discount?.isScan);
|
|
515
538
|
if (!scanDiscounts.length) return;
|
|
@@ -998,27 +1021,41 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
998
1021
|
now: (0, _utils.formatDateTime)(new Date())
|
|
999
1022
|
});
|
|
1000
1023
|
}
|
|
1001
|
-
|
|
1024
|
+
clearTempOrderCustomerWalletSnapshots(tempOrder) {
|
|
1002
1025
|
const orderMetaList = (0, _utils.normalizeOrderMetaList)(tempOrder.order_meta_list);
|
|
1003
1026
|
if (!orderMetaList) return;
|
|
1004
1027
|
const nextOrderMetaList = {
|
|
1005
1028
|
...orderMetaList
|
|
1006
1029
|
};
|
|
1007
1030
|
delete nextOrderMetaList.point_cards_snapshot;
|
|
1031
|
+
delete nextOrderMetaList.virtual_currency_snapshot;
|
|
1008
1032
|
if (Object.keys(nextOrderMetaList).length === 0) {
|
|
1009
1033
|
delete tempOrder.order_meta_list;
|
|
1010
1034
|
return;
|
|
1011
1035
|
}
|
|
1012
1036
|
tempOrder.order_meta_list = nextOrderMetaList;
|
|
1013
1037
|
}
|
|
1014
|
-
|
|
1038
|
+
clearCustomerWalletState(tempOrder) {
|
|
1039
|
+
this.clearCustomerWalletRuntimeState();
|
|
1040
|
+
this.clearTempOrderCustomerWalletSnapshots(tempOrder);
|
|
1041
|
+
}
|
|
1042
|
+
clearCustomerWalletRuntimeState() {
|
|
1043
|
+
this.customerWalletPrepareConfigEpoch += 1;
|
|
1044
|
+
this.store.availableWalletIds = [];
|
|
1045
|
+
this.store.virtualCurrencyList = [];
|
|
1046
|
+
}
|
|
1047
|
+
writeCustomerWalletSnapshotsFromPrepareConfig(params) {
|
|
1015
1048
|
const tempOrder = this.store.tempOrder;
|
|
1016
1049
|
if (!tempOrder) return;
|
|
1017
1050
|
if (String(tempOrder.customer_id ?? '') !== String(params.customerId)) return;
|
|
1051
|
+
const virtualCurrencyList = Array.isArray(params.virtualCurrencyList) ? params.virtualCurrencyList : [];
|
|
1018
1052
|
tempOrder.order_meta_list = {
|
|
1019
1053
|
...((0, _utils.normalizeOrderMetaList)(tempOrder.order_meta_list) || {}),
|
|
1020
|
-
point_cards_snapshot: (0, _utils.buildPointCardSnapshotFromWalletPassList)(params.availableWalletPassList)
|
|
1054
|
+
point_cards_snapshot: (0, _utils.buildPointCardSnapshotFromWalletPassList)(params.availableWalletPassList),
|
|
1055
|
+
virtual_currency_snapshot: (0, _utils.buildVirtualCurrencySnapshotFromList)(virtualCurrencyList)
|
|
1021
1056
|
};
|
|
1057
|
+
this.store.availableWalletIds = [...params.availableWalletIds];
|
|
1058
|
+
this.store.virtualCurrencyList = (0, _lodashEs.cloneDeep)(virtualCurrencyList);
|
|
1022
1059
|
this.persistTempOrder();
|
|
1023
1060
|
this.saveDraftInBackground();
|
|
1024
1061
|
}
|
|
@@ -1801,6 +1838,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1801
1838
|
const freshTempOrder = this.createDefaultTempOrderInstance();
|
|
1802
1839
|
this.ensureExternalSaleNumber(freshTempOrder);
|
|
1803
1840
|
this.store.tempOrder = freshTempOrder;
|
|
1841
|
+
this.clearCustomerWalletRuntimeState();
|
|
1804
1842
|
this.store.summary = (0, _utils.createEmptySummary)();
|
|
1805
1843
|
this.store.lastOrderInfo = undefined;
|
|
1806
1844
|
this.store.syncState = undefined;
|
|
@@ -1821,6 +1859,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1821
1859
|
ensureIdentity: false
|
|
1822
1860
|
});
|
|
1823
1861
|
this.store.tempOrder = nextTempOrder;
|
|
1862
|
+
this.clearCustomerWalletRuntimeState();
|
|
1824
1863
|
if (options?.recalculateSummary !== false) {
|
|
1825
1864
|
await this.recalculateSummary({
|
|
1826
1865
|
createIfMissing: false
|
|
@@ -2691,8 +2730,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2691
2730
|
});
|
|
2692
2731
|
const nextCustomerId = tempOrder.customer_id ?? null;
|
|
2693
2732
|
if (String(previousCustomerId ?? '') !== String(nextCustomerId ?? '')) {
|
|
2694
|
-
this.
|
|
2695
|
-
this.clearTempOrderPointCardSnapshot(tempOrder);
|
|
2733
|
+
this.clearCustomerWalletState(tempOrder);
|
|
2696
2734
|
}
|
|
2697
2735
|
this.persistTempOrder();
|
|
2698
2736
|
return {
|
|
@@ -2728,9 +2766,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2728
2766
|
}
|
|
2729
2767
|
const nextCustomerId = tempOrder.customer_id ?? null;
|
|
2730
2768
|
if (String(previousCustomerId ?? '') !== String(nextCustomerId ?? '')) {
|
|
2731
|
-
this.
|
|
2732
|
-
this.store.virtualCurrencyList = [];
|
|
2733
|
-
this.clearTempOrderPointCardSnapshot(tempOrder);
|
|
2769
|
+
this.clearCustomerWalletState(tempOrder);
|
|
2734
2770
|
(0, _utils.clearTempOrderHolderAssignments)(tempOrder);
|
|
2735
2771
|
this.clearCustomerBoundDiscounts(tempOrder);
|
|
2736
2772
|
this.applyDiscount();
|
|
@@ -2768,9 +2804,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2768
2804
|
tempOrder.email = '';
|
|
2769
2805
|
tempOrder.customer = null;
|
|
2770
2806
|
if (tempOrder._extend) delete tempOrder._extend.customerSnapshot;
|
|
2771
|
-
this.
|
|
2772
|
-
this.store.virtualCurrencyList = [];
|
|
2773
|
-
this.clearTempOrderPointCardSnapshot(tempOrder);
|
|
2807
|
+
this.clearCustomerWalletState(tempOrder);
|
|
2774
2808
|
this.clearCustomerBoundDiscounts(tempOrder);
|
|
2775
2809
|
this.applyDiscount();
|
|
2776
2810
|
this.persistTempOrder();
|
|
@@ -4770,6 +4804,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4770
4804
|
allowUnresolvedSalesNotes: isSessionStorageHydrate
|
|
4771
4805
|
});
|
|
4772
4806
|
this.store.tempOrder = nextTempOrder;
|
|
4807
|
+
this.clearCustomerWalletRuntimeState();
|
|
4773
4808
|
if (isSessionStorageHydrate) {
|
|
4774
4809
|
// 会话快照是未提交购物车,不应获得编辑订单的 saved/edit 标记与服务端基线。
|
|
4775
4810
|
const restoredSessionDiscounts = Array.isArray(raw.discount_list) ? (0, _lodashEs.cloneDeep)(raw.discount_list) : [];
|
|
@@ -203,8 +203,18 @@ export interface PointCardSnapshotItem {
|
|
|
203
203
|
par_value: string;
|
|
204
204
|
used_par_value: string;
|
|
205
205
|
}
|
|
206
|
+
export interface VirtualCurrencySnapshotItem {
|
|
207
|
+
id: number | string;
|
|
208
|
+
tag: 'virtual_currency';
|
|
209
|
+
product_id?: number | string;
|
|
210
|
+
product_name: string;
|
|
211
|
+
par_value: string;
|
|
212
|
+
used_par_value: string;
|
|
213
|
+
name: Record<string, string>;
|
|
214
|
+
}
|
|
206
215
|
export interface OrderMetaList {
|
|
207
216
|
point_cards_snapshot?: PointCardSnapshotItem[];
|
|
217
|
+
virtual_currency_snapshot?: VirtualCurrencySnapshotItem[];
|
|
208
218
|
}
|
|
209
219
|
export interface OrderProduct extends OrderProductIdentity {
|
|
210
220
|
order_detail_id: number | null;
|
|
@@ -964,6 +974,7 @@ export interface OrderModuleAPI {
|
|
|
964
974
|
}) => Promise<Discount[]>;
|
|
965
975
|
getDiscountList: () => Discount[];
|
|
966
976
|
getAvailableWalletIds: () => number[];
|
|
977
|
+
getCustomerWalletPrepareConfigEpoch: () => number;
|
|
967
978
|
applyDiscount: () => void;
|
|
968
979
|
/**
|
|
969
980
|
* 注入促销评估器。
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Decimal from 'decimal.js';
|
|
2
2
|
import type { CartItem } from "../Cart";
|
|
3
|
-
import type { OrderProductDiscountItem, OrderMetaList, OrderProduct, OrderSubmitPayload, OrderSubmitProduct, OrderSummary, OrderTempOrder, PointCardSnapshotItem } from './types';
|
|
3
|
+
import type { OrderProductDiscountItem, OrderMetaList, OrderProduct, OrderSubmitPayload, OrderSubmitProduct, OrderSummary, OrderTempOrder, PointCardSnapshotItem, VirtualCurrencySnapshotItem } from './types';
|
|
4
4
|
import type { RulesParamsHooks } from '../Rules/types';
|
|
5
5
|
import type { MapOrderPaymentsOptions, OrderPaymentData, OrderPaymentSource } from './types';
|
|
6
6
|
import { createUuidV4 } from './utils/orderCollectionIdentity';
|
|
@@ -18,6 +18,8 @@ export interface OrderProductsDepositSummary {
|
|
|
18
18
|
import type { WindowPlugin } from '../../plugins';
|
|
19
19
|
export declare function normalizePointCardSnapshotItem(value: unknown): PointCardSnapshotItem | null;
|
|
20
20
|
export declare function buildPointCardSnapshotFromWalletPassList(value: unknown): PointCardSnapshotItem[];
|
|
21
|
+
export declare function normalizeVirtualCurrencySnapshotItem(value: unknown): VirtualCurrencySnapshotItem | null;
|
|
22
|
+
export declare function buildVirtualCurrencySnapshotFromList(value: unknown): VirtualCurrencySnapshotItem[];
|
|
21
23
|
export declare function normalizeOrderMetaList(value: unknown): OrderMetaList | undefined;
|
|
22
24
|
/**
|
|
23
25
|
* 把"含 option 的主商品单价"与 bundle 合成"单行 composite 单价"。
|
|
@@ -11,6 +11,7 @@ Object.defineProperty(exports, "buildManualProductDiscountItem", {
|
|
|
11
11
|
});
|
|
12
12
|
exports.buildPointCardSnapshotFromWalletPassList = buildPointCardSnapshotFromWalletPassList;
|
|
13
13
|
exports.buildSubmitPayload = buildSubmitPayload;
|
|
14
|
+
exports.buildVirtualCurrencySnapshotFromList = buildVirtualCurrencySnapshotFromList;
|
|
14
15
|
exports.calculateOrderProductsDeposit = calculateOrderProductsDeposit;
|
|
15
16
|
exports.clearTempOrderHolderAssignments = clearTempOrderHolderAssignments;
|
|
16
17
|
exports.composeLinePrice = composeLinePrice;
|
|
@@ -74,6 +75,7 @@ exports.normalizePointCardSnapshotItem = normalizePointCardSnapshotItem;
|
|
|
74
75
|
exports.normalizeProductSkuOptions = normalizeProductSkuOptions;
|
|
75
76
|
exports.normalizeSubmitBooking = normalizeSubmitBooking;
|
|
76
77
|
exports.normalizeSubmitCollectPaxValue = normalizeSubmitCollectPaxValue;
|
|
78
|
+
exports.normalizeVirtualCurrencySnapshotItem = normalizeVirtualCurrencySnapshotItem;
|
|
77
79
|
exports.productRequiresFormSubject = productRequiresFormSubject;
|
|
78
80
|
exports.resolveEffectivePerUnitDiscount = resolveEffectivePerUnitDiscount;
|
|
79
81
|
exports.resolveIsFormSubject = resolveIsFormSubject;
|
|
@@ -133,6 +135,7 @@ var _salesNotes = require("./salesNotes");
|
|
|
133
135
|
var _manualProductDiscount = require("./utils/manualProductDiscount");
|
|
134
136
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
135
137
|
const POINT_CARD_SNAPSHOT_TAG = 'point_card';
|
|
138
|
+
const VIRTUAL_CURRENCY_SNAPSHOT_TAG = 'virtual_currency';
|
|
136
139
|
function isPlainObject(value) {
|
|
137
140
|
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
138
141
|
}
|
|
@@ -170,6 +173,101 @@ function buildPointCardSnapshotFromWalletPassList(value) {
|
|
|
170
173
|
return result;
|
|
171
174
|
}, []);
|
|
172
175
|
}
|
|
176
|
+
function normalizeSnapshotNameMap(value) {
|
|
177
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
178
|
+
const normalizedText = String(value).trim();
|
|
179
|
+
return normalizedText ? {
|
|
180
|
+
original: normalizedText
|
|
181
|
+
} : {};
|
|
182
|
+
}
|
|
183
|
+
if (!isPlainObject(value)) return {};
|
|
184
|
+
return Object.entries(value).reduce((result, [locale, text]) => {
|
|
185
|
+
if (!locale.trim()) return result;
|
|
186
|
+
if (typeof text !== 'string' && typeof text !== 'number') return result;
|
|
187
|
+
const normalizedText = String(text).trim();
|
|
188
|
+
if (normalizedText) result[locale] = normalizedText;
|
|
189
|
+
return result;
|
|
190
|
+
}, {});
|
|
191
|
+
}
|
|
192
|
+
function buildVirtualCurrencySnapshotName(value) {
|
|
193
|
+
if (!isPlainObject(value)) return {};
|
|
194
|
+
const amountFormat = String(value.amount_format ?? '').trim();
|
|
195
|
+
let configuredName;
|
|
196
|
+
if (amountFormat === '{{amount}} {{unit}}') {
|
|
197
|
+
configuredName = value.unit_label;
|
|
198
|
+
} else if (amountFormat === '{{amount}} {{sym}}') {
|
|
199
|
+
configuredName = value.symbol;
|
|
200
|
+
} else {
|
|
201
|
+
return {};
|
|
202
|
+
}
|
|
203
|
+
const configuredNameMap = normalizeSnapshotNameMap(configuredName);
|
|
204
|
+
const shortNameMap = normalizeSnapshotNameMap(value.short_name);
|
|
205
|
+
|
|
206
|
+
// The configured unit/symbol is resolved before short_name. If it already
|
|
207
|
+
// carries a global fallback, keep it authoritative so (for example)
|
|
208
|
+
// short_name.en cannot mask unit_label.original. When it only has explicit
|
|
209
|
+
// locale entries, merge short_name so other receipt locales can still fall
|
|
210
|
+
// back after the configured value has no match.
|
|
211
|
+
const hasConfiguredGlobalFallback = ['original', 'auto', 'default', 'en'].some(locale => Boolean(configuredNameMap[locale]));
|
|
212
|
+
if (hasConfiguredGlobalFallback) return configuredNameMap;
|
|
213
|
+
return {
|
|
214
|
+
...shortNameMap,
|
|
215
|
+
...configuredNameMap
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
function normalizeVirtualCurrencySnapshotItem(value) {
|
|
219
|
+
if (!isPlainObject(value)) return null;
|
|
220
|
+
const id = normalizeSnapshotScalar(value.id);
|
|
221
|
+
if (id === undefined) return null;
|
|
222
|
+
if (String(value.tag || '').trim().toLowerCase() !== VIRTUAL_CURRENCY_SNAPSHOT_TAG) {
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
const snapshot = {
|
|
226
|
+
id,
|
|
227
|
+
tag: 'virtual_currency',
|
|
228
|
+
product_name: String(value.product_name ?? ''),
|
|
229
|
+
par_value: String(value.par_value ?? ''),
|
|
230
|
+
used_par_value: String(value.used_par_value ?? ''),
|
|
231
|
+
name: normalizeSnapshotNameMap(value.name)
|
|
232
|
+
};
|
|
233
|
+
const productId = normalizeSnapshotScalar(value.product_id);
|
|
234
|
+
if (productId !== undefined) {
|
|
235
|
+
snapshot.product_id = productId;
|
|
236
|
+
}
|
|
237
|
+
return snapshot;
|
|
238
|
+
}
|
|
239
|
+
function normalizeVirtualCurrencySnapshotList(value) {
|
|
240
|
+
if (!Array.isArray(value)) return [];
|
|
241
|
+
return value.reduce((result, item) => {
|
|
242
|
+
const normalized = normalizeVirtualCurrencySnapshotItem(item);
|
|
243
|
+
if (normalized) result.push(normalized);
|
|
244
|
+
return result;
|
|
245
|
+
}, []);
|
|
246
|
+
}
|
|
247
|
+
function buildVirtualCurrencySnapshotFromList(value) {
|
|
248
|
+
if (!Array.isArray(value)) return [];
|
|
249
|
+
return value.reduce((result, item) => {
|
|
250
|
+
if (!isPlainObject(item)) return result;
|
|
251
|
+
const id = normalizeSnapshotScalar(item.id);
|
|
252
|
+
if (id === undefined) return result;
|
|
253
|
+
const sourceTag = String(item.tag ?? '').trim().toLowerCase();
|
|
254
|
+
if (sourceTag !== VIRTUAL_CURRENCY_SNAPSHOT_TAG) return result;
|
|
255
|
+
const snapshot = {
|
|
256
|
+
id,
|
|
257
|
+
tag: 'virtual_currency',
|
|
258
|
+
product_name: String(item.product_name ?? ''),
|
|
259
|
+
par_value: String(item.par_value ?? ''),
|
|
260
|
+
used_par_value: String(item.used_par_value ?? ''),
|
|
261
|
+
name: buildVirtualCurrencySnapshotName(item.virtual_currency_display)
|
|
262
|
+
};
|
|
263
|
+
const productId = normalizeSnapshotScalar(item.product_id);
|
|
264
|
+
if (productId !== undefined) {
|
|
265
|
+
snapshot.product_id = productId;
|
|
266
|
+
}
|
|
267
|
+
result.push(snapshot);
|
|
268
|
+
return result;
|
|
269
|
+
}, []);
|
|
270
|
+
}
|
|
173
271
|
function normalizeOrderMetaList(value) {
|
|
174
272
|
if (value === undefined) return undefined;
|
|
175
273
|
if (!isPlainObject(value)) return undefined;
|
|
@@ -177,6 +275,9 @@ function normalizeOrderMetaList(value) {
|
|
|
177
275
|
if (Object.prototype.hasOwnProperty.call(value, 'point_cards_snapshot')) {
|
|
178
276
|
normalized.point_cards_snapshot = buildPointCardSnapshotFromWalletPassList(value.point_cards_snapshot);
|
|
179
277
|
}
|
|
278
|
+
if (Object.prototype.hasOwnProperty.call(value, 'virtual_currency_snapshot')) {
|
|
279
|
+
normalized.virtual_currency_snapshot = normalizeVirtualCurrencySnapshotList(value.virtual_currency_snapshot);
|
|
280
|
+
}
|
|
180
281
|
if (Object.keys(normalized).length > 0) return normalized;
|
|
181
282
|
return {};
|
|
182
283
|
}
|
|
@@ -2017,6 +2017,12 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2017
2017
|
mergedRecord[field] = (0, _lodashEs.cloneDeep)(incomingRecord[field]);
|
|
2018
2018
|
}
|
|
2019
2019
|
|
|
2020
|
+
// order_meta_list 是一次性生成的完整业务快照。incoming 明确携带时
|
|
2021
|
+
// 必须整体覆盖(包括 null / 空对象 / 空数组);省略时才保留 existing。
|
|
2022
|
+
if (Object.prototype.hasOwnProperty.call(incomingRecord, 'order_meta_list')) {
|
|
2023
|
+
mergedRecord.order_meta_list = (0, _lodashEs.cloneDeep)(incomingRecord.order_meta_list);
|
|
2024
|
+
}
|
|
2025
|
+
|
|
2020
2026
|
// 子项数组遵循完整快照语义:incoming 自有且为数组(包括 [])时权威替换;
|
|
2021
2027
|
// 字段缺席或不是数组时视为稀疏 patch,继续保留 existing。
|
|
2022
2028
|
for (const field of ORDER_AUTHORITATIVE_COLLECTION_FIELDS) {
|
|
@@ -456,6 +456,15 @@ export interface OrderData {
|
|
|
456
456
|
par_value: string;
|
|
457
457
|
used_par_value: string;
|
|
458
458
|
}>;
|
|
459
|
+
virtual_currency_snapshot?: Array<{
|
|
460
|
+
id: number | string;
|
|
461
|
+
tag: 'virtual_currency';
|
|
462
|
+
product_id?: number | string;
|
|
463
|
+
product_name: string;
|
|
464
|
+
par_value: string;
|
|
465
|
+
used_par_value: string;
|
|
466
|
+
name: Record<string, string>;
|
|
467
|
+
}>;
|
|
459
468
|
};
|
|
460
469
|
/**
|
|
461
470
|
* 金额汇总(仅输出)。
|
|
@@ -1378,20 +1378,30 @@ function resolveRefundPayment(refund, payments) {
|
|
|
1378
1378
|
return matchedPayment || refund;
|
|
1379
1379
|
}
|
|
1380
1380
|
function buildWallets(params) {
|
|
1381
|
+
const virtualCurrencySnapshots = collectVirtualCurrencySnapshots(params.order);
|
|
1381
1382
|
const displayedWalletPayments = normalizeArray(params.order.payments).filter(payment => isPrintablePayment(payment) && !!getFundRecord(payment));
|
|
1382
|
-
const paymentWallets = displayedWalletPayments.map(payment =>
|
|
1383
|
-
payment,
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1383
|
+
const paymentWallets = displayedWalletPayments.map(payment => {
|
|
1384
|
+
const virtualCurrencySnapshot = findVirtualCurrencySnapshotForPayment(payment, virtualCurrencySnapshots.byId);
|
|
1385
|
+
return buildPaymentItems({
|
|
1386
|
+
payment,
|
|
1387
|
+
locale: params.locale,
|
|
1388
|
+
currencySymbol: params.currencySymbol,
|
|
1389
|
+
includeFundRecordBalance: true,
|
|
1390
|
+
includeFundRecordUsage: false,
|
|
1391
|
+
includePaymentAmount: false,
|
|
1392
|
+
virtualCurrencyUnit: virtualCurrencySnapshot ? getVirtualCurrencySnapshotUnit(virtualCurrencySnapshot, params.locale) : undefined
|
|
1393
|
+
});
|
|
1394
|
+
});
|
|
1390
1395
|
const displayedWalletPassIds = collectDisplayedWalletPassIds(displayedWalletPayments);
|
|
1391
1396
|
return [...paymentWallets, ...buildVoucherAssets(params), ...buildPointCardSnapshotAssets({
|
|
1392
1397
|
order: params.order,
|
|
1393
1398
|
locale: params.locale,
|
|
1394
1399
|
displayedWalletPassIds
|
|
1400
|
+
}), ...buildVirtualCurrencySnapshotAssets({
|
|
1401
|
+
snapshots: virtualCurrencySnapshots.items,
|
|
1402
|
+
order: params.order,
|
|
1403
|
+
locale: params.locale,
|
|
1404
|
+
displayedWalletPassIds
|
|
1395
1405
|
})];
|
|
1396
1406
|
}
|
|
1397
1407
|
function collectDisplayedWalletPassIds(payments) {
|
|
@@ -1438,6 +1448,88 @@ function buildPointCardSnapshotAssets(params) {
|
|
|
1438
1448
|
return [rows];
|
|
1439
1449
|
});
|
|
1440
1450
|
}
|
|
1451
|
+
function collectVirtualCurrencySnapshots(order) {
|
|
1452
|
+
const items = [];
|
|
1453
|
+
const byId = new Map();
|
|
1454
|
+
const snapshots = order.order_meta_list?.virtual_currency_snapshot;
|
|
1455
|
+
if (!Array.isArray(snapshots)) return {
|
|
1456
|
+
items,
|
|
1457
|
+
byId
|
|
1458
|
+
};
|
|
1459
|
+
snapshots.forEach(snapshot => {
|
|
1460
|
+
if (!snapshot || typeof snapshot !== 'object' || Array.isArray(snapshot)) return;
|
|
1461
|
+
const virtualCurrency = snapshot;
|
|
1462
|
+
if (stringify(virtualCurrency.tag).trim().toLowerCase() !== 'virtual_currency') return;
|
|
1463
|
+
const id = normalizeWalletPassId(virtualCurrency.id);
|
|
1464
|
+
if (!id || byId.has(id)) return;
|
|
1465
|
+
byId.set(id, virtualCurrency);
|
|
1466
|
+
items.push(virtualCurrency);
|
|
1467
|
+
});
|
|
1468
|
+
return {
|
|
1469
|
+
items,
|
|
1470
|
+
byId
|
|
1471
|
+
};
|
|
1472
|
+
}
|
|
1473
|
+
function findVirtualCurrencySnapshotForPayment(payment, snapshotsById) {
|
|
1474
|
+
const fundRecord = getFundRecord(payment);
|
|
1475
|
+
for (const value of [fundRecord?.voucher_id, payment.voucher_id]) {
|
|
1476
|
+
const id = normalizeWalletPassId(value);
|
|
1477
|
+
if (!id) continue;
|
|
1478
|
+
const snapshot = snapshotsById.get(id);
|
|
1479
|
+
if (snapshot) return snapshot;
|
|
1480
|
+
}
|
|
1481
|
+
return undefined;
|
|
1482
|
+
}
|
|
1483
|
+
function buildVirtualCurrencySnapshotAssets(params) {
|
|
1484
|
+
const snapshotTime = firstPresentValue(params.order.updated_at, params.order.created_at);
|
|
1485
|
+
return params.snapshots.flatMap(virtualCurrency => {
|
|
1486
|
+
const id = normalizeWalletPassId(virtualCurrency.id);
|
|
1487
|
+
if (!id || params.displayedWalletPassIds.has(id)) return [];
|
|
1488
|
+
const rows = [{
|
|
1489
|
+
item: stringify(virtualCurrency.product_name).trim(),
|
|
1490
|
+
value: ''
|
|
1491
|
+
}];
|
|
1492
|
+
const balance = getVirtualCurrencySnapshotBalance(virtualCurrency);
|
|
1493
|
+
if (balance) {
|
|
1494
|
+
rows.push({
|
|
1495
|
+
item: label(params.locale, 'balance'),
|
|
1496
|
+
value: formatVirtualCurrencyBalance(balance, getVirtualCurrencySnapshotUnit(virtualCurrency, params.locale))
|
|
1497
|
+
});
|
|
1498
|
+
}
|
|
1499
|
+
if (isPresentId(snapshotTime)) {
|
|
1500
|
+
rows.push({
|
|
1501
|
+
item: formatDateTime(snapshotTime, params.locale),
|
|
1502
|
+
value: ''
|
|
1503
|
+
});
|
|
1504
|
+
}
|
|
1505
|
+
return [rows];
|
|
1506
|
+
});
|
|
1507
|
+
}
|
|
1508
|
+
function getVirtualCurrencySnapshotBalance(snapshot) {
|
|
1509
|
+
if (!isNumericAmount(snapshot.par_value) || !isNumericAmount(snapshot.used_par_value)) {
|
|
1510
|
+
return null;
|
|
1511
|
+
}
|
|
1512
|
+
return _decimal.default.max(new _decimal.default(snapshot.par_value).minus(new _decimal.default(snapshot.used_par_value)), 0);
|
|
1513
|
+
}
|
|
1514
|
+
function getVirtualCurrencySnapshotUnit(snapshot, locale) {
|
|
1515
|
+
return getNonEmptyLocalizedValue(snapshot.name, locale);
|
|
1516
|
+
}
|
|
1517
|
+
function getNonEmptyLocalizedValue(value, locale) {
|
|
1518
|
+
if (value === undefined || value === null) return '';
|
|
1519
|
+
if (typeof value !== 'object' || Array.isArray(value)) return stringify(value).trim();
|
|
1520
|
+
const dashedLocale = locale.replace('_', '-');
|
|
1521
|
+
const underscoredLocale = locale.replace('-', '_');
|
|
1522
|
+
for (const candidate of [value[locale], value[dashedLocale], value[underscoredLocale], value.original, value.auto, value.default, value.en]) {
|
|
1523
|
+
const text = stringify(candidate).trim();
|
|
1524
|
+
if (text) return text;
|
|
1525
|
+
}
|
|
1526
|
+
return '';
|
|
1527
|
+
}
|
|
1528
|
+
function formatVirtualCurrencyBalance(value, unit) {
|
|
1529
|
+
const amount = trimDecimal(value);
|
|
1530
|
+
const normalizedUnit = unit.trim();
|
|
1531
|
+
return normalizedUnit ? `${amount} ${normalizedUnit}` : amount;
|
|
1532
|
+
}
|
|
1441
1533
|
function normalizeWalletPassId(value) {
|
|
1442
1534
|
if (typeof value === 'number') return Number.isFinite(value) ? String(value) : null;
|
|
1443
1535
|
if (typeof value !== 'string') return null;
|
|
@@ -1604,7 +1696,8 @@ function buildPaymentItems(params) {
|
|
|
1604
1696
|
currencySymbol,
|
|
1605
1697
|
includeFundRecordBalance,
|
|
1606
1698
|
includeFundRecordUsage,
|
|
1607
|
-
includePaymentAmount
|
|
1699
|
+
includePaymentAmount,
|
|
1700
|
+
virtualCurrencyUnit
|
|
1608
1701
|
} = params;
|
|
1609
1702
|
const serviceFee = getPaymentServiceFee(payment);
|
|
1610
1703
|
const items = [{
|
|
@@ -1630,7 +1723,8 @@ function buildPaymentItems(params) {
|
|
|
1630
1723
|
locale,
|
|
1631
1724
|
currencySymbol,
|
|
1632
1725
|
includeBalance: includeFundRecordBalance,
|
|
1633
|
-
includeUsage: includeFundRecordUsage
|
|
1726
|
+
includeUsage: includeFundRecordUsage,
|
|
1727
|
+
virtualCurrencyUnit
|
|
1634
1728
|
}));
|
|
1635
1729
|
} else {
|
|
1636
1730
|
const remainingAmount = payment.remaining_amount ?? payment.balance ?? payment.metadata?.remaining_amount;
|
|
@@ -1695,7 +1789,8 @@ function buildFundRecordPaymentItems(params) {
|
|
|
1695
1789
|
locale,
|
|
1696
1790
|
currencySymbol,
|
|
1697
1791
|
includeBalance,
|
|
1698
|
-
includeUsage
|
|
1792
|
+
includeUsage,
|
|
1793
|
+
virtualCurrencyUnit
|
|
1699
1794
|
} = params;
|
|
1700
1795
|
const items = [];
|
|
1701
1796
|
const usingBeforeValue = fundRecord.using_before_value;
|
|
@@ -1717,6 +1812,14 @@ function buildFundRecordPaymentItems(params) {
|
|
|
1717
1812
|
return items;
|
|
1718
1813
|
}
|
|
1719
1814
|
if (includeBalance && usingAfterValue !== undefined && usingAfterValue !== null) {
|
|
1815
|
+
if (virtualCurrencyUnit !== undefined) {
|
|
1816
|
+
if (!isNumericAmount(usingAfterValue)) return items;
|
|
1817
|
+
items.push({
|
|
1818
|
+
item: label(locale, 'balance'),
|
|
1819
|
+
value: formatVirtualCurrencyBalance(new _decimal.default(usingAfterValue), virtualCurrencyUnit)
|
|
1820
|
+
});
|
|
1821
|
+
return items;
|
|
1822
|
+
}
|
|
1720
1823
|
items.push({
|
|
1721
1824
|
item: label(locale, 'balance'),
|
|
1722
1825
|
value: formatMoney(usingAfterValue, currencySymbol)
|
|
@@ -273,6 +273,12 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
|
|
|
273
273
|
private mergeHistoricalDiscountList;
|
|
274
274
|
private shouldSkipAutoApplyFetchedDiscountsInEditMode;
|
|
275
275
|
private mergeCurrentDiscountSelectionState;
|
|
276
|
+
private resolveDiscountConfigCustomerId;
|
|
277
|
+
/**
|
|
278
|
+
* Stable across notifyTempOrderChanged's immutable object replacement, while
|
|
279
|
+
* still distinguishing two local orders for the same customer.
|
|
280
|
+
*/
|
|
281
|
+
private getDiscountConfigOrderIdentityKey;
|
|
276
282
|
loadDiscountConfig(params?: {
|
|
277
283
|
customerId?: number;
|
|
278
284
|
action?: 'create' | 'edit';
|