@pisell/pisellos 2.3.128 → 2.3.130
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/index.d.ts +2 -0
- package/dist/index.js +3 -1
- package/dist/model/strategy/adapter/promotion/index.js +0 -9
- package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
- package/dist/model/strategy/adapter/walletPass/evaluator.js +4 -2
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +58 -19
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +24 -12
- package/dist/modules/Customer/index.js +6 -3
- package/dist/modules/Customer/types.d.ts +2 -0
- package/dist/modules/Discount/availability.d.ts +7 -0
- package/dist/modules/Discount/availability.js +49 -0
- package/dist/modules/Discount/entitlementPass.d.ts +34 -0
- package/dist/modules/Discount/entitlementPass.js +147 -0
- package/dist/modules/Discount/index.d.ts +2 -2
- package/dist/modules/Discount/index.js +37 -151
- package/dist/modules/Discount/types.d.ts +36 -5
- package/dist/modules/FulfillmentTiming/index.d.ts +11 -0
- package/dist/modules/FulfillmentTiming/index.js +407 -0
- package/dist/modules/FulfillmentTiming/types.d.ts +67 -0
- package/dist/modules/FulfillmentTiming/types.js +1 -0
- package/dist/modules/OpenData/types.d.ts +6 -0
- package/dist/modules/Order/index.d.ts +12 -0
- package/dist/modules/Order/index.js +498 -247
- package/dist/modules/Order/pickupTiming.d.ts +46 -0
- package/dist/modules/Order/pickupTiming.js +53 -0
- package/dist/modules/Order/types.d.ts +5 -1
- package/dist/modules/Order/utils/orderCollectionIdentity.js +16 -12
- package/dist/modules/Order/utils.d.ts +1 -1
- package/dist/modules/Order/utils.js +117 -66
- package/dist/modules/Payment/index.js +9 -10
- package/dist/modules/Payment/types.d.ts +21 -1
- package/dist/modules/Payment/types.js +2 -0
- package/dist/modules/Payment/walletpass.d.ts +1 -1
- package/dist/modules/Payment/walletpass.js +80 -47
- package/dist/modules/Rules/index.d.ts +2 -2
- package/dist/modules/Rules/index.js +480 -186
- package/dist/modules/Rules/types.d.ts +4 -0
- package/dist/modules/Schedule/index.d.ts +8 -0
- package/dist/modules/Schedule/index.js +141 -39
- package/dist/modules/index.d.ts +1 -0
- package/dist/modules/index.js +1 -0
- package/dist/plugins/request.d.ts +7 -0
- package/dist/server/modules/order/types.d.ts +2 -0
- package/dist/server/utils/small-ticket.d.ts +1 -85
- package/dist/server/utils/small-ticket.js +2 -2542
- package/dist/shared/payment/loadPaymentMethods.d.ts +9 -0
- package/dist/shared/payment/loadPaymentMethods.js +66 -0
- package/dist/shared/receipt/loadCustomerInvoiceLayout.d.ts +22 -0
- package/dist/shared/receipt/loadCustomerInvoiceLayout.js +142 -0
- package/dist/shared/receipt/small-ticket.d.ts +85 -0
- package/dist/shared/receipt/small-ticket.js +2576 -0
- package/dist/shared/sales/loadSalesOrderSnapshot.d.ts +9 -0
- package/dist/shared/sales/loadSalesOrderSnapshot.js +21 -0
- package/dist/solution/BaseSales/index.d.ts +25 -0
- package/dist/solution/BaseSales/index.js +1226 -1040
- package/dist/solution/BaseSales/pickupTiming.d.ts +43 -0
- package/dist/solution/BaseSales/pickupTiming.js +589 -0
- package/dist/solution/BaseSales/types.d.ts +2 -2
- package/dist/solution/BaseSales/utils/cartPromotion.js +141 -126
- package/dist/solution/BaseSales/utils/parseSalesResponse.js +3 -0
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +4 -5
- package/dist/solution/BookingTicket/index.js +60 -63
- package/dist/solution/BookingTicket/types.d.ts +5 -1
- package/dist/solution/BookingTicket/utils/cartView.js +3 -1
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +2 -0
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +338 -147
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +8 -4
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +6 -0
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +19 -6
- package/dist/solution/OrderInvoicePreview/index.d.ts +56 -0
- package/dist/solution/OrderInvoicePreview/index.js +269 -0
- package/dist/solution/ShopDiscount/index.d.ts +2 -0
- package/dist/solution/ShopDiscount/index.js +99 -42
- package/dist/solution/ShopDiscount/utils.d.ts +4 -2
- package/dist/solution/ShopDiscount/utils.js +43 -23
- package/dist/solution/UnifiedBookingSales/index.d.ts +13 -4
- package/dist/solution/UnifiedBookingSales/index.js +874 -709
- package/dist/solution/index.d.ts +1 -0
- package/dist/solution/index.js +2 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +21 -1
- package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
- package/lib/model/strategy/adapter/walletPass/evaluator.js +2 -0
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +35 -6
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +13 -6
- package/lib/modules/Customer/index.js +5 -1
- package/lib/modules/Customer/types.d.ts +2 -0
- package/lib/modules/Discount/availability.d.ts +7 -0
- package/lib/modules/Discount/availability.js +43 -0
- package/lib/modules/Discount/entitlementPass.d.ts +34 -0
- package/lib/modules/Discount/entitlementPass.js +141 -0
- package/lib/modules/Discount/index.d.ts +2 -2
- package/lib/modules/Discount/index.js +23 -129
- package/lib/modules/Discount/types.d.ts +36 -5
- package/lib/modules/FulfillmentTiming/index.d.ts +11 -0
- package/lib/modules/FulfillmentTiming/index.js +359 -0
- package/lib/modules/FulfillmentTiming/types.d.ts +67 -0
- package/lib/modules/FulfillmentTiming/types.js +5 -0
- package/lib/modules/OpenData/types.d.ts +6 -0
- package/lib/modules/Order/index.d.ts +12 -0
- package/lib/modules/Order/index.js +252 -48
- package/lib/modules/Order/pickupTiming.d.ts +46 -0
- package/lib/modules/Order/pickupTiming.js +61 -0
- package/lib/modules/Order/types.d.ts +5 -1
- package/lib/modules/Order/utils/orderCollectionIdentity.js +14 -11
- package/lib/modules/Order/utils.d.ts +1 -1
- package/lib/modules/Order/utils.js +51 -7
- package/lib/modules/Payment/index.js +3 -4
- package/lib/modules/Payment/types.d.ts +21 -1
- package/lib/modules/Payment/types.js +1 -0
- package/lib/modules/Payment/walletpass.d.ts +1 -1
- package/lib/modules/Payment/walletpass.js +29 -9
- package/lib/modules/Rules/index.d.ts +2 -2
- package/lib/modules/Rules/index.js +357 -110
- package/lib/modules/Rules/types.d.ts +4 -0
- package/lib/modules/Schedule/index.d.ts +8 -0
- package/lib/modules/Schedule/index.js +68 -12
- package/lib/modules/index.d.ts +1 -0
- package/lib/modules/index.js +11 -0
- package/lib/plugins/request.d.ts +7 -0
- package/lib/server/modules/order/types.d.ts +2 -0
- package/lib/server/utils/small-ticket.d.ts +1 -85
- package/lib/server/utils/small-ticket.js +9 -2305
- package/lib/shared/payment/loadPaymentMethods.d.ts +9 -0
- package/lib/shared/payment/loadPaymentMethods.js +40 -0
- package/lib/shared/receipt/loadCustomerInvoiceLayout.d.ts +22 -0
- package/lib/shared/receipt/loadCustomerInvoiceLayout.js +86 -0
- package/lib/shared/receipt/small-ticket.d.ts +85 -0
- package/lib/shared/receipt/small-ticket.js +2342 -0
- package/lib/shared/sales/loadSalesOrderSnapshot.d.ts +9 -0
- package/lib/shared/sales/loadSalesOrderSnapshot.js +22 -0
- package/lib/solution/BaseSales/index.d.ts +25 -0
- package/lib/solution/BaseSales/index.js +102 -3
- package/lib/solution/BaseSales/pickupTiming.d.ts +43 -0
- package/lib/solution/BaseSales/pickupTiming.js +269 -0
- package/lib/solution/BaseSales/types.d.ts +2 -2
- package/lib/solution/BaseSales/utils/cartPromotion.js +12 -4
- package/lib/solution/BaseSales/utils/parseSalesResponse.js +3 -0
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +4 -5
- package/lib/solution/BookingTicket/index.js +36 -33
- package/lib/solution/BookingTicket/types.d.ts +5 -1
- package/lib/solution/BookingTicket/utils/cartView.js +3 -1
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +2 -0
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +174 -42
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +8 -4
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +6 -0
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +11 -3
- package/lib/solution/OrderInvoicePreview/index.d.ts +56 -0
- package/lib/solution/OrderInvoicePreview/index.js +192 -0
- package/lib/solution/ShopDiscount/index.d.ts +2 -0
- package/lib/solution/ShopDiscount/index.js +55 -9
- package/lib/solution/ShopDiscount/utils.d.ts +4 -2
- package/lib/solution/ShopDiscount/utils.js +42 -25
- package/lib/solution/UnifiedBookingSales/index.d.ts +13 -4
- package/lib/solution/UnifiedBookingSales/index.js +132 -48
- package/lib/solution/index.d.ts +1 -0
- package/lib/solution/index.js +11 -0
- package/package.json +1 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { ScheduleItem } from '../Schedule/types';
|
|
2
|
+
export type PickupTimingMode = 'asap_only' | 'scheduled_only' | 'asap_and_scheduled';
|
|
3
|
+
export interface PickupTimingConfig {
|
|
4
|
+
handoverModes: string[];
|
|
5
|
+
timingMode: PickupTimingMode;
|
|
6
|
+
scheduleIds: number[];
|
|
7
|
+
/** Empty or absent means no additional store-hours restriction. */
|
|
8
|
+
operatingHoursScheduleIds?: number[];
|
|
9
|
+
slotIntervalMinutes: number;
|
|
10
|
+
preparationTimeMinutes: number;
|
|
11
|
+
advanceDays: number;
|
|
12
|
+
fulfillmentRefMode?: string;
|
|
13
|
+
manualInputType?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface PickupTimingSelection {
|
|
16
|
+
serviceType: string;
|
|
17
|
+
mode: 'asap' | 'scheduled';
|
|
18
|
+
date?: string;
|
|
19
|
+
time?: string;
|
|
20
|
+
/** The absolute instant disambiguates a repeated local minute during DST. */
|
|
21
|
+
instant?: string;
|
|
22
|
+
source?: 'schedule' | 'pos_manual' | 'asap';
|
|
23
|
+
}
|
|
24
|
+
export interface PickupTimingSlot {
|
|
25
|
+
id: string;
|
|
26
|
+
date: string;
|
|
27
|
+
time: string;
|
|
28
|
+
instant: string;
|
|
29
|
+
}
|
|
30
|
+
export interface PickupTimingAvailability {
|
|
31
|
+
/** Config remains available when Schedule or store timezone cannot be loaded. */
|
|
32
|
+
error?: string;
|
|
33
|
+
config: PickupTimingConfig;
|
|
34
|
+
timezone: string;
|
|
35
|
+
now: string;
|
|
36
|
+
today: string;
|
|
37
|
+
maxDate: string;
|
|
38
|
+
date: string;
|
|
39
|
+
dates: Array<{
|
|
40
|
+
date: string;
|
|
41
|
+
status: 'available' | 'unavailable';
|
|
42
|
+
}>;
|
|
43
|
+
slots: PickupTimingSlot[];
|
|
44
|
+
/** Earliest legal candidate across all permitted dates, for POS prefill. */
|
|
45
|
+
firstSlot?: PickupTimingSlot;
|
|
46
|
+
}
|
|
47
|
+
export interface PickupTimingClockInput {
|
|
48
|
+
config: PickupTimingConfig;
|
|
49
|
+
timezone: string;
|
|
50
|
+
now: Date | string | number;
|
|
51
|
+
}
|
|
52
|
+
export interface PickupTimingComputeInput extends PickupTimingClockInput {
|
|
53
|
+
schedules: ScheduleItem[];
|
|
54
|
+
date?: string;
|
|
55
|
+
}
|
|
56
|
+
export interface PickupTimingValidationResult {
|
|
57
|
+
valid: boolean;
|
|
58
|
+
code?: string;
|
|
59
|
+
message?: string;
|
|
60
|
+
slot?: PickupTimingSlot;
|
|
61
|
+
}
|
|
62
|
+
export interface PickupTimingBookingTimes {
|
|
63
|
+
start_date: string;
|
|
64
|
+
start_time: string;
|
|
65
|
+
end_date: string;
|
|
66
|
+
end_time: string;
|
|
67
|
+
}
|
|
@@ -77,6 +77,12 @@ export interface OpenDataConfig {
|
|
|
77
77
|
'sale.sale_number_prefix'?: string | null;
|
|
78
78
|
'sale.enabled_item_rules'?: number[];
|
|
79
79
|
'fulfillment.enable_pickup'?: boolean;
|
|
80
|
+
'fulfillment.handover_mode'?: string[];
|
|
81
|
+
'fulfillment.pickup.timing_mode'?: 'asap_only' | 'scheduled_only' | 'asap_and_scheduled';
|
|
82
|
+
'fulfillment.pickup.schedule'?: number[];
|
|
83
|
+
'fulfillment.pickup.advance_days'?: number;
|
|
84
|
+
'fulfillment.pickup.slot_interval_minutes'?: number;
|
|
85
|
+
'fulfillment.pickup.preparation_time_minutes'?: number;
|
|
80
86
|
'fulfillment.overdue_reminder'?: boolean;
|
|
81
87
|
'fulfillment.manual_input_type'?: string;
|
|
82
88
|
'fulfillment.enable_auto_complete'?: boolean;
|
|
@@ -3,6 +3,7 @@ import { BaseModule } from '../BaseModule';
|
|
|
3
3
|
import { OrderModuleAPI, CommitOrderParams, UpdateOrderBookingParams, UpdateOrderProductParams, UpdateOrderProductQuantityParams, CancelOrderParams, ChangeBookingStatusParams, CheckoutOrderParams } from './types';
|
|
4
4
|
import { CartItem } from '../Cart/types';
|
|
5
5
|
import { type SubmitPayloadEnhancer } from './utils';
|
|
6
|
+
import { type PickupTimingBooking, type PickupTimingBookingInput } from './pickupTiming';
|
|
6
7
|
import type { OrderAmountSnapshot, AddProductBookingInput, AddProductToOrderOptions, OrderIdentitySnapshot, OrderPaymentSource, OrderSnapshot, OrderSyncState, SyncPaymentsToOrderParams, SyncPaymentsToOrderResult, SubmitSalesOrderParams, OrderProduct, OrderProductIdentity, OrderSummary, OrderTempOrder, OrderPaymentData, OrderPaymentUpdateOptions, OrderPaymentUpdateResult, SendCustomerPayLinkParams, UpdateTempOrderCustomerInput, OrderCustomerPatch, OrderCustomerView, ReplaceTempOrderOptions, OrderPromotionEvaluator, OrderGiftSelectResolver, OrderUnfulfilledPromotion, OrderLastGiftActions, RemoveProductsFromOrderOptions, SalesNote, SalesNotesMutationSnapshot, SetSalesNoteInput, PickupReferenceMode, PointCardSnapshotMergeContext, PointCardSnapshotItem, ShopServiceData, ShopServiceType } from './types';
|
|
7
8
|
import type { ICustomer } from '../AccountList/types';
|
|
8
9
|
import type { Discount } from '../Discount/types';
|
|
@@ -111,6 +112,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
111
112
|
applyDiscount(options?: {
|
|
112
113
|
reapplyBookingDiscountProductUids?: string[];
|
|
113
114
|
reapplyWeighedDiscountProductUids?: string[];
|
|
115
|
+
preferredEntitlementPassIds?: number[];
|
|
114
116
|
}): void;
|
|
115
117
|
/**
|
|
116
118
|
* 注入促销评估器。
|
|
@@ -353,6 +355,9 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
353
355
|
private updateTempOrderShopServiceData;
|
|
354
356
|
updateTempOrderPickupReferenceMode(mode: PickupReferenceMode): ShopServiceData;
|
|
355
357
|
updateTempOrderServiceType(serviceType: ShopServiceType): ShopServiceData;
|
|
358
|
+
getPickupTimingBooking(): PickupTimingBooking | null;
|
|
359
|
+
setPickupTimingBooking(input: PickupTimingBookingInput): PickupTimingBooking;
|
|
360
|
+
clearPickupTimingBooking(): void;
|
|
356
361
|
updateTempOrderContactsInfo(contactsInfo: Record<string, any> | null): Record<string, any> | null;
|
|
357
362
|
private buildTempOrderCustomer;
|
|
358
363
|
private isCustomerBoundDiscount;
|
|
@@ -489,7 +494,12 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
489
494
|
}>, options?: {
|
|
490
495
|
skipEditDiscountConfigRefresh?: boolean;
|
|
491
496
|
}): Promise<OrderProduct[]>;
|
|
497
|
+
private getFullCoveragePassDiscounts;
|
|
498
|
+
private hasEntitlementPassDiscount;
|
|
492
499
|
private hasGoodPassDiscount;
|
|
500
|
+
private isPersistedProductLine;
|
|
501
|
+
private isRuntimeEntitlementAppend;
|
|
502
|
+
private hasSameEntitlementMergePriceConfig;
|
|
493
503
|
private getBundleRuntimeIdentity;
|
|
494
504
|
private preservePersistedBundlePriceFields;
|
|
495
505
|
private applyOrderProductUpdateToTempOrder;
|
|
@@ -658,3 +668,5 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
658
668
|
getVouchers(): any[];
|
|
659
669
|
}
|
|
660
670
|
export type { AddProductToOrderOptions, OrderMetaList, PointCardSnapshotItem, VirtualCurrencySnapshotItem, RemoveProductsFromOrderOptions, SalesNote, SalesNoteDraftInput, SalesNoteLocalizedSelection, SalesNoteLocalizedText, SalesNoteRelation, SalesNoteTextInput, SetSalesNoteInput, UpdateOrderBookingParams, UpdateOrderProductParams, UpdateOrderProductQuantityParams, } from './types';
|
|
671
|
+
export { isFulfillmentTimingBooking } from './pickupTiming';
|
|
672
|
+
export type { PickupTimingBooking, PickupTimingBookingInput, PickupTimingBookingMetadata, PickupTimingSelectionMode, PickupTimingSource, } from './pickupTiming';
|
|
@@ -4,12 +4,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.OrderModule = void 0;
|
|
7
|
+
Object.defineProperty(exports, "isFulfillmentTimingBooking", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _pickupTiming.isFulfillmentTimingBooking;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
var _loadSalesOrderSnapshot = require("../../shared/sales/loadSalesOrderSnapshot");
|
|
7
14
|
var _BaseModule = require("../BaseModule");
|
|
8
15
|
var _types = require("./types");
|
|
9
16
|
var _utils = require("./utils");
|
|
10
17
|
var _utils2 = require("../Product/utils");
|
|
11
18
|
var _weighedProduct = require("./utils/weighedProduct");
|
|
19
|
+
var _pickupTiming = require("./pickupTiming");
|
|
12
20
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
21
|
+
var _availability = require("../Discount/availability");
|
|
13
22
|
var _osPrivatePayload = require("../../utils/os-private-payload");
|
|
14
23
|
var _salesNotes = require("./salesNotes");
|
|
15
24
|
var _paymentUtils = require("./payment-utils");
|
|
@@ -23,6 +32,7 @@ var _discountProductLineIdentity = require("./utils/discountProductLineIdentity"
|
|
|
23
32
|
var _virtualSettlement = require("./utils/virtualSettlement");
|
|
24
33
|
var _Discount = require("../Discount");
|
|
25
34
|
var _Rules = require("../Rules");
|
|
35
|
+
var _entitlementPass = require("../Discount/entitlementPass");
|
|
26
36
|
var _types2 = require("../Rules/types");
|
|
27
37
|
var _decimal = _interopRequireDefault(require("decimal.js"));
|
|
28
38
|
var _lodashEs = require("lodash-es");
|
|
@@ -42,9 +52,27 @@ function isSameDiscountList(left, right) {
|
|
|
42
52
|
function isManualProductDiscountProduct(product) {
|
|
43
53
|
return (0, _manualProductDiscount.hasManualProductDiscountFlag)(product?.metadata) || (product?.discount_list || []).some(item => item?.type === 'product');
|
|
44
54
|
}
|
|
55
|
+
function syncReducedEntitlementPassUsageCount(discountList, previousQuantity, nextQuantity) {
|
|
56
|
+
if (!Array.isArray(discountList)) return discountList;
|
|
57
|
+
const previousCount = (0, _utils3.getSafeProductNum)(previousQuantity);
|
|
58
|
+
const nextCount = (0, _utils3.getSafeProductNum)(nextQuantity);
|
|
59
|
+
if (nextCount >= previousCount) return discountList;
|
|
60
|
+
return discountList.map(discount => {
|
|
61
|
+
if (!(0, _entitlementPass.isEntitlementPass)(discount)) return discount;
|
|
62
|
+
const rawUsageCount = Number(discount?.metadata?.num ?? previousCount);
|
|
63
|
+
const usageCount = Number.isFinite(rawUsageCount) ? Math.max(Math.floor(rawUsageCount), 0) : previousCount;
|
|
64
|
+
return {
|
|
65
|
+
...discount,
|
|
66
|
+
metadata: {
|
|
67
|
+
...(discount?.metadata || {}),
|
|
68
|
+
num: Math.min(usageCount, nextCount)
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
}
|
|
45
73
|
const ORDER_PAYMENT_STATUS_PAID = 'paid';
|
|
46
74
|
const ORDER_PAYMENT_STATUS_PENDING = 'payment_pending';
|
|
47
|
-
const CUSTOMER_PROMOTION_DISCOUNT_TAGS = new Set(['good_pass', 'product_discount_card', 'discount_card']);
|
|
75
|
+
const CUSTOMER_PROMOTION_DISCOUNT_TAGS = new Set(['entitlement_pass', 'good_pass', 'product_discount_card', 'discount_card']);
|
|
48
76
|
function isCustomerPromotionDiscount(discount) {
|
|
49
77
|
return CUSTOMER_PROMOTION_DISCOUNT_TAGS.has(String(discount?.tag || discount?.type || '').toLowerCase());
|
|
50
78
|
}
|
|
@@ -74,6 +102,28 @@ function getVoucherPaymentLifecycleKey(payment) {
|
|
|
74
102
|
if (!isVoucherPaymentRecord(payment)) return null;
|
|
75
103
|
return `${String(payment.voucher_id)}::${String(payment.status || '')}`;
|
|
76
104
|
}
|
|
105
|
+
function getDiscountIdentityKey(discount) {
|
|
106
|
+
const id = discount?.id;
|
|
107
|
+
if (id === undefined || id === null || id === '') return null;
|
|
108
|
+
return String(id);
|
|
109
|
+
}
|
|
110
|
+
function mergeCommittedEntitlementWithRuntime(committed, runtime) {
|
|
111
|
+
const committedAppliedProductDetails = committed.committedAppliedProductDetails?.length ? committed.committedAppliedProductDetails : committed.appliedProductDetails || [];
|
|
112
|
+
return {
|
|
113
|
+
...committed,
|
|
114
|
+
...runtime,
|
|
115
|
+
id: runtime.id ?? committed.id,
|
|
116
|
+
tag: runtime.tag || committed.tag,
|
|
117
|
+
type: runtime.type || committed.type,
|
|
118
|
+
isEditMode: false,
|
|
119
|
+
isDisabled: runtime.isDisabled ?? false,
|
|
120
|
+
isSelected: runtime.isSelected ?? committed.isSelected,
|
|
121
|
+
isUsed: committed.isUsed || runtime.isUsed,
|
|
122
|
+
committedAppliedProductDetails: [...committedAppliedProductDetails],
|
|
123
|
+
applicableProductDetails: [...(committed.applicableProductDetails || []), ...(runtime.applicableProductDetails || [])],
|
|
124
|
+
appliedProductDetails: [...committedAppliedProductDetails, ...(runtime.appliedProductDetails || [])]
|
|
125
|
+
};
|
|
126
|
+
}
|
|
77
127
|
class OrderModule extends _BaseModule.BaseModule {
|
|
78
128
|
defaultName = 'order';
|
|
79
129
|
defaultVersion = '1.0.0';
|
|
@@ -129,6 +179,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
129
179
|
const key = Number.isFinite(id) ? id : String(resourceId);
|
|
130
180
|
const title = item?.discount?.title ?? {};
|
|
131
181
|
const amount = Number(item?.amount || 0);
|
|
182
|
+
const encoded = item?.metadata?.encoded || item?.encoded || item?.discount?.encoded || '';
|
|
132
183
|
const discountCardType = item?.discount?.discount_card_type;
|
|
133
184
|
const parValue = isDiscountCard ? discountCardType === 'fixed_amount' ? item?.discount?.fixed_amount ?? item?.amount : item?.discount?.percent : '0';
|
|
134
185
|
const detail = {
|
|
@@ -139,11 +190,21 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
139
190
|
original_amount: String(item?.discount?.original_amount ?? item?.amount ?? '0'),
|
|
140
191
|
num: Number(item?.metadata?.num ?? product?.num ?? product?.product_quantity ?? 1) || 1,
|
|
141
192
|
metadata: item?.metadata,
|
|
142
|
-
discount:
|
|
193
|
+
discount: {
|
|
194
|
+
...(item?.discount || {}),
|
|
195
|
+
product_id: item?.discount?.product_id ?? product?.product_id
|
|
196
|
+
},
|
|
143
197
|
_num: Number(item?.metadata?.num ?? product?.num ?? product?.product_quantity ?? 1) || 1
|
|
144
198
|
};
|
|
145
199
|
const existed = discountMap.get(key);
|
|
146
200
|
if (existed) {
|
|
201
|
+
if (!existed.encoded && encoded) {
|
|
202
|
+
existed.encoded = encoded;
|
|
203
|
+
existed.metadata = {
|
|
204
|
+
...existed.metadata,
|
|
205
|
+
encoded
|
|
206
|
+
};
|
|
207
|
+
}
|
|
147
208
|
existed.amount = Number(existed.amount || 0) + amount;
|
|
148
209
|
existed.used_par_value = String(Number(existed.used_par_value || 0) + amount);
|
|
149
210
|
if (!isDiscountCard) {
|
|
@@ -163,8 +224,11 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
163
224
|
discountMap.set(key, {
|
|
164
225
|
id: key,
|
|
165
226
|
product_name: '',
|
|
166
|
-
encoded
|
|
167
|
-
code: '',
|
|
227
|
+
encoded,
|
|
228
|
+
code: item?.code || item?.discount?.code || '',
|
|
229
|
+
metadata: {
|
|
230
|
+
encoded
|
|
231
|
+
},
|
|
168
232
|
tag: type,
|
|
169
233
|
product_id: item?.discount?.discount_product_id ?? product?.product_id ?? 0,
|
|
170
234
|
relation_type: '',
|
|
@@ -455,7 +519,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
455
519
|
this.store.rules = rules;
|
|
456
520
|
}
|
|
457
521
|
createDefaultRulesHooks() {
|
|
458
|
-
return (0, _utils.createDefaultOrderRulesHooks)();
|
|
522
|
+
return (0, _utils.createDefaultOrderRulesHooks)(() => this.store.tempOrder?.bookings || []);
|
|
459
523
|
}
|
|
460
524
|
|
|
461
525
|
/**
|
|
@@ -481,6 +545,8 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
481
545
|
with_wallet_pass_holder: 1,
|
|
482
546
|
with_available_wallet_flag: 1,
|
|
483
547
|
with_available_wallet_pass_flag: 1,
|
|
548
|
+
with_entitlement_pass: 1,
|
|
549
|
+
filter_order_wallet_pass_usage: 0,
|
|
484
550
|
with_virtual_currency: 1,
|
|
485
551
|
request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
486
552
|
...(orderId ? {
|
|
@@ -502,17 +568,61 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
502
568
|
}
|
|
503
569
|
if (discountList) {
|
|
504
570
|
const currentDiscountList = this.store.discount?.getDiscountList() || [];
|
|
505
|
-
const
|
|
571
|
+
const currentCommittedDiscounts = currentDiscountList.filter(discount => discount?.isEditMode || discount?.committedAppliedProductDetails?.length);
|
|
506
572
|
const currentScanDiscounts = currentDiscountList.filter(discount => discount?.isScan);
|
|
507
|
-
const
|
|
573
|
+
const currentScanDiscountById = new Map(currentScanDiscounts.flatMap(discount => {
|
|
574
|
+
const id = getDiscountIdentityKey(discount);
|
|
575
|
+
return id === null ? [] : [[id, discount]];
|
|
576
|
+
}));
|
|
577
|
+
const committedDiscountById = new Map(currentCommittedDiscounts.flatMap(discount => {
|
|
578
|
+
const id = getDiscountIdentityKey(discount);
|
|
579
|
+
return id === null ? [] : [[id, discount]];
|
|
580
|
+
}));
|
|
581
|
+
const mergedCommittedDiscountIds = new Set();
|
|
582
|
+
const refreshedScanDiscountIds = new Set();
|
|
508
583
|
const runtimeDiscountIds = new Set();
|
|
509
|
-
const runtimeDiscounts = discountList.
|
|
510
|
-
|
|
511
|
-
if (
|
|
512
|
-
runtimeDiscountIds.
|
|
513
|
-
|
|
584
|
+
const runtimeDiscounts = discountList.flatMap(discount => {
|
|
585
|
+
const id = getDiscountIdentityKey(discount);
|
|
586
|
+
if (id === null) return [discount];
|
|
587
|
+
if (runtimeDiscountIds.has(id)) return [];
|
|
588
|
+
runtimeDiscountIds.add(id);
|
|
589
|
+
const currentScanDiscount = currentScanDiscountById.get(id);
|
|
590
|
+
if (currentScanDiscount && (!(0, _entitlementPass.isEntitlementPass)(currentScanDiscount) || !(0, _entitlementPass.isEntitlementPass)(discount))) {
|
|
591
|
+
return [];
|
|
592
|
+
}
|
|
593
|
+
const committedDiscount = committedDiscountById.get(id);
|
|
594
|
+
let nextDiscount = discount;
|
|
595
|
+
if (committedDiscount && (0, _entitlementPass.isEntitlementPass)(committedDiscount) && (0, _entitlementPass.isEntitlementPass)(discount)) {
|
|
596
|
+
mergedCommittedDiscountIds.add(id);
|
|
597
|
+
nextDiscount = mergeCommittedEntitlementWithRuntime(committedDiscount, discount);
|
|
598
|
+
}
|
|
599
|
+
if (currentScanDiscount) {
|
|
600
|
+
refreshedScanDiscountIds.add(id);
|
|
601
|
+
nextDiscount = {
|
|
602
|
+
...nextDiscount,
|
|
603
|
+
isScan: true,
|
|
604
|
+
isSelected: currentScanDiscount.isSelected ?? nextDiscount.isSelected,
|
|
605
|
+
isManualSelect: currentScanDiscount.isManualSelect ?? nextDiscount.isManualSelect
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
return [nextDiscount];
|
|
609
|
+
});
|
|
610
|
+
const retainedCommittedDiscounts = currentCommittedDiscounts.filter(discount => {
|
|
611
|
+
const id = getDiscountIdentityKey(discount);
|
|
612
|
+
return id === null || !mergedCommittedDiscountIds.has(id);
|
|
613
|
+
}).map(discount => discount.committedAppliedProductDetails?.length ? {
|
|
614
|
+
...discount,
|
|
615
|
+
isEditMode: true,
|
|
616
|
+
isDisabled: true,
|
|
617
|
+
isSelected: true,
|
|
618
|
+
isUsed: true,
|
|
619
|
+
appliedProductDetails: [...discount.committedAppliedProductDetails]
|
|
620
|
+
} : discount);
|
|
621
|
+
const retainedScanDiscounts = currentScanDiscounts.filter(discount => {
|
|
622
|
+
const id = getDiscountIdentityKey(discount);
|
|
623
|
+
return id === null || !refreshedScanDiscountIds.has(id);
|
|
514
624
|
});
|
|
515
|
-
const mergedDiscountList = [...
|
|
625
|
+
const mergedDiscountList = [...retainedCommittedDiscounts, ...retainedScanDiscounts, ...runtimeDiscounts];
|
|
516
626
|
if (!isCurrentRequest()) return this.getDiscountList();
|
|
517
627
|
await this.store.discount?.setOriginalDiscountList(mergedDiscountList);
|
|
518
628
|
if (!isCurrentRequest()) return this.getDiscountList();
|
|
@@ -633,19 +743,34 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
633
743
|
isAvailable: false,
|
|
634
744
|
discountList: this.getDiscountList()
|
|
635
745
|
};
|
|
636
|
-
const
|
|
746
|
+
const scannedIds = new Set(withScanList.map(discount => String(discount.id)));
|
|
747
|
+
const evaluatedScannedDiscounts = (evaluatedDiscountList || withScanList).filter(discount => scannedIds.has(String(discount.id)) && isCustomerPromotionDiscount(discount) && !(0, _availability.getDiscountLifecycleReason)(discount));
|
|
748
|
+
const shouldRetainForLater = !isAvailable && evaluatedScannedDiscounts.length > 0;
|
|
637
749
|
const normalizedNewDiscountList = newDiscountList ? markScannedDiscounts(newDiscountList, withScanList) : undefined;
|
|
638
|
-
const retainedDiscountList = evaluatedDiscountList ? markScannedDiscounts(evaluatedDiscountList, withScanList) : normalizedNewDiscountList;
|
|
639
750
|
let resolvedDiscountList = normalizedNewDiscountList || this.getDiscountList();
|
|
640
751
|
if (isAvailable && normalizedNewDiscountList) {
|
|
641
752
|
await this.store.discount?.setDiscountList(normalizedNewDiscountList);
|
|
642
|
-
|
|
753
|
+
// 实际写回商品时沿用扫码试算的优先级,避免旧商品行的选卡覆盖本次扫码。
|
|
754
|
+
this.applyDiscount({
|
|
755
|
+
preferredEntitlementPassIds: withScanList.filter(discount => (0, _entitlementPass.isEntitlementPass)(discount)).map(discount => discount.id)
|
|
756
|
+
});
|
|
643
757
|
await this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
|
|
644
758
|
resolvedDiscountList = this.getDiscountList();
|
|
645
|
-
} else if (shouldRetainForLater
|
|
646
|
-
//
|
|
647
|
-
|
|
648
|
-
|
|
759
|
+
} else if (shouldRetainForLater) {
|
|
760
|
+
// 只合并本次识别的卡券;不把试算产生的其他选券状态写回订单。
|
|
761
|
+
const retainedDiscounts = new Map(this.getDiscountList().map(discount => [String(discount.id), discount]));
|
|
762
|
+
evaluatedScannedDiscounts.forEach(discount => {
|
|
763
|
+
retainedDiscounts.set(String(discount.id), {
|
|
764
|
+
...discount,
|
|
765
|
+
isScan: true,
|
|
766
|
+
isAvailable: false,
|
|
767
|
+
isSelected: false,
|
|
768
|
+
reasonCode: discount.reasonCode || 'product_not_applicable',
|
|
769
|
+
appliedProductDetails: [],
|
|
770
|
+
savedAmount: 0
|
|
771
|
+
});
|
|
772
|
+
});
|
|
773
|
+
await this.store.discount?.setDiscountList([...retainedDiscounts.values()]);
|
|
649
774
|
await this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
|
|
650
775
|
resolvedDiscountList = this.getDiscountList();
|
|
651
776
|
}
|
|
@@ -654,7 +779,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
654
779
|
isAvailable: isAvailable || false,
|
|
655
780
|
isAccepted: Boolean(isAvailable || shouldRetainForLater),
|
|
656
781
|
discountList: resolvedDiscountList,
|
|
657
|
-
scannedDiscountList:
|
|
782
|
+
scannedDiscountList: evaluatedScannedDiscounts,
|
|
658
783
|
unavailableReason
|
|
659
784
|
};
|
|
660
785
|
}
|
|
@@ -687,7 +812,8 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
687
812
|
orderTotalAmount: Number(this.store.summary?.total_amount || 0)
|
|
688
813
|
}, {
|
|
689
814
|
reapplyBookingDiscountProductUids: options?.reapplyBookingDiscountProductUids,
|
|
690
|
-
reapplyWeighedDiscountProductUids: options?.reapplyWeighedDiscountProductUids
|
|
815
|
+
reapplyWeighedDiscountProductUids: options?.reapplyWeighedDiscountProductUids,
|
|
816
|
+
preferredEntitlementPassIds: options?.preferredEntitlementPassIds
|
|
691
817
|
});
|
|
692
818
|
if (result?.productList) {
|
|
693
819
|
const previousProductsByUid = (0, _utils.indexOrderProductsByUid)(tempOrder.products);
|
|
@@ -1643,7 +1769,8 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1643
1769
|
const sku = product?.product_sku || {};
|
|
1644
1770
|
const metadata = product?.metadata || {};
|
|
1645
1771
|
const discountTypes = (product?.discount_list || []).map(discount => discount?.type ?? discount?.tag);
|
|
1646
|
-
const
|
|
1772
|
+
const fullCoveragePassType = discountTypes.find(type => ['entitlement_pass', 'good_pass'].includes(type));
|
|
1773
|
+
const extensionType = product?.extension_type || fullCoveragePassType || 'normal';
|
|
1647
1774
|
return {
|
|
1648
1775
|
product_id: product?.product_id ?? null,
|
|
1649
1776
|
product_variant_id: product?.product_variant_id ?? null,
|
|
@@ -1696,7 +1823,8 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1696
1823
|
const sku = product?.product_sku || {};
|
|
1697
1824
|
const metadata = product?.metadata || {};
|
|
1698
1825
|
const discountTypes = (product?.discount_list || []).map(discount => discount?.type ?? discount?.tag);
|
|
1699
|
-
const
|
|
1826
|
+
const fullCoveragePassType = discountTypes.find(type => ['entitlement_pass', 'good_pass'].includes(type));
|
|
1827
|
+
const extensionType = product?.extension_type || fullCoveragePassType || 'normal';
|
|
1700
1828
|
return {
|
|
1701
1829
|
product_id: product?.product_id ?? null,
|
|
1702
1830
|
product_variant_id: product?.product_variant_id ?? null,
|
|
@@ -2155,6 +2283,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2155
2283
|
const bookingByBookingUid = new Map();
|
|
2156
2284
|
bookings.forEach(booking => {
|
|
2157
2285
|
if (!booking || typeof booking !== 'object') return;
|
|
2286
|
+
if ((0, _pickupTiming.isFulfillmentTimingBooking)(booking)) return;
|
|
2158
2287
|
const productUid = booking.product_uid || booking.metadata?.product_uid;
|
|
2159
2288
|
if (productUid !== undefined && productUid !== null && String(productUid) !== '') {
|
|
2160
2289
|
bookingByProductUid.set(String(productUid), booking);
|
|
@@ -2205,6 +2334,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2205
2334
|
let baseHolder = null;
|
|
2206
2335
|
const seen = new Set();
|
|
2207
2336
|
for (const booking of tempOrder.bookings || []) {
|
|
2337
|
+
if ((0, _pickupTiming.isFulfillmentTimingBooking)(booking)) continue;
|
|
2208
2338
|
const holder = booking?.holder && typeof booking.holder === 'object' ? booking.holder : null;
|
|
2209
2339
|
if (!baseHolder && holder) {
|
|
2210
2340
|
baseHolder = holder;
|
|
@@ -2245,7 +2375,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2245
2375
|
* this.syncTempOrderHolderFromBookings(tempOrder);
|
|
2246
2376
|
*/
|
|
2247
2377
|
syncTempOrderHolderFromBookings(tempOrder) {
|
|
2248
|
-
const bookings = tempOrder.bookings || [];
|
|
2378
|
+
const bookings = (tempOrder.bookings || []).filter(booking => !(0, _pickupTiming.isFulfillmentTimingBooking)(booking));
|
|
2249
2379
|
const hasHolderSource = bookings.some(booking => {
|
|
2250
2380
|
return booking?.holder !== undefined || booking?.metadata?.holder_id !== undefined;
|
|
2251
2381
|
});
|
|
@@ -2270,6 +2400,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2270
2400
|
const bookingUid = product?.booking_uid || product?.metadata?.booking_uid;
|
|
2271
2401
|
if (!productUid && !bookingUid) return;
|
|
2272
2402
|
tempOrder.bookings = (tempOrder.bookings || []).filter(booking => {
|
|
2403
|
+
if ((0, _pickupTiming.isFulfillmentTimingBooking)(booking)) return true;
|
|
2273
2404
|
const currentBookingUid = this.getBookingUniqueIdentificationNumber(booking);
|
|
2274
2405
|
if (bookingUid && currentBookingUid === String(bookingUid)) return false;
|
|
2275
2406
|
if (productUid && String(booking?.product_uid || '') === String(productUid)) return false;
|
|
@@ -2683,10 +2814,33 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2683
2814
|
});
|
|
2684
2815
|
}
|
|
2685
2816
|
updateTempOrderServiceType(serviceType) {
|
|
2817
|
+
if (serviceType !== 'pick_up') {
|
|
2818
|
+
const tempOrder = this.ensureTempOrder();
|
|
2819
|
+
tempOrder.bookings = (tempOrder.bookings || []).filter(booking => !(0, _pickupTiming.isFulfillmentTimingBooking)(booking));
|
|
2820
|
+
}
|
|
2686
2821
|
return this.updateTempOrderShopServiceData({
|
|
2687
2822
|
service_type: serviceType
|
|
2688
2823
|
});
|
|
2689
2824
|
}
|
|
2825
|
+
getPickupTimingBooking() {
|
|
2826
|
+
return (this.store.tempOrder?.bookings || []).find(_pickupTiming.isFulfillmentTimingBooking) || null;
|
|
2827
|
+
}
|
|
2828
|
+
setPickupTimingBooking(input) {
|
|
2829
|
+
const tempOrder = this.ensureTempOrder();
|
|
2830
|
+
const bookings = tempOrder.bookings || [];
|
|
2831
|
+
const firstIndex = bookings.findIndex(_pickupTiming.isFulfillmentTimingBooking);
|
|
2832
|
+
const nextBooking = (0, _pickupTiming.buildPickupTimingBooking)(input, bookings[firstIndex]);
|
|
2833
|
+
// Keep the first row's identity and position; repair duplicate marked rows only.
|
|
2834
|
+
tempOrder.bookings = firstIndex === -1 ? [...bookings, nextBooking] : bookings.flatMap((booking, index) => index === firstIndex ? [nextBooking] : (0, _pickupTiming.isFulfillmentTimingBooking)(booking) ? [] : [booking]);
|
|
2835
|
+
this.notifyTempOrderChanged();
|
|
2836
|
+
return nextBooking;
|
|
2837
|
+
}
|
|
2838
|
+
clearPickupTimingBooking() {
|
|
2839
|
+
const tempOrder = this.store.tempOrder;
|
|
2840
|
+
if (!tempOrder?.bookings?.some(_pickupTiming.isFulfillmentTimingBooking)) return;
|
|
2841
|
+
tempOrder.bookings = tempOrder.bookings.filter(booking => !(0, _pickupTiming.isFulfillmentTimingBooking)(booking));
|
|
2842
|
+
this.notifyTempOrderChanged();
|
|
2843
|
+
}
|
|
2690
2844
|
updateTempOrderContactsInfo(contactsInfo) {
|
|
2691
2845
|
const tempOrder = this.ensureTempOrder();
|
|
2692
2846
|
tempOrder.contacts_info = contactsInfo && typeof contactsInfo === 'object' && !Array.isArray(contactsInfo) ? contactsInfo : null;
|
|
@@ -2711,7 +2865,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2711
2865
|
}
|
|
2712
2866
|
isCustomerBoundDiscount(discount) {
|
|
2713
2867
|
const type = discount?.type ?? discount?.tag;
|
|
2714
|
-
return type === 'good_pass' || type === 'discount_card' || type === 'product_discount_card';
|
|
2868
|
+
return type === 'entitlement_pass' || type === 'good_pass' || type === 'discount_card' || type === 'product_discount_card';
|
|
2715
2869
|
}
|
|
2716
2870
|
shouldKeepCustomerBoundDiscountAfterCustomerChange(discount) {
|
|
2717
2871
|
return Boolean(discount?.isScan || discount?.isEditMode);
|
|
@@ -3334,17 +3488,35 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3334
3488
|
}
|
|
3335
3489
|
normalizedIncoming.discount_list = (0, _utils.normalizeOrderProductDiscountList)(normalizedIncoming.discount_list);
|
|
3336
3490
|
const hasIncomingGoodPass = this.hasGoodPassDiscount(normalizedIncoming);
|
|
3491
|
+
const hasIncomingEntitlementPass = this.hasEntitlementPassDiscount(normalizedIncoming);
|
|
3492
|
+
const isIncomingEntitlementAppend = this.isRuntimeEntitlementAppend(productToAdd, tempOrder);
|
|
3493
|
+
const isIncomingPersistedEntitlementPass = hasIncomingEntitlementPass && this.isPersistedProductLine(normalizedIncoming);
|
|
3337
3494
|
const hasIncomingProductNote = this.hasOrderProductLineNote(normalizedIncoming);
|
|
3338
3495
|
const hasIncomingManualProductDiscount = isManualProductDiscountProduct(normalizedIncoming);
|
|
3339
3496
|
const hasIncomingBookingUid = this.hasLinkedBookingUid(productToAdd) || this.hasLinkedBookingUid(normalizedIncoming);
|
|
3340
3497
|
const isIncomingCustomItem = productToAdd.metadata?.origin?.isCustomItem === true || productToAdd._origin?.isCustomItem === true;
|
|
3341
|
-
const shouldForceNewLine = disableMerge || !!booking ||
|
|
3342
|
-
const matchedIndex =
|
|
3498
|
+
const shouldForceNewLine = disableMerge || !!booking || hasIncomingGoodPass || isIncomingPersistedEntitlementPass || hasIncomingBookingUid || isIncomingCustomItem || isWeighingProduct;
|
|
3499
|
+
const matchedIndex = shouldForceNewLine ? -1 : tempOrder.products.findIndex(item => {
|
|
3343
3500
|
if (this.hasGoodPassDiscount(item)) return false;
|
|
3344
|
-
|
|
3345
|
-
if (
|
|
3346
|
-
|
|
3347
|
-
|
|
3501
|
+
const isRuntimeEntitlementPass = this.isRuntimeEntitlementAppend(item, tempOrder);
|
|
3502
|
+
if (isIncomingEntitlementAppend !== isRuntimeEntitlementPass) {
|
|
3503
|
+
return false;
|
|
3504
|
+
}
|
|
3505
|
+
if (isIncomingEntitlementAppend && this.isPersistedProductLine(item)) {
|
|
3506
|
+
return false;
|
|
3507
|
+
}
|
|
3508
|
+
const hasExistingProductNote = this.hasOrderProductLineNote(item);
|
|
3509
|
+
if ((hasIncomingProductNote || hasExistingProductNote) && (!isRuntimeEntitlementPass || String(normalizedIncoming.note || '').trim() !== String(item.note || '').trim())) {
|
|
3510
|
+
return false;
|
|
3511
|
+
}
|
|
3512
|
+
const hasExistingManualProductDiscount = isManualProductDiscountProduct(item);
|
|
3513
|
+
if (isRuntimeEntitlementPass && !this.hasSameEntitlementMergePriceConfig(normalizedIncoming, item)) {
|
|
3514
|
+
return false;
|
|
3515
|
+
}
|
|
3516
|
+
if ((hasIncomingManualProductDiscount || hasExistingManualProductDiscount) && !isRuntimeEntitlementPass) {
|
|
3517
|
+
return false;
|
|
3518
|
+
}
|
|
3519
|
+
if (this.isPersistedProductLine(item)) return false;
|
|
3348
3520
|
if (item.product_id !== productToAdd.product_id) return false;
|
|
3349
3521
|
if (item.product_variant_id !== productToAdd.product_variant_id) return false;
|
|
3350
3522
|
const existedFingerprint = (0, _utils3.buildProductLineFingerprint)((0, _utils.getProductSkuOptions)(item), item.product_bundle);
|
|
@@ -3645,17 +3817,51 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3645
3817
|
});
|
|
3646
3818
|
return tempOrder.products;
|
|
3647
3819
|
}
|
|
3648
|
-
|
|
3649
|
-
const
|
|
3650
|
-
if (hasMainGoodPass) return true;
|
|
3651
|
-
const bundleDiscountList = [];
|
|
3820
|
+
getFullCoveragePassDiscounts(product) {
|
|
3821
|
+
const discountList = [...(product.discount_list || [])];
|
|
3652
3822
|
(product.product_bundle || []).forEach(item => {
|
|
3653
|
-
|
|
3823
|
+
discountList.push(...(item?.discount_list || []));
|
|
3654
3824
|
});
|
|
3655
3825
|
(product?._extend?.other?.bundle || []).forEach(item => {
|
|
3656
|
-
|
|
3826
|
+
discountList.push(...(item?.discount_list || []));
|
|
3657
3827
|
});
|
|
3658
|
-
return
|
|
3828
|
+
return discountList.filter(item => (0, _entitlementPass.isFullCoveragePass)(item));
|
|
3829
|
+
}
|
|
3830
|
+
hasEntitlementPassDiscount(product) {
|
|
3831
|
+
return this.getFullCoveragePassDiscounts(product).some(item => (0, _entitlementPass.isEntitlementPass)(item));
|
|
3832
|
+
}
|
|
3833
|
+
hasGoodPassDiscount(product) {
|
|
3834
|
+
return this.getFullCoveragePassDiscounts(product).some(item => !(0, _entitlementPass.isEntitlementPass)(item));
|
|
3835
|
+
}
|
|
3836
|
+
isPersistedProductLine(product) {
|
|
3837
|
+
return product.order_detail_id !== undefined && product.order_detail_id !== null && product.order_detail_id !== '' || product.metadata?.is_edit_for_runtime === true;
|
|
3838
|
+
}
|
|
3839
|
+
isRuntimeEntitlementAppend(product, tempOrder) {
|
|
3840
|
+
if (this.isPersistedProductLine(product)) return false;
|
|
3841
|
+
const uid = product.metadata?.unique_identification_number ?? product.unique_identification_number;
|
|
3842
|
+
const storedOrigin = uid !== undefined && uid !== null && uid !== '' ? tempOrder._extend?.productsByUid?.[String(uid)]?.origin : undefined;
|
|
3843
|
+
return Boolean(product?._origin?.__entitlementPassRuntimeAppend === true || storedOrigin?.__entitlementPassRuntimeAppend === true);
|
|
3844
|
+
}
|
|
3845
|
+
hasSameEntitlementMergePriceConfig(incoming, existing) {
|
|
3846
|
+
const buildPriceConfig = product => {
|
|
3847
|
+
const metadata = product.metadata || {};
|
|
3848
|
+
const bundle = (product.product_bundle || []).map(item => ({
|
|
3849
|
+
bundle_id: item.bundle_id ?? item.id ?? null,
|
|
3850
|
+
bundle_product_id: item.bundle_product_id ?? item._bundle_product_id ?? item.product_id ?? null,
|
|
3851
|
+
bundle_variant_id: item.bundle_variant_id ?? item.product_variant_id ?? 0,
|
|
3852
|
+
price_type: item.price_type ?? item.custom_price_type ?? '',
|
|
3853
|
+
price_type_ext: item.price_type_ext ?? item.custom_price_type_ext ?? ''
|
|
3854
|
+
})).sort((left, right) => JSON.stringify(left).localeCompare(JSON.stringify(right)));
|
|
3855
|
+
return JSON.stringify({
|
|
3856
|
+
original_price: this.normalizeFingerprintMoney(product.original_price),
|
|
3857
|
+
source_product_price: this.normalizeFingerprintMoney(metadata.source_product_price),
|
|
3858
|
+
main_product_original_price: this.normalizeFingerprintMoney(metadata.main_product_original_price),
|
|
3859
|
+
price_override: this.normalizeFingerprintMoney(metadata.price_override),
|
|
3860
|
+
is_manual_discount: Boolean(metadata.is_manual_discount),
|
|
3861
|
+
bundle
|
|
3862
|
+
});
|
|
3863
|
+
};
|
|
3864
|
+
return buildPriceConfig(incoming) === buildPriceConfig(existing);
|
|
3659
3865
|
}
|
|
3660
3866
|
getBundleRuntimeIdentity(bundle) {
|
|
3661
3867
|
if (!bundle || typeof bundle !== 'object') return '';
|
|
@@ -3893,7 +4099,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3893
4099
|
// normalizeOrderProduct 幂等:v2 metadata 存在 → 保留 main_product_* 折扣重算 composite;
|
|
3894
4100
|
// 否则 → 把顶层 selling_price 视作 source,派生 main_product_* 并写 price_schema_version: 2。
|
|
3895
4101
|
let normalizedProduct = this.normalizeVirtualSettlementProductIfEnabled((0, _utils.mergeOrderProductDisplayFields)(nextProduct, (0, _utils3.normalizeOrderProduct)(nextProduct)));
|
|
3896
|
-
normalizedProduct.discount_list = (0, _utils.normalizeOrderProductDiscountList)(normalizedProduct.discount_list);
|
|
4102
|
+
normalizedProduct.discount_list = (0, _utils.normalizeOrderProductDiscountList)(isPersistedOrderLine ? syncReducedEntitlementPassUsageCount(normalizedProduct.discount_list, targetProduct.num, normalizedProduct.num) : normalizedProduct.discount_list);
|
|
3897
4103
|
const preservedBookingUid = nextProduct.booking_uid || nextProduct.metadata?.booking_uid || targetProduct.booking_uid || targetProduct.metadata?.booking_uid;
|
|
3898
4104
|
if (!booking && preservedBookingUid) {
|
|
3899
4105
|
normalizedProduct.booking_uid = preservedBookingUid;
|
|
@@ -4018,6 +4224,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4018
4224
|
throw new Error('[Order] 目标商品不存在,无法更新数量');
|
|
4019
4225
|
}
|
|
4020
4226
|
const targetProduct = tempOrder.products[productIndex];
|
|
4227
|
+
const isPersistedOrderLine = targetProduct.order_detail_id !== undefined && targetProduct.order_detail_id !== null;
|
|
4021
4228
|
const normalizedProduct = this.normalizeVirtualSettlementProductIfEnabled((0, _utils3.normalizeOrderProduct)({
|
|
4022
4229
|
...targetProduct,
|
|
4023
4230
|
num: (0, _utils3.getSafeProductNum)(num),
|
|
@@ -4026,7 +4233,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4026
4233
|
unique_identification_number: targetProduct.metadata?.unique_identification_number || unique_identification_number
|
|
4027
4234
|
}
|
|
4028
4235
|
}));
|
|
4029
|
-
normalizedProduct.discount_list = (0, _utils.normalizeOrderProductDiscountList)(normalizedProduct.discount_list);
|
|
4236
|
+
normalizedProduct.discount_list = (0, _utils.normalizeOrderProductDiscountList)(isPersistedOrderLine ? syncReducedEntitlementPassUsageCount(normalizedProduct.discount_list, targetProduct.num, normalizedProduct.num) : normalizedProduct.discount_list);
|
|
4030
4237
|
const settlementSnapshot = (0, _virtualSettlement.getSelectedSettlementSnapshot)(normalizedProduct);
|
|
4031
4238
|
if (this.isMultiCurrencySettlementEnabled() && settlementSnapshot?.settlement_type === 'virtual_currency' && tempOrder.customer_id && Number(tempOrder.customer_id) !== 1) {
|
|
4032
4239
|
const currencyProductId = Number(settlementSnapshot.currency_product_id);
|
|
@@ -4871,13 +5078,10 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4871
5078
|
if (lookup.startsWith('LOCAL_')) {
|
|
4872
5079
|
params.forceRemote = false;
|
|
4873
5080
|
}
|
|
4874
|
-
const res = await this.request
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
} : {})
|
|
4879
|
-
}, {
|
|
4880
|
-
osServer: true
|
|
5081
|
+
const res = await (0, _loadSalesOrderSnapshot.loadSalesOrderSnapshot)(this.request, {
|
|
5082
|
+
lookup,
|
|
5083
|
+
transport: 'os-server',
|
|
5084
|
+
forceRemote: params.forceRemote
|
|
4881
5085
|
});
|
|
4882
5086
|
if (res.code === 200) {
|
|
4883
5087
|
this.store.lastOrderInfo = res.data;
|