@pisell/pisellos 0.10.90 → 0.10.93
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/itemRule/adapter.d.ts +3 -1
- package/dist/model/strategy/adapter/itemRule/adapter.js +74 -7
- package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +3 -1
- package/dist/model/strategy/adapter/itemRule/evaluator.js +13 -0
- package/dist/model/strategy/adapter/itemRule/type.d.ts +40 -1
- package/dist/model/strategy/adapter/itemRule/type.js +10 -0
- package/dist/model/strategy/adapter/promotion/evaluator.d.ts +2 -1
- package/dist/model/strategy/adapter/promotion/evaluator.js +103 -112
- package/dist/modules/BookingContext/utils/calendarBooking.d.ts +15 -0
- package/dist/modules/BookingContext/utils/calendarBooking.js +207 -0
- package/dist/modules/BookingContext/utils/index.d.ts +1 -0
- package/dist/modules/BookingContext/utils/index.js +1 -0
- package/dist/modules/BookingContext/utils/productExtend.d.ts +21 -0
- package/dist/modules/BookingContext/utils/productExtend.js +132 -33
- package/dist/modules/BookingContext/utils/resources.js +1 -1
- package/dist/modules/Cart/index.js +4 -3
- package/dist/modules/Cart/types.d.ts +2 -0
- package/dist/modules/Cart/utils/cartProduct.d.ts +3 -1
- package/dist/modules/Cart/utils/cartProduct.js +59 -32
- package/dist/modules/Date/index.d.ts +1 -1
- package/dist/modules/Date/index.js +60 -14
- package/dist/modules/Date/types.d.ts +5 -0
- package/dist/modules/OpenData/salesSettings.js +1 -1
- package/dist/modules/OpenData/types.d.ts +9 -0
- package/dist/modules/OpenData/utils.d.ts +1 -1
- package/dist/modules/OpenData/utils.js +3 -2
- package/dist/modules/Order/index.d.ts +22 -7
- package/dist/modules/Order/index.js +1565 -1161
- package/dist/modules/Order/localEftposState.d.ts +13 -0
- package/dist/modules/Order/localEftposState.js +39 -0
- package/dist/modules/Order/types.d.ts +33 -11
- package/dist/modules/Order/types.js +2 -2
- package/dist/modules/Order/unpaidAmountGap.d.ts +6 -0
- package/dist/modules/Order/unpaidAmountGap.js +72 -0
- package/dist/modules/Order/utils.d.ts +4 -1
- package/dist/modules/Order/utils.js +75 -52
- package/dist/modules/Payment/walletpass.js +32 -6
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/Product/types.d.ts +16 -0
- package/dist/modules/ProductList/index.js +1 -1
- package/dist/modules/ResourcePlanner/planner.d.ts +2 -0
- package/dist/modules/ResourcePlanner/planner.js +383 -24
- package/dist/modules/ResourcePlanner/types.d.ts +42 -0
- package/dist/modules/Rules/index.js +86 -54
- package/dist/modules/Schedule/index.d.ts +7 -1
- package/dist/modules/Schedule/index.js +155 -39
- package/dist/modules/Schedule/types.d.ts +2 -0
- package/dist/modules/bookingReadValidation.d.ts +6 -0
- package/dist/modules/bookingReadValidation.js +72 -0
- package/dist/plugins/request.d.ts +2 -0
- package/dist/server/index.d.ts +9 -0
- package/dist/server/index.js +1928 -1462
- package/dist/server/modules/form/index.d.ts +19 -0
- package/dist/server/modules/form/index.js +205 -0
- package/dist/server/modules/form/types.d.ts +13 -0
- package/dist/server/modules/form/types.js +3 -0
- package/dist/server/modules/index.d.ts +3 -0
- package/dist/server/modules/index.js +4 -0
- package/dist/server/modules/order/index.d.ts +21 -0
- package/dist/server/modules/order/index.js +1399 -831
- package/dist/server/modules/order/types.d.ts +3 -0
- package/dist/server/modules/order/utils/filterOrders.js +20 -0
- package/dist/server/modules/products/index.d.ts +28 -7
- package/dist/server/modules/products/index.js +1295 -769
- package/dist/server/modules/products/replication.d.ts +8 -0
- package/dist/server/modules/products/replication.js +69 -0
- package/dist/server/modules/products/types.d.ts +12 -1
- package/dist/server/modules/products/types.js +4 -0
- package/dist/shared/receipt/customerInvoiceLanguages.d.ts +1 -1
- package/dist/shared/receipt/customerInvoiceLanguages.js +5 -3
- package/dist/shared/receipt/small-ticket.d.ts +1 -0
- package/dist/shared/receipt/small-ticket.js +58 -26
- package/dist/shared/receipt/templateVisibility.d.ts +3 -0
- package/dist/shared/receipt/templateVisibility.js +6 -2
- package/dist/solution/BaseSales/fulfillmentItemRules.d.ts +27 -0
- package/dist/solution/BaseSales/fulfillmentItemRules.js +750 -0
- package/dist/solution/BaseSales/index.d.ts +22 -6
- package/dist/solution/BaseSales/index.js +1881 -1347
- package/dist/solution/BaseSales/pickupTiming.d.ts +4 -0
- package/dist/solution/BaseSales/pickupTiming.js +35 -8
- package/dist/solution/BaseSales/types.d.ts +4 -0
- package/dist/solution/BaseSales/types.js +1 -0
- package/dist/solution/BaseSales/utils/posDurationPricing.d.ts +21 -0
- package/dist/solution/BaseSales/utils/posDurationPricing.js +174 -0
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +2 -0
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +8 -8
- package/dist/solution/BookingByStep/index.d.ts +20 -4
- package/dist/solution/BookingByStep/index.js +681 -361
- package/dist/solution/BookingByStep/utils/resources.d.ts +10 -0
- package/dist/solution/BookingByStep/utils/resources.js +117 -76
- package/dist/solution/BookingTicket/index.d.ts +10 -0
- package/dist/solution/BookingTicket/index.js +686 -598
- package/dist/solution/BookingTicket/types.d.ts +1 -1
- package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +2 -1
- package/dist/solution/BookingTicket/utils/addProductDecision.js +35 -8
- package/dist/solution/BookingTicket/utils/redeemArrival.d.ts +8 -8
- package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
- package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.js +188 -0
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +58 -94
- package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +1 -3
- package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +33 -62
- package/dist/solution/OrderInvoicePreview/index.js +4 -3
- package/dist/solution/Sales/index.js +1 -1
- package/dist/solution/ScanOrder/index.d.ts +2 -0
- package/dist/solution/ScanOrder/index.js +230 -97
- package/dist/solution/ScanOrder/menuAvailability.d.ts +24 -0
- package/dist/solution/ScanOrder/menuAvailability.js +363 -0
- package/dist/solution/ScanOrder/types.d.ts +3 -0
- package/dist/solution/UnifiedBookingSales/index.d.ts +42 -10
- package/dist/solution/UnifiedBookingSales/index.js +2493 -1496
- package/dist/solution/UnifiedBookingSales/salesSettings.js +1 -1
- package/dist/solution/UnifiedBookingSales/types.d.ts +20 -5
- package/dist/utils/pos-receipt-auto-print.d.ts +4 -0
- package/dist/utils/pos-receipt-auto-print.js +14 -0
- package/lib/model/strategy/adapter/itemRule/adapter.d.ts +3 -1
- package/lib/model/strategy/adapter/itemRule/adapter.js +54 -4
- package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +3 -1
- package/lib/model/strategy/adapter/itemRule/evaluator.js +9 -0
- package/lib/model/strategy/adapter/itemRule/type.d.ts +40 -1
- package/lib/model/strategy/adapter/itemRule/type.js +10 -0
- package/lib/model/strategy/adapter/promotion/evaluator.d.ts +2 -1
- package/lib/model/strategy/adapter/promotion/evaluator.js +22 -21
- package/lib/modules/BookingContext/utils/calendarBooking.d.ts +15 -0
- package/lib/modules/BookingContext/utils/calendarBooking.js +156 -0
- package/lib/modules/BookingContext/utils/index.d.ts +1 -0
- package/lib/modules/BookingContext/utils/index.js +11 -0
- package/lib/modules/BookingContext/utils/productExtend.d.ts +21 -0
- package/lib/modules/BookingContext/utils/productExtend.js +104 -5
- package/lib/modules/BookingContext/utils/resources.js +1 -1
- package/lib/modules/Cart/index.js +4 -2
- package/lib/modules/Cart/types.d.ts +2 -0
- package/lib/modules/Cart/utils/cartProduct.d.ts +3 -1
- package/lib/modules/Cart/utils/cartProduct.js +39 -20
- package/lib/modules/Date/index.d.ts +1 -1
- package/lib/modules/Date/index.js +28 -5
- package/lib/modules/Date/types.d.ts +5 -0
- package/lib/modules/OpenData/salesSettings.js +1 -1
- package/lib/modules/OpenData/types.d.ts +9 -0
- package/lib/modules/OpenData/utils.d.ts +1 -1
- package/lib/modules/OpenData/utils.js +3 -2
- package/lib/modules/Order/index.d.ts +22 -7
- package/lib/modules/Order/index.js +457 -174
- package/lib/modules/Order/localEftposState.d.ts +13 -0
- package/lib/modules/Order/localEftposState.js +44 -0
- package/lib/modules/Order/types.d.ts +33 -11
- package/lib/modules/Order/types.js +2 -2
- package/lib/modules/Order/unpaidAmountGap.d.ts +6 -0
- package/lib/modules/Order/unpaidAmountGap.js +60 -0
- package/lib/modules/Order/utils.d.ts +4 -1
- package/lib/modules/Order/utils.js +29 -3
- package/lib/modules/Payment/walletpass.js +23 -1
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Product/types.d.ts +16 -0
- package/lib/modules/ProductList/index.js +1 -1
- package/lib/modules/ResourcePlanner/planner.d.ts +2 -0
- package/lib/modules/ResourcePlanner/planner.js +299 -9
- package/lib/modules/ResourcePlanner/types.d.ts +42 -0
- package/lib/modules/Rules/index.js +32 -3
- package/lib/modules/Schedule/index.d.ts +7 -1
- package/lib/modules/Schedule/index.js +68 -4
- package/lib/modules/Schedule/types.d.ts +2 -0
- package/lib/modules/bookingReadValidation.d.ts +6 -0
- package/lib/modules/bookingReadValidation.js +56 -0
- package/lib/plugins/request.d.ts +2 -0
- package/lib/server/index.d.ts +9 -0
- package/lib/server/index.js +279 -30
- package/lib/server/modules/form/index.d.ts +19 -0
- package/lib/server/modules/form/index.js +73 -0
- package/lib/server/modules/form/types.d.ts +13 -0
- package/lib/server/modules/form/types.js +9 -0
- package/lib/server/modules/index.d.ts +3 -0
- package/lib/server/modules/index.js +15 -1
- package/lib/server/modules/order/index.d.ts +21 -0
- package/lib/server/modules/order/index.js +344 -35
- package/lib/server/modules/order/types.d.ts +3 -0
- package/lib/server/modules/order/utils/filterOrders.js +18 -0
- package/lib/server/modules/products/index.d.ts +28 -7
- package/lib/server/modules/products/index.js +224 -62
- package/lib/server/modules/products/replication.d.ts +8 -0
- package/lib/server/modules/products/replication.js +30 -0
- package/lib/server/modules/products/types.d.ts +12 -1
- package/lib/server/modules/products/types.js +3 -0
- package/lib/shared/receipt/customerInvoiceLanguages.d.ts +1 -1
- package/lib/shared/receipt/customerInvoiceLanguages.js +5 -3
- package/lib/shared/receipt/small-ticket.d.ts +1 -0
- package/lib/shared/receipt/small-ticket.js +53 -25
- package/lib/shared/receipt/templateVisibility.d.ts +3 -0
- package/lib/shared/receipt/templateVisibility.js +6 -2
- package/lib/solution/BaseSales/fulfillmentItemRules.d.ts +27 -0
- package/lib/solution/BaseSales/fulfillmentItemRules.js +259 -0
- package/lib/solution/BaseSales/index.d.ts +22 -6
- package/lib/solution/BaseSales/index.js +347 -59
- package/lib/solution/BaseSales/pickupTiming.d.ts +4 -0
- package/lib/solution/BaseSales/pickupTiming.js +24 -3
- package/lib/solution/BaseSales/types.d.ts +4 -0
- package/lib/solution/BaseSales/types.js +1 -0
- package/lib/solution/BaseSales/utils/posDurationPricing.d.ts +21 -0
- package/lib/solution/BaseSales/utils/posDurationPricing.js +133 -0
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +2 -0
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +1 -1
- package/lib/solution/BookingByStep/index.d.ts +20 -4
- package/lib/solution/BookingByStep/index.js +229 -17
- package/lib/solution/BookingByStep/utils/resources.d.ts +10 -0
- package/lib/solution/BookingByStep/utils/resources.js +25 -15
- package/lib/solution/BookingTicket/index.d.ts +10 -0
- package/lib/solution/BookingTicket/index.js +57 -6
- package/lib/solution/BookingTicket/types.d.ts +1 -1
- package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +2 -1
- package/lib/solution/BookingTicket/utils/addProductDecision.js +34 -4
- package/lib/solution/BookingTicket/utils/redeemArrival.d.ts +8 -8
- package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
- package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.js +136 -0
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +2 -14
- package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +1 -3
- package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +17 -34
- package/lib/solution/OrderInvoicePreview/index.js +1 -0
- package/lib/solution/Sales/index.js +1 -1
- package/lib/solution/ScanOrder/index.d.ts +2 -0
- package/lib/solution/ScanOrder/index.js +131 -22
- package/lib/solution/ScanOrder/menuAvailability.d.ts +24 -0
- package/lib/solution/ScanOrder/menuAvailability.js +203 -0
- package/lib/solution/ScanOrder/types.d.ts +3 -0
- package/lib/solution/UnifiedBookingSales/index.d.ts +42 -10
- package/lib/solution/UnifiedBookingSales/index.js +717 -144
- package/lib/solution/UnifiedBookingSales/salesSettings.js +1 -1
- package/lib/solution/UnifiedBookingSales/types.d.ts +20 -5
- package/lib/utils/pos-receipt-auto-print.d.ts +4 -0
- package/lib/utils/pos-receipt-auto-print.js +13 -0
- package/package.json +1 -1
|
@@ -11,6 +11,7 @@ Object.defineProperty(exports, "isFulfillmentTimingBooking", {
|
|
|
11
11
|
}
|
|
12
12
|
});
|
|
13
13
|
var _loadSalesOrderSnapshot = require("../../shared/sales/loadSalesOrderSnapshot");
|
|
14
|
+
var _localEftposState = require("./localEftposState");
|
|
14
15
|
var _BaseModule = require("../BaseModule");
|
|
15
16
|
var _types = require("./types");
|
|
16
17
|
var _utils = require("./utils");
|
|
@@ -139,6 +140,10 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
139
140
|
openCache = false;
|
|
140
141
|
sessionStoragePersistEnabled = false;
|
|
141
142
|
sessionStorageRestoreRecord = null;
|
|
143
|
+
orderSessionId = null;
|
|
144
|
+
orderSessionDestroyed = false;
|
|
145
|
+
orderSessionAliases = new Set();
|
|
146
|
+
orderReplacement = null;
|
|
142
147
|
/** 只允许当前订单最新的 prepare/config 请求回写客户资产态。 */
|
|
143
148
|
customerWalletPrepareConfigEpoch = 0;
|
|
144
149
|
/** Payment 可能早于 prepare/config 返回;先按实例 ID 暂存卡号等待 Snapshot。 */
|
|
@@ -156,39 +161,32 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
156
161
|
}
|
|
157
162
|
|
|
158
163
|
/** Use the exact Order normalizers/merge rules on a private draft, not a second projection. */
|
|
159
|
-
beginCartMutation(
|
|
164
|
+
beginCartMutation() {
|
|
160
165
|
const current = this.ensureTempOrder();
|
|
161
166
|
const guard = this.orderHooks?.onBeforeCartCommit;
|
|
162
|
-
if (!
|
|
163
|
-
current,
|
|
167
|
+
if (!guard && !current._extend?.productVoucherGroups?.length) return {
|
|
164
168
|
draft: current,
|
|
165
169
|
commit: undefined
|
|
166
170
|
};
|
|
167
171
|
const before = (0, _lodashEs.cloneDeep)(current);
|
|
168
172
|
const draft = (0, _lodashEs.cloneDeep)(current);
|
|
169
173
|
return {
|
|
170
|
-
current,
|
|
171
174
|
draft,
|
|
172
|
-
commit: async
|
|
175
|
+
commit: async options => {
|
|
176
|
+
if (options?.isCurrentOrder && !options.isCurrentOrder()) return current;
|
|
173
177
|
(0, _productVoucherGroups.validateProductVoucherGroups)(draft, this.getDiscountList(), before);
|
|
174
178
|
await guard?.({
|
|
175
179
|
currentItems: (0, _lodashEs.cloneDeep)(before.products),
|
|
176
180
|
proposedItems: (0, _lodashEs.cloneDeep)(draft.products)
|
|
177
181
|
});
|
|
182
|
+
if (options?.isCurrentOrder && !options.isCurrentOrder()) return current;
|
|
178
183
|
if (this.store.tempOrder !== current || guard !== this.orderHooks?.onBeforeCartCommit || !(0, _lodashEs.isEqual)(current, before)) {
|
|
179
184
|
throw Object.assign(new Error('The cart changed. Please try again.'), {
|
|
180
185
|
code: 'SALES_GUARD_REJECTED'
|
|
181
186
|
});
|
|
182
187
|
}
|
|
183
|
-
// Recheck
|
|
184
|
-
beforeCommit?.();
|
|
185
|
-
// Opt-in booking guards may inspect or reject the source snapshot here.
|
|
186
|
-
// Never publish over a mutation made by that last synchronous callback.
|
|
187
|
-
if (options?.forceDraft && (this.store.tempOrder !== current || !(0, _lodashEs.isEqual)(current, before))) {
|
|
188
|
-
throw Object.assign(new Error('The cart changed. Please try again.'), {
|
|
189
|
-
code: 'SALES_GUARD_REJECTED'
|
|
190
|
-
});
|
|
191
|
-
}
|
|
188
|
+
// Recheck synchronous order/availability guards after async inventory validation.
|
|
189
|
+
options?.beforeCommit?.();
|
|
192
190
|
Object.assign(current, draft);
|
|
193
191
|
return current;
|
|
194
192
|
}
|
|
@@ -431,6 +429,10 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
431
429
|
async initialize(core, options) {
|
|
432
430
|
this.core = core;
|
|
433
431
|
this.store = options.store;
|
|
432
|
+
this.orderReplacement = null;
|
|
433
|
+
this.orderSessionId = null;
|
|
434
|
+
this.orderSessionDestroyed = false;
|
|
435
|
+
this.orderSessionAliases.clear();
|
|
434
436
|
const otherParams = options.otherParams || {};
|
|
435
437
|
this.syncSessionStorageOptions(otherParams);
|
|
436
438
|
if (this.sessionStoragePersistEnabled) {
|
|
@@ -470,10 +472,14 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
470
472
|
this.orderHooks = this.moduleHooksOverride || otherParams.order?.hooks || otherParams.hooks?.order;
|
|
471
473
|
this.otherParams = otherParams;
|
|
472
474
|
this.registerDiscountModules(options);
|
|
475
|
+
this.publishOrderSession(this.store.tempOrder);
|
|
473
476
|
this.logInfo('OrderModule initialized successfully');
|
|
474
477
|
}
|
|
475
478
|
async destroy() {
|
|
476
479
|
this.sessionStorageRestoreRecord = null;
|
|
480
|
+
this.orderReplacement = null;
|
|
481
|
+
this.orderSessionDestroyed = true;
|
|
482
|
+
this.publishOrderSession(null);
|
|
477
483
|
const childModules = [this.store?.discount, this.store?.rules];
|
|
478
484
|
for (const childModule of childModules) {
|
|
479
485
|
if (!childModule || typeof childModule.destroy !== 'function') continue;
|
|
@@ -1076,22 +1082,12 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1076
1082
|
}
|
|
1077
1083
|
} else {
|
|
1078
1084
|
for (const addAction of result.giftActions.toAdd) {
|
|
1079
|
-
//
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
if (sameStrategy && !sameStrategy.booking_uid && !sameStrategy.metadata?.booking_uid) {
|
|
1083
|
-
sameStrategy.num = (Number(sameStrategy.num) || 0) + (addAction.giftCount || 1);
|
|
1084
|
-
continue;
|
|
1085
|
-
}
|
|
1086
|
-
}
|
|
1087
|
-
const giftBaseline = options?.isCurrentOrder ? (0, _lodashEs.cloneDeep)({
|
|
1085
|
+
// 唯一候选也可能有规格/套餐。每次补赠都交给 SDK 判断,不能复用旧赠品的选择。
|
|
1086
|
+
|
|
1087
|
+
const giftMutationBaseline = options?.isCurrentOrder ? (0, _lodashEs.cloneDeep)({
|
|
1088
1088
|
products: tempOrder.products,
|
|
1089
1089
|
bookings: tempOrder.bookings
|
|
1090
1090
|
}) : null;
|
|
1091
|
-
const isGiftResultCurrent = () => !options?.isCurrentOrder || options.isCurrentOrder() && (0, _lodashEs.isEqual)(giftBaseline, {
|
|
1092
|
-
products: tempOrder.products,
|
|
1093
|
-
bookings: tempOrder.bookings
|
|
1094
|
-
});
|
|
1095
1091
|
try {
|
|
1096
1092
|
const giftResult = await this.giftSelectResolver({
|
|
1097
1093
|
strategyId: addAction.strategyId,
|
|
@@ -1100,7 +1096,11 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1100
1096
|
giftOptions: addAction.giftOptions,
|
|
1101
1097
|
sourceProductIds: addAction.sourceProductIds
|
|
1102
1098
|
});
|
|
1103
|
-
if (!
|
|
1099
|
+
if (options?.isCurrentOrder && !options.isCurrentOrder()) return null;
|
|
1100
|
+
if (options?.isCurrentOrder && !(0, _lodashEs.isEqual)({
|
|
1101
|
+
products: tempOrder.products,
|
|
1102
|
+
bookings: tempOrder.bookings
|
|
1103
|
+
}, giftMutationBaseline)) return null;
|
|
1104
1104
|
const giftProducts = Array.isArray(giftResult) ? giftResult : giftResult?.products;
|
|
1105
1105
|
const giftBookings = Array.isArray(giftResult) ? [] : giftResult?.bookings || [];
|
|
1106
1106
|
if (Array.isArray(giftProducts) && giftProducts.length > 0) {
|
|
@@ -1121,7 +1121,11 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1121
1121
|
}
|
|
1122
1122
|
}
|
|
1123
1123
|
} catch (error) {
|
|
1124
|
-
if (!
|
|
1124
|
+
if (options?.isCurrentOrder && !options.isCurrentOrder()) return null;
|
|
1125
|
+
if (options?.isCurrentOrder && !(0, _lodashEs.isEqual)({
|
|
1126
|
+
products: tempOrder.products,
|
|
1127
|
+
bookings: tempOrder.bookings
|
|
1128
|
+
}, giftMutationBaseline)) return null;
|
|
1125
1129
|
// 用户取消 / 选择失败 → 视为放弃本次新增
|
|
1126
1130
|
console.warn('[OrderModule] giftSelectResolver rejected, skip add gift', addAction.strategyId, error);
|
|
1127
1131
|
}
|
|
@@ -1130,6 +1134,10 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1130
1134
|
}
|
|
1131
1135
|
if (options?.isCurrentOrder && !options.isCurrentOrder()) return null;
|
|
1132
1136
|
tempOrder.products = result.products;
|
|
1137
|
+
if (tempOrder.products.length === 0) {
|
|
1138
|
+
// 删除主商品后,促销重算可能继续移除最后的赠品。
|
|
1139
|
+
tempOrder.shop_discount = '0.00';
|
|
1140
|
+
}
|
|
1133
1141
|
this.lastUnfulfilledPromotions = result.unfulfilledPromotions;
|
|
1134
1142
|
this.lastGiftActions = result.giftActions;
|
|
1135
1143
|
const payload = {
|
|
@@ -1296,6 +1304,111 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1296
1304
|
|
|
1297
1305
|
// ─── TempOrder: 创建 & 获取 ───
|
|
1298
1306
|
|
|
1307
|
+
getOrderSessionAliases(order) {
|
|
1308
|
+
const aliases = new Set();
|
|
1309
|
+
if (!order) return aliases;
|
|
1310
|
+
for (const key of ['external_sale_number', 'order_id']) {
|
|
1311
|
+
const value = order[key];
|
|
1312
|
+
if (value !== null && value !== undefined && String(value).trim() !== '' && (key !== 'order_id' || String(value) !== '0')) {
|
|
1313
|
+
aliases.add(`${key}:${String(value).trim()}`);
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
return aliases;
|
|
1317
|
+
}
|
|
1318
|
+
publishOrderSession(order, fresh = false) {
|
|
1319
|
+
const previousSessionId = this.orderSessionId;
|
|
1320
|
+
if (!order) {
|
|
1321
|
+
this.orderSessionId = null;
|
|
1322
|
+
this.orderSessionAliases.clear();
|
|
1323
|
+
} else {
|
|
1324
|
+
if (fresh || !this.orderSessionId) {
|
|
1325
|
+
this.orderSessionId = (0, _utils.createUuidV4)();
|
|
1326
|
+
this.orderSessionAliases = new Set();
|
|
1327
|
+
}
|
|
1328
|
+
this.getOrderSessionAliases(order).forEach(alias => this.orderSessionAliases.add(alias));
|
|
1329
|
+
}
|
|
1330
|
+
if (previousSessionId === this.orderSessionId || !this.core?.effects) return;
|
|
1331
|
+
// The session is already published. A listener failure must not turn a successful
|
|
1332
|
+
// reset into a failed reset or roll the active order back.
|
|
1333
|
+
const reportError = error => this.logWarning('Order session listener failed', {
|
|
1334
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1335
|
+
});
|
|
1336
|
+
try {
|
|
1337
|
+
void Promise.resolve(this.effectsEmit('onOrderSessionChanged', {
|
|
1338
|
+
sessionId: this.orderSessionId,
|
|
1339
|
+
previousSessionId
|
|
1340
|
+
})).catch(reportError);
|
|
1341
|
+
} catch (error) {
|
|
1342
|
+
reportError(error);
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
getOrderSessionId() {
|
|
1346
|
+
if (this.orderSessionDestroyed) return null;
|
|
1347
|
+
if (this.orderReplacement) return this.orderReplacement.sessionId;
|
|
1348
|
+
// Existing in-memory orders can be adopted during initialization. Adding a
|
|
1349
|
+
// remote ID later only extends the aliases; it does not create a new order.
|
|
1350
|
+
this.publishOrderSession(this.store?.tempOrder || null);
|
|
1351
|
+
return this.orderSessionId;
|
|
1352
|
+
}
|
|
1353
|
+
isOrderSessionCurrent(sessionId) {
|
|
1354
|
+
return !this.orderReplacement && Boolean(sessionId) && this.getOrderSessionId() === sessionId;
|
|
1355
|
+
}
|
|
1356
|
+
beginOrderReplacement(preserveOrderSessionId) {
|
|
1357
|
+
if (this.orderReplacement) {
|
|
1358
|
+
throw Object.assign(new Error('An order replacement is already pending'), {
|
|
1359
|
+
code: 'ORDER_SESSION_TRANSITION_PENDING'
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1362
|
+
const sessionId = this.getOrderSessionId();
|
|
1363
|
+
if (preserveOrderSessionId && preserveOrderSessionId !== sessionId) {
|
|
1364
|
+
throw Object.assign(new Error('The order session has changed'), {
|
|
1365
|
+
code: 'ORDER_SESSION_CHANGED'
|
|
1366
|
+
});
|
|
1367
|
+
}
|
|
1368
|
+
const discount = this.store.discount;
|
|
1369
|
+
const replacement = {
|
|
1370
|
+
state: {
|
|
1371
|
+
...this.store
|
|
1372
|
+
},
|
|
1373
|
+
sessionId,
|
|
1374
|
+
aliases: new Set(this.orderSessionAliases),
|
|
1375
|
+
originalDiscounts: (0, _lodashEs.cloneDeep)(discount?.getOriginalDiscountList?.() || []),
|
|
1376
|
+
discounts: (0, _lodashEs.cloneDeep)(discount?.getDiscountList?.() || []),
|
|
1377
|
+
walletEpoch: this.customerWalletPrepareConfigEpoch,
|
|
1378
|
+
pointCardCandidates: new Map(this.pointCardSnapshotCodeCandidates),
|
|
1379
|
+
sessionStorageRestoreRecord: this.sessionStorageRestoreRecord
|
|
1380
|
+
};
|
|
1381
|
+
this.orderReplacement = replacement;
|
|
1382
|
+
return replacement;
|
|
1383
|
+
}
|
|
1384
|
+
assertOrderReplacementCurrent(replacement) {
|
|
1385
|
+
if (this.orderReplacement !== replacement) {
|
|
1386
|
+
throw Object.assign(new Error('The order changed while its replacement was pending'), {
|
|
1387
|
+
code: 'ORDER_SESSION_CHANGED'
|
|
1388
|
+
});
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
completeOrderReplacement(replacement, nextOrder, preserveOrderSessionId) {
|
|
1392
|
+
this.assertOrderReplacementCurrent(replacement);
|
|
1393
|
+
const aliases = this.getOrderSessionAliases(nextOrder);
|
|
1394
|
+
const sameOrder = Boolean(replacement.sessionId) && (preserveOrderSessionId === replacement.sessionId || [...aliases].some(alias => replacement.aliases.has(alias)));
|
|
1395
|
+
this.orderReplacement = null;
|
|
1396
|
+
this.publishOrderSession(nextOrder, !sameOrder);
|
|
1397
|
+
}
|
|
1398
|
+
async rollbackOrderReplacement(replacement) {
|
|
1399
|
+
// An explicit reset wins over the pending result, including its rollback.
|
|
1400
|
+
if (this.orderReplacement !== replacement) return;
|
|
1401
|
+
Object.assign(this.store, replacement.state);
|
|
1402
|
+
this.customerWalletPrepareConfigEpoch = replacement.walletEpoch;
|
|
1403
|
+
this.pointCardSnapshotCodeCandidates = replacement.pointCardCandidates;
|
|
1404
|
+
this.sessionStorageRestoreRecord = replacement.sessionStorageRestoreRecord;
|
|
1405
|
+
const discount = this.store.discount;
|
|
1406
|
+
const restore = await Promise.allSettled([discount?.setOriginalDiscountList(replacement.originalDiscounts), discount?.setDiscountList(replacement.discounts)]);
|
|
1407
|
+
if (restore.some(result => result.status === 'rejected')) {
|
|
1408
|
+
this.logWarning('Order replacement discount rollback listener failed');
|
|
1409
|
+
}
|
|
1410
|
+
if (this.orderReplacement === replacement) this.orderReplacement = null;
|
|
1411
|
+
}
|
|
1299
1412
|
createDefaultTempOrderInstance() {
|
|
1300
1413
|
return (0, _utils.createDefaultTempOrder)({
|
|
1301
1414
|
now: (0, _utils.formatDateTime)(new Date())
|
|
@@ -1487,7 +1600,37 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1487
1600
|
}, new _decimal.default(0));
|
|
1488
1601
|
}
|
|
1489
1602
|
getDepositAmount(tempOrder, summary) {
|
|
1490
|
-
|
|
1603
|
+
const summaryAmount = summary.deposit_amount;
|
|
1604
|
+
const amount = summaryAmount === '' ? tempOrder.deposit_amount : summaryAmount ?? tempOrder.deposit_amount;
|
|
1605
|
+
return _decimal.default.min(_decimal.default.max(new _decimal.default(amount || 0), 0), this.getOrderExpectedAmount(summary));
|
|
1606
|
+
}
|
|
1607
|
+
isDepositSelectionDisabled(tempOrder) {
|
|
1608
|
+
return tempOrder._extend?.depositSelectionDisabled === true || tempOrder.is_deposit === 0 && new _decimal.default(tempOrder.deposit_amount || 0).gt(0);
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1611
|
+
/** Cap only the active target; product rules, manual intent and saved snapshots stay raw. */
|
|
1612
|
+
applyEffectiveDepositSummary(tempOrder, summary) {
|
|
1613
|
+
const disabled = this.isDepositSelectionDisabled(tempOrder);
|
|
1614
|
+
if (disabled) {
|
|
1615
|
+
tempOrder._extend = {
|
|
1616
|
+
...(tempOrder._extend || {}),
|
|
1617
|
+
depositSelectionDisabled: true
|
|
1618
|
+
};
|
|
1619
|
+
}
|
|
1620
|
+
const depositAmount = this.getDepositAmount(tempOrder, summary).toFixed(2);
|
|
1621
|
+
const hasDepositAmount = new _decimal.default(depositAmount).gt(0);
|
|
1622
|
+
const nextSummary = {
|
|
1623
|
+
...summary,
|
|
1624
|
+
deposit_amount: depositAmount,
|
|
1625
|
+
deposit: hasDepositAmount ? {
|
|
1626
|
+
...(summary.deposit || {}),
|
|
1627
|
+
total: depositAmount,
|
|
1628
|
+
hasDeposit: true
|
|
1629
|
+
} : undefined
|
|
1630
|
+
};
|
|
1631
|
+
tempOrder.deposit_amount = depositAmount;
|
|
1632
|
+
tempOrder.is_deposit = hasDepositAmount && tempOrder.is_deposit === 1 && !disabled ? 1 : 0;
|
|
1633
|
+
return nextSummary;
|
|
1491
1634
|
}
|
|
1492
1635
|
normalizeDepositAmount(amount) {
|
|
1493
1636
|
return _decimal.default.max(new _decimal.default(Number(amount) || 0), 0).toDecimalPlaces(2).toFixed(2);
|
|
@@ -1501,8 +1644,19 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1501
1644
|
if (!source || typeof source !== 'object') return null;
|
|
1502
1645
|
const record = source;
|
|
1503
1646
|
const rawDepositAmount = record.deposit_amount ?? record.summary?.deposit_amount;
|
|
1647
|
+
if (rawDepositAmount === undefined || rawDepositAmount === null || rawDepositAmount === '') return null;
|
|
1504
1648
|
const depositAmount = this.normalizeDepositAmount(rawDepositAmount ?? 0);
|
|
1505
|
-
if (!new _decimal.default(depositAmount).gt(0))
|
|
1649
|
+
if (!new _decimal.default(depositAmount).gt(0)) {
|
|
1650
|
+
// A saved zero is meaningful for an existing deposit product, but must not
|
|
1651
|
+
// freeze ordinary historical retail orders when a deposit product is added.
|
|
1652
|
+
const products = Array.isArray(record.products) ? record.products : [];
|
|
1653
|
+
const hasDepositContext = this.normalizeDepositFlag(record.is_deposit) === 1 || products.some(product => Number(product?.deposit?.total) > 0) || (0, _utils.calculateOrderProductsDeposit)(products.map(product => ({
|
|
1654
|
+
...product
|
|
1655
|
+
})), {
|
|
1656
|
+
productsByUid: record._extend?.productsByUid
|
|
1657
|
+
}).hasDeposit;
|
|
1658
|
+
if (!hasDepositContext) return null;
|
|
1659
|
+
}
|
|
1506
1660
|
return {
|
|
1507
1661
|
// 兼容历史数据:旧快照缺少 is_deposit 时,沿用正定金金额的推导规则。
|
|
1508
1662
|
isDeposit: this.normalizeDepositFlag(record.is_deposit) ?? 1,
|
|
@@ -1566,7 +1720,9 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1566
1720
|
return tempOrder.is_deposit === 1 && depositAmount.gt(0);
|
|
1567
1721
|
}
|
|
1568
1722
|
getOrderExpectedAmount(summary) {
|
|
1569
|
-
|
|
1723
|
+
const expected = summary.expect_amount;
|
|
1724
|
+
const amount = expected === '' ? summary.total_amount : expected ?? summary.total_amount;
|
|
1725
|
+
return _decimal.default.max(new _decimal.default(amount || 0), 0);
|
|
1570
1726
|
}
|
|
1571
1727
|
isDepositCovered(params) {
|
|
1572
1728
|
const depositAmount = this.getDepositAmount(params.tempOrder, params.summary);
|
|
@@ -1615,7 +1771,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1615
1771
|
});
|
|
1616
1772
|
}
|
|
1617
1773
|
resolveNextOrderPaymentType(tempOrder) {
|
|
1618
|
-
const depositAmount =
|
|
1774
|
+
const depositAmount = this.getDepositAmount(tempOrder, this.store.summary || (0, _utils.createEmptySummary)());
|
|
1619
1775
|
if (!this.isDepositOrder(tempOrder, depositAmount)) return 'normal';
|
|
1620
1776
|
if (depositAmount.lte(0)) return 'normal';
|
|
1621
1777
|
if (this.hasPaidNormalPayment(tempOrder.payments || [])) return 'normal';
|
|
@@ -2116,6 +2272,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2116
2272
|
tempOrder.is_deposit = historicalDepositSnapshot.isDeposit;
|
|
2117
2273
|
}
|
|
2118
2274
|
}
|
|
2275
|
+
summary = this.applyEffectiveDepositSummary(tempOrder, summary);
|
|
2119
2276
|
const isPayableAmountUnchanged = this.isSnapshotPayableAmountUnchanged(tempOrder, snapshot, summary);
|
|
2120
2277
|
if (!isPayableAmountUnchanged) return null;
|
|
2121
2278
|
const currentPaidPaymentSummary = this.calculatePaidPaymentSummary(tempOrder.payments || []);
|
|
@@ -2131,8 +2288,6 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2131
2288
|
tempOrder.surcharges = (0, _lodashEs.cloneDeep)(snapshot.surcharges);
|
|
2132
2289
|
}
|
|
2133
2290
|
tempOrder.surcharge_fee = summary.surcharge_fee || tempOrder.surcharge_fee;
|
|
2134
|
-
tempOrder.deposit_amount = this.normalizeDepositAmount(summary.deposit_amount || 0);
|
|
2135
|
-
tempOrder.is_deposit = shouldUseManualDepositOverride ? new _decimal.default(tempOrder.deposit_amount).gt(0) ? 1 : 0 : historicalDepositSnapshot?.isDeposit ?? (new _decimal.default(tempOrder.deposit_amount).gt(0) ? 1 : 0);
|
|
2136
2291
|
const previousSummary = this.store.summary;
|
|
2137
2292
|
this.store.summary = summary;
|
|
2138
2293
|
this.updateTempOrderPaymentStatus(tempOrder, {
|
|
@@ -2175,16 +2330,19 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2175
2330
|
ensureTempOrder() {
|
|
2176
2331
|
if (this.store.tempOrder) {
|
|
2177
2332
|
this.ensureExternalSaleNumber(this.store.tempOrder);
|
|
2333
|
+
if (!this.orderReplacement) this.publishOrderSession(this.store.tempOrder);
|
|
2178
2334
|
return this.store.tempOrder;
|
|
2179
2335
|
}
|
|
2180
2336
|
const newOrder = this.createDefaultTempOrderInstance();
|
|
2181
2337
|
this.ensureExternalSaleNumber(newOrder);
|
|
2182
2338
|
this.store.tempOrder = newOrder;
|
|
2339
|
+
this.publishOrderSession(newOrder, true);
|
|
2183
2340
|
this.persistTempOrder();
|
|
2184
2341
|
return newOrder;
|
|
2185
2342
|
}
|
|
2186
2343
|
restoreOrder() {
|
|
2187
2344
|
this.logInfo('restoreOrder start', {});
|
|
2345
|
+
this.orderReplacement = null;
|
|
2188
2346
|
this.sessionStorageRestoreRecord = null;
|
|
2189
2347
|
const freshTempOrder = this.createDefaultTempOrderInstance();
|
|
2190
2348
|
this.ensureExternalSaleNumber(freshTempOrder);
|
|
@@ -2195,36 +2353,45 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2195
2353
|
this.store.syncState = undefined;
|
|
2196
2354
|
void this.store.discount?.setOriginalDiscountList([]);
|
|
2197
2355
|
void this.store.discount?.setDiscountList([]);
|
|
2356
|
+
this.publishOrderSession(freshTempOrder, true);
|
|
2198
2357
|
this.persistTempOrder();
|
|
2199
2358
|
return freshTempOrder;
|
|
2200
2359
|
}
|
|
2201
2360
|
getTempOrder() {
|
|
2202
|
-
return this.store.tempOrder;
|
|
2361
|
+
return this.orderReplacement ? this.orderReplacement.state.tempOrder : this.store.tempOrder;
|
|
2203
2362
|
}
|
|
2204
2363
|
async replaceTempOrder(tempOrder, options) {
|
|
2205
2364
|
if (!(0, _utils.isTempOrder)(tempOrder)) {
|
|
2206
2365
|
throw new Error('无效的 tempOrder 数据');
|
|
2207
2366
|
}
|
|
2208
|
-
this.sessionStorageRestoreRecord = null;
|
|
2209
2367
|
const nextTempOrder = this.normalizeTempOrderForRuntime((0, _lodashEs.cloneDeep)(tempOrder), {
|
|
2210
2368
|
ensureIdentity: false
|
|
2211
2369
|
});
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2370
|
+
const replacement = this.beginOrderReplacement(options?.preserveOrderSessionId);
|
|
2371
|
+
try {
|
|
2372
|
+
this.sessionStorageRestoreRecord = null;
|
|
2373
|
+
this.store.tempOrder = nextTempOrder;
|
|
2374
|
+
this.clearCustomerWalletRuntimeState();
|
|
2375
|
+
if (options?.recalculateSummary !== false) {
|
|
2376
|
+
await this.recalculateSummary({
|
|
2377
|
+
createIfMissing: false,
|
|
2378
|
+
isCurrentOrder: () => this.orderReplacement === replacement
|
|
2379
|
+
});
|
|
2380
|
+
} else {
|
|
2381
|
+
this.store.summary = (0, _utils.createEmptySummary)();
|
|
2382
|
+
}
|
|
2383
|
+
this.assertOrderReplacementCurrent(replacement);
|
|
2384
|
+
if (options?.saveDraft) {
|
|
2385
|
+
await this.saveDraft();
|
|
2386
|
+
this.assertOrderReplacementCurrent(replacement);
|
|
2387
|
+
}
|
|
2388
|
+
if (options?.persist !== false) this.persistTempOrder();
|
|
2389
|
+
this.completeOrderReplacement(replacement, nextTempOrder, options?.preserveOrderSessionId);
|
|
2390
|
+
return nextTempOrder;
|
|
2391
|
+
} catch (error) {
|
|
2392
|
+
await this.rollbackOrderReplacement(replacement);
|
|
2393
|
+
throw error;
|
|
2226
2394
|
}
|
|
2227
|
-
return nextTempOrder;
|
|
2228
2395
|
}
|
|
2229
2396
|
getOrderIdentity() {
|
|
2230
2397
|
const tempOrder = this.store.tempOrder;
|
|
@@ -2253,7 +2420,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2253
2420
|
const tempOrder = this.store.tempOrder;
|
|
2254
2421
|
if (!tempOrder) return null;
|
|
2255
2422
|
const summary = this.store.summary || (0, _utils.createEmptySummary)();
|
|
2256
|
-
const depositAmount = tempOrder
|
|
2423
|
+
const depositAmount = this.getDepositAmount(tempOrder, summary);
|
|
2257
2424
|
const paidPaymentSummary = this.calculatePaidPaymentSummary(tempOrder.payments || []);
|
|
2258
2425
|
const amountGap = this.calculateSummaryAmountGap({
|
|
2259
2426
|
tempOrder,
|
|
@@ -2261,10 +2428,10 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2261
2428
|
orderPaidAmount: paidPaymentSummary.gapPaidAmount
|
|
2262
2429
|
});
|
|
2263
2430
|
return {
|
|
2264
|
-
isDeposit: tempOrder
|
|
2265
|
-
depositAmount,
|
|
2266
|
-
expectAmount: summary.expect_amount
|
|
2267
|
-
totalAmount: summary.total_amount
|
|
2431
|
+
isDeposit: this.isDepositOrder(tempOrder, depositAmount),
|
|
2432
|
+
depositAmount: depositAmount.toFixed(2),
|
|
2433
|
+
expectAmount: String(summary.expect_amount ?? '0.00'),
|
|
2434
|
+
totalAmount: String(summary.total_amount ?? '0.00'),
|
|
2268
2435
|
amountGap,
|
|
2269
2436
|
summary
|
|
2270
2437
|
};
|
|
@@ -2582,6 +2749,13 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2582
2749
|
return this.core.getModule(this.salesSummaryModuleName);
|
|
2583
2750
|
}
|
|
2584
2751
|
applyOrderProductsDepositSummary(tempOrder, summary) {
|
|
2752
|
+
const isExistingDepositDisabled = this.isDepositSelectionDisabled(tempOrder);
|
|
2753
|
+
if (isExistingDepositDisabled) {
|
|
2754
|
+
tempOrder._extend = {
|
|
2755
|
+
...(tempOrder._extend || {}),
|
|
2756
|
+
depositSelectionDisabled: true
|
|
2757
|
+
};
|
|
2758
|
+
}
|
|
2585
2759
|
const depositSummary = (0, _utils.calculateOrderProductsDeposit)(tempOrder.products || [], {
|
|
2586
2760
|
productsByUid: tempOrder._extend?.productsByUid
|
|
2587
2761
|
});
|
|
@@ -2603,10 +2777,9 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2603
2777
|
hasDeposit: true
|
|
2604
2778
|
} : undefined
|
|
2605
2779
|
};
|
|
2606
|
-
const isExistingDepositDisabled = tempOrder.is_deposit === 0 && new _decimal.default(tempOrder.deposit_amount || 0).gt(0);
|
|
2607
2780
|
tempOrder.deposit_amount = depositAmount;
|
|
2608
2781
|
tempOrder.is_deposit = hasDepositAmount && !isExistingDepositDisabled ? 1 : 0;
|
|
2609
|
-
return shouldUseManualDepositOverride ? nextSummary : this.applyLastOrderDepositSnapshot(tempOrder, nextSummary);
|
|
2782
|
+
return this.applyEffectiveDepositSummary(tempOrder, shouldUseManualDepositOverride ? nextSummary : this.applyLastOrderDepositSnapshot(tempOrder, nextSummary));
|
|
2610
2783
|
}
|
|
2611
2784
|
async recalculateSummary(options) {
|
|
2612
2785
|
if (options?.isCurrentOrder && !options.isCurrentOrder()) return null;
|
|
@@ -2657,7 +2830,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2657
2830
|
});
|
|
2658
2831
|
return this.store.summary;
|
|
2659
2832
|
}
|
|
2660
|
-
const
|
|
2833
|
+
const summaryMutationBaseline = options?.isCurrentOrder ? (0, _lodashEs.cloneDeep)({
|
|
2661
2834
|
tempOrder,
|
|
2662
2835
|
summary: this.store.summary
|
|
2663
2836
|
}) : null;
|
|
@@ -2670,10 +2843,11 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2670
2843
|
channel: this.otherParams.channel
|
|
2671
2844
|
} : {})
|
|
2672
2845
|
});
|
|
2673
|
-
if (options?.isCurrentOrder &&
|
|
2846
|
+
if (options?.isCurrentOrder && !options.isCurrentOrder()) return null;
|
|
2847
|
+
if (options?.isCurrentOrder && !(0, _lodashEs.isEqual)({
|
|
2674
2848
|
tempOrder,
|
|
2675
2849
|
summary: this.store.summary
|
|
2676
|
-
}))
|
|
2850
|
+
}, summaryMutationBaseline)) return null;
|
|
2677
2851
|
if (shouldFullRecalculateFromSnapshot || options?.isCurrentOrder) {
|
|
2678
2852
|
tempOrder.products = summaryProducts;
|
|
2679
2853
|
}
|
|
@@ -2940,11 +3114,15 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2940
3114
|
updateTempOrderDepositAmount(amount) {
|
|
2941
3115
|
const tempOrder = this.ensureTempOrder();
|
|
2942
3116
|
const depositAmount = this.normalizeDepositAmount(amount);
|
|
3117
|
+
tempOrder._extend = {
|
|
3118
|
+
...(tempOrder._extend || {}),
|
|
3119
|
+
depositSelectionDisabled: new _decimal.default(depositAmount).lte(0)
|
|
3120
|
+
};
|
|
2943
3121
|
const previousSummary = this.store.summary || (0, _utils.createEmptySummary)();
|
|
2944
|
-
const summaryWithDeposit = this.applyDepositAmountToSummary(tempOrder, {
|
|
3122
|
+
const summaryWithDeposit = this.applyEffectiveDepositSummary(tempOrder, this.applyDepositAmountToSummary(tempOrder, {
|
|
2945
3123
|
...(0, _utils.createEmptySummary)(),
|
|
2946
3124
|
...previousSummary
|
|
2947
|
-
}, depositAmount);
|
|
3125
|
+
}, depositAmount));
|
|
2948
3126
|
this.setManualDepositOverride(tempOrder, depositAmount);
|
|
2949
3127
|
const paidPaymentSummary = this.calculatePaidPaymentSummary(tempOrder.payments || []);
|
|
2950
3128
|
const summary = {
|
|
@@ -3297,6 +3475,18 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3297
3475
|
const matchMode = options.matchBy === 'compat' || options.matchBy === 'legacy' ? 'compat' : 'payment_number';
|
|
3298
3476
|
const matchedPayment = (0, _paymentUtils.resolveOrderPaymentIdentity)(tempOrder.payments || [], identity, matchMode);
|
|
3299
3477
|
if (!matchedPayment) {
|
|
3478
|
+
try {
|
|
3479
|
+
void Promise.resolve(this.logger?.addLog?.({
|
|
3480
|
+
type: 'warning',
|
|
3481
|
+
title: '[PaymentTrace] payment-missing',
|
|
3482
|
+
metadata: {
|
|
3483
|
+
moduleName: this.name,
|
|
3484
|
+
saleId: tempOrder.external_sale_number,
|
|
3485
|
+
paymentNumber: identity,
|
|
3486
|
+
currentPaymentNumbers: (tempOrder.payments || []).map(p => p.payment_number)
|
|
3487
|
+
}
|
|
3488
|
+
})).catch(() => {});
|
|
3489
|
+
} catch {/* 日志失败不影响原异常。 */}
|
|
3300
3490
|
throw new Error(`未找到支付项: ${identity}`);
|
|
3301
3491
|
}
|
|
3302
3492
|
let updatedPayment = null;
|
|
@@ -3604,27 +3794,30 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3604
3794
|
* await this.finalizeProductOrderMutation(tempOrder);
|
|
3605
3795
|
*/
|
|
3606
3796
|
async finalizeProductOrderMutation(tempOrder, options) {
|
|
3607
|
-
|
|
3797
|
+
const isCurrentOrder = options?.isCurrentOrder;
|
|
3798
|
+
if (isCurrentOrder && !isCurrentOrder()) return;
|
|
3608
3799
|
this.syncTempOrderHolderFromBookings(tempOrder);
|
|
3609
3800
|
this.prepareVirtualSettlementTempOrder(tempOrder);
|
|
3610
3801
|
const isVirtualSettlement = this.isActiveVirtualSettlementOrder(tempOrder);
|
|
3611
3802
|
if (!options?.skipEditDiscountConfigRefresh && !isVirtualSettlement) {
|
|
3612
3803
|
await this.ensureEditDiscountConfigForProductChange(tempOrder);
|
|
3613
3804
|
}
|
|
3614
|
-
if (
|
|
3615
|
-
const promotionPayload = !options?.skipDiscountRecalculation && !isVirtualSettlement ? await this.evaluatePromotion({
|
|
3616
|
-
isCurrentOrder
|
|
3617
|
-
}) : null;
|
|
3618
|
-
if (
|
|
3805
|
+
if (isCurrentOrder && !isCurrentOrder()) return;
|
|
3806
|
+
const promotionPayload = !options?.skipDiscountRecalculation && !isVirtualSettlement ? await this.evaluatePromotion(isCurrentOrder ? {
|
|
3807
|
+
isCurrentOrder
|
|
3808
|
+
} : undefined) : null;
|
|
3809
|
+
if (isCurrentOrder && !isCurrentOrder()) return;
|
|
3619
3810
|
if (!options?.skipDiscountRecalculation && !isVirtualSettlement) {
|
|
3620
3811
|
this.applyDiscount();
|
|
3621
3812
|
}
|
|
3622
3813
|
this.sanitizeTempOrderProducts(tempOrder);
|
|
3623
3814
|
const summary = await this.recalculateSummary({
|
|
3624
3815
|
createIfMissing: true,
|
|
3625
|
-
isCurrentOrder
|
|
3816
|
+
...(isCurrentOrder ? {
|
|
3817
|
+
isCurrentOrder
|
|
3818
|
+
} : {})
|
|
3626
3819
|
});
|
|
3627
|
-
if (
|
|
3820
|
+
if (isCurrentOrder && (!isCurrentOrder() || !summary)) return;
|
|
3628
3821
|
this.persistTempOrder();
|
|
3629
3822
|
this.emitPromotionApplied(promotionPayload);
|
|
3630
3823
|
}
|
|
@@ -3869,21 +4062,26 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3869
4062
|
return this.queueCartCommand(() => this.addProductToOrderDraft(product, booking, options), Boolean(options?.availabilityCommitGuard || options?.availabilityCommitTargetGuard));
|
|
3870
4063
|
}
|
|
3871
4064
|
async addProductToOrderDraft(product, booking, options) {
|
|
3872
|
-
const
|
|
3873
|
-
|
|
3874
|
-
const
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
const
|
|
3879
|
-
const
|
|
3880
|
-
const
|
|
3881
|
-
const
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
4065
|
+
const availabilityCommitGuard = options?.availabilityCommitGuard;
|
|
4066
|
+
availabilityCommitGuard?.();
|
|
4067
|
+
const liveTempOrder = this.ensureTempOrder();
|
|
4068
|
+
const beforeCommit = this.createCartIntentCommitGuard('add_product', liveTempOrder);
|
|
4069
|
+
const mutation = this.beginCartMutation();
|
|
4070
|
+
// 库存/商品券校验与自动预约共用草稿,全部门禁通过后才发布完整批次。
|
|
4071
|
+
const tempOrder = availabilityCommitGuard && !mutation.commit ? (0, _lodashEs.cloneDeep)(liveTempOrder) : mutation.draft;
|
|
4072
|
+
const beforeAppend = mutation.commit ? undefined : beforeCommit;
|
|
4073
|
+
const guardedMutationFields = ['products', 'bookings', 'notes', '_extend', 'metadata', 'currency_code', 'currency_symbol', 'currency_format', ...(!booking && Array.isArray(product._extend?.holder_relations) ? ['holder_relations'] : [])];
|
|
4074
|
+
const readGuardedMutationFields = order => Object.fromEntries(guardedMutationFields.map(key => [key, order[key]]));
|
|
4075
|
+
const guardedMutationBaseline = availabilityCommitGuard ? (0, _lodashEs.cloneDeep)(readGuardedMutationFields(liveTempOrder)) : null;
|
|
4076
|
+
const beforePublish = () => {
|
|
4077
|
+
availabilityCommitGuard?.();
|
|
4078
|
+
beforeCommit();
|
|
4079
|
+
// 调用方的结构 revision 可能不包括备注、价格或结算元数据。
|
|
4080
|
+
if (availabilityCommitGuard && !(0, _lodashEs.isEqual)(readGuardedMutationFields(liveTempOrder), guardedMutationBaseline)) {
|
|
4081
|
+
throw Object.assign(new Error('预约加购期间订单已变化,请重新选择'), {
|
|
4082
|
+
code: 'AVAILABILITY_SELECTION_STALE'
|
|
4083
|
+
});
|
|
4084
|
+
}
|
|
3887
4085
|
};
|
|
3888
4086
|
if (options?.productVoucherGroupKey) {
|
|
3889
4087
|
if (!tempOrder._extend?.productVoucherGroups?.some(group => group.key === options.productVoucherGroupKey)) throw (0, _productVoucherGroups.voucherGroupError)();
|
|
@@ -3936,7 +4134,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3936
4134
|
const uid = line.metadata?.unique_identification_number || line.unique_identification_number;
|
|
3937
4135
|
return uid !== undefined && uid !== null && String(uid) === String(insertAfterProductUid);
|
|
3938
4136
|
}) : -1;
|
|
3939
|
-
let insertAtIndex = anchorIndex >= 0 ? anchorIndex + 1 : undefined;
|
|
4137
|
+
let insertAtIndex = options?.insertAtStart ? 0 : anchorIndex >= 0 ? anchorIndex + 1 : undefined;
|
|
3940
4138
|
try {
|
|
3941
4139
|
if (booking) {
|
|
3942
4140
|
const productRecord = product;
|
|
@@ -3965,8 +4163,9 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3965
4163
|
const committedProduct = await this.appendProductLineToTempOrder(tempOrder, splitLine.product, splitLine.booking, {
|
|
3966
4164
|
insertAtIndex,
|
|
3967
4165
|
disableMerge: options?.disableMerge,
|
|
3968
|
-
beforeCommit
|
|
4166
|
+
beforeCommit: beforeAppend
|
|
3969
4167
|
});
|
|
4168
|
+
availabilityCommitGuard?.();
|
|
3970
4169
|
attachSalesNoteDrafts(committedProduct);
|
|
3971
4170
|
if (insertAtIndex !== undefined) insertAtIndex += 1;
|
|
3972
4171
|
}
|
|
@@ -3974,27 +4173,44 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3974
4173
|
const committedProduct = await this.appendProductLineToTempOrder(tempOrder, product, (0, _lodashEs.cloneDeep)(booking), {
|
|
3975
4174
|
insertAtIndex,
|
|
3976
4175
|
disableMerge: options?.disableMerge,
|
|
3977
|
-
beforeCommit
|
|
4176
|
+
beforeCommit: beforeAppend
|
|
3978
4177
|
});
|
|
4178
|
+
availabilityCommitGuard?.();
|
|
3979
4179
|
attachSalesNoteDrafts(committedProduct);
|
|
3980
4180
|
}
|
|
3981
4181
|
} else {
|
|
3982
4182
|
const committedProduct = await this.appendProductLineToTempOrder(tempOrder, product, undefined, {
|
|
3983
4183
|
insertAtIndex,
|
|
3984
4184
|
disableMerge: options?.disableMerge,
|
|
3985
|
-
beforeCommit
|
|
4185
|
+
beforeCommit: beforeAppend
|
|
3986
4186
|
});
|
|
4187
|
+
availabilityCommitGuard?.();
|
|
3987
4188
|
attachSalesNoteDrafts(committedProduct);
|
|
3988
4189
|
}
|
|
4190
|
+
if (mutation.commit) {
|
|
4191
|
+
await mutation.commit({
|
|
4192
|
+
beforeCommit: beforePublish
|
|
4193
|
+
});
|
|
4194
|
+
} else if (availabilityCommitGuard) {
|
|
4195
|
+
beforePublish();
|
|
4196
|
+
// 从最后一次门禁到真正新增之间不再 await。只发布本次新增会改写的
|
|
4197
|
+
// 字段;其余订单字段继续使用 live 对象,外部持有的订单引用也不变。
|
|
4198
|
+
Object.assign(liveTempOrder, readGuardedMutationFields(tempOrder));
|
|
4199
|
+
}
|
|
3989
4200
|
} catch (error) {
|
|
3990
4201
|
rollbackProductAndNotesMutation();
|
|
3991
4202
|
throw error;
|
|
3992
4203
|
}
|
|
3993
|
-
|
|
3994
|
-
|
|
4204
|
+
// 发布后预约已加购;后续促销/summary 沿用既有收尾,不用自身新增后的
|
|
4205
|
+
// revision 再执行提交 CAS,也不会把已加购预约因收尾耗时而撤回。
|
|
4206
|
+
if (availabilityCommitGuard) {
|
|
4207
|
+
const committedIdentity = [liveTempOrder.order_id, liveTempOrder.external_sale_number];
|
|
4208
|
+
const isCurrentOrder = () => this.store.tempOrder === liveTempOrder && liveTempOrder.order_id === committedIdentity[0] && liveTempOrder.external_sale_number === committedIdentity[1] && (options?.availabilityCommitTargetGuard?.() ?? true);
|
|
3995
4209
|
try {
|
|
4210
|
+
// 新增已发布,即使后续报价/促销收尾失败,也不能向调用方报告未加购。
|
|
4211
|
+
// 先保存已提交行;异步结果只允许写回仍属于本次提交的订单。
|
|
3996
4212
|
if (isCurrentOrder()) this.persistTempOrder();
|
|
3997
|
-
await this.finalizeProductOrderMutation(
|
|
4213
|
+
await this.finalizeProductOrderMutation(liveTempOrder, {
|
|
3998
4214
|
isCurrentOrder
|
|
3999
4215
|
});
|
|
4000
4216
|
} catch (error) {
|
|
@@ -4005,13 +4221,13 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4005
4221
|
});
|
|
4006
4222
|
}
|
|
4007
4223
|
} else {
|
|
4008
|
-
await this.finalizeProductOrderMutation(
|
|
4224
|
+
await this.finalizeProductOrderMutation(liveTempOrder);
|
|
4009
4225
|
}
|
|
4010
4226
|
this.logInfo('addProductToOrder success', {
|
|
4011
4227
|
product_id: product.product_id,
|
|
4012
4228
|
with_booking: !!booking
|
|
4013
4229
|
});
|
|
4014
|
-
return
|
|
4230
|
+
return liveTempOrder.products;
|
|
4015
4231
|
}
|
|
4016
4232
|
|
|
4017
4233
|
/**
|
|
@@ -4020,14 +4236,12 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4020
4236
|
* an old whole-order snapshot over concurrent edits or a newly selected order.
|
|
4021
4237
|
*/
|
|
4022
4238
|
async replaceBookingProductWithRelatedRetail(params) {
|
|
4023
|
-
return this.queueCartCommand(() => this.replaceBookingProductWithRelatedRetailDraft(params)
|
|
4239
|
+
return this.queueCartCommand(() => this.replaceBookingProductWithRelatedRetailDraft(params));
|
|
4024
4240
|
}
|
|
4025
4241
|
async replaceBookingProductWithRelatedRetailDraft(params) {
|
|
4026
4242
|
params.availabilityCommitGuard();
|
|
4027
|
-
const
|
|
4028
|
-
|
|
4029
|
-
});
|
|
4030
|
-
const live = mutation.current;
|
|
4243
|
+
const live = this.ensureTempOrder();
|
|
4244
|
+
const mutation = this.beginCartMutation();
|
|
4031
4245
|
const beforeCommit = this.createCartIntentCommitGuard('update_product', live);
|
|
4032
4246
|
const uid = String(params.productLineUid || '');
|
|
4033
4247
|
const getUid = line => String(line.metadata?.unique_identification_number || line.unique_identification_number || '');
|
|
@@ -4035,11 +4249,11 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4035
4249
|
const target = live.products[targetIndex];
|
|
4036
4250
|
const scopeKey = String(target?.metadata?.venue_booking_scope_key || '');
|
|
4037
4251
|
const targetBookingUid = String(target?.booking_uid || target?.metadata?.booking_uid || '');
|
|
4038
|
-
if (!uid || !target || !scopeKey || live.order_id ||
|
|
4252
|
+
if (!uid || !target || !scopeKey || live.order_id || target.order_detail_id != null || Number(target.num) !== 1 || Number(params.product.num ?? 1) !== 1 || target.metadata?.venue_booking_role !== 'party_main' || params.product.metadata?.venue_booking_role !== 'party_main' || params.product.metadata?.venue_booking_scope_key !== scopeKey || !Array.isArray(params.relatedRetailProducts) || (live.payments || []).length > 0 || !targetBookingUid || String(params.booking.metadata?.unique_identification_number || '') !== targetBookingUid || (live.bookings || []).filter(booking => this.getBookingUniqueIdentificationNumber(booking) === targetBookingUid).length !== 1 || live.products.filter(line => line.metadata?.venue_booking_role === 'party_main' && line.metadata?.venue_booking_scope_key === scopeKey).length !== 1) {
|
|
4039
4253
|
throw new Error('[Order] Party replacement requires one unsubmitted, unpaid main booking in the same scope');
|
|
4040
4254
|
}
|
|
4041
4255
|
const children = live.products.filter(line => line.metadata?.venue_booking_role === 'party_extra' && String(line.metadata?.venue_booking_parent_uid || '') === uid);
|
|
4042
|
-
if (children.some(line => !getUid(line) ||
|
|
4256
|
+
if (children.some(line => !getUid(line) || line.metadata?.venue_booking_scope_key !== scopeKey || line.order_detail_id != null || this.hasLinkedBookingUid(line))) {
|
|
4043
4257
|
throw new Error('[Order] Related retail line does not belong to this local Party scope');
|
|
4044
4258
|
}
|
|
4045
4259
|
const start = params.booking.start_at || `${params.booking.start_date || ''} ${params.booking.start_time || ''}`.trim();
|
|
@@ -4077,7 +4291,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4077
4291
|
const baseline = (0, _lodashEs.cloneDeep)(readFields(live, guardedFields));
|
|
4078
4292
|
const identity = [live.order_id, live.external_sale_number];
|
|
4079
4293
|
const isCurrentOrder = () => this.store.tempOrder === live && live.order_id === identity[0] && live.external_sale_number === identity[1] && (params.availabilityCommitTargetGuard?.() ?? true);
|
|
4080
|
-
const draft = mutation.draft;
|
|
4294
|
+
const draft = mutation.commit ? mutation.draft : (0, _lodashEs.cloneDeep)(live);
|
|
4081
4295
|
this.ensureSalesNotesLoadedForMutation(draft);
|
|
4082
4296
|
const removed = draft.products.filter(line => getUid(line) === uid || ownedUids.has(getUid(line)));
|
|
4083
4297
|
draft.products = draft.products.filter(line => getUid(line) !== uid && !ownedUids.has(getUid(line)));
|
|
@@ -4109,9 +4323,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4109
4323
|
}
|
|
4110
4324
|
this.removeSalesNotesForMissingProductLines(draft);
|
|
4111
4325
|
this.syncTempOrderHolderFromBookings(draft);
|
|
4112
|
-
|
|
4113
|
-
// the availability intent after that await, immediately before its publication.
|
|
4114
|
-
await mutation.commit?.(() => {
|
|
4326
|
+
const beforePublish = () => {
|
|
4115
4327
|
params.availabilityCommitGuard();
|
|
4116
4328
|
beforeCommit();
|
|
4117
4329
|
if (!isCurrentOrder() || !(0, _lodashEs.isEqual)(readFields(live, guardedFields), baseline)) {
|
|
@@ -4119,7 +4331,17 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4119
4331
|
code: 'AVAILABILITY_SELECTION_STALE'
|
|
4120
4332
|
});
|
|
4121
4333
|
}
|
|
4122
|
-
}
|
|
4334
|
+
};
|
|
4335
|
+
beforePublish();
|
|
4336
|
+
if (mutation.commit) {
|
|
4337
|
+
// Preserve beta's inventory and product-voucher checks before publishing.
|
|
4338
|
+
await mutation.commit({
|
|
4339
|
+
beforeCommit: beforePublish
|
|
4340
|
+
});
|
|
4341
|
+
} else {
|
|
4342
|
+
// No await between the final CAS and publication; preserve every unrelated live field.
|
|
4343
|
+
Object.assign(live, readFields(draft, publishedFields));
|
|
4344
|
+
}
|
|
4123
4345
|
try {
|
|
4124
4346
|
if (isCurrentOrder()) this.persistTempOrder();
|
|
4125
4347
|
await this.finalizeProductOrderMutation(live, {
|
|
@@ -4152,7 +4374,8 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4152
4374
|
const mutation = this.beginCartMutation();
|
|
4153
4375
|
let tempOrder = mutation.draft;
|
|
4154
4376
|
if (!Array.isArray(items) || items.length === 0) return tempOrder.products;
|
|
4155
|
-
const beforeCommit = this.createCartIntentCommitGuard('add_product'
|
|
4377
|
+
const beforeCommit = this.createCartIntentCommitGuard('add_product');
|
|
4378
|
+
const beforeAppend = mutation.commit ? undefined : beforeCommit;
|
|
4156
4379
|
for (const item of items || []) {
|
|
4157
4380
|
const {
|
|
4158
4381
|
product,
|
|
@@ -4166,7 +4389,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4166
4389
|
for (let i = 0; i < splitCount; i += 1) {
|
|
4167
4390
|
const splitLine = this.createSplitBookingLine(productRecord, booking, i, splitCount);
|
|
4168
4391
|
const appendResult = this.appendProductLineToTempOrder(tempOrder, splitLine.product, splitLine.booking, {
|
|
4169
|
-
beforeCommit
|
|
4392
|
+
beforeCommit: beforeAppend
|
|
4170
4393
|
});
|
|
4171
4394
|
if (appendResult) await appendResult;
|
|
4172
4395
|
}
|
|
@@ -4174,11 +4397,13 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4174
4397
|
}
|
|
4175
4398
|
}
|
|
4176
4399
|
const appendResult = this.appendProductLineToTempOrder(tempOrder, product, booking, {
|
|
4177
|
-
beforeCommit
|
|
4400
|
+
beforeCommit: beforeAppend
|
|
4178
4401
|
});
|
|
4179
4402
|
if (appendResult) await appendResult;
|
|
4180
4403
|
}
|
|
4181
|
-
if (mutation.commit) tempOrder = await mutation.commit(
|
|
4404
|
+
if (mutation.commit) tempOrder = await mutation.commit({
|
|
4405
|
+
beforeCommit
|
|
4406
|
+
});
|
|
4182
4407
|
await this.finalizeProductOrderMutation(tempOrder, options);
|
|
4183
4408
|
this.logInfo('addProductsToOrder success', {
|
|
4184
4409
|
itemsCount: items.length
|
|
@@ -4527,11 +4752,13 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4527
4752
|
async updateOrderProductDraft(params) {
|
|
4528
4753
|
const mutation = this.beginCartMutation();
|
|
4529
4754
|
let tempOrder = mutation.draft;
|
|
4530
|
-
const beforeCommit = this.isRestrictedCartProductUpdate(tempOrder, params) ? this.createCartIntentCommitGuard('update_product'
|
|
4531
|
-
beforeCommit?.();
|
|
4755
|
+
const beforeCommit = this.isRestrictedCartProductUpdate(tempOrder, params) ? this.createCartIntentCommitGuard('update_product') : undefined;
|
|
4756
|
+
if (!mutation.commit) beforeCommit?.();
|
|
4532
4757
|
const reapplyWeighedDiscountProductUids = [];
|
|
4533
4758
|
const updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params, reapplyWeighedDiscountProductUids);
|
|
4534
|
-
if (mutation.commit) tempOrder = await mutation.commit(
|
|
4759
|
+
if (mutation.commit) tempOrder = await mutation.commit({
|
|
4760
|
+
beforeCommit
|
|
4761
|
+
});
|
|
4535
4762
|
const promotionPayload = await this.evaluatePromotion();
|
|
4536
4763
|
this.applyDiscount({
|
|
4537
4764
|
reapplyWeighedDiscountProductUids,
|
|
@@ -4549,7 +4776,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4549
4776
|
return tempOrder.products;
|
|
4550
4777
|
}
|
|
4551
4778
|
async updateOrderProducts(paramsList, options) {
|
|
4552
|
-
return this.queueCartCommand(() => this.updateOrderProductsDraft(paramsList, options)
|
|
4779
|
+
return this.queueCartCommand(() => this.updateOrderProductsDraft(paramsList, options));
|
|
4553
4780
|
}
|
|
4554
4781
|
async updateOrderProductsDraft(paramsList, options) {
|
|
4555
4782
|
if (options) return this.updateOrderProductsGuarded(paramsList, options);
|
|
@@ -4558,8 +4785,8 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4558
4785
|
if (!paramsList.length) {
|
|
4559
4786
|
return tempOrder.products;
|
|
4560
4787
|
}
|
|
4561
|
-
const beforeCommit = paramsList.some(params => this.isRestrictedCartProductUpdate(tempOrder, params)) ? this.createCartIntentCommitGuard('update_product'
|
|
4562
|
-
beforeCommit?.();
|
|
4788
|
+
const beforeCommit = paramsList.some(params => this.isRestrictedCartProductUpdate(tempOrder, params)) ? this.createCartIntentCommitGuard('update_product') : undefined;
|
|
4789
|
+
if (!mutation.commit) beforeCommit?.();
|
|
4563
4790
|
const reapplyWeighedDiscountProductUids = [];
|
|
4564
4791
|
const reapplyBookingDiscountProductUids = paramsList.reduce((acc, params) => {
|
|
4565
4792
|
const updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params, reapplyWeighedDiscountProductUids);
|
|
@@ -4569,7 +4796,9 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4569
4796
|
}
|
|
4570
4797
|
return acc;
|
|
4571
4798
|
}, []);
|
|
4572
|
-
if (mutation.commit) tempOrder = await mutation.commit(
|
|
4799
|
+
if (mutation.commit) tempOrder = await mutation.commit({
|
|
4800
|
+
beforeCommit
|
|
4801
|
+
});
|
|
4573
4802
|
await this.finalizeAfterProductsMutation(tempOrder, {
|
|
4574
4803
|
reapplyWeighedDiscountProductUids,
|
|
4575
4804
|
reapplyBookingDiscountProductUids: reapplyBookingDiscountProductUids.length ? reapplyBookingDiscountProductUids : undefined
|
|
@@ -4585,11 +4814,9 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4585
4814
|
});
|
|
4586
4815
|
options.beforeApply?.();
|
|
4587
4816
|
if (options.isCurrentOrder && !options.isCurrentOrder()) throw stale();
|
|
4588
|
-
const
|
|
4589
|
-
forceDraft: true
|
|
4590
|
-
});
|
|
4591
|
-
const live = mutation.current;
|
|
4817
|
+
const live = this.ensureTempOrder();
|
|
4592
4818
|
if (!paramsList.length) return live.products;
|
|
4819
|
+
const mutation = this.beginCartMutation();
|
|
4593
4820
|
const identity = [live.order_id, live.external_sale_number];
|
|
4594
4821
|
const isCurrentOrder = () => this.store.tempOrder === live && live.order_id === identity[0] && live.external_sale_number === identity[1] && (options.isCurrentOrder?.() ?? true);
|
|
4595
4822
|
const beforeCommit = this.createCartIntentCommitGuard('update_product', live);
|
|
@@ -4597,7 +4824,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4597
4824
|
const guardedFields = [...publishedFields, 'customer_id', 'discount_list', 'shop_discount', 'payments'];
|
|
4598
4825
|
const readFields = (order, fields) => Object.fromEntries(fields.map(key => [key, order[key]]));
|
|
4599
4826
|
const baseline = (0, _lodashEs.cloneDeep)(readFields(live, guardedFields));
|
|
4600
|
-
const draft = mutation.draft;
|
|
4827
|
+
const draft = mutation.commit ? mutation.draft : (0, _lodashEs.cloneDeep)(live);
|
|
4601
4828
|
const seen = new Set();
|
|
4602
4829
|
const reapplyWeighedDiscountProductUids = [];
|
|
4603
4830
|
const reapplyBookingDiscountProductUids = [];
|
|
@@ -4611,11 +4838,19 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4611
4838
|
const updatedUid = this.applyOrderProductUpdateToTempOrder(draft, (0, _lodashEs.cloneDeep)(params), reapplyWeighedDiscountProductUids);
|
|
4612
4839
|
if (params.allow_booking_discount_reapply && updatedUid) reapplyBookingDiscountProductUids.push(updatedUid);
|
|
4613
4840
|
}
|
|
4614
|
-
|
|
4841
|
+
const beforePublish = () => {
|
|
4615
4842
|
options.beforeApply?.();
|
|
4616
4843
|
beforeCommit();
|
|
4617
4844
|
if (!isCurrentOrder() || !(0, _lodashEs.isEqual)(readFields(live, guardedFields), baseline)) throw stale();
|
|
4618
|
-
}
|
|
4845
|
+
};
|
|
4846
|
+
beforePublish();
|
|
4847
|
+
if (mutation.commit) {
|
|
4848
|
+
await mutation.commit({
|
|
4849
|
+
beforeCommit: beforePublish
|
|
4850
|
+
});
|
|
4851
|
+
} else {
|
|
4852
|
+
Object.assign(live, readFields(draft, publishedFields));
|
|
4853
|
+
}
|
|
4619
4854
|
try {
|
|
4620
4855
|
if (isCurrentOrder()) this.persistTempOrder();
|
|
4621
4856
|
await this.finalizeAfterProductsMutation(live, {
|
|
@@ -4631,10 +4866,12 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4631
4866
|
}
|
|
4632
4867
|
return live.products;
|
|
4633
4868
|
}
|
|
4634
|
-
async updateOrderProductQuantity(params) {
|
|
4635
|
-
return this.queueCartCommand(() => this.updateOrderProductQuantityDraft(params));
|
|
4869
|
+
async updateOrderProductQuantity(params, options) {
|
|
4870
|
+
return this.queueCartCommand(() => this.updateOrderProductQuantityDraft(params, options));
|
|
4636
4871
|
}
|
|
4637
|
-
async updateOrderProductQuantityDraft(params) {
|
|
4872
|
+
async updateOrderProductQuantityDraft(params, options) {
|
|
4873
|
+
const isCurrentOrder = options?.isCurrentOrder;
|
|
4874
|
+
if (isCurrentOrder && !isCurrentOrder()) return this.store.tempOrder?.products || [];
|
|
4638
4875
|
const {
|
|
4639
4876
|
product_id,
|
|
4640
4877
|
product_variant_id,
|
|
@@ -4701,22 +4938,35 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4701
4938
|
throw new _virtualSettlement.VirtualCurrencyBalanceError(balance.toFixed(2), requiredAmount.toFixed(2));
|
|
4702
4939
|
}
|
|
4703
4940
|
}
|
|
4704
|
-
const beforeCommit = normalizedProduct.num > targetProduct.num ? this.createCartIntentCommitGuard('increase_quantity'
|
|
4705
|
-
beforeCommit?.();
|
|
4941
|
+
const beforeCommit = normalizedProduct.num > targetProduct.num ? this.createCartIntentCommitGuard('increase_quantity') : undefined;
|
|
4942
|
+
if (!mutation.commit) beforeCommit?.();
|
|
4943
|
+
if (isCurrentOrder && !isCurrentOrder()) return tempOrder.products;
|
|
4706
4944
|
tempOrder.products[productIndex] = normalizedProduct;
|
|
4707
|
-
if (mutation.commit)
|
|
4708
|
-
|
|
4709
|
-
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4945
|
+
if (mutation.commit) {
|
|
4946
|
+
tempOrder = await mutation.commit({
|
|
4947
|
+
beforeCommit,
|
|
4948
|
+
isCurrentOrder
|
|
4949
|
+
});
|
|
4950
|
+
}
|
|
4951
|
+
if (isCurrentOrder) {
|
|
4952
|
+
await this.finalizeProductOrderMutation(tempOrder, {
|
|
4953
|
+
skipEditDiscountConfigRefresh: true,
|
|
4954
|
+
isCurrentOrder
|
|
4955
|
+
});
|
|
4956
|
+
} else {
|
|
4957
|
+
this.prepareVirtualSettlementTempOrder(tempOrder);
|
|
4958
|
+
const isVirtualSettlement = this.isActiveVirtualSettlementOrder(tempOrder);
|
|
4959
|
+
const promotionPayload = !isVirtualSettlement ? await this.evaluatePromotion() : null;
|
|
4960
|
+
if (!isVirtualSettlement) {
|
|
4961
|
+
this.applyDiscount();
|
|
4962
|
+
}
|
|
4963
|
+
this.sanitizeTempOrderProducts(tempOrder);
|
|
4964
|
+
await this.recalculateSummary({
|
|
4965
|
+
createIfMissing: true
|
|
4966
|
+
});
|
|
4967
|
+
this.persistTempOrder();
|
|
4968
|
+
this.emitPromotionApplied(promotionPayload);
|
|
4713
4969
|
}
|
|
4714
|
-
this.sanitizeTempOrderProducts(tempOrder);
|
|
4715
|
-
await this.recalculateSummary({
|
|
4716
|
-
createIfMissing: true
|
|
4717
|
-
});
|
|
4718
|
-
this.persistTempOrder();
|
|
4719
|
-
this.emitPromotionApplied(promotionPayload);
|
|
4720
4970
|
this.logInfo('updateOrderProductQuantity success', {
|
|
4721
4971
|
params
|
|
4722
4972
|
});
|
|
@@ -4796,29 +5046,14 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4796
5046
|
return this.queueCartCommand(() => this.removeProductsFromOrderDraft(identities, options), Boolean(options?.isCurrentOrder || options?.beforeApply));
|
|
4797
5047
|
}
|
|
4798
5048
|
async removeProductsFromOrderDraft(identities, options) {
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
|
|
4802
|
-
//
|
|
5049
|
+
const isCurrentOrder = options?.isCurrentOrder;
|
|
5050
|
+
if (isCurrentOrder && !isCurrentOrder()) return this.store.tempOrder?.products || [];
|
|
5051
|
+
// Keep the pre-removal snapshot guard separate from the ownership guard:
|
|
5052
|
+
// deleting these rows must not make the async finalization reject its own mutation.
|
|
4803
5053
|
if (identities.length) options?.beforeApply?.();
|
|
4804
|
-
if (
|
|
4805
|
-
|
|
4806
|
-
}
|
|
4807
|
-
const guarded = Boolean(options?.isCurrentOrder || options?.beforeApply);
|
|
4808
|
-
const mutation = this.beginCartMutation({
|
|
4809
|
-
forceDraft: guarded
|
|
4810
|
-
});
|
|
5054
|
+
if (isCurrentOrder && !isCurrentOrder()) return this.store.tempOrder?.products || [];
|
|
5055
|
+
const mutation = this.beginCartMutation();
|
|
4811
5056
|
let tempOrder = mutation.draft;
|
|
4812
|
-
const identity = [mutation.current.order_id, mutation.current.external_sale_number];
|
|
4813
|
-
const isCurrentOrder = () => this.store.tempOrder === mutation.current && mutation.current.order_id === identity[0] && mutation.current.external_sale_number === identity[1] && (options?.isCurrentOrder?.() ?? true);
|
|
4814
|
-
const beforeCommit = guarded ? () => {
|
|
4815
|
-
// Inventory validation can await. Recheck the live source snapshot before
|
|
4816
|
-
// publication; never run this row-snapshot guard during finalization.
|
|
4817
|
-
options?.beforeApply?.();
|
|
4818
|
-
if (!isCurrentOrder()) throw Object.assign(new Error('Order product removal interrupted by an order change'), {
|
|
4819
|
-
code: 'AVAILABILITY_SELECTION_STALE'
|
|
4820
|
-
});
|
|
4821
|
-
} : undefined;
|
|
4822
5057
|
if (!identities.length) {
|
|
4823
5058
|
return tempOrder.products;
|
|
4824
5059
|
}
|
|
@@ -4886,10 +5121,22 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4886
5121
|
}
|
|
4887
5122
|
(0, _holderRelations.removeProductHolderRelations)(tempOrder, productsBeforeRemove.filter(product => !tempOrder.products.includes(product)));
|
|
4888
5123
|
this.removeSalesNotesForMissingProductLines(tempOrder);
|
|
4889
|
-
if (
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
}
|
|
5124
|
+
if (tempOrder.products.length === 0) {
|
|
5125
|
+
// 整单折扣随购物车清空,避免重新加购时沿用上一批商品的优惠。
|
|
5126
|
+
tempOrder.shop_discount = '0.00';
|
|
5127
|
+
}
|
|
5128
|
+
if (mutation.commit) tempOrder = await mutation.commit({
|
|
5129
|
+
isCurrentOrder,
|
|
5130
|
+
beforeCommit: options?.beforeApply
|
|
5131
|
+
});
|
|
5132
|
+
if (isCurrentOrder) {
|
|
5133
|
+
await this.finalizeProductOrderMutation(tempOrder, {
|
|
5134
|
+
skipEditDiscountConfigRefresh: true,
|
|
5135
|
+
isCurrentOrder
|
|
5136
|
+
});
|
|
5137
|
+
} else {
|
|
5138
|
+
await this.finalizeAfterProductsMutation(tempOrder);
|
|
5139
|
+
}
|
|
4893
5140
|
this.logInfo('removeProductsFromOrder success', {
|
|
4894
5141
|
identities
|
|
4895
5142
|
});
|
|
@@ -4900,7 +5147,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4900
5147
|
}
|
|
4901
5148
|
|
|
4902
5149
|
/**
|
|
4903
|
-
*
|
|
5150
|
+
* 清空购物车行(products / bookings)及整单折扣,不重置整单。
|
|
4904
5151
|
* 普通整单 note 保持不变;以商品行为主体的 Sales Notes 同步删除。
|
|
4905
5152
|
*/
|
|
4906
5153
|
async clearOrderCartLines() {
|
|
@@ -4913,6 +5160,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4913
5160
|
(0, _holderRelations.removeProductHolderRelations)(tempOrder, tempOrder.products);
|
|
4914
5161
|
tempOrder.products = [];
|
|
4915
5162
|
tempOrder.bookings = [];
|
|
5163
|
+
tempOrder.shop_discount = '0.00';
|
|
4916
5164
|
(0, _virtualSettlement.releaseTempOrderSettlementState)(tempOrder);
|
|
4917
5165
|
this.removeSalesNotesForMissingProductLines(tempOrder);
|
|
4918
5166
|
this.syncTempOrderHolderFromBookings(tempOrder);
|
|
@@ -5060,6 +5308,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
5060
5308
|
}
|
|
5061
5309
|
async runSubmitTempOrder(params) {
|
|
5062
5310
|
const tempOrder = this.ensureTempOrder();
|
|
5311
|
+
if ((0, _localEftposState.requiresLocalPaymentRefresh)(tempOrder)) throw new Error(_localEftposState.PAYMENT_REFRESH_MESSAGE);
|
|
5063
5312
|
(0, _productVoucherGroups.validateProductVoucherGroups)(tempOrder, this.getDiscountList(), undefined, true);
|
|
5064
5313
|
this.prepareVirtualSettlementTempOrder(tempOrder);
|
|
5065
5314
|
const isOnlineStorePlatform = this.isOnlineStorePlatform();
|
|
@@ -5535,7 +5784,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
5535
5784
|
query
|
|
5536
5785
|
} = params;
|
|
5537
5786
|
const fetchUrl = url || '/order/sales/checkout';
|
|
5538
|
-
const requestQuery = this.isSalesCheckoutHandledByOsServer(fetchUrl) ? query : (0, _osPrivatePayload.stripOsPrivatePayloadFields)(query);
|
|
5787
|
+
const requestQuery = this.isSalesCheckoutHandledByOsServer(fetchUrl) ? query : (0, _localEftposState.stripLocalEftposState)((0, _osPrivatePayload.stripOsPrivatePayloadFields)(query));
|
|
5539
5788
|
return this.request.post(fetchUrl, requestQuery, {
|
|
5540
5789
|
osServer: true,
|
|
5541
5790
|
customToast: () => {}
|
|
@@ -5598,6 +5847,19 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
5598
5847
|
* 例如数组字段、商品行唯一值、价格 metadata、summary 派生状态和 _extend。
|
|
5599
5848
|
*/
|
|
5600
5849
|
async hydrateTempOrderFromRecord(record, options) {
|
|
5850
|
+
const replacement = this.beginOrderReplacement(options?.preserveOrderSessionId);
|
|
5851
|
+
try {
|
|
5852
|
+
const nextTempOrder = await this.prepareHydratedTempOrder(record, options, replacement);
|
|
5853
|
+
this.assertOrderReplacementCurrent(replacement);
|
|
5854
|
+
this.persistTempOrder();
|
|
5855
|
+
this.completeOrderReplacement(replacement, nextTempOrder, options?.preserveOrderSessionId);
|
|
5856
|
+
return nextTempOrder;
|
|
5857
|
+
} catch (error) {
|
|
5858
|
+
await this.rollbackOrderReplacement(replacement);
|
|
5859
|
+
throw error;
|
|
5860
|
+
}
|
|
5861
|
+
}
|
|
5862
|
+
async prepareHydratedTempOrder(record, options, replacement) {
|
|
5601
5863
|
const sourceRaw = record && typeof record === 'object' && record.data && record.order_id == null ? record.data : record || {};
|
|
5602
5864
|
const duplicateProductIdentityRepair = (0, _orderCollectionIdentity.repairDuplicateProductLineIdentities)(Array.isArray(sourceRaw.products) ? sourceRaw.products : [], sourceRaw._extend?.productsByUid);
|
|
5603
5865
|
const duplicateIdentityReadySource = duplicateProductIdentityRepair.repairs.length ? {
|
|
@@ -5653,13 +5915,15 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
5653
5915
|
this.store.summary = (0, _utils.createEmptySummary)();
|
|
5654
5916
|
this.store.lastOrderInfo = undefined;
|
|
5655
5917
|
await this.store.discount?.setOriginalDiscountList((0, _lodashEs.cloneDeep)(restoredSessionDiscounts));
|
|
5918
|
+
this.assertOrderReplacementCurrent(replacement);
|
|
5656
5919
|
await this.store.discount?.setDiscountList((0, _lodashEs.cloneDeep)(restoredSessionDiscounts));
|
|
5920
|
+
this.assertOrderReplacementCurrent(replacement);
|
|
5657
5921
|
if (options?.recalcOnHydrate) {
|
|
5658
5922
|
await this.recalculateSummary({
|
|
5659
|
-
createIfMissing: false
|
|
5923
|
+
createIfMissing: false,
|
|
5924
|
+
isCurrentOrder: () => this.orderReplacement === replacement
|
|
5660
5925
|
});
|
|
5661
5926
|
}
|
|
5662
|
-
this.persistTempOrder();
|
|
5663
5927
|
return nextTempOrder;
|
|
5664
5928
|
}
|
|
5665
5929
|
|
|
@@ -5672,6 +5936,9 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
5672
5936
|
};
|
|
5673
5937
|
const rawSummary = raw.summary && typeof raw.summary === 'object' ? raw.summary : {};
|
|
5674
5938
|
const historicalDepositSnapshot = this.getHistoricalDepositSnapshot(sourceLastOrderInfo);
|
|
5939
|
+
if (historicalDepositSnapshot && this.normalizeDepositFlag(raw.is_deposit) === null) {
|
|
5940
|
+
nextTempOrder.is_deposit = historicalDepositSnapshot.isDeposit;
|
|
5941
|
+
}
|
|
5675
5942
|
const summarySurcharges = Array.isArray(rawSummary.surcharges) ? rawSummary.surcharges.map(s => ({
|
|
5676
5943
|
...(s || {})
|
|
5677
5944
|
})) : (0, _lodashEs.cloneDeep)(nextTempOrder.surcharges || []);
|
|
@@ -5716,14 +5983,30 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
5716
5983
|
if (!shouldSkipEmptyDiscountSync) {
|
|
5717
5984
|
OrderModule.populateSavedAmounts(nextTempOrder.products, nextDiscounts);
|
|
5718
5985
|
await this.store.discount?.setOriginalDiscountList(nextDiscounts);
|
|
5986
|
+
this.assertOrderReplacementCurrent(replacement);
|
|
5719
5987
|
await this.store.discount?.setDiscountList(nextDiscounts);
|
|
5988
|
+
this.assertOrderReplacementCurrent(replacement);
|
|
5720
5989
|
}
|
|
5721
5990
|
if (options?.recalcOnHydrate) {
|
|
5722
5991
|
await this.recalculateSummary({
|
|
5723
|
-
createIfMissing: false
|
|
5992
|
+
createIfMissing: false,
|
|
5993
|
+
isCurrentOrder: () => this.orderReplacement === replacement
|
|
5994
|
+
});
|
|
5995
|
+
} else if (!isMergedSalesDetailHydrate && [rawSummary.expect_amount, rawSummary.total_amount].some(amount => amount !== undefined && amount !== null && amount !== '')) {
|
|
5996
|
+
// Keep the remote baseline intact; only normalize the active priced order.
|
|
5997
|
+
const previousSummary = this.store.summary;
|
|
5998
|
+
const summary = this.applyEffectiveDepositSummary(nextTempOrder, previousSummary);
|
|
5999
|
+
summary.amount_gap = this.calculateSummaryAmountGap({
|
|
6000
|
+
tempOrder: nextTempOrder,
|
|
6001
|
+
summary,
|
|
6002
|
+
orderPaidAmount: this.calculatePaidPaymentSummary(nextTempOrder.payments || []).gapPaidAmount
|
|
6003
|
+
});
|
|
6004
|
+
this.store.summary = summary;
|
|
6005
|
+
this.updateTempOrderPaymentStatus(nextTempOrder, {
|
|
6006
|
+
previousSummary,
|
|
6007
|
+
summary
|
|
5724
6008
|
});
|
|
5725
6009
|
}
|
|
5726
|
-
this.persistTempOrder();
|
|
5727
6010
|
return nextTempOrder;
|
|
5728
6011
|
}
|
|
5729
6012
|
|