@pisell/pisellos 2.3.114 → 2.3.115
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modules/Order/index.d.ts +14 -4
- 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 +1 -0
- package/dist/solution/BookingTicket/index.js +37 -16
- package/lib/modules/Order/index.d.ts +14 -4
- 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 +1 -0
- package/lib/solution/BookingTicket/index.js +23 -5
- package/package.json +1 -1
|
@@ -326,7 +326,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
326
326
|
date: string;
|
|
327
327
|
status: string;
|
|
328
328
|
week: string;
|
|
329
|
-
weekNum: 0 | 2 | 3 |
|
|
329
|
+
weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
|
|
330
330
|
}[]>;
|
|
331
331
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
332
332
|
private getScheduleDataByIds;
|
|
@@ -29,6 +29,7 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
|
|
|
29
29
|
private addTimeProductsCatalog;
|
|
30
30
|
private orderCustomerDiscountRefreshInFlight;
|
|
31
31
|
private orderCustomerDiscountRefreshCustomerId;
|
|
32
|
+
private orderCustomerDiscountRefreshTarget;
|
|
32
33
|
private orderCustomerPromotionRefreshInFlight;
|
|
33
34
|
protected loadOpenDataInFlight: Promise<OpenDataConfig> | null;
|
|
34
35
|
protected loadOpenDataInFlightTarget: string | null;
|
|
@@ -180,6 +180,7 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseSalesImpl) {
|
|
|
180
180
|
_defineProperty(_assertThisInitialized(_this), "addTimeProductsCatalog", []);
|
|
181
181
|
_defineProperty(_assertThisInitialized(_this), "orderCustomerDiscountRefreshInFlight", null);
|
|
182
182
|
_defineProperty(_assertThisInitialized(_this), "orderCustomerDiscountRefreshCustomerId", null);
|
|
183
|
+
_defineProperty(_assertThisInitialized(_this), "orderCustomerDiscountRefreshTarget", null);
|
|
183
184
|
_defineProperty(_assertThisInitialized(_this), "orderCustomerPromotionRefreshInFlight", null);
|
|
184
185
|
_defineProperty(_assertThisInitialized(_this), "loadOpenDataInFlight", null);
|
|
185
186
|
_defineProperty(_assertThisInitialized(_this), "loadOpenDataInFlightTarget", null);
|
|
@@ -1890,15 +1891,24 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseSalesImpl) {
|
|
|
1890
1891
|
}, {
|
|
1891
1892
|
key: "refreshDiscountConfigAfterOrderCustomerChange",
|
|
1892
1893
|
value: function refreshDiscountConfigAfterOrderCustomerChange(customerId) {
|
|
1893
|
-
var
|
|
1894
|
+
var _this$store$order$get4,
|
|
1895
|
+
_this$store$order6,
|
|
1896
|
+
_this$getOrderIdentit,
|
|
1897
|
+
_this5 = this;
|
|
1894
1898
|
if (!customerId || customerId === 1) return Promise.resolve();
|
|
1895
|
-
|
|
1899
|
+
var tempOrder = (_this$store$order$get4 = (_this$store$order6 = this.store.order).getTempOrder) === null || _this$store$order$get4 === void 0 ? void 0 : _this$store$order$get4.call(_this$store$order6);
|
|
1900
|
+
var orderIdentity = (_this$getOrderIdentit = this.getOrderIdentity) === null || _this$getOrderIdentit === void 0 ? void 0 : _this$getOrderIdentit.call(this);
|
|
1901
|
+
var orderId = (tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.order_id) || (orderIdentity === null || orderIdentity === void 0 ? void 0 : orderIdentity.orderId);
|
|
1902
|
+
var action = !orderId || String(orderId).startsWith('local_order') ? 'create' : 'edit';
|
|
1903
|
+
var orderTarget = orderId ? "order:".concat(String(orderId)) : "external:".concat(String((tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.external_sale_number) || (orderIdentity === null || orderIdentity === void 0 ? void 0 : orderIdentity.externalSaleNumber) || (orderIdentity === null || orderIdentity === void 0 ? void 0 : orderIdentity.localId) || 'new'));
|
|
1904
|
+
var refreshTarget = "".concat(customerId, ":").concat(action, ":").concat(orderTarget);
|
|
1905
|
+
if (this.orderCustomerDiscountRefreshInFlight && this.orderCustomerDiscountRefreshTarget === refreshTarget) {
|
|
1896
1906
|
return this.orderCustomerDiscountRefreshInFlight;
|
|
1897
1907
|
}
|
|
1898
1908
|
var previousRefresh = this.orderCustomerDiscountRefreshInFlight;
|
|
1899
1909
|
var refreshTask = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
|
|
1900
1910
|
var _this5$store$order$ge, _this5$store$order, _this5$getOrderIdenti;
|
|
1901
|
-
var currentCustomer,
|
|
1911
|
+
var currentCustomer, currentTempOrder, currentOrderIdentity, currentOrderId, currentAction, currentOrderTarget;
|
|
1902
1912
|
return _regeneratorRuntime().wrap(function _callee25$(_context25) {
|
|
1903
1913
|
while (1) switch (_context25.prev = _context25.next) {
|
|
1904
1914
|
case 0:
|
|
@@ -1918,15 +1928,24 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseSalesImpl) {
|
|
|
1918
1928
|
}
|
|
1919
1929
|
return _context25.abrupt("return");
|
|
1920
1930
|
case 6:
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1931
|
+
currentTempOrder = (_this5$store$order$ge = (_this5$store$order = _this5.store.order).getTempOrder) === null || _this5$store$order$ge === void 0 ? void 0 : _this5$store$order$ge.call(_this5$store$order);
|
|
1932
|
+
currentOrderIdentity = (_this5$getOrderIdenti = _this5.getOrderIdentity) === null || _this5$getOrderIdenti === void 0 ? void 0 : _this5$getOrderIdenti.call(_this5);
|
|
1933
|
+
currentOrderId = (currentTempOrder === null || currentTempOrder === void 0 ? void 0 : currentTempOrder.order_id) || (currentOrderIdentity === null || currentOrderIdentity === void 0 ? void 0 : currentOrderIdentity.orderId);
|
|
1934
|
+
currentAction = !currentOrderId || String(currentOrderId).startsWith('local_order') ? 'create' : 'edit';
|
|
1935
|
+
currentOrderTarget = currentOrderId ? "order:".concat(String(currentOrderId)) : "external:".concat(String((currentTempOrder === null || currentTempOrder === void 0 ? void 0 : currentTempOrder.external_sale_number) || (currentOrderIdentity === null || currentOrderIdentity === void 0 ? void 0 : currentOrderIdentity.externalSaleNumber) || (currentOrderIdentity === null || currentOrderIdentity === void 0 ? void 0 : currentOrderIdentity.localId) || 'new'));
|
|
1936
|
+
if (!("".concat(customerId, ":").concat(currentAction, ":").concat(currentOrderTarget) !== refreshTarget)) {
|
|
1937
|
+
_context25.next = 13;
|
|
1938
|
+
break;
|
|
1939
|
+
}
|
|
1940
|
+
return _context25.abrupt("return");
|
|
1941
|
+
case 13:
|
|
1942
|
+
_context25.next = 15;
|
|
1925
1943
|
return _this5.loadDiscountConfig({
|
|
1926
1944
|
customerId: customerId,
|
|
1927
|
-
action: action
|
|
1945
|
+
action: action,
|
|
1946
|
+
force: true
|
|
1928
1947
|
});
|
|
1929
|
-
case
|
|
1948
|
+
case 15:
|
|
1930
1949
|
case "end":
|
|
1931
1950
|
return _context25.stop();
|
|
1932
1951
|
}
|
|
@@ -1934,12 +1953,14 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseSalesImpl) {
|
|
|
1934
1953
|
}))();
|
|
1935
1954
|
this.orderCustomerDiscountRefreshInFlight = refreshTask;
|
|
1936
1955
|
this.orderCustomerDiscountRefreshCustomerId = customerId;
|
|
1956
|
+
this.orderCustomerDiscountRefreshTarget = refreshTarget;
|
|
1937
1957
|
refreshTask.catch(function (error) {
|
|
1938
1958
|
console.error('Failed to load discount config after customer change:', error);
|
|
1939
1959
|
}).finally(function () {
|
|
1940
1960
|
if (_this5.orderCustomerDiscountRefreshInFlight !== refreshTask) return;
|
|
1941
1961
|
_this5.orderCustomerDiscountRefreshInFlight = null;
|
|
1942
1962
|
_this5.orderCustomerDiscountRefreshCustomerId = null;
|
|
1963
|
+
_this5.orderCustomerDiscountRefreshTarget = null;
|
|
1943
1964
|
});
|
|
1944
1965
|
return refreshTask;
|
|
1945
1966
|
}
|
|
@@ -2503,10 +2524,10 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseSalesImpl) {
|
|
|
2503
2524
|
}, {
|
|
2504
2525
|
key: "buildAddProductCtx",
|
|
2505
2526
|
value: function buildAddProductCtx(extra) {
|
|
2506
|
-
var _extra$date2, _ref12, _this$getOrderCustome4, _this$getOrderCustome5, _this$store$order$
|
|
2527
|
+
var _extra$date2, _ref12, _this$getOrderCustome4, _this$getOrderCustome5, _this$store$order$get5, _extra$presetStartTim2;
|
|
2507
2528
|
var bookingContextState = this.store.bookingContext.getState();
|
|
2508
2529
|
var date = (_extra$date2 = extra === null || extra === void 0 ? void 0 : extra.date) !== null && _extra$date2 !== void 0 ? _extra$date2 : bookingContextState.date;
|
|
2509
|
-
var orderCustomerId = (_ref12 = (_this$getOrderCustome4 = (_this$getOrderCustome5 = this.getOrderCustomerSnapshot()) === null || _this$getOrderCustome5 === void 0 ? void 0 : _this$getOrderCustome5.id) !== null && _this$getOrderCustome4 !== void 0 ? _this$getOrderCustome4 : (_this$store$order$
|
|
2530
|
+
var orderCustomerId = (_ref12 = (_this$getOrderCustome4 = (_this$getOrderCustome5 = this.getOrderCustomerSnapshot()) === null || _this$getOrderCustome5 === void 0 ? void 0 : _this$getOrderCustome5.id) !== null && _this$getOrderCustome4 !== void 0 ? _this$getOrderCustome4 : (_this$store$order$get5 = this.store.order.getTempOrder()) === null || _this$store$order$get5 === void 0 ? void 0 : _this$store$order$get5.customer_id) !== null && _ref12 !== void 0 ? _ref12 : undefined;
|
|
2510
2531
|
return _objectSpread(_objectSpread({
|
|
2511
2532
|
bookingConfig: bookingContextState.bookingConfig,
|
|
2512
2533
|
resourcesOrigin: bookingContextState.resourcesOrigin,
|
|
@@ -2999,7 +3020,7 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseSalesImpl) {
|
|
|
2999
3020
|
key: "handlePrintWristband",
|
|
3000
3021
|
value: function () {
|
|
3001
3022
|
var _handlePrintWristband = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
|
|
3002
|
-
var _this$
|
|
3023
|
+
var _this$getOrderIdentit2;
|
|
3003
3024
|
var deviceTask, deviceId, idempotencyKey;
|
|
3004
3025
|
return _regeneratorRuntime().wrap(function _callee36$(_context36) {
|
|
3005
3026
|
while (1) switch (_context36.prev = _context36.next) {
|
|
@@ -3036,7 +3057,7 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseSalesImpl) {
|
|
|
3036
3057
|
payload: {
|
|
3037
3058
|
type: 'WRISTBAND',
|
|
3038
3059
|
data: {
|
|
3039
|
-
order_id: (_this$
|
|
3060
|
+
order_id: (_this$getOrderIdentit2 = this.getOrderIdentity()) === null || _this$getOrderIdentit2 === void 0 ? void 0 : _this$getOrderIdentit2.orderId,
|
|
3040
3061
|
voucher_ids: Array.isArray(params.voucher_ids) ? params.voucher_ids : [params.voucher_ids]
|
|
3041
3062
|
}
|
|
3042
3063
|
},
|
|
@@ -3061,7 +3082,7 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseSalesImpl) {
|
|
|
3061
3082
|
key: "handleRedeem",
|
|
3062
3083
|
value: function () {
|
|
3063
3084
|
var _handleRedeem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(params) {
|
|
3064
|
-
var _this$store$
|
|
3085
|
+
var _this$store$order7, _this$store$order7$ge, _this$store$order8, _ref20, _tempOrder$order_id2;
|
|
3065
3086
|
var voucherIds, status, voucherIdSet, tempOrder, vouchers, hasUpdatedVoucher, nextVouchers, identity, externalSaleNumber, orderId, orderLookup;
|
|
3066
3087
|
return _regeneratorRuntime().wrap(function _callee37$(_context37) {
|
|
3067
3088
|
while (1) switch (_context37.prev = _context37.next) {
|
|
@@ -3077,8 +3098,8 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseSalesImpl) {
|
|
|
3077
3098
|
}
|
|
3078
3099
|
});
|
|
3079
3100
|
voucherIdSet = new Set(voucherIds);
|
|
3080
|
-
tempOrder = (_this$store$
|
|
3081
|
-
vouchers = (tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.vouchers) || ((_this$store$
|
|
3101
|
+
tempOrder = (_this$store$order7 = this.store.order) === null || _this$store$order7 === void 0 || (_this$store$order7$ge = _this$store$order7.getTempOrder) === null || _this$store$order7$ge === void 0 ? void 0 : _this$store$order7$ge.call(_this$store$order7);
|
|
3102
|
+
vouchers = (tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.vouchers) || ((_this$store$order8 = this.store.order) === null || _this$store$order8 === void 0 ? void 0 : _this$store$order8.getVouchers()) || [];
|
|
3082
3103
|
hasUpdatedVoucher = false;
|
|
3083
3104
|
nextVouchers = vouchers.map(function (voucher) {
|
|
3084
3105
|
if (!voucherIdSet.has(voucher.voucher_id)) return voucher;
|
|
@@ -20,6 +20,8 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
20
20
|
private openCache;
|
|
21
21
|
private sessionStoragePersistEnabled;
|
|
22
22
|
private sessionStorageRestoreRecord;
|
|
23
|
+
/** 只允许当前订单最新的 prepare/config 请求回写客户资产态。 */
|
|
24
|
+
private customerWalletPrepareConfigEpoch;
|
|
23
25
|
private salesSummaryModuleName;
|
|
24
26
|
private rulesHooksOverride?;
|
|
25
27
|
private moduleHooksOverride?;
|
|
@@ -78,6 +80,11 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
78
80
|
private logError;
|
|
79
81
|
private registerDiscountModules;
|
|
80
82
|
private createDefaultRulesHooks;
|
|
83
|
+
/**
|
|
84
|
+
* Stable across notifyTempOrderChanged's immutable copy, but changes when a
|
|
85
|
+
* different local/server order becomes current.
|
|
86
|
+
*/
|
|
87
|
+
private getDiscountConfigOrderIdentityKey;
|
|
81
88
|
loadDiscountConfig(params: {
|
|
82
89
|
customerId: number;
|
|
83
90
|
action?: 'create' | 'edit';
|
|
@@ -87,6 +94,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
87
94
|
getDiscountList(): Discount[];
|
|
88
95
|
getAvailableWalletIds(): number[];
|
|
89
96
|
getVirtualCurrencyList(): import("../Discount/types").VirtualCurrencyAsset[];
|
|
97
|
+
getCustomerWalletPrepareConfigEpoch(): number;
|
|
90
98
|
private syncScannedDiscountsToOriginalDiscountList;
|
|
91
99
|
private ensureEditDiscountConfigForProductChange;
|
|
92
100
|
scanCode(code: string, customerId?: number): Promise<{
|
|
@@ -176,8 +184,10 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
176
184
|
consumeSessionStorageRestore(): Record<string, any> | null;
|
|
177
185
|
notifyTempOrderChanged(): void;
|
|
178
186
|
private createDefaultTempOrderInstance;
|
|
179
|
-
private
|
|
180
|
-
private
|
|
187
|
+
private clearTempOrderCustomerWalletSnapshots;
|
|
188
|
+
private clearCustomerWalletState;
|
|
189
|
+
private clearCustomerWalletRuntimeState;
|
|
190
|
+
private writeCustomerWalletSnapshotsFromPrepareConfig;
|
|
181
191
|
private createExternalSaleNumber;
|
|
182
192
|
private ensureExternalSaleNumber;
|
|
183
193
|
private ensureRequestUniqueIdempotencyToken;
|
|
@@ -557,7 +567,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
557
567
|
generateIdempotencyToken(): string;
|
|
558
568
|
syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
|
|
559
569
|
createOrder(params: CommitOrderParams['query']): {
|
|
560
|
-
type: "
|
|
570
|
+
type: "virtual" | "appointment_booking";
|
|
561
571
|
platform: string;
|
|
562
572
|
sales_channel: string;
|
|
563
573
|
order_sales_channel: string;
|
|
@@ -635,4 +645,4 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
635
645
|
getOrderInfo(order_id: number): Promise<any>;
|
|
636
646
|
getVouchers(): any[];
|
|
637
647
|
}
|
|
638
|
-
export type { AddProductToOrderOptions, OrderMetaList, PointCardSnapshotItem, RemoveProductsFromOrderOptions, SalesNote, SalesNoteDraftInput, SalesNoteLocalizedSelection, SalesNoteLocalizedText, SalesNoteRelation, SalesNoteTextInput, SetSalesNoteInput, UpdateOrderBookingParams, UpdateOrderProductParams, UpdateOrderProductQuantityParams, } from './types';
|
|
648
|
+
export type { AddProductToOrderOptions, OrderMetaList, PointCardSnapshotItem, VirtualCurrencySnapshotItem, RemoveProductsFromOrderOptions, SalesNote, SalesNoteDraftInput, SalesNoteLocalizedSelection, SalesNoteLocalizedText, SalesNoteRelation, SalesNoteTextInput, SetSalesNoteInput, UpdateOrderBookingParams, UpdateOrderProductParams, UpdateOrderProductQuantityParams, } from './types';
|
|
@@ -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
|
* 金额汇总(仅输出)。
|